Improve RSA Key Compatibility, Public Key Extraction, and Pubsub Connection Handling #1107
+102
−6
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.
What was wrong?
Issue #1106
The py-libp2p implementation had few issues which is causing problems during py-peer of universal connectivity interoperability:
How was it fixed?
1. Enhanced RSA Key Parsing
Added fallback parsing logic in
libp2p/crypto/rsa.pythat uses thecryptographylibrary when PyCryptodome fails. When a PKIX-formatted key is encountered, it's converted to PKCS1 format that PyCryptodome can handle:2. Implemented Public Key Extraction
Added
extract_public_key()method to theIDclass inlibp2p/peer/id.pythat:Nonefor peer IDs using SHA-256 hash (RSA and other large keys)3. Updated Signature Validation Logic
Modified
signature_validator()inlibp2p/pubsub/validators.pyto:msg.keyfield if extraction returnsNoneThis approach aligns with the libp2p specification and reduces message overhead for small keys.
4. Improved Pubsub Connection Management
Enhanced
libp2p/pubsub/pubsub.pywith:_handle_new_peer()in_handle_new_peer_safe()to prevent service crashesc.muxed_conn.is_closedto filter out closed connections when checking if a peer should be removedAll changes are fully backward compatible and maintain existing functionality while adding robustness and spec compliance.
To-Do
Cute Animal Picture