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

client: sign and verify hashed messages (sig fix stage 2) #1529

Merged
merged 2 commits into from
Apr 19, 2022

Conversation

chappjc
Copy link
Member

@chappjc chappjc commented Mar 17, 2022

Rebased on #1528

This is stage 2 of the signature message truncation fix plan outlined in #1526.

In these commits, client begins signing the hashed messages, but continues to recognize the buggy signatures from the server. This is because the while the server understands the correct hashed message signatures as of stage 1, it is still sending the old signatures with its messages.

This work can be backported to a 0.4.3+ release if #1528 has been deployed with 0.4.2.

In the next stage, the server begins sending the correct signatures.

@chappjc
Copy link
Member Author

chappjc commented Apr 15, 2022

@@ -2184,12 +2184,13 @@ func (btc *baseWallet) SignMessage(coin asset.Coin, msg dex.Bytes) (pubkeys, sig
return nil, nil, err
}
pk := privKey.PubKey()
sig, err := privKey.Sign(msg)
hash := sha256.Sum256(msg) // legacy servers will not accept this signature!
Copy link
Member

Choose a reason for hiding this comment

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

btc test will use chainhash.HashB, just confirming you meant to use sha256.Sum256 It is the same though https://github.com/btcsuite/btcd/blob/bf64c8bdbbbfc6db51312769742e1210b8ac8ed0/chaincfg/chainhash/hashfuncs.go#L10-L14

This creates message signatures using a message hash (sha256) instead of
the message itself, which was truncated.

Verification of server signatures in incoming messages recognizes both
signatures.  When v0 is purged (V0PURGE), this should be removed.

Also insert our pubkey back into register response.
Update Wallet.SignMessage impls to use an asset-specific hash function
with the provided message.  The resulting signatures will not be
accepted by legacy servers.
@chappjc chappjc merged commit 8aaed77 into decred:master Apr 19, 2022
@chappjc chappjc deleted the sig-fix-stage-2 branch April 19, 2022 03:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants