From 45ea8aa5463942b0b777fcc0b354cef5821c908d Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Tue, 6 Oct 2015 21:16:39 +0200 Subject: Add "--masterkey=" parameter for recovery purposes --- gocryptfs_main/masterkey.go | 54 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 gocryptfs_main/masterkey.go (limited to 'gocryptfs_main/masterkey.go') diff --git a/gocryptfs_main/masterkey.go b/gocryptfs_main/masterkey.go new file mode 100644 index 0000000..205f2ab --- /dev/null +++ b/gocryptfs_main/masterkey.go @@ -0,0 +1,54 @@ +package main + +import ( + "os" + "fmt" + "encoding/hex" + "strings" + "github.com/rfjakob/gocryptfs/cryptfs" +) + + +// printMasterKey - remind the user that he should store the master key in +// a safe place +func printMasterKey(key []byte) { + h := hex.EncodeToString(key) + var hChunked string + + // Try to make it less scary by splitting it up in chunks + for i := 0; i < len(h); i+=8 { + hChunked += h[i:i+8] + if i < 52 { + hChunked += "-" + } + if i == 24 { + hChunked += "\n " + } + } + + fmt.Printf(` +ATTENTION: + + Your master key is: %s + +If the gocryptfs.conf file becomes corrupted or you ever forget your password, +there is only one hope for recovery: The master key. Print it to a piece of +paper and store it in a drawer. + +`, hChunked) +} + +// Parse a hex-encoded master key that was passed on the command line +func parseMasterKey(masterkey string) []byte { + masterkey = strings.Replace(masterkey, "-", "", -1) + key, err := hex.DecodeString(masterkey) + if err != nil { + fmt.Printf("Could not parse master key: %v\n", err) + os.Exit(1) + } + if len(key) != cryptfs.KEY_LEN { + fmt.Printf("Master key has length %d but we require length %d\n", len(key), cryptfs.KEY_LEN) + os.Exit(1) + } + return key +} -- cgit v1.2.3