From 36994e4e0b2be1362f99048d08b907628088e2bb Mon Sep 17 00:00:00 2001 From: SjonHortensius Date: Mon, 12 Aug 2019 11:00:38 +0200 Subject: all: replace passPHRASE with passWORD in user interactions (#19932) * Ref #19906 - replace passPHRASE with passWORD in any user interactions this skips doccomments and variablenames to minimize impact. It does however include a rename of the `ethkey` `changepassphrase` parameter * console: fix JavaScript error capitalization --- cmd/ethkey/README.md | 12 +++--- cmd/ethkey/changepassphrase.go | 88 ------------------------------------------ cmd/ethkey/changepassword.go | 88 ++++++++++++++++++++++++++++++++++++++++++ cmd/ethkey/main.go | 2 +- cmd/ethkey/message_test.go | 6 +-- cmd/ethkey/utils.go | 12 +++--- 6 files changed, 104 insertions(+), 104 deletions(-) delete mode 100644 cmd/ethkey/changepassphrase.go create mode 100644 cmd/ethkey/changepassword.go (limited to 'cmd/ethkey') diff --git a/cmd/ethkey/README.md b/cmd/ethkey/README.md index 48d3c9e9b..bfddd1467 100644 --- a/cmd/ethkey/README.md +++ b/cmd/ethkey/README.md @@ -35,18 +35,18 @@ It is possible to refer to a file containing the message. To sign a message contained in a file, use the --msgfile flag. -### `ethkey changepassphrase ` +### `ethkey changepassword ` -Change the passphrase of a keyfile. +Change the password of a keyfile. use the `--newpasswordfile` to point to the new password file. -## Passphrases +## Passwords For every command that uses a keyfile, you will be prompted to provide the -passphrase for decrypting the keyfile. To avoid this message, it is possible -to pass the passphrase by using the `--passwordfile` flag pointing to a file that -contains the passphrase. +password for decrypting the keyfile. To avoid this message, it is possible +to pass the password by using the `--passwordfile` flag pointing to a file that +contains the password. ## JSON diff --git a/cmd/ethkey/changepassphrase.go b/cmd/ethkey/changepassphrase.go deleted file mode 100644 index 5d8e8af64..000000000 --- a/cmd/ethkey/changepassphrase.go +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright 2018 The go-ethereum Authors -// This file is part of go-ethereum. -// -// go-ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// go-ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with go-ethereum. If not, see . - -package main - -import ( - "fmt" - "io/ioutil" - "strings" - - "github.com/ethereum/go-ethereum/accounts/keystore" - "github.com/ethereum/go-ethereum/cmd/utils" - "gopkg.in/urfave/cli.v1" -) - -var newPassphraseFlag = cli.StringFlag{ - Name: "newpasswordfile", - Usage: "the file that contains the new passphrase for the keyfile", -} - -var commandChangePassphrase = cli.Command{ - Name: "changepassphrase", - Usage: "change the passphrase on a keyfile", - ArgsUsage: "", - Description: ` -Change the passphrase of a keyfile.`, - Flags: []cli.Flag{ - passphraseFlag, - newPassphraseFlag, - }, - Action: func(ctx *cli.Context) error { - keyfilepath := ctx.Args().First() - - // Read key from file. - keyjson, err := ioutil.ReadFile(keyfilepath) - if err != nil { - utils.Fatalf("Failed to read the keyfile at '%s': %v", keyfilepath, err) - } - - // Decrypt key with passphrase. - passphrase := getPassphrase(ctx) - key, err := keystore.DecryptKey(keyjson, passphrase) - if err != nil { - utils.Fatalf("Error decrypting key: %v", err) - } - - // Get a new passphrase. - fmt.Println("Please provide a new passphrase") - var newPhrase string - if passFile := ctx.String(newPassphraseFlag.Name); passFile != "" { - content, err := ioutil.ReadFile(passFile) - if err != nil { - utils.Fatalf("Failed to read new passphrase file '%s': %v", passFile, err) - } - newPhrase = strings.TrimRight(string(content), "\r\n") - } else { - newPhrase = promptPassphrase(true) - } - - // Encrypt the key with the new passphrase. - newJson, err := keystore.EncryptKey(key, newPhrase, keystore.StandardScryptN, keystore.StandardScryptP) - if err != nil { - utils.Fatalf("Error encrypting with new passphrase: %v", err) - } - - // Then write the new keyfile in place of the old one. - if err := ioutil.WriteFile(keyfilepath, newJson, 600); err != nil { - utils.Fatalf("Error writing new keyfile to disk: %v", err) - } - - // Don't print anything. Just return successfully, - // producing a positive exit code. - return nil - }, -} diff --git a/cmd/ethkey/changepassword.go b/cmd/ethkey/changepassword.go new file mode 100644 index 000000000..5689c2661 --- /dev/null +++ b/cmd/ethkey/changepassword.go @@ -0,0 +1,88 @@ +// Copyright 2018 The go-ethereum Authors +// This file is part of go-ethereum. +// +// go-ethereum is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// go-ethereum is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with go-ethereum. If not, see . + +package main + +import ( + "fmt" + "io/ioutil" + "strings" + + "github.com/ethereum/go-ethereum/accounts/keystore" + "github.com/ethereum/go-ethereum/cmd/utils" + "gopkg.in/urfave/cli.v1" +) + +var newPassphraseFlag = cli.StringFlag{ + Name: "newpasswordfile", + Usage: "the file that contains the new password for the keyfile", +} + +var commandChangePassphrase = cli.Command{ + Name: "changepassword", + Usage: "change the password on a keyfile", + ArgsUsage: "", + Description: ` +Change the password of a keyfile.`, + Flags: []cli.Flag{ + passphraseFlag, + newPassphraseFlag, + }, + Action: func(ctx *cli.Context) error { + keyfilepath := ctx.Args().First() + + // Read key from file. + keyjson, err := ioutil.ReadFile(keyfilepath) + if err != nil { + utils.Fatalf("Failed to read the keyfile at '%s': %v", keyfilepath, err) + } + + // Decrypt key with passphrase. + passphrase := getPassphrase(ctx) + key, err := keystore.DecryptKey(keyjson, passphrase) + if err != nil { + utils.Fatalf("Error decrypting key: %v", err) + } + + // Get a new passphrase. + fmt.Println("Please provide a new password") + var newPhrase string + if passFile := ctx.String(newPassphraseFlag.Name); passFile != "" { + content, err := ioutil.ReadFile(passFile) + if err != nil { + utils.Fatalf("Failed to read new password file '%s': %v", passFile, err) + } + newPhrase = strings.TrimRight(string(content), "\r\n") + } else { + newPhrase = promptPassphrase(true) + } + + // Encrypt the key with the new passphrase. + newJson, err := keystore.EncryptKey(key, newPhrase, keystore.StandardScryptN, keystore.StandardScryptP) + if err != nil { + utils.Fatalf("Error encrypting with new password: %v", err) + } + + // Then write the new keyfile in place of the old one. + if err := ioutil.WriteFile(keyfilepath, newJson, 600); err != nil { + utils.Fatalf("Error writing new keyfile to disk: %v", err) + } + + // Don't print anything. Just return successfully, + // producing a positive exit code. + return nil + }, +} diff --git a/cmd/ethkey/main.go b/cmd/ethkey/main.go index a8399ad7c..5b545d5f9 100644 --- a/cmd/ethkey/main.go +++ b/cmd/ethkey/main.go @@ -49,7 +49,7 @@ func init() { var ( passphraseFlag = cli.StringFlag{ Name: "passwordfile", - Usage: "the file that contains the passphrase for the keyfile", + Usage: "the file that contains the password for the keyfile", } jsonFlag = cli.BoolFlag{ Name: "json", diff --git a/cmd/ethkey/message_test.go b/cmd/ethkey/message_test.go index 39352b1d2..e9e8eeeaf 100644 --- a/cmd/ethkey/message_test.go +++ b/cmd/ethkey/message_test.go @@ -37,8 +37,8 @@ func TestMessageSignVerify(t *testing.T) { generate := runEthkey(t, "generate", keyfile) generate.Expect(` !! Unsupported terminal, password will be echoed. -Passphrase: {{.InputLine "foobar"}} -Repeat passphrase: {{.InputLine "foobar"}} +Password: {{.InputLine "foobar"}} +Repeat password: {{.InputLine "foobar"}} `) _, matches := generate.ExpectRegexp(`Address: (0x[0-9a-fA-F]{40})\n`) address := matches[1] @@ -48,7 +48,7 @@ Repeat passphrase: {{.InputLine "foobar"}} sign := runEthkey(t, "signmessage", keyfile, message) sign.Expect(` !! Unsupported terminal, password will be echoed. -Passphrase: {{.InputLine "foobar"}} +Password: {{.InputLine "foobar"}} `) _, matches = sign.ExpectRegexp(`Signature: ([0-9a-f]+)\n`) signature := matches[1] diff --git a/cmd/ethkey/utils.go b/cmd/ethkey/utils.go index 6f60ebaf1..c6cf5c25a 100644 --- a/cmd/ethkey/utils.go +++ b/cmd/ethkey/utils.go @@ -31,18 +31,18 @@ import ( // 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: ") + passphrase, err := console.Stdin.PromptPassword("Password: ") if err != nil { - utils.Fatalf("Failed to read passphrase: %v", err) + utils.Fatalf("Failed to read password: %v", err) } if confirmation { - confirm, err := console.Stdin.PromptPassword("Repeat passphrase: ") + confirm, err := console.Stdin.PromptPassword("Repeat password: ") if err != nil { - utils.Fatalf("Failed to read passphrase confirmation: %v", err) + utils.Fatalf("Failed to read password confirmation: %v", err) } if passphrase != confirm { - utils.Fatalf("Passphrases do not match") + utils.Fatalf("Passwords do not match") } } @@ -58,7 +58,7 @@ func getPassphrase(ctx *cli.Context) string { if passphraseFile != "" { content, err := ioutil.ReadFile(passphraseFile) if err != nil { - utils.Fatalf("Failed to read passphrase file '%s': %v", + utils.Fatalf("Failed to read password file '%s': %v", passphraseFile, err) } return strings.TrimRight(string(content), "\r\n") -- cgit v1.2.3