Repository navigation
feat(crypto): add publicKeyForPeer to bind keys to peer ids - #3667
Merged
Merged
Conversation
Returns a peer's public key, accepting a supplied key only if it derives to the peer id.
Verify signatures with publicKeyForPeer and add tests that forge messages through the RPC path.
…KeyForPeer Also correct the doc comment, which implied a mismatched key falls back to the inlined one.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds
publicKeyForPeer(peer, key?, options?)to@libp2p/crypto/keys. It returns a peer's public key that is safe to verify the peer's signatures with:PublicKey) is returned only if its multihash equals the peer id's. Otherwise it throwsInvalidPublicKeyError, even when the peer id inlines a key.InvalidPublicKeyErrorif there isn't one (RSA and URL peer ids).InvalidPublicKeyError.floodsub, gossipsub and libp2p each hand-wrote this check, and their behaviour had drifted apart. They now share the helper:
verifySignature: a message whosekeyfield does not derive to its Ed25519 or secp256k1 author is now rejected. Previously the field was ignored and the inlined key was used. This matches gossipsub and go-libp2p-pubsub.validateToRawMessage: no behaviour change. Mismatched, missing and malformed keys still map toValidateError.InvalidPeerId.getPublicKey: keys fetched through content routing are checked with the helper. A mismatch still throwsInvalidPublicKeyError, but the message text changed.Notes & open questions
publicKeyForPeeris async even though nothing inside it awaits today. That leaves room for key parsing to become async without changing callers.Change checklist