Add new "-wpanic" option and enable it for the automated tests

This commit is contained in:
Jakob Unterwurzacher 2016-01-31 18:09:39 +01:00
parent 4c9e249e3a
commit 6454db68d9
5 changed files with 25 additions and 6 deletions

View File

@ -104,6 +104,10 @@ mounting but makes the password susceptible to brute-force attacks (default 16)
**-version** **-version**
: Print version and exit : Print version and exit
**-wpanic**
: When encountering a warning, panic and exit immediately. This is
useful in regression testing.
**-zerokey** **-zerokey**
: Use all-zero dummy master key. This options is only intended for : Use all-zero dummy master key. This options is only intended for
automated testing as it does not provide any security. automated testing as it does not provide any security.

View File

@ -2,6 +2,7 @@ package cryptfs
import ( import (
"encoding/json" "encoding/json"
"fmt"
"log" "log"
"os" "os"
) )
@ -17,7 +18,10 @@ func JSONDump(obj interface{}) string {
// toggledLogger - a Logger than can be enabled and disabled // toggledLogger - a Logger than can be enabled and disabled
type toggledLogger struct { type toggledLogger struct {
// Enable or disable output
Enabled bool Enabled bool
// Panic after logging a message, useful in regression tests
PanicAfter bool
*log.Logger *log.Logger
} }
@ -26,12 +30,18 @@ func (l *toggledLogger) Printf(format string, v ...interface{}) {
return return
} }
l.Logger.Printf(format, v...) l.Logger.Printf(format, v...)
if l.PanicAfter {
panic("PanicAfter: " + fmt.Sprintf(format, v...))
}
} }
func (l *toggledLogger) Println(v ...interface{}) { func (l *toggledLogger) Println(v ...interface{}) {
if !l.Enabled { if !l.Enabled {
return return
} }
l.Logger.Println(v...) l.Logger.Println(v...)
if l.PanicAfter {
panic("PanicAfter: " + fmt.Sprintln(v...))
}
} }
// As defined by http://elinux.org/Debugging_by_printing#Log_Levels // As defined by http://elinux.org/Debugging_by_printing#Log_Levels
@ -45,7 +55,7 @@ var Info *toggledLogger
var Warn *toggledLogger var Warn *toggledLogger
func init() { func init() {
Debug = &toggledLogger{false, log.New(os.Stdout, "", 0)} Debug = &toggledLogger{false, false, log.New(os.Stdout, "", 0)}
Info = &toggledLogger{true, log.New(os.Stdout, "", 0)} Info = &toggledLogger{true, false, log.New(os.Stdout, "", 0)}
Warn = &toggledLogger{true, log.New(os.Stderr, "", 0)} Warn = &toggledLogger{true, false, log.New(os.Stderr, "", 0)}
} }

View File

@ -53,7 +53,7 @@ func resetTmpDir() {
func mount(c string, p string, extraArgs ...string) { func mount(c string, p string, extraArgs ...string) {
var args []string var args []string
args = append(args, extraArgs...) args = append(args, extraArgs...)
args = append(args, "-q") args = append(args, "-q", "-wpanic")
//args = append(args, "--fusedebug") //args = append(args, "--fusedebug")
args = append(args, c) args = append(args, c)
args = append(args, p) args = append(args, p)

View File

@ -37,7 +37,7 @@ const (
type argContainer struct { type argContainer struct {
debug, init, zerokey, fusedebug, openssl, passwd, foreground, version, debug, init, zerokey, fusedebug, openssl, passwd, foreground, version,
plaintextnames, quiet, diriv, emenames, gcmiv128, nosyslog bool plaintextnames, quiet, diriv, emenames, gcmiv128, nosyslog, wpanic bool
masterkey, mountpoint, cipherdir, cpuprofile, config, extpass, masterkey, mountpoint, cipherdir, cpuprofile, config, extpass,
memprofile string memprofile string
notifypid, scryptn int notifypid, scryptn int
@ -160,6 +160,7 @@ func main() {
flagSet.BoolVar(&args.emenames, "emenames", true, "Use EME filename encryption. This option implies diriv.") flagSet.BoolVar(&args.emenames, "emenames", true, "Use EME filename encryption. This option implies diriv.")
flagSet.BoolVar(&args.gcmiv128, "gcmiv128", true, "Use an 128-bit IV for GCM encryption instead of Go's default of 96 bits") flagSet.BoolVar(&args.gcmiv128, "gcmiv128", true, "Use an 128-bit IV for GCM encryption instead of Go's default of 96 bits")
flagSet.BoolVar(&args.nosyslog, "nosyslog", false, "Do not redirect output to syslog when running in the background") flagSet.BoolVar(&args.nosyslog, "nosyslog", false, "Do not redirect output to syslog when running in the background")
flagSet.BoolVar(&args.wpanic, "wpanic", false, "When encountering a warning, panic and exit immediately")
flagSet.StringVar(&args.masterkey, "masterkey", "", "Mount with explicit master key") flagSet.StringVar(&args.masterkey, "masterkey", "", "Mount with explicit master key")
flagSet.StringVar(&args.cpuprofile, "cpuprofile", "", "Write cpu profile to specified file") flagSet.StringVar(&args.cpuprofile, "cpuprofile", "", "Write cpu profile to specified file")
flagSet.StringVar(&args.memprofile, "memprofile", "", "Write memory profile to specified file") flagSet.StringVar(&args.memprofile, "memprofile", "", "Write memory profile to specified file")
@ -184,6 +185,10 @@ func main() {
cryptfs.Debug.Enabled = true cryptfs.Debug.Enabled = true
cryptfs.Debug.Printf("Debug output enabled") cryptfs.Debug.Printf("Debug output enabled")
} }
if args.wpanic {
cryptfs.Warn.PanicAfter = true
cryptfs.Debug.Printf("Panicing on warnings")
}
// Every operation below requires CIPHERDIR. Check that we have it. // Every operation below requires CIPHERDIR. Check that we have it.
if flagSet.NArg() >= 1 { if flagSet.NArg() >= 1 {
args.cipherdir, _ = filepath.Abs(flagSet.Arg(0)) args.cipherdir, _ = filepath.Abs(flagSet.Arg(0))

View File

@ -15,7 +15,7 @@ func (fs *FS) isFiltered(path string) bool {
} }
// gocryptfs.conf in the root directory is forbidden // gocryptfs.conf in the root directory is forbidden
if path == cryptfs.ConfDefaultName { if path == cryptfs.ConfDefaultName {
cryptfs.Warn.Printf("The name /%s is reserved when -plaintextnames is used\n", cryptfs.Info.Printf("The name /%s is reserved when -plaintextnames is used\n",
cryptfs.ConfDefaultName) cryptfs.ConfDefaultName)
return true return true
} }