Closed WHALEEYE closed 2 months ago
The changes introduce enhancements to the crab
project by implementing encryption and decryption mechanisms for secure data handling. Key functionalities include conditional encryption in action handling, updates to the API for raw action processing, and the introduction of utility functions for encryption. A new dependency on the cryptography
package is added, along with unit tests to validate the encryption processes.
Files | Change Summary |
---|---|
crab/core/environment.py |
Added _enc_key for encryption; modified _action_endpoint for conditional encryption and decryption. |
crab/server/api.py |
Updated raw_action endpoint to read raw content and conditionally decrypt or encrypt responses based on the key. |
crab/utils/__init__.py |
Introduced file to initialize utilities; imported functions for base64 and encryption handling. |
crab/utils/encryption.py |
Implemented AES 256 encryption functions: encrypt_message , decrypt_message , and generate_key_from_env . |
pyproject.toml |
Added cryptography package dependency for cryptographic functionalities. |
test/core/test_utils.py |
Created unit test test_encrypt_decrypt to validate encryption and decryption functionality. |
test/server/test_api.py |
Replaced test_raw_action with test_raw_action_unencrypted and test_raw_action_encrypted ; added mock_env fixture. |
crab/agents/backend_models/camel_model.py |
Updated type annotations to use pipe (| ) syntax for type unions, enhancing readability. |
sequenceDiagram
participant Client
participant API
participant Environment
participant Utils
Client->>API: Send Action
API->>Environment: Process Action
Environment->>Utils: Encrypt Action Data (if key present)
Utils-->>Environment: Encrypted Data
Environment->>API: Send Encrypted Data
API->>Client: Return Response
Client->>API: Request Response
API->>Environment: Process Response
Environment->>Utils: Decrypt Response Data (if key present)
Utils-->>Environment: Decrypted Data
Environment->>API: Send Decrypted Data
API->>Client: Return Decrypted Response
π In the burrow deep, where secrets lie,
A key was found, oh my, oh my!
With whispers of code, the data's tight,
Encryption dances in the moonlight.
Hops of joy, letβs cheer and play,
For safety's here in a brand new way! πβ¨
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?
Overall it looks very good. We can consider add an API test for encrypt mode.
Ref:
https://github.com/camel-ai/crab/blob/main/test/server/test_api.py
close #18
Add encryption support for communication between client and server. User can enable encryption by setting env variable
CRAB_ENC_KEY
.Summary by CodeRabbit
New Features
Bug Fixes
Tests
Chores