2018-02-22 07:17:19 -08:00
|
|
|
package keys
|
|
|
|
|
|
|
|
import (
|
2019-06-22 02:24:59 -07:00
|
|
|
"bufio"
|
2018-12-10 06:27:25 -08:00
|
|
|
|
2019-06-08 03:04:52 -07:00
|
|
|
"github.com/spf13/cobra"
|
2020-01-22 09:54:56 -08:00
|
|
|
"github.com/spf13/viper"
|
2019-06-22 02:24:59 -07:00
|
|
|
|
2020-01-22 09:54:56 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
2019-06-22 02:24:59 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/input"
|
2018-02-22 07:17:19 -08:00
|
|
|
)
|
|
|
|
|
2019-12-12 13:52:24 -08:00
|
|
|
// UpdateKeyCommand changes the password of a key in the keybase.
|
|
|
|
// It takes no effect on keys managed by new the keyring-based keybase implementation.
|
|
|
|
func UpdateKeyCommand() *cobra.Command {
|
2018-02-22 08:20:25 -08:00
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "update <name>",
|
|
|
|
Short: "Change the password used to protect private key",
|
2019-11-14 06:17:21 -08:00
|
|
|
Deprecated: `it takes no effect with the new keyring
|
|
|
|
based backend and is provided only for backward compatibility with the
|
|
|
|
legacy LevelDB based backend.
|
|
|
|
Refer to your operating system's manual to learn how to change your
|
|
|
|
keyring's password.
|
|
|
|
`,
|
|
|
|
RunE: runUpdateCmd,
|
|
|
|
Args: cobra.ExactArgs(1),
|
2018-02-22 08:20:25 -08:00
|
|
|
}
|
|
|
|
return cmd
|
2018-02-22 07:17:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
func runUpdateCmd(cmd *cobra.Command, args []string) error {
|
|
|
|
name := args[0]
|
|
|
|
|
2019-06-22 02:24:59 -07:00
|
|
|
buf := bufio.NewReader(cmd.InOrStdin())
|
2020-01-22 09:54:56 -08:00
|
|
|
kb, err := NewKeyBaseFromDir(viper.GetString(flags.FlagHome))
|
2018-02-22 07:17:19 -08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-06-22 02:24:59 -07:00
|
|
|
oldpass, err := input.GetPassword("Enter the current passphrase:", buf)
|
2018-02-22 07:17:19 -08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-07-10 19:56:09 -07:00
|
|
|
getNewpass := func() (string, error) {
|
2019-05-28 01:44:04 -07:00
|
|
|
return input.GetCheckPassword(
|
2018-07-10 19:56:09 -07:00
|
|
|
"Enter the new passphrase:",
|
|
|
|
"Repeat the new passphrase:", buf)
|
2018-02-22 07:17:19 -08:00
|
|
|
}
|
2019-06-22 02:24:59 -07:00
|
|
|
if err := kb.Update(name, oldpass, getNewpass); err != nil {
|
2018-02-22 07:17:19 -08:00
|
|
|
return err
|
|
|
|
}
|
2019-06-22 02:24:59 -07:00
|
|
|
|
|
|
|
cmd.PrintErrln("Password successfully updated!")
|
2018-02-22 07:17:19 -08:00
|
|
|
return nil
|
|
|
|
}
|