diff options
author | Steven Roose <stevenroose@gmail.com> | 2018-06-08 21:07:07 +0800 |
---|---|---|
committer | Felix Lange <fjl@users.noreply.github.com> | 2018-06-08 21:07:07 +0800 |
commit | 13af27641829f61d1e6b383e37aab6caae22f2c1 (patch) | |
tree | 35607044459f66249bf8d39e32996b1fcd0c4cf7 /cmd/ethkey/utils.go | |
parent | ea06da089264508601a9f967160b8c7f335071fa (diff) | |
download | go-tangerine-13af27641829f61d1e6b383e37aab6caae22f2c1.tar go-tangerine-13af27641829f61d1e6b383e37aab6caae22f2c1.tar.gz go-tangerine-13af27641829f61d1e6b383e37aab6caae22f2c1.tar.bz2 go-tangerine-13af27641829f61d1e6b383e37aab6caae22f2c1.tar.lz go-tangerine-13af27641829f61d1e6b383e37aab6caae22f2c1.tar.xz go-tangerine-13af27641829f61d1e6b383e37aab6caae22f2c1.tar.zst go-tangerine-13af27641829f61d1e6b383e37aab6caae22f2c1.zip |
cmd/ethkey: add command to change key passphrase (#16516)
This change introduces
ethkey changepassphrase <keyfile>
to change the passphrase of a key file.
Diffstat (limited to 'cmd/ethkey/utils.go')
-rw-r--r-- | cmd/ethkey/utils.go | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/cmd/ethkey/utils.go b/cmd/ethkey/utils.go index 0e563bf92..6f60ebaf1 100644 --- a/cmd/ethkey/utils.go +++ b/cmd/ethkey/utils.go @@ -28,26 +28,14 @@ import ( "gopkg.in/urfave/cli.v1" ) -// getPassPhrase obtains a passphrase given by the user. It first checks the -// --passphrase command line flag and ultimately prompts the user for a -// passphrase. -func getPassPhrase(ctx *cli.Context, confirmation bool) string { - // Look for the --passphrase flag. - passphraseFile := ctx.String(passphraseFlag.Name) - if passphraseFile != "" { - content, err := ioutil.ReadFile(passphraseFile) - if err != nil { - utils.Fatalf("Failed to read passphrase file '%s': %v", - passphraseFile, err) - } - return strings.TrimRight(string(content), "\r\n") - } - - // Otherwise prompt the user for the passphrase. +// promptPassphrase prompts the user for a passphrase. Set confirmation to true +// to require the user to confirm the passphrase. +func promptPassphrase(confirmation bool) string { passphrase, err := console.Stdin.PromptPassword("Passphrase: ") if err != nil { utils.Fatalf("Failed to read passphrase: %v", err) } + if confirmation { confirm, err := console.Stdin.PromptPassword("Repeat passphrase: ") if err != nil { @@ -57,9 +45,29 @@ func getPassPhrase(ctx *cli.Context, confirmation bool) string { utils.Fatalf("Passphrases do not match") } } + return passphrase } +// getPassphrase obtains a passphrase given by the user. It first checks the +// --passfile command line flag and ultimately prompts the user for a +// passphrase. +func getPassphrase(ctx *cli.Context) string { + // Look for the --passwordfile flag. + passphraseFile := ctx.String(passphraseFlag.Name) + if passphraseFile != "" { + content, err := ioutil.ReadFile(passphraseFile) + if err != nil { + utils.Fatalf("Failed to read passphrase file '%s': %v", + passphraseFile, err) + } + return strings.TrimRight(string(content), "\r\n") + } + + // Otherwise prompt the user for the passphrase. + return promptPassphrase(false) +} + // signHash is a helper function that calculates a hash for the given message // that can be safely used to calculate a signature from. // |