aboutsummaryrefslogtreecommitdiff
path: root/info.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2017-05-30 19:01:32 +0200
committerJakob Unterwurzacher2017-05-30 19:01:32 +0200
commit1e598e96fcd2ef53ab2ee1e2b408e4ebe920e59b (patch)
tree6dd5bcae81e54b4935ecda0817518eca0ee45ebc /info.go
parentca5f469ea334bc5e93e25dae11140887d77b9673 (diff)
main: add "-info" option
Pretty-prints the config while stripping out sensitive (and uninteresting) data https://github.com/rfjakob/gocryptfs/issues/111
Diffstat (limited to 'info.go')
-rw-r--r--info.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/info.go b/info.go
new file mode 100644
index 0000000..c2e0038
--- /dev/null
+++ b/info.go
@@ -0,0 +1,45 @@
+package main
+
+import (
+ "encoding/json"
+ "fmt"
+ "io/ioutil"
+ "os"
+ "strings"
+
+ "github.com/rfjakob/gocryptfs/internal/configfile"
+ "github.com/rfjakob/gocryptfs/internal/contentenc"
+ "github.com/rfjakob/gocryptfs/internal/exitcodes"
+ "github.com/rfjakob/gocryptfs/internal/tlog"
+)
+
+// info pretty-prints the contents of the config file at "filename" for human
+// consumption, stripping out sensitive data.
+// This is called when you pass the "-info" option.
+func info(filename string) {
+ // Read from disk
+ js, err := ioutil.ReadFile(filename)
+ if err != nil {
+ tlog.Fatal.Printf("info: ReadFile: %#v\n", err)
+ os.Exit(exitcodes.LoadConf)
+ }
+ // Unmarshal
+ var cf configfile.ConfFile
+ err = json.Unmarshal(js, &cf)
+ if err != nil {
+ tlog.Fatal.Printf("Failed to unmarshal config file")
+ os.Exit(exitcodes.LoadConf)
+ }
+ if cf.Version != contentenc.CurrentVersion {
+ tlog.Fatal.Printf("Unsupported on-disk format %d", cf.Version)
+ os.Exit(exitcodes.LoadConf)
+ }
+ // Pretty-print
+ fmt.Printf("Creator: %s\n", cf.Creator)
+ fmt.Printf("FeatureFlags: %s\n", strings.Join(cf.FeatureFlags, " "))
+ fmt.Printf("EncryptedKey: %dB\n", len(cf.EncryptedKey))
+ s := cf.ScryptObject
+ fmt.Printf("ScryptObject: Salt=%dB N=%d R=%d P=%d KeyLen=%d\n",
+ len(s.Salt), s.N, s.R, s.P, s.KeyLen)
+ os.Exit(0)
+}