diff --git a/.gitignore b/.gitignore index d13c42d20c..0aa250bbfd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ -cmd/dcrd/dcrd -cmd/dcrd/dcrctl +dcrd +cmd/dcrctl/dcrctl +cmd/promptsecret/promptsecret *~ *.pyc vendor/ diff --git a/cmd/promptsecret/promptsecret.go b/cmd/promptsecret/promptsecret.go new file mode 100644 index 0000000000..4bf91de75e --- /dev/null +++ b/cmd/promptsecret/promptsecret.go @@ -0,0 +1,36 @@ +// Copyright (c) 2017 The Decred developers +// Use of this source code is governed by an ISC +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" + "os" + + "golang.org/x/crypto/ssh/terminal" +) + +func zero(b []byte) { + for i := 0; i < len(b); i++ { + b[i] = 0x00 + } +} + +func main() { + fmt.Fprint(os.Stderr, "Secret: ") + + secret, err := terminal.ReadPassword(int(os.Stdin.Fd())) + fmt.Fprint(os.Stderr, "\n") + if err != nil { + fmt.Fprintf(os.Stderr, "unable to read secret: %v\n", err) + os.Exit(1) + } + + _, err = os.Stdout.Write(secret) + zero(secret) + if err != nil { + fmt.Fprintf(os.Stderr, "unable to write to stdout: %v\n", err) + os.Exit(1) + } +}