Skip to content

Commit

Permalink
Force password to 'yes' when deleting ledger-offline keys
Browse files Browse the repository at this point in the history
Closes: #2921
  • Loading branch information
Alessio Treglia committed Nov 29, 2018
1 parent b2b026b commit 5cb4501
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
12 changes: 10 additions & 2 deletions client/keys/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"os"

"github.com/cosmos/cosmos-sdk/client"
keys "github.com/cosmos/cosmos-sdk/crypto/keys"
Expand Down Expand Up @@ -31,11 +32,18 @@ func runDeleteCmd(cmd *cobra.Command, args []string) error {
return err
}

_, err = kb.Get(name)
info, err := kb.Get(name)
if err != nil {
return err
}

if info.GetType() == keys.TypeLedger || info.GetType() == keys.TypeOffline {
if err := kb.Delete(name, "yes"); err != nil {
return err
}
fmt.Fprintln(os.Stderr, "Deleted")
}

buf := client.BufferStdin()
oldpass, err := client.GetPassword(
"DANGER - enter password to permanently delete key:", buf)
Expand All @@ -47,7 +55,7 @@ func runDeleteCmd(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
fmt.Println("Password deleted forever (uh oh!)")
fmt.Fprintln(os.Stderr, "Password deleted forever (uh oh!)")
return nil
}

Expand Down
17 changes: 11 additions & 6 deletions crypto/keys/keybase.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,13 +386,9 @@ func (kb dbKeybase) Delete(name, passphrase string) error {
kb.db.DeleteSync(infoKey(name))
return nil
case ledgerInfo:
return kb.deleteOfflineLedgerKey(info, passphrase)
case offlineInfo:
if passphrase != "yes" {
return fmt.Errorf("enter 'yes' exactly to delete the key - this cannot be undone")
}
kb.db.DeleteSync(addrKey(info.GetAddress()))
kb.db.DeleteSync(infoKey(name))
return nil
return kb.deleteOfflineLedgerKey(info, passphrase)
}

return nil
Expand Down Expand Up @@ -469,3 +465,12 @@ func addrKey(address types.AccAddress) []byte {
func infoKey(name string) []byte {
return []byte(fmt.Sprintf("%s.%s", name, infoSuffix))
}

func (kb dbKeybase) deleteOfflineLedgerKey(info Info, yesPassphrase string) error {
if yesPassphrase != "yes" {
return fmt.Errorf("enter 'yes' exactly to delete the key - this cannot be undone")
}
kb.db.DeleteSync(addrKey(info.GetAddress()))
kb.db.DeleteSync(infoKey(info.GetName()))
return nil
}

0 comments on commit 5cb4501

Please sign in to comment.