Skip to content

Commit

Permalink
R4R: add command asks for encryption password once too many (cosmos#2970
Browse files Browse the repository at this point in the history
)

* add command asks for encryption password once too many

* keep additional explanatory text
  • Loading branch information
alessio authored and jackzampolin committed Nov 30, 2018
1 parent 956c222 commit 535822c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
22 changes: 7 additions & 15 deletions client/keys/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ 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]
if viper.GetBool(flagDryRun) {
// 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 {
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/gaia/cli_test/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 535822c

Please sign in to comment.