Add "--plaintextnames" option

Also, gather all the command line arguments into an anonymous struct
"args".
This commit is contained in:
Jakob Unterwurzacher 2015-11-02 23:08:51 +01:00
parent a324407082
commit 0ec17c3939
2 changed files with 50 additions and 43 deletions

View File

@ -22,11 +22,13 @@ type ConfFile struct {
ScryptObject scryptKdf ScryptObject scryptKdf
// The On-Disk-Format version this filesystem uses // The On-Disk-Format version this filesystem uses
Version uint16 Version uint16
// Do not encrypt filenames
PlaintextNames bool
} }
// CreateConfFile - create a new config with a random key encrypted with // CreateConfFile - create a new config with a random key encrypted with
// "password" and write it to "filename" // "password" and write it to "filename"
func CreateConfFile(filename string, password string) error { func CreateConfFile(filename string, password string, plaintextNames bool) error {
var cf ConfFile var cf ConfFile
cf.filename = filename cf.filename = filename
@ -39,10 +41,10 @@ func CreateConfFile(filename string, password string) error {
cf.Version = HEADER_CURRENT_VERSION cf.Version = HEADER_CURRENT_VERSION
// Write file to disk cf.PlaintextNames = plaintextNames
err := cf.WriteFile()
return err // Write file to disk
return cf.WriteFile()
} }
// LoadConfFile - read config file from disk and decrypt the // LoadConfFile - read config file from disk and decrypt the

83
main.go
View File

@ -36,7 +36,7 @@ const (
// GitVersion will be set by the build script "build.bash" // GitVersion will be set by the build script "build.bash"
var GitVersion = "[version not set - please compile using ./build.bash]" var GitVersion = "[version not set - please compile using ./build.bash]"
func initDir(dirArg string) { func initDir(dirArg string, plaintextNames bool) {
dir, _ := filepath.Abs(dirArg) dir, _ := filepath.Abs(dirArg)
err := checkDirEmpty(dir) err := checkDirEmpty(dir)
@ -48,7 +48,7 @@ func initDir(dirArg string) {
confName := filepath.Join(dir, cryptfs.ConfDefaultName) confName := filepath.Join(dir, cryptfs.ConfDefaultName)
fmt.Printf("Choose a password for protecting your files.\n") fmt.Printf("Choose a password for protecting your files.\n")
password := readPasswordTwice() password := readPasswordTwice()
err = cryptfs.CreateConfFile(confName, password) err = cryptfs.CreateConfFile(confName, password, plaintextNames)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
os.Exit(ERREXIT_INIT) os.Exit(ERREXIT_INIT)
@ -67,55 +67,60 @@ func main() {
runtime.GOMAXPROCS(4) runtime.GOMAXPROCS(4)
// Parse command line arguments // Parse command line arguments
var debug, init, zerokey, fusedebug, openssl, passwd, foreground, version bool var args struct {
var masterkey, mountpoint, cipherdir string debug, init, zerokey, fusedebug, openssl, passwd, foreground, version,
plaintextnames bool
masterkey, mountpoint, cipherdir string
cpuprofile *string
}
flag.Usage = usageText flag.Usage = usageText
flag.BoolVar(&debug, "debug", false, "Enable debug output") flag.BoolVar(&args.debug, "debug", false, "Enable debug output")
flag.BoolVar(&fusedebug, "fusedebug", false, "Enable fuse library debug output") flag.BoolVar(&args.fusedebug, "fusedebug", false, "Enable fuse library debug output")
flag.BoolVar(&init, "init", false, "Initialize encrypted directory") flag.BoolVar(&args.init, "init", false, "Initialize encrypted directory")
flag.BoolVar(&zerokey, "zerokey", false, "Use all-zero dummy master key") flag.BoolVar(&args.zerokey, "zerokey", false, "Use all-zero dummy master key")
flag.BoolVar(&openssl, "openssl", true, "Use OpenSSL instead of built-in Go crypto") flag.BoolVar(&args.openssl, "openssl", true, "Use OpenSSL instead of built-in Go crypto")
flag.BoolVar(&passwd, "passwd", false, "Change password") flag.BoolVar(&args.passwd, "passwd", false, "Change password")
flag.BoolVar(&foreground, "f", false, "Stay in the foreground") flag.BoolVar(&args.foreground, "f", false, "Stay in the foreground")
flag.BoolVar(&version, "version", false, "Print version and exit") flag.BoolVar(&args.version, "version", false, "Print version and exit")
flag.StringVar(&masterkey, "masterkey", "", "Mount with explicit master key") flag.BoolVar(&args.plaintextnames, "plaintextnames", false, "Do not encrypt file names")
var cpuprofile = flag.String("cpuprofile", "", "Write cpu profile to specified file") flag.StringVar(&args.masterkey, "masterkey", "", "Mount with explicit master key")
args.cpuprofile = flag.String("cpuprofile", "", "Write cpu profile to specified file")
flag.Parse() flag.Parse()
if version { if args.version {
fmt.Printf("%s %s; ", PROGRAM_NAME, GitVersion) fmt.Printf("%s %s; ", PROGRAM_NAME, GitVersion)
fmt.Printf("on-disk format %d\n", cryptfs.HEADER_CURRENT_VERSION) fmt.Printf("on-disk format %d\n", cryptfs.HEADER_CURRENT_VERSION)
os.Exit(0) os.Exit(0)
} }
if !foreground { if !args.foreground {
daemonize() // does not return daemonize() // does not return
} }
if *cpuprofile != "" { if *args.cpuprofile != "" {
f, err := os.Create(*cpuprofile) f, err := os.Create(*args.cpuprofile)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
os.Exit(ERREXIT_INIT) os.Exit(ERREXIT_INIT)
} }
fmt.Printf("Writing CPU profile to %s\n", *cpuprofile) fmt.Printf("Writing CPU profile to %s\n", *args.cpuprofile)
pprof.StartCPUProfile(f) pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile() defer pprof.StopCPUProfile()
} }
if debug { if args.debug {
cryptfs.Debug.Enable() cryptfs.Debug.Enable()
cryptfs.Debug.Printf("Debug output enabled\n") cryptfs.Debug.Printf("Debug output enabled\n")
} }
if openssl == false { if args.openssl == false {
fmt.Printf("Openssl disabled\n") fmt.Printf("Openssl disabled\n")
} }
if init { if args.init {
if flag.NArg() != 1 { if flag.NArg() != 1 {
fmt.Printf("Usage: %s --init CIPHERDIR\n", PROGRAM_NAME) fmt.Printf("Usage: %s --init CIPHERDIR\n", PROGRAM_NAME)
os.Exit(ERREXIT_USAGE) os.Exit(ERREXIT_USAGE)
} }
initDir(flag.Arg(0)) // does not return initDir(flag.Arg(0), args.plaintextnames) // does not return
} }
if passwd { if args.passwd {
if flag.NArg() != 1 { if flag.NArg() != 1 {
fmt.Printf("Usage: %s --passwd CIPHERDIR\n", PROGRAM_NAME) fmt.Printf("Usage: %s --passwd CIPHERDIR\n", PROGRAM_NAME)
os.Exit(ERREXIT_USAGE) os.Exit(ERREXIT_USAGE)
@ -126,15 +131,15 @@ func main() {
usageText() usageText()
os.Exit(ERREXIT_USAGE) os.Exit(ERREXIT_USAGE)
} }
mountpoint, _ = filepath.Abs(flag.Arg(1)) args.mountpoint, _ = filepath.Abs(flag.Arg(1))
err := checkDirEmpty(mountpoint) err := checkDirEmpty(args.mountpoint)
if err != nil { if err != nil {
fmt.Printf("Invalid MOUNTPOINT: %v\n", err) fmt.Printf("Invalid MOUNTPOINT: %v\n", err)
os.Exit(ERREXIT_MOUNTPOINT) os.Exit(ERREXIT_MOUNTPOINT)
} }
} }
cipherdir, _ = filepath.Abs(flag.Arg(0)) args.cipherdir, _ = filepath.Abs(flag.Arg(0))
err := checkDir(cipherdir) err := checkDir(args.cipherdir)
if err != nil { if err != nil {
fmt.Printf("Invalid CIPHERDIR: %v\n", err) fmt.Printf("Invalid CIPHERDIR: %v\n", err)
os.Exit(ERREXIT_CIPHERDIR) os.Exit(ERREXIT_CIPHERDIR)
@ -143,20 +148,20 @@ func main() {
var cf *cryptfs.ConfFile var cf *cryptfs.ConfFile
var currentPassword string var currentPassword string
key := make([]byte, cryptfs.KEY_LEN) key := make([]byte, cryptfs.KEY_LEN)
if zerokey { if args.zerokey {
fmt.Printf("Zerokey mode active: using all-zero dummy master key.\n") fmt.Printf("Zerokey mode active: using all-zero dummy master key.\n")
} else if len(masterkey) > 0 { } else if len(args.masterkey) > 0 {
key = parseMasterKey(masterkey) key = parseMasterKey(args.masterkey)
fmt.Printf("Using explicit master key.\n") fmt.Printf("Using explicit master key.\n")
} else { } else {
cfname := filepath.Join(cipherdir, cryptfs.ConfDefaultName) cfname := filepath.Join(args.cipherdir, cryptfs.ConfDefaultName)
_, err = os.Stat(cfname) _, err = os.Stat(cfname)
if err != nil { if err != nil {
fmt.Printf("Error: %s not found in CIPHERDIR\n", cryptfs.ConfDefaultName) fmt.Printf("Error: %s not found in CIPHERDIR\n", cryptfs.ConfDefaultName)
fmt.Printf("Please run \"%s --init %s\" first\n", os.Args[0], flag.Arg(0)) fmt.Printf("Please run \"%s --init %s\" first\n", os.Args[0], flag.Arg(0))
os.Exit(ERREXIT_LOADCONF) os.Exit(ERREXIT_LOADCONF)
} }
if passwd == true { if args.passwd == true {
fmt.Printf("Old password: ") fmt.Printf("Old password: ")
} else { } else {
fmt.Printf("Password: ") fmt.Printf("Password: ")
@ -172,7 +177,7 @@ func main() {
} }
fmt.Printf("done.\n") fmt.Printf("done.\n")
} }
if passwd == true { if args.passwd == true {
fmt.Printf("Please enter the new password.\n") fmt.Printf("Please enter the new password.\n")
newPassword := readPasswordTwice() newPassword := readPasswordTwice()
if newPassword == currentPassword { if newPassword == currentPassword {
@ -189,13 +194,13 @@ func main() {
os.Exit(0) os.Exit(0)
} }
srv := pathfsFrontend(key, cipherdir, mountpoint, fusedebug, openssl) srv := pathfsFrontend(key, args.cipherdir, args.mountpoint, args.fusedebug, args.openssl)
if zerokey == false && len(masterkey) == 0 { if args.zerokey == false && len(args.masterkey) == 0 {
printMasterKey(key) printMasterKey(key)
} else if zerokey == true { } else if args.zerokey == true {
fmt.Printf("ZEROKEY MODE PROVIDES NO SECURITY AT ALL AND SHOULD ONLY BE USED FOR TESTING.\n") fmt.Printf("ZEROKEY MODE PROVIDES NO SECURITY AT ALL AND SHOULD ONLY BE USED FOR TESTING.\n")
} else if len(masterkey) > 0 { } else if len(args.masterkey) > 0 {
fmt.Printf("THE MASTER KEY IS VISIBLE VIA \"ps -auxwww\", ONLY USE THIS MODE FOR EMERGENCIES.\n") fmt.Printf("THE MASTER KEY IS VISIBLE VIA \"ps -auxwww\", ONLY USE THIS MODE FOR EMERGENCIES.\n")
} }
@ -204,7 +209,7 @@ func main() {
sendUsr1() sendUsr1()
// Wait for SIGING in the background and unmount ourselves if we get it // Wait for SIGING in the background and unmount ourselves if we get it
// This prevents a dangling "Transport endpoint is not connected" mountpoint // This prevents a dangling "Transport endpoint is not connected" mountpoint
handleSigint(srv, mountpoint) handleSigint(srv, args.mountpoint)
// Jump into server loop. Returns when it gets an umount request from the kernel. // Jump into server loop. Returns when it gets an umount request from the kernel.
srv.Serve() srv.Serve()
// main returns with code 0 // main returns with code 0