From 7f5ae5f8436442c1243609d0de7fd9678f9c33d5 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sun, 28 May 2017 17:11:50 +0200 Subject: gocryptfs-xray: add function to dump the master key Fixes https://github.com/rfjakob/gocryptfs/issues/83 --- gocryptfs-xray/xray_main.go | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'gocryptfs-xray') diff --git a/gocryptfs-xray/xray_main.go b/gocryptfs-xray/xray_main.go index 0073c3d..6cce1c6 100644 --- a/gocryptfs-xray/xray_main.go +++ b/gocryptfs-xray/xray_main.go @@ -7,13 +7,16 @@ import ( "io" "os" + "github.com/rfjakob/gocryptfs/internal/configfile" "github.com/rfjakob/gocryptfs/internal/contentenc" "github.com/rfjakob/gocryptfs/internal/cryptocore" + "github.com/rfjakob/gocryptfs/internal/readpassword" ) const ( ivLen = contentenc.DefaultIVBits / 8 blockSize = contentenc.DefaultBS + ivLen + cryptocore.AuthTagLen + myName = "gocryptfs-xray" ) func errExit(err error) { @@ -27,17 +30,42 @@ func prettyPrintHeader(h *contentenc.FileHeader) { } func main() { + dumpmasterkey := flag.Bool("dumpmasterkey", false, "Decrypt and dump the master key") flag.Parse() if flag.NArg() != 1 { - fmt.Printf("Usage: xray FILE\n") + fmt.Fprintf(os.Stderr, "Usage: %s [OPTIONS] FILE\n"+ + "\n"+ + "Options:\n", myName) + flag.PrintDefaults() + fmt.Fprintf(os.Stderr, "\n"+ + "Examples:\n"+ + " gocryptfs-xray myfs/mCXnISiv7nEmyc0glGuhTQ\n"+ + " gocryptfs-xray -dumpmasterkey myfs/gocryptfs.conf\n") os.Exit(1) } - f := flag.Arg(0) - fd, err := os.Open(f) + fn := flag.Arg(0) + fd, err := os.Open(fn) if err != nil { errExit(err) } + defer fd.Close() + if *dumpmasterkey { + dumpMasterKey(fn) + } else { + inspectCiphertext(fd) + } +} + +func dumpMasterKey(fn string) { + pw := readpassword.Once("") + masterkey, _, err := configfile.LoadConfFile(fn, pw) + if err != nil { + fmt.Fprintln(os.Stderr, err) + } + fmt.Println(hex.EncodeToString(masterkey)) +} +func inspectCiphertext(fd *os.File) { headerBytes := make([]byte, contentenc.HeaderLen) n, err := fd.ReadAt(headerBytes, 0) if err == io.EOF && n == 0 { -- cgit v1.2.3