2 NNCP -- Node to Node copy, utilities for store-and-forward data exchange
3 Copyright (C) 2016-2018 Sergey Matveev <stargrave@stargrave.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 // NNCP configuration file encrypter/decrypter.
32 "github.com/davecgh/go-xdr/xdr2"
33 "golang.org/x/crypto/blake2b"
34 "golang.org/x/crypto/ssh/terminal"
38 fmt.Fprintf(os.Stderr, nncp.UsageHeader())
39 fmt.Fprintf(os.Stderr, "nncp-cfgenc -- encrypt/decrypt configuration file\n\n")
40 fmt.Fprintf(os.Stderr, "Usage: %s [options] cfg.yaml > cfg.yaml.eblob\n", os.Args[0])
41 fmt.Fprintf(os.Stderr, " %s [options] -d cfg.yaml.eblob > cfg.yaml\n", os.Args[0])
42 fmt.Fprintf(os.Stderr, " %s [options] -dump cfg.yaml.eblob\n", os.Args[0])
43 fmt.Fprintln(os.Stderr, "Options:")
49 decrypt = flag.Bool("d", false, "Decrypt the file")
50 dump = flag.Bool("dump", false, "Print human-readable eblob information")
51 sOpt = flag.Int("s", nncp.DefaultS, "Balloon space cost, in 32 bytes chunks")
52 tOpt = flag.Int("t", nncp.DefaultT, "Balloon time cost, number of rounds")
53 pOpt = flag.Int("p", nncp.DefaultP, "Balloon number of parallel jobs")
54 version = flag.Bool("version", false, "Print version information")
55 warranty = flag.Bool("warranty", false, "Print warranty information")
60 fmt.Println(nncp.Warranty)
64 fmt.Println(nncp.VersionGet())
73 data, err := ioutil.ReadFile(flag.Arg(0))
75 log.Fatalln("Can not read data:", err)
79 if _, err := xdr.Unmarshal(bytes.NewReader(data), &eblob); err != nil {
82 if eblob.Magic != nncp.MagicNNCPBv2 {
83 log.Fatalln(errors.New("Unknown eblob type"))
85 fmt.Println("Strengthening function: Balloon with BLAKE2b-256")
86 fmt.Printf("Memory space cost: %d bytes\n", eblob.SCost*blake2b.Size256)
87 fmt.Printf("Number of rounds: %d\n", eblob.TCost)
88 fmt.Printf("Number of parallel jobs: %d\n", eblob.PCost)
89 fmt.Printf("Blob size: %d\n", len(eblob.Blob))
93 os.Stderr.WriteString("Passphrase:")
94 password, err := terminal.ReadPassword(0)
98 os.Stderr.WriteString("\n")
99 cfgRaw, err := nncp.DeEBlob(data, password)
103 os.Stdout.Write(cfgRaw)
105 os.Stderr.WriteString("Passphrase:")
106 password1, err := terminal.ReadPassword(0)
110 os.Stderr.WriteString("\n")
111 os.Stderr.WriteString("Repeat passphrase:")
112 password2, err := terminal.ReadPassword(0)
116 os.Stderr.WriteString("\n")
117 if bytes.Compare(password1, password2) != 0 {
118 log.Fatalln(errors.New("Passphrases do not match"))
120 eblob, err := nncp.NewEBlob(*sOpt, *tOpt, *pOpt, password1, data)
124 os.Stdout.Write(eblob)