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

crypto/keyring: fix offline keys migration #8639

Merged
merged 43 commits into from
Mar 1, 2021
Merged

Conversation

sahith-narahari
Copy link
Contributor

@sahith-narahari sahith-narahari commented Feb 19, 2021

Description

closes: #8633
I tested this branch against gaia, and works for migrating multisig keys. I'm not sure about the ledger though, having issues connecting mine. Would be nice if someone can test this.

Steps for testing

1) cosmos-sdk: git checkout sahith/fix-key-multisig

2) gaia: git checkout v2.0.15 && make install

3) create local keys, multisig key and a ledger key

4) gaia: git checkout v4.0.3

5) add the following replace directive to go.mod in gaia - 
       replace github.com/cosmos/cosmos-sdk => <path to cosmos-sdk with specified branch>

6) make install

7) gaiad keys migrate --home <path to gaiacli(default: $HOME/.gaiacli)>

Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer
  • Review Codecov Report in the comment section below once CI passes

@lgtm-com
Copy link

lgtm-com bot commented Feb 19, 2021

This pull request introduces 2 alerts when merging 5610039 into ef8dabc - view on LGTM.com

new alerts:

  • 2 for Useless assignment to local variable

@lgtm-com
Copy link

lgtm-com bot commented Feb 19, 2021

This pull request introduces 2 alerts when merging f599220 into ef8dabc - view on LGTM.com

new alerts:

  • 2 for Useless assignment to local variable

@lgtm-com
Copy link

lgtm-com bot commented Feb 19, 2021

This pull request introduces 2 alerts when merging 48286a3 into 7e481cc - view on LGTM.com

new alerts:

  • 2 for Useless assignment to local variable

Copy link
Contributor

@alessio alessio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh hold on - tests are failing

@sahith-narahari
Copy link
Contributor Author

oh hold on - tests are failing

yes, working on them. I wanted others to test using a ledger if possible, updated the description for the same.

@alessio
Copy link
Contributor

alessio commented Feb 23, 2021

testing is failing with ledger:

alessio@phoenix:~$ gaiad --log_level=info keys --keyring-backend=file migrate --home=/home/alessio/.gaiacli
Migrating key: 'bar (local)' ...
Skip key migration? [y/N]: n
Enter passphrase to decrypt key:
Enter keyring passphrase:
Re-enter keyring passphrase:
Migrating key: 'ledger (ledger)' ...
Skip key migration? [y/N]: n
Error: unmarshal to types.PubKey failed after 4 bytes (unrecognized prefix bytes 03497EC0): 03497EC092EF901027049E4F39200C60040D3562CD7F104A39F62E6E5A39A818F4

@alessio
Copy link
Contributor

alessio commented Feb 23, 2021

It fails with offline keys too (pubkeys info only):

Migrating key: 'pub1 (offline)' ...
Skip key migration? [y/N]: n
Error: unmarshal to types.PubKey failed after 4 bytes (unrecognized prefix bytes 0392A330): 0392A33059328676A9F6CD8A795F91A86E2B0DD4AF51035178C40D19EF30502689
Usage:
  gaiad keys migrate [flags]

@alessio
Copy link
Contributor

alessio commented Feb 23, 2021

Failure seems to happen in crypto/keyring/keyring.go, line 320:

	pubKey, err := legacy.PubKeyFromBytes(pubBytes)
	if err != nil {
		return err
	}

@robert-zaremba
Copy link
Collaborator

Is this PR ready for review or it's still in draft?

if err != nil {
return err
}

defer legacyKb.Close()
defer func() { _ = legacyKb.Close() }()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we need to do this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to ignore that error, as it does not really matter whether the keybase can be closed or not (we are basically doing only read-only ops)

InfoImporter is implemented by those Keyring implementations
that support import of Info objects.
@alessio alessio changed the title Fix multisig keys migrate crypto/keyring: fix offline keys migration Feb 27, 2021
Copy link
Contributor

@amaury1093 amaury1093 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK. I tested (last Friday) on local and ledger keys.

@alessio alessio added A:automerge Automatically merge PR once all prerequisites pass. and removed A:automerge Automatically merge PR once all prerequisites pass. labels Mar 1, 2021
client/keys/migrate.go Outdated Show resolved Hide resolved
@alessio alessio merged commit b1c72fd into master Mar 1, 2021
@alessio alessio deleted the sahith/fix-key-multi branch March 1, 2021 12:41
@alessio
Copy link
Contributor

alessio commented Mar 1, 2021

@mergifyhq backport release/v0.41.x

@mergify
Copy link
Contributor

mergify bot commented Mar 1, 2021

Command backport release/v0.41.x: failure

No backport have been created
GitHub App like Mergify are not allowed to create pull request where .github/workflows is changed.

Hey, I reacted but my real name is @Mergifyio

alessio pushed a commit that referenced this pull request Mar 1, 2021
Fix `keys migrate` command (#8703)

crypto/keyring: reinstate the InfoImporter interface

InfoImporter is implemented by those Keyring implementations
that support import of Info objects.

Co-authored-by: Alessio Treglia <[email protected]>
Co-authored-by: Jonathan Gimeno <[email protected]>
Co-authored-by: Amaury <[email protected]>
alessio pushed a commit that referenced this pull request Mar 2, 2021
* crypto/keyring: fix offline keys migration (#8639)

Fix `keys migrate` command (#8703)

crypto/keyring: reinstate the InfoImporter interface

InfoImporter is implemented by those Keyring implementations
that support import of Info objects.

Co-authored-by: Alessio Treglia <[email protected]>
Co-authored-by: Jonathan Gimeno <[email protected]>
Co-authored-by: Amaury <[email protected]>

* refresh golangci-lint

* Rename InfoImporter -> LegacyInfoImporter (#8739)

Avoid namespace clash with the InfoImporter interface
that already exists in the v0.41 release series.

* Revert "refresh golangci-lint"

This reverts commit 38e1349.

Co-authored-by: SaReN <[email protected]>
Co-authored-by: Jonathan Gimeno <[email protected]>
Co-authored-by: Amaury <[email protected]>
@amaury1093 amaury1093 mentioned this pull request Mar 3, 2021
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:Keys Keybase, KMS and HSMs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issues with account key migration from Gaia 2.X to Gaia 4.X
6 participants