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: LedgerShowAddress's public key comparison equality == instead of .Equals will soon result in unexpected results if we upgrade modules of tendermint/crypto #6677

Closed
Tracked by #14007
odeke-em opened this issue Jul 10, 2020 · 1 comment
Labels

Comments

@odeke-em
Copy link
Collaborator

During an audit, I noticed that the code for LedgerShowAddress compares PubKeySecp256k1 values by equality i.e.

if pubKey != expectedPubKey {
return fmt.Errorf("the key's pubkey does not match with the one retrieved from Ledger. Check that the HD path and device are the correct ones")
}

and given that we are at go module github.com/tendermint/[email protected], the type of PubKeySecp256k1 is a BYTE ARRAY aka [SIZE]byte.

getPubKeyUnsafe returns an interface so that'll mask the problem until runtime where it'll panic.

Byte arrays have equality defined on them, but as soon as we upgrade to a new module, that type turns into a byte slice that'll panic, but will fail e.g.
https://play.golang.org/p/sZdl964nL8b

Recommendation

Both versions have a defined .Equals method, we should use that and it'll guard against that sensitivity for any interfaces

@hxrts hxrts added the C:Crypto label Nov 26, 2020
@JulianToledano
Copy link
Contributor

Hello 👋 @odeke-em
do you think we can close this? as right now PubKey.Equals() is being used?

if !pubKey.Equals(expectedPubKey) {
return fmt.Errorf("the key's pubkey does not match with the one retrieved from Ledger. Check that the HD path and device are the correct ones")
}
pubKey2, _, err := getPubKeyAddrSafe(device, path, accountAddressPrefix)
if err != nil {
return err
}
if !pubKey2.Equals(expectedPubKey) {
return fmt.Errorf("the key's pubkey does not match with the one retrieved from Ledger. Check that the HD path and device are the correct ones")
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants