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

Allow OBJECT_OP_UNWRAP to modify attributes #728

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

antoinelochet
Copy link

@antoinelochet antoinelochet commented Oct 27, 2023

Allow attributes update when CKA_MODIFIABLE is false and the operation is UNWRAP.
Here is my proposed fix for #707

Summary by CodeRabbit

  • New Features

    • Enhanced attribute modification logic to support unwrapping operations.
    • Introduced a new method for wrapping and unwrapping AES keys in a non-modifiable context.
  • Bug Fixes

    • Improved control flow for attribute updates during object unwrapping.
    • Added validation checks for key management operations involving non-modifiable keys.

@jschlyter jschlyter linked an issue Nov 29, 2024 that may be closed by this pull request
@jschlyter jschlyter changed the title Fixed issue #707 Allow OBJECT_OP_UNWRAP to modify attributes Allow OBJECT_OP_UNWRAP to modify attributes Nov 29, 2024
@jschlyter jschlyter added the bug Some isn't right label Nov 29, 2024
@jschlyter
Copy link
Contributor

Please rebase on develop and mark as ready when ready.

@jschlyter jschlyter marked this pull request as draft November 29, 2024 16:27
@antoinelochet antoinelochet marked this pull request as ready for review November 29, 2024 19:04
@antoinelochet antoinelochet requested a review from a team as a code owner November 29, 2024 19:04
@antoinelochet
Copy link
Author

Hello @jschlyter
Done :)

@jschlyter
Copy link
Contributor

@coderabbitai review

Copy link

coderabbitai bot commented Jan 29, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

coderabbitai bot commented Jan 29, 2025

Walkthrough

The changes in the P11Attributes.cpp file modify the update method of the P11Attribute class to incorporate the OBJECT_OP_UNWRAP operation in the conditions for attribute modification. This update allows attributes to be modified during the unwrapping process, alongside the previously permitted operations: OBJECT_OP_GENERATE and OBJECT_OP_CREATE. Additionally, a new method aesWrapUnwrapNonModifiableGeneric is introduced in the SymmetricAlgorithmTests class to test AES key wrapping and unwrapping while ensuring keys remain non-modifiable.

Changes

File Change Summary
src/lib/P11Attributes.cpp - Updated update method to include OBJECT_OP_UNWRAP in mutability and trusted checks.
src/lib/test/SymmetricAlgorithmTests.cpp - Added method aesWrapUnwrapNonModifiableGeneric for AES key wrapping and unwrapping with non-modifiable attributes.
src/lib/test/SymmetricAlgorithmTests.h - Declared new method aesWrapUnwrapNonModifiableGeneric for AES key operations.

Suggested reviewers

  • jschlyter

Poem

🐰 A Rabbit's Ode to Attribute Unwrapping 🔓

In lines of code, a new path unfurls,
Where attributes dance and logic swirls.
Unwrap with grace, modify with might,
Flexibility blooms, constraints take flight.
A cryptographic waltz, precise and free!

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9e67f7e and 1c98eb5.

📒 Files selected for processing (3)
  • src/lib/P11Attributes.cpp (1 hunks)
  • src/lib/test/SymmetricAlgorithmTests.cpp (2 hunks)
  • src/lib/test/SymmetricAlgorithmTests.h (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/lib/test/SymmetricAlgorithmTests.h
  • src/lib/P11Attributes.cpp
🔇 Additional comments (2)
src/lib/test/SymmetricAlgorithmTests.cpp (2)

1189-1288: LGTM! Well-structured test implementation.

The new test method correctly verifies that keys can be unwrapped with CKA_MODIFIABLE=FALSE. The implementation follows the established test patterns and includes proper assertions.


1747-1748: LGTM! Good test coverage.

The test method is appropriately called with both CKM_AES_KEY_WRAP and CKM_AES_CBC_PAD mechanisms, providing good coverage of non-modifiable key unwrapping scenarios.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

🪧 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.

@jschlyter jschlyter requested a review from bjosv January 29, 2025 05:38
Copy link
Contributor

@bjosv bjosv left a comment

Choose a reason for hiding this comment

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

I would be nice with a test in SymmetricAlgorithmTests.cpp similar to its testNonModifiableDesKeyGeneration.

Copy link

@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

🔭 Outside diff range comments (1)
src/lib/test/SymmetricAlgorithmTests.h (1)

44-58: Add the new test to the test suite.

The new method aesWrapUnwrapNonModifiableGeneric is not included in the test suite. Consider adding it to ensure the new functionality is tested.

Apply this diff to add the test:

 CPPUNIT_TEST_SUITE(SymmetricAlgorithmTests);
 CPPUNIT_TEST(testAesEncryptDecrypt);
 CPPUNIT_TEST(testDesEncryptDecrypt);
#ifdef HAVE_AES_KEY_WRAP
 CPPUNIT_TEST(testAesWrapUnwrap);
+CPPUNIT_TEST(testAesWrapUnwrapNonModifiable);
#endif
 CPPUNIT_TEST(testNullTemplate);

You'll also need to add the corresponding public test method. Let me know if you'd like me to help with that implementation.

🧹 Nitpick comments (2)
src/lib/test/SymmetricAlgorithmTests.cpp (2)

1189-1190: Add documentation for the test method.

Please add comments explaining that this test verifies unwrapping behavior when CKA_MODIFIABLE is set to false.

+// Test that unwrapping works correctly when CKA_MODIFIABLE is set to false.
+// This verifies the fix for issue #707 which allows OBJECT_OP_UNWRAP to modify attributes
+// even when CKA_MODIFIABLE is false.
 void SymmetricAlgorithmTests::aesWrapUnwrapNonModifiableGeneric(CK_MECHANISM_TYPE mechanismType, CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hKey)

1189-1288: Consider refactoring to reduce code duplication.

This method shares a lot of code with aesWrapUnwrapGeneric. Consider extracting the common functionality into helper methods to improve maintainability.

For example:

  1. Extract key generation and wrapping into a helper method
  2. Extract unwrapping and verification into another helper method
  3. Pass CKA_MODIFIABLE value as a parameter
+// Helper method for key generation and wrapping
+void wrapKey(CK_SESSION_HANDLE hSession, CK_MECHANISM_TYPE mechanismType, 
+             CK_OBJECT_HANDLE hKey, CK_BBOOL bExtractable,
+             CK_BYTE_PTR& wrappedPtr, CK_ULONG& wrappedLen) {
+    // Common key generation and wrapping code
+}
+
+// Helper method for unwrapping and verification  
+void unwrapAndVerifyKey(CK_SESSION_HANDLE hSession, CK_MECHANISM_TYPE mechanismType,
+                       CK_OBJECT_HANDLE hKey, CK_BBOOL bModifiable,
+                       CK_BYTE_PTR wrappedPtr, CK_ULONG wrappedLen) {
+    // Common unwrapping and verification code
+}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 14749ef and 9e67f7e.

📒 Files selected for processing (3)
  • src/lib/P11Attributes.cpp (1 hunks)
  • src/lib/test/SymmetricAlgorithmTests.cpp (1 hunks)
  • src/lib/test/SymmetricAlgorithmTests.h (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/lib/P11Attributes.cpp
🔇 Additional comments (1)
src/lib/test/SymmetricAlgorithmTests.h (1)

91-91: LGTM! Method signature follows existing patterns.

The new method aesWrapUnwrapNonModifiableGeneric follows the established pattern of similar methods in the class, maintaining consistency in the codebase.

…ify attributes when CKA_MODIFIABLE is true
@antoinelochet
Copy link
Author

antoinelochet commented Feb 6, 2025

I would be nice with a test in SymmetricAlgorithmTests.cpp similar to its testNonModifiableDesKeyGeneration.

I have added a aesWrapUnwrapNonModifiableGeneric test where the unwrap template sets CKA_UNMODIFIABLE to false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Some isn't right
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CKA_MODIFIABLE must be true to Unwrap AES Key
3 participants