This repository has been archived by the owner on Aug 7, 2023. It is now read-only.
forked from decred/dcrd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new tool, promptsecret (decred#649)
promptsecret is used to read a secret from stdin without echoing and write it to stdout.
- Loading branch information
Showing
2 changed files
with
39 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |