2015-10-06 21:16:39 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/hex"
|
2015-10-07 22:58:22 +02:00
|
|
|
"os"
|
|
|
|
"strings"
|
2016-02-06 19:20:54 +01:00
|
|
|
|
|
|
|
"github.com/rfjakob/gocryptfs/internal/cryptocore"
|
2016-06-15 23:30:44 +02:00
|
|
|
"github.com/rfjakob/gocryptfs/internal/tlog"
|
2015-10-06 21:16:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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
|
2015-10-07 22:58:22 +02:00
|
|
|
for i := 0; i < len(h); i += 8 {
|
|
|
|
hChunked += h[i : i+8]
|
2015-10-06 21:16:39 +02:00
|
|
|
if i < 52 {
|
|
|
|
hChunked += "-"
|
|
|
|
}
|
|
|
|
if i == 24 {
|
2015-12-19 15:46:19 +01:00
|
|
|
hChunked += "\n "
|
2015-10-06 21:16:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-15 23:30:44 +02:00
|
|
|
tlog.Info.Printf(`
|
2015-12-19 15:46:19 +01:00
|
|
|
Your master key is:
|
2015-10-06 21:16:39 +02:00
|
|
|
|
2015-12-19 15:46:19 +01:00
|
|
|
%s
|
2015-10-06 21:16:39 +02:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2016-06-15 23:30:44 +02:00
|
|
|
`, tlog.ColorGrey+hChunked+tlog.ColorReset)
|
2015-10-06 21:16:39 +02:00
|
|
|
}
|
|
|
|
|
2015-11-14 21:25:10 +01:00
|
|
|
// parseMasterKey - Parse a hex-encoded master key that was passed on the command line
|
|
|
|
// Calls os.Exit on failure
|
2015-10-06 21:16:39 +02:00
|
|
|
func parseMasterKey(masterkey string) []byte {
|
|
|
|
masterkey = strings.Replace(masterkey, "-", "", -1)
|
|
|
|
key, err := hex.DecodeString(masterkey)
|
|
|
|
if err != nil {
|
2016-06-15 23:30:44 +02:00
|
|
|
tlog.Fatal.Printf("Could not parse master key: %v\n", err)
|
2015-10-06 21:16:39 +02:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
2016-02-06 19:20:54 +01:00
|
|
|
if len(key) != cryptocore.KeyLen {
|
2016-06-15 23:30:44 +02:00
|
|
|
tlog.Fatal.Printf("Master key has length %d but we require length %d\n", len(key), cryptocore.KeyLen)
|
2015-10-06 21:16:39 +02:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
return key
|
|
|
|
}
|