From 535822ca689aa22931ccded0fe0d3efdfe0c4c4d Mon Sep 17 00:00:00 2001 From: Alessio Treglia Date: Fri, 30 Nov 2018 23:00:53 +0000 Subject: [PATCH] R4R: add command asks for encryption password once too many (#2970) * add command asks for encryption password once too many * keep additional explanatory text --- client/keys/add.go | 22 +++++++--------------- cmd/gaia/cli_test/cli_test.go | 4 ++-- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/client/keys/add.go b/client/keys/add.go index d50c2509f1..dbf5f4f30a 100644 --- a/client/keys/add.go +++ b/client/keys/add.go @@ -69,7 +69,7 @@ output func runAddCmd(cmd *cobra.Command, args []string) error { var kb keys.Keybase var err error - var pass string + var encrypPassword string buf := client.BufferStdin() name := args[0] @@ -77,7 +77,7 @@ func runAddCmd(cmd *cobra.Command, args []string) error { // we throw this away, so don't enforce args, // we want to get a new random seed phrase quickly kb = client.MockKeyBase() - pass = "throwing-this-key-away" + encrypPassword = "throwing-this-key-away" } else { kb, err = GetKeyBaseWithWritePerm() if err != nil { @@ -95,9 +95,9 @@ func runAddCmd(cmd *cobra.Command, args []string) error { // ask for a password when generating a local key if !viper.GetBool(client.FlagUseLedger) { - pass, err = client.GetCheckPassword( - "> Enter a passphrase for your key:", - "> Repeat the passphrase:", buf) + encrypPassword, err = client.GetCheckPassword( + "Enter a passphrase to encrypt your key to disk:", + "Repeat the passphrase:", buf) if err != nil { return err } @@ -135,7 +135,7 @@ func runAddCmd(cmd *cobra.Command, args []string) error { if err != nil { return err } - info, err := kb.CreateKey(name, seed, pass) + info, err := kb.CreateKey(name, seed, encrypPassword) if err != nil { return err } @@ -189,15 +189,7 @@ func runAddCmd(cmd *cobra.Command, args []string) error { } } - // get the encryption password - encryptPassword, err := client.GetCheckPassword( - "> Enter a passphrase to encrypt your key to disk:", - "> Repeat the passphrase:", buf) - if err != nil { - return err - } - - info, err := kb.Derive(name, mnemonic, bip39Passphrase, encryptPassword, *bip44Params) + info, err := kb.Derive(name, mnemonic, bip39Passphrase, encrypPassword, *bip44Params) if err != nil { return err } diff --git a/cmd/gaia/cli_test/cli_test.go b/cmd/gaia/cli_test/cli_test.go index 882644cc6e..5c500cbac1 100644 --- a/cmd/gaia/cli_test/cli_test.go +++ b/cmd/gaia/cli_test/cli_test.go @@ -618,8 +618,8 @@ func initializeFixtures(t *testing.T) (chainID, servAddr, port string) { os.RemoveAll(filepath.Join(gaiadHome, "config", "gentx")) executeWrite(t, fmt.Sprintf("gaiacli keys delete --home=%s --force foo", gaiacliHome)) executeWrite(t, fmt.Sprintf("gaiacli keys delete --home=%s --force bar", gaiacliHome)) - executeWriteCheckErr(t, fmt.Sprintf("gaiacli keys add --home=%s foo", gaiacliHome), app.DefaultKeyPass, app.DefaultKeyPass) - executeWriteCheckErr(t, fmt.Sprintf("gaiacli keys add --home=%s bar", gaiacliHome), app.DefaultKeyPass, app.DefaultKeyPass) + executeWriteCheckErr(t, fmt.Sprintf("gaiacli keys add --home=%s foo", gaiacliHome), app.DefaultKeyPass) + executeWriteCheckErr(t, fmt.Sprintf("gaiacli keys add --home=%s bar", gaiacliHome), app.DefaultKeyPass) fooAddr, _ := executeGetAddrPK(t, fmt.Sprintf( "gaiacli keys show foo --output=json --home=%s", gaiacliHome)) chainID = executeInit(t, fmt.Sprintf("gaiad init -o --moniker=foo --home=%s", gaiadHome))