Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Commit

Permalink
Add new tool, promptsecret (decred#649)
Browse files Browse the repository at this point in the history
promptsecret is used to read a secret from stdin without echoing and
write it to stdout.
  • Loading branch information
dajohi authored Mar 31, 2017
1 parent 64a414c commit 44c5d6a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
cmd/dcrd/dcrd
cmd/dcrd/dcrctl
dcrd
cmd/dcrctl/dcrctl
cmd/promptsecret/promptsecret
*~
*.pyc
vendor/
36 changes: 36 additions & 0 deletions cmd/promptsecret/promptsecret.go
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit 44c5d6a

Please sign in to comment.