From c8eea49909155e6921f82cb8d2de28810d1dc25c Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sat, 25 Mar 2017 18:00:42 +0100 Subject: [PATCH] debug: Allow creating insecure repositories Uses low-security KDF parameters for scrypt(). Do not use in production! --- src/cmds/restic/global_debug.go | 13 +++++++++++++ src/restic/repository/testing.go | 6 +++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/cmds/restic/global_debug.go b/src/cmds/restic/global_debug.go index 6e443f2a0..998f349b2 100644 --- a/src/cmds/restic/global_debug.go +++ b/src/cmds/restic/global_debug.go @@ -8,6 +8,7 @@ import ( _ "net/http/pprof" "os" "restic/errors" + "restic/repository" "github.com/pkg/profile" ) @@ -16,6 +17,7 @@ var ( listenMemoryProfile string memProfilePath string cpuProfilePath string + insecure bool prof interface { Stop() @@ -27,6 +29,13 @@ func init() { f.StringVar(&listenMemoryProfile, "listen-profile", "", "listen on this `address:port` for memory profiling") f.StringVar(&memProfilePath, "mem-profile", "", "write memory profile to `dir`") f.StringVar(&cpuProfilePath, "cpu-profile", "", "write cpu profile to `dir`") + f.BoolVar(&insecure, "insecure-kdf", false, "use insecure KDF settings") +} + +type fakeTestingTB struct{} + +func (fakeTestingTB) Logf(msg string, args ...interface{}) { + fmt.Fprintf(os.Stderr, msg, args...) } func runDebug() error { @@ -50,6 +59,10 @@ func runDebug() error { prof = profile.Start(profile.Quiet, profile.CPUProfile, profile.ProfilePath(memProfilePath)) } + if insecure { + repository.TestUseLowSecurityKDFParameters(fakeTestingTB{}) + } + return nil } diff --git a/src/restic/repository/testing.go b/src/restic/repository/testing.go index 6f590e13a..a24912257 100644 --- a/src/restic/repository/testing.go +++ b/src/restic/repository/testing.go @@ -19,8 +19,12 @@ var testKDFParams = crypto.KDFParams{ P: 1, } +type logger interface { + Logf(format string, args ...interface{}) +} + // TestUseLowSecurityKDFParameters configures low-security KDF parameters for testing. -func TestUseLowSecurityKDFParameters(t testing.TB) { +func TestUseLowSecurityKDFParameters(t logger) { t.Logf("using low-security KDF parameters for test") KDFParams = &testKDFParams }