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

fix: INTERCOM messages RSA #44

Merged
merged 2 commits into from
Jan 1, 2025
Merged

fix: INTERCOM messages RSA #44

merged 2 commits into from
Jan 1, 2025

Conversation

JarbasAl
Copy link
Member

@JarbasAl JarbasAl commented Jan 1, 2025

these were still using the removed pgpy, missed in #42

Summary by CodeRabbit

  • New Features

    • Updated encryption mechanism from PGP to RSA for message handling
    • Enhanced message serialization and signature generation
  • Security Improvements

    • Implemented more robust encryption and decryption methods
    • Added support for hex-encoded message signatures
  • Technical Updates

    • Replaced pgpy library with RSA-based cryptographic methods
    • Updated message handling to support new encryption approach

these were still using the removed pgpy
Copy link
Contributor

coderabbitai bot commented Jan 1, 2025

Warning

Rate limit exceeded

@JarbasAl has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 9 minutes and 35 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 712508b and dd1b2ac.

📒 Files selected for processing (2)
  • hivemind_bus_client/client.py (3 hunks)
  • hivemind_bus_client/protocol.py (2 hunks)

Walkthrough

The pull request introduces a significant cryptographic transformation in the hivemind bus client, transitioning from PGP to RSA encryption. The changes primarily affect message serialization, encryption, and decryption processes in both client.py and protocol.py. The modifications replace pgpy with RSA-based encryption methods, updating import statements, method signatures, and internal encryption logic while maintaining the overall structure of the message handling system.

Changes

File Changes
hivemind_bus_client/client.py - Updated import statements to include binascii.hexlify and Cryptodome.PublicKey.RSA
- Modified emit_intercom method signature to accept RSA keys
- Replaced PGP encryption with RSA encryption methods
hivemind_bus_client/protocol.py - Added unhexlify import from binascii
- Updated handle_intercom method to process hex-encoded ciphertext and signature
- Added new utility methods load_RSA_key and decrypt_RSA

Sequence Diagram

sequenceDiagram
    participant Sender
    participant MessageBus
    participant Receiver
    
    Sender->>MessageBus: emit_intercom(message, pubkey)
    MessageBus->>MessageBus: Encrypt with RSA
    MessageBus->>MessageBus: Sign message
    MessageBus->>Receiver: Send encrypted message
    Receiver->>Receiver: Decrypt with RSA key
    Receiver->>Receiver: Verify signature
Loading

Poem

🐰 A Rabbit's Crypto Dance 🔐

From PGP's embrace, we now RSA twirl,
Encryption's new dance, our keys now unfurl
Hex-encoded secrets, signatures tight
A cryptographic waltz of digital might
Hop, hop, encryption's new delight! 🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added fix and removed fix labels Jan 1, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
hivemind_bus_client/client.py (1)

497-508: New emit_intercom method implementing RSA encryption and signing.

  1. The RSA-based code properly encrypts and signs the message.
  2. Consider adding error handling for missing or invalid private keys.
  3. Consider clarifying docstrings about the expected type(s) of pubkey.
hivemind_bus_client/protocol.py (1)

281-284: Consider implementing signature verification.
The commented-out code suggests a plan to verify RSA signatures. Verifying signatures helps ensure message authenticity and integrity.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5407634 and 712508b.

📒 Files selected for processing (2)
  • hivemind_bus_client/client.py (3 hunks)
  • hivemind_bus_client/protocol.py (2 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
hivemind_bus_client/protocol.py

279-279: Local variable signature is assigned to but never used

Remove assignment to unused variable signature

(F841)

🔇 Additional comments (8)
hivemind_bus_client/client.py (4)

3-3: Import usage is consistent with RSA-based encryption.
No issues found with the usage of hexlify for hex-encoding the ciphertext and signature.


7-8: New cryptographic imports.
Using pybase64 and Cryptodome.PublicKey.RSA aligns with the revised RSA encryption approach. Please ensure these dependencies are installed and compatible with your runtime environment.


14-15: Additional imports from ovos_utils.
These appear consistent with the rest of the codebase and introduce no apparent conflicts.


23-23: Removal of pgpy references in favor of RSA methods.
Importing encrypt_RSA, load_RSA_key, and sign_RSA completes the transition away from PGP.

hivemind_bus_client/protocol.py (4)

1-1: Hex-decoding for RSA ciphertext.
No issues with introducing unhexlify; it matches the message flow for RSA decryption.


3-3: Addition of Optional import.
Usage is consistent with existing type hints.


14-15: Transition to RSA-based decryption.
Imports for decrypt_RSA and load_RSA_key confirm that references to pgpy have been removed.


285-287: Error handling when decrypting.
Consider catching exceptions if private key loading or decryption fails. This can ensure graceful handling of invalid or corrupted keys.

Comment on lines 278 to 280
ciphertext = unhexlify(pload["ciphertext"])
signature = unhexlify(pload["signature"])

Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Unused signature variable.
As flagged by static analysis, signature is assigned but never utilized. You can remove it if you’re not performing signature verification:

- signature = unhexlify(pload["signature"])
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
ciphertext = unhexlify(pload["ciphertext"])
signature = unhexlify(pload["signature"])
ciphertext = unhexlify(pload["ciphertext"])
🧰 Tools
🪛 Ruff (0.8.2)

279-279: Local variable signature is assigned to but never used

Remove assignment to unused variable signature

(F841)

these were still using the removed pgpy
@JarbasAl JarbasAl merged commit d33d690 into dev Jan 1, 2025
1 check passed
@JarbasAl JarbasAl deleted the fix/intercom_pgpy branch January 8, 2025 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant