debug: Allow creating insecure repositories

Uses low-security KDF parameters for scrypt(). Do not use in production!
This commit is contained in:
Alexander Neumann 2017-03-25 18:00:42 +01:00
parent 95c354fe81
commit c8eea49909
2 changed files with 18 additions and 1 deletions

View file

@ -8,6 +8,7 @@ import (
_ "net/http/pprof" _ "net/http/pprof"
"os" "os"
"restic/errors" "restic/errors"
"restic/repository"
"github.com/pkg/profile" "github.com/pkg/profile"
) )
@ -16,6 +17,7 @@ var (
listenMemoryProfile string listenMemoryProfile string
memProfilePath string memProfilePath string
cpuProfilePath string cpuProfilePath string
insecure bool
prof interface { prof interface {
Stop() Stop()
@ -27,6 +29,13 @@ func init() {
f.StringVar(&listenMemoryProfile, "listen-profile", "", "listen on this `address:port` for memory profiling") 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(&memProfilePath, "mem-profile", "", "write memory profile to `dir`")
f.StringVar(&cpuProfilePath, "cpu-profile", "", "write cpu 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 { func runDebug() error {
@ -50,6 +59,10 @@ func runDebug() error {
prof = profile.Start(profile.Quiet, profile.CPUProfile, profile.ProfilePath(memProfilePath)) prof = profile.Start(profile.Quiet, profile.CPUProfile, profile.ProfilePath(memProfilePath))
} }
if insecure {
repository.TestUseLowSecurityKDFParameters(fakeTestingTB{})
}
return nil return nil
} }

View file

@ -19,8 +19,12 @@ var testKDFParams = crypto.KDFParams{
P: 1, P: 1,
} }
type logger interface {
Logf(format string, args ...interface{})
}
// TestUseLowSecurityKDFParameters configures low-security KDF parameters for testing. // 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") t.Logf("using low-security KDF parameters for test")
KDFParams = &testKDFParams KDFParams = &testKDFParams
} }