-
Notifications
You must be signed in to change notification settings - Fork 2
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
Widen API to allow storing keychain entries for an authenticated user #53
Widen API to allow storing keychain entries for an authenticated user #53
Conversation
WalkthroughThe changes enhance password management within the Mac Keychain by introducing a new parameter for OS authentication in the Changes
Possibly related PRs
Suggested reviewers
Recent review detailsConfiguration used: CodeRabbit UI Files selected for processing (1)
Additional comments not posted (1)
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (5)
- pom.xml (1 hunks)
- src/main/headers/org_cryptomator_macos_keychain_MacKeychain_Native.h (1 hunks)
- src/main/java/org/cryptomator/macos/keychain/MacKeychain.java (2 hunks)
- src/main/java/org/cryptomator/macos/keychain/MacSystemKeychainAccess.java (1 hunks)
- src/main/native/org_cryptomator_macos_keychain_MacKeychain_Native.m (3 hunks)
Additional comments not posted (10)
src/main/headers/org_cryptomator_macos_keychain_MacKeychain_Native.h (1)
18-24
: New JNI method declaration added.The new method
storePasswordForAuthenticatedUser
has been correctly added following the JNI conventions. Ensure that the corresponding implementation is correctly defined in the native code.src/main/java/org/cryptomator/macos/keychain/MacSystemKeychainAccess.java (1)
42-45
: New methodstorePassphraseForAuthenticatedUser
added.The new method
storePassphraseForAuthenticatedUser
integrates well with the existing code. It correctly calls the corresponding method in theMacKeychain
class and throws aKeychainAccessException
if an error occurs.src/main/java/org/cryptomator/macos/keychain/MacKeychain.java (2)
37-47
: New methodstorePassphraseForAuthenticatedUser
added.The new method
storePassphraseForAuthenticatedUser
is well-integrated with the existing code. It correctly handles the conversion of the password to a byte array, calls the native method, and handles potential errors by throwing aKeychainAccessException
. The use ofArrays.fill
to clear sensitive data from memory is a good security practice.
128-129
: New native method declaration added.The new native method
storePasswordForAuthenticatedUser
has been correctly added. Ensure that the corresponding implementation is correctly defined in the native code.src/main/native/org_cryptomator_macos_keychain_MacKeychain_Native.m (5)
16-22
: LGTM! Singleton pattern forLAContext
.The
getSharedLAContext
function correctly implements a singleton pattern forLAContext
, ensuring that only one instance is created and reused.
24-35
: LGTM! Access control creation.The
createAccessControl
function correctly creates aSecAccessControlRef
with thekSecAccessControlUserPresence
flag, ensuring that user presence is required for accessing the stored password.
124-139
: LGTM! Secure password loading with authentication.The
Java_org_cryptomator_macos_keychain_MacKeychain_00024Native_loadPassword
function correctly includeskSecUseAuthenticationContext
in the query dictionary, ensuring that authentication is required for loading passwords.
163-173
: LGTM! Secure password deletion with authentication.The
Java_org_cryptomator_macos_keychain_MacKeychain_00024Native_deletePassword
function correctly includeskSecUseAuthenticationContext
in the query dictionary, ensuring that authentication is required for deleting passwords.
79-123
: LGTM! Secure password storage with authentication.The
Java_org_cryptomator_macos_keychain_MacKeychain_00024Native_storePasswordForAuthenticatedUser
function correctly integrates local authentication usingsharedContext
and handles both updating existing entries and adding new ones in the keychain.Ensure that the function is used correctly in the codebase.
pom.xml (1)
33-33
: Verify the compatibility and stability of the new API version.The API version has been updated from
1.3.1
to1.4.0-SNAPSHOT
. Snapshot versions may introduce new features or fixes but could also be unstable. Ensure compatibility and stability with the rest of the codebase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Outside diff range, codebase verification and nitpick comments (3)
src/main/headers/org_cryptomator_macos_keychain_MacKeychain_Native.h (1)
13-16
: Missing JNI Implementation forstorePassword
MethodThe JNI method
Java_org_cryptomator_macos_keychain_MacKeychain_00024Native_storePassword
is declared in the header file but lacks an implementation in the C source files. This needs to be addressed to ensure the method functions correctly. On the Java side, all invocations ofstorePassword
have been correctly updated to pass the newjboolean
parameter.
- Ensure the JNI method is implemented in the C source files.
Analysis chain
Verify JNI implementation and calling code.
The
storePassword
method signature has been updated to include ajboolean
parameter. Ensure that the JNI implementation is updated accordingly and that all Java code invoking this method is adjusted to pass the new parameter.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify JNI implementation and calling code for `storePassword`. # Test: Search for the JNI implementation. Expect: Implementation matches the new signature. rg --type c 'Java_org_cryptomator_macos_keychain_MacKeychain_00024Native_storePassword' # Test: Search for Java code invoking `storePassword`. Expect: All invocations pass the new parameter. rg --type java 'storePassword('Length of output: 366
Script:
#!/bin/bash # Corrected script to verify JNI implementation and calling code for `storePassword`. # Test: Search for the JNI implementation. Expect: Implementation matches the new signature. rg --type c 'Java_org_cryptomator_macos_keychain_MacKeychain_00024Native_storePassword' --context 5 # Test: Search for Java code invoking `storePassword`. Expect: All invocations pass the new parameter. rg --type java 'storePassword\(' --context 2Length of output: 7585
src/test/java/org/cryptomator/macos/keychain/MacKeychainTest.java (1)
20-20
: Add test cases forstorePassword
withtrue
parameter.Currently, all test cases for
storePassword
usefalse
as the boolean parameter. To ensure comprehensive testing, add test cases that cover scenarios withtrue
for the boolean parameter.
src/test/java/org/cryptomator/macos/keychain/MacKeychainTest.java
src/test/java/org/cryptomator/macos/keychain/MacSystemKeychainAccessTest.java
Analysis chain
Ensure test coverage for new functionality.
The
storePassword
method now includes afalse
parameter. Verify that test cases cover scenarios with different values for this parameter to ensure comprehensive testing of the new functionality.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify test coverage for `storePassword` with different boolean parameter values. # Test: Search for test cases invoking `storePassword`. Expect: Test cases cover different boolean values. rg --type java 'storePassword('Length of output: 112
Script:
#!/bin/bash # Description: Verify test coverage for `storePassword` with different boolean parameter values. # Test: Search for test cases invoking `storePassword`. Expect: Test cases cover different boolean values. rg --type java 'storePassword\('Length of output: 1917
src/main/java/org/cryptomator/macos/keychain/MacSystemKeychainAccess.java (1)
65-65
: ClarifychangePassphrase
behavior.The
changePassphrase
method now explicitly passesfalse
forrequireOsAuthentication
. Ensure this behavior is documented and aligns with the intended security requirements.Consider adding documentation to clarify the behavior and rationale for not requiring OS authentication during passphrase changes.
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (6)
- src/main/headers/org_cryptomator_macos_keychain_MacKeychain_Native.h (1 hunks)
- src/main/java/org/cryptomator/macos/keychain/MacKeychain.java (3 hunks)
- src/main/java/org/cryptomator/macos/keychain/MacSystemKeychainAccess.java (2 hunks)
- src/main/native/org_cryptomator_macos_keychain_MacKeychain_Native.m (4 hunks)
- src/test/java/org/cryptomator/macos/keychain/MacKeychainTest.java (1 hunks)
- src/test/java/org/cryptomator/macos/keychain/MacSystemKeychainAccessTest.java (3 hunks)
Additional comments not posted (10)
src/main/java/org/cryptomator/macos/keychain/MacSystemKeychainAccess.java (1)
38-39
: Verify logic forrequireOsAuthentication
.The
storePassphrase
method now includes arequireOsAuthentication
parameter. Ensure that the logic correctly handles this parameter and aligns with the intended functionality.Verification successful
Logic for
requireOsAuthentication
is correctly implemented.The
storePassphrase
method correctly handles therequireOsAuthentication
parameter by passing it to thestorePassword
method. This logic is thoroughly tested in theMacSystemKeychainAccessTest
class, ensuring it functions as intended. No issues were found.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify logic for handling `requireOsAuthentication` in `storePassphrase`. # Test: Search for logic handling `requireOsAuthentication`. Expect: Logic aligns with intended functionality. rg --type java 'storePassphrase('Length of output: 118
Script:
#!/bin/bash # Description: Verify logic for handling `requireOsAuthentication` in `storePassphrase`. # Test: Search for logic handling `requireOsAuthentication`. Expect: Logic aligns with intended functionality. rg --type java 'storePassphrase\(' -A 5Length of output: 3102
src/test/java/org/cryptomator/macos/keychain/MacSystemKeychainAccessTest.java (4)
34-34
: LGTM! Test method updated correctly.The
storePassword
method now includes theoverwrite
parameter, and the test reflects this change accurately.
41-44
: LGTM! Exception handling updated correctly.The test method now verifies the updated
storePassword
signature, ensuring proper exception handling.
96-96
: LGTM! Test method updated correctly.The
storePassword
method now includes theoverwrite
parameter, and the test reflects this change accurately.
106-106
: LGTM! Test method updated correctly.The test ensures that
storePassword
is not called when the password is not found, reflecting the updated method signature.src/main/java/org/cryptomator/macos/keychain/MacKeychain.java (2)
79-79
: LGTM! Migration logic updated correctly.The
storePassword
call now includesfalse
forrequireOsAuthentication
, ensuring no authentication is required during migration.
20-30
: LGTM! Method signature and documentation updated correctly.The
storePassword
method now includes therequireOsAuthentication
parameter, and the documentation accurately reflects this change. The parameter is correctly passed to the native method.Ensure that the native method implementation handles this parameter correctly.
Verification successful
Native Method Correctly Handles
requireOsAuthentication
ParameterThe native method
storePassword
insrc/main/native/org_cryptomator_macos_keychain_MacKeychain_Native.m
properly utilizes therequireOsAuthentication
parameter. It is used in a conditional block to manage authentication logic, confirming its correct integration into the method.
- File:
src/main/native/org_cryptomator_macos_keychain_MacKeychain_Native.m
- Line: Conditional use of
requireOsAuthentication
found.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that the native method implementation handles the `requireOsAuthentication` parameter correctly. # Test: Search for the native method implementation. Expect: Correct handling of the new parameter. ast-grep --lang objc --pattern $'JNIEXPORT jint JNICALL Java_org_cryptomator_macos_keychain_MacKeychain_00024Native_storePassword(JNIEnv *env, jobject thisObj, jbyteArray service, jbyteArray key, jbyteArray password, jboolean requireOsAuthentication) { $$$ }'Length of output: 371
Script:
#!/bin/bash # Search for the native method implementation in C/C++ or Objective-C files rg 'JNIEXPORT jint JNICALL Java_org_cryptomator_macos_keychain_MacKeychain_00024Native_storePassword' --type c --type cpp --type objc -A 10Length of output: 2692
src/main/native/org_cryptomator_macos_keychain_MacKeychain_Native.m (3)
16-22
: LGTM! Efficient initialization of LAContext.The
getSharedLAContext
function usesdispatch_once
for thread-safe, one-time initialization ofLAContext
.
24-35
: LGTM! Access control setup enhances security.The
createAccessControl
function correctly sets up access control to require user presence, enhancing security.
Line range hint
37-95
:
LGTM! Native method updated for OS-level authentication.The
storePassword
native method correctly integratesLAContext
to handle therequireOsAuthentication
parameter, ensuring authentication is required when specified.
@purejava I released integrations-api:1.4.0-beta3. Can you update your branch, such that we can run it on the CI? |
@infeo Sure. Done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- pom.xml (1 hunks)
Additional comments not posted (1)
pom.xml (1)
33-33
: Consider verifying compatibility with the beta API version.The
api.version
has been updated to1.4.0-beta3
, which is a beta release. While this may introduce new features or fixes, it could also imply potential instability. Ensure that the application is compatible with this version and thoroughly tested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! To be honest, I just did some reformattings and refactorings to keep the diff small. I'm not sure if I've introduced any bugs. Please re-test before merging. 😉
@purejava Do you want to do the honor? |
Thanks for the overhaul @tobihagemann. I made a review reading the refactorings and tested the new commits. LGTM! |
😄 Definitely! Done. LGTM. |
Belongs to cryptomator/cryptomator#3311