Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[backport/v0.41.x]: Fix keyring import from older versions. #8489

Merged
merged 1 commit into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

## Unreleased

### Bug Fixes

* (client/keys) [\#8436](https://github.com/cosmos/cosmos-sdk/pull/8436) Fix keybase->keyring keys migration.

### Improvements

* (x/bank) [\#8479](https://github.com/cosmos/cosmos-sdk/pull/8479) Aditional client denom metadata validation for `base` and `display` denoms.
Expand Down
26 changes: 16 additions & 10 deletions client/keys/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func runMigrateCmd(cmd *cobra.Command, args []string) error {

var (
tmpDir string
migrator keyring.InfoImporter
migrator keyring.Importer
)

if dryRun, _ := cmd.Flags().GetBool(flags.FlagDryRun); dryRun {
Expand All @@ -73,10 +73,10 @@ func runMigrateCmd(cmd *cobra.Command, args []string) error {

defer os.RemoveAll(tmpDir)

migrator, err = keyring.NewInfoImporter(keyringServiceName, "test", tmpDir, buf)
migrator, err = keyring.New(keyringServiceName, keyring.BackendTest, tmpDir, buf)
} else {
backend, _ := cmd.Flags().GetString(flags.FlagKeyringBackend)
migrator, err = keyring.NewInfoImporter(keyringServiceName, backend, rootDir, buf)
migrator, err = keyring.New(keyringServiceName, backend, rootDir, buf)
}

if err != nil {
Expand All @@ -86,12 +86,12 @@ func runMigrateCmd(cmd *cobra.Command, args []string) error {
))
}

for _, key := range oldKeys {
legKeyInfo, err := legacyKb.Export(key.GetName())
if err != nil {
return err
}
if len(oldKeys) == 0 {
cmd.Print("Migration Aborted: no keys to migrate")
return nil
}

for _, key := range oldKeys {
keyName := key.GetName()
keyType := key.GetType()

Expand All @@ -107,7 +107,12 @@ func runMigrateCmd(cmd *cobra.Command, args []string) error {
}

if keyType != keyring.TypeLocal {
if err := migrator.Import(keyName, legKeyInfo); err != nil {
pubkeyArmor, err := legacyKb.ExportPubKey(keyName)
if err != nil {
return err
}

if err := migrator.ImportPubKey(keyName, pubkeyArmor); err != nil {
return err
}

Expand All @@ -127,10 +132,11 @@ func runMigrateCmd(cmd *cobra.Command, args []string) error {
return err
}

if err := migrator.Import(keyName, armoredPriv); err != nil {
if err := migrator.ImportPrivKey(keyName, armoredPriv, migratePassphrase); err != nil {
return err
}
}
cmd.Print("Migration Complete")

return err
}
Binary file removed client/keys/testdata/keys/keys.db/000002.ldb
Binary file not shown.
2 changes: 1 addition & 1 deletion client/keys/testdata/keys/keys.db/CURRENT
Original file line number Diff line number Diff line change
@@ -1 +1 @@
MANIFEST-000004
MANIFEST-000005
2 changes: 1 addition & 1 deletion client/keys/testdata/keys/keys.db/CURRENT.bak
Original file line number Diff line number Diff line change
@@ -1 +1 @@
MANIFEST-000000
MANIFEST-000003
48 changes: 30 additions & 18 deletions client/keys/testdata/keys/keys.db/LOG
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
=============== Mar 30, 2020 (CEST) ===============
02:07:34.137606 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed
02:07:34.144547 db@open opening
02:07:34.144770 version@stat F·[] S·0B[] Sc·[]
02:07:34.145843 db@janitor F·2 G·0
02:07:34.145875 db@open done T·1.315251ms
02:07:34.335635 db@close closing
02:07:34.335736 db@close done T·98.95µs
=============== Mar 30, 2020 (CEST) ===============
02:08:33.239115 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed
02:08:33.239264 version@stat F·[] S·0B[] Sc·[]
02:08:33.239281 db@open opening
02:08:33.239310 journal@recovery F·1
02:08:33.239398 journal@recovery recovering @1
02:08:33.322008 memdb@flush created L0@2 N·4 S·391B "cos..ess,v4":"run..nfo,v3"
02:08:33.323091 version@stat F·[1] S·391B[391B] Sc·[0.25]
02:08:33.421979 db@janitor F·3 G·0
02:08:33.422153 db@open done T·182.707962ms
=============== Feb 2, 2021 (IST) ===============
00:03:25.348369 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed
00:03:25.350695 db@open opening
00:03:25.350888 version@stat F·[] S·0B[] Sc·[]
00:03:25.351864 db@janitor F·2 G·0
00:03:25.351881 db@open done T·1.169825ms
00:03:25.351895 db@close closing
00:03:25.351929 db@close done T·33.042µs
=============== Feb 2, 2021 (IST) ===============
00:03:34.450638 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed
00:03:34.450722 version@stat F·[] S·0B[] Sc·[]
00:03:34.450737 db@open opening
00:03:34.450765 journal@recovery F·1
00:03:34.450851 journal@recovery recovering @1
00:03:34.451173 version@stat F·[] S·0B[] Sc·[]
00:03:34.454278 db@janitor F·2 G·0
00:03:34.454298 db@open done T·3.548046ms
00:03:34.454307 db@close closing
00:03:34.454327 db@close done T·19.017µs
=============== Feb 2, 2021 (IST) ===============
00:03:42.025705 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed
00:03:42.025892 version@stat F·[] S·0B[] Sc·[]
00:03:42.025907 db@open opening
00:03:42.025943 journal@recovery F·1
00:03:42.026790 journal@recovery recovering @2
00:03:42.026946 version@stat F·[] S·0B[] Sc·[]
00:03:42.031645 db@janitor F·2 G·0
00:03:42.031661 db@open done T·5.750008ms
00:03:42.283102 db@close closing
00:03:42.283162 db@close done T·58.775µs
Binary file removed client/keys/testdata/keys/keys.db/MANIFEST-000004
Binary file not shown.
Binary file added client/keys/testdata/keys/keys.db/MANIFEST-000005
Binary file not shown.
1 change: 1 addition & 0 deletions crypto/keyring/keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ type Signer interface {
type Importer interface {
// ImportPrivKey imports ASCII armored passphrase-encrypted private keys.
ImportPrivKey(uid, armor, passphrase string) error

// ImportPubKey imports ASCII armored public keys.
ImportPubKey(uid string, armor string) error
}
Expand Down