Repository navigation
Add Touch ID - #36
Add Touch ID #36purejava wants to merge 5 commits into
Conversation
WalkthroughThis update introduces integration with the macOS system keychain to the Cryptomator project, allowing the application to securely store, retrieve, and manage passphrase entries directly within the macOS keychain. It involves adding support for the Changes
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 as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Review Status
Actionable comments generated: 8
Configuration used: CodeRabbit UI
Files ignored due to path filters (1)
pom.xmlis excluded by:!**/*.xml
Files selected for processing (11)
- src/main/java/module-info.java (1 hunks)
- src/main/java/org/cryptomator/macos/keychain/MacSystemKeychain.java (1 hunks)
- src/main/java/org/cryptomator/macos/keychain/MacSystemKeychainAccess.java (4 hunks)
- src/main/native/Integrations.xcodeproj/project.pbxproj (2 hunks)
- src/main/native/MacSystemKeychain.xcodeproj/project.pbxproj (1 hunks)
- src/main/native/MacSystemKeychain.xcodeproj/project.xcworkspace/contents.xcworkspacedata (1 hunks)
- src/main/native/MacSystemKeychain.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist (1 hunks)
- src/main/native/MacSystemKeychain/MacSystemKeychain.entitlements (1 hunks)
- src/main/native/MacSystemKeychain/MacSystemKeychain.h (1 hunks)
- src/main/native/MacSystemKeychain/MacSystemKeychain.m (1 hunks)
- src/test/java/org/cryptomator/macos/keychain/MacSystemKeychainAccessTest.java (2 hunks)
Additional comments: 8
src/main/native/MacSystemKeychain.xcodeproj/project.xcworkspace/contents.xcworkspacedata (1)
- 1-7: The workspace configuration is minimal and correct for an Xcode project.
src/main/native/MacSystemKeychain.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist (1)
- 1-8: The IDEWorkspaceChecks.plist file correctly suppresses the 32-bit warning for Xcode, which is necessary for macOS development.
src/main/native/MacSystemKeychain/MacSystemKeychain.entitlements (1)
- 1-10: The entitlements file correctly specifies the keychain access group, which is essential for the app's security and functionality.
src/main/java/org/cryptomator/macos/keychain/MacSystemKeychain.java (1)
- 1-12: The interface definition for MacSystemKeychain is correctly defined and follows Java conventions for naming and method signatures.
src/main/native/MacSystemKeychain/MacSystemKeychain.h (1)
- 1-24: The header file correctly declares the native methods and the createAccessControl function, following Objective-C and C conventions.
src/main/java/module-info.java (1)
- 15-15: The addition of
com.sun.jnaas a module requirement is correctly implemented to enable Java Native Access, which is necessary for the Touch ID integration.src/main/native/MacSystemKeychain.xcodeproj/project.pbxproj (1)
- 1-308: The project configuration in project.pbxproj appears to be correctly set up for building a dynamic library, including the correct deployment target and code signing settings.
src/main/native/Integrations.xcodeproj/project.pbxproj (1)
- 8-13: > 📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [1-1]
Verify the removal of
org_cryptomator_macos_keychain_MacKeychain_Native.mfrom the project does not impact the build process or the integration of Touch ID functionality. Ensure all dependencies and references to this file in the project are appropriately updated or removed.
| var errorCode = NATIVELIB.addItemToKeychain(SERVICE_NAME, key, passphrase.toString()); | ||
| if (errorCode != OSSTATUS_SUCCESS) { | ||
| throw new KeychainAccessException("Failed to store password. Error code " + errorCode); |
There was a problem hiding this comment.
Ensure proper error handling and logging for different error codes returned by addItemToKeychain to provide more detailed diagnostics.
if (errorCode != OSSTATUS_SUCCESS) {
- throw new KeychainAccessException("Failed to store password. Error code " + errorCode);
+ LOG.error("Failed to store password. Error code: {}", errorCode);
+ throw new KeychainAccessException("Failed to store password. Error code: " + errorCode);
}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.
| var errorCode = NATIVELIB.addItemToKeychain(SERVICE_NAME, key, passphrase.toString()); | |
| if (errorCode != OSSTATUS_SUCCESS) { | |
| throw new KeychainAccessException("Failed to store password. Error code " + errorCode); | |
| var errorCode = NATIVELIB.addItemToKeychain(SERVICE_NAME, key, passphrase.toString()); | |
| if (errorCode != OSSTATUS_SUCCESS) { | |
| LOG.error("Failed to store password. Error code: {}", errorCode); | |
| throw new KeychainAccessException("Failed to store password. Error code " + errorCode); |
| } else if (errorCode == OSSTATUS_NOT_FOUND) { | ||
| LOG.debug("Password was not deleted"); | ||
| } else { | ||
| throw new KeychainAccessException("Failed to delete password. Error code " + errorCode); |
There was a problem hiding this comment.
Consider handling specific error codes in deleteItemFromKeychain method to provide more detailed diagnostics and error handling.
} else {
+ LOG.error("Failed to delete password. Error code: {}", errorCode);
throw new KeychainAccessException("Failed to delete password. Error code " + errorCode);
}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.
| throw new KeychainAccessException("Failed to delete password. Error code " + errorCode); | |
| } else { | |
| LOG.error("Failed to delete password. Error code: {}", errorCode); | |
| throw new KeychainAccessException("Failed to delete password. Error code " + errorCode); | |
| } |
| }); | ||
| Assertions.assertSame(thrown, e); | ||
|
|
||
| Assertions.assertSame(e, thrown.getMessage()); |
There was a problem hiding this comment.
Incorrect use of assertSame for comparing exception messages. Use assertEquals to compare the content of strings.
- Assertions.assertSame(e, thrown.getMessage());
+ Assertions.assertEquals(e.getMessage(), thrown.getMessage());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.
| Assertions.assertSame(e, thrown.getMessage()); | |
| Assertions.assertEquals(e.getMessage(), thrown.getMessage()); |
| }); | ||
| Assertions.assertSame(thrown, e); | ||
|
|
||
| Assertions.assertSame(e, thrown.getMessage()); |
There was a problem hiding this comment.
Incorrect use of assertSame for comparing exception messages in testDeleteError. Use assertEquals for string comparison.
- Assertions.assertSame(e, thrown.getMessage());
+ Assertions.assertEquals(e.getMessage(), thrown.getMessage());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.
| Assertions.assertSame(e, thrown.getMessage()); | |
| Assertions.assertEquals(e.getMessage(), thrown.getMessage()); |
| keychainAccess.changePassphrase("key", "newpass"); | ||
| keychainAccess.changePassphrase("key", "displayName", "newpass"); | ||
| }); | ||
|
|
There was a problem hiding this comment.
Incorrect assertion in testChangeError. Use assertEquals to compare exception messages.
- Assertions.assertSame(thrown, e);
+ Assertions.assertEquals(e.getMessage(), thrown.getMessage());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.
| if (status == errSecSuccess) { | ||
| NSLog(@"Item added to keychain successfully."); | ||
| } else { | ||
| NSLog(@"Error adding item to keychain. Status code: %d", (int)status); |
There was a problem hiding this comment.
Consider handling specific error codes in addItemToKeychain to provide more detailed diagnostics and error handling.
} else {
+ NSLog(@"Error adding item to keychain. Status code: %d, Service: %@, Key: %@", (int)status, [NSString stringWithCString:kServiceName encoding:NSUTF8StringEncoding], [NSString stringWithCString:key encoding:NSUTF8StringEncoding]);
}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.
| NSLog(@"Error adding item to keychain. Status code: %d", (int)status); | |
| NSLog(@"Error adding item to keychain. Status code: %d, Service: %@, Key: %@", (int)status, [NSString stringWithCString:kServiceName encoding:NSUTF8StringEncoding], [NSString stringWithCString:key encoding:NSUTF8StringEncoding]); |
| } else if (status == errSecItemNotFound) { | ||
| NSLog(@"No matching item found in the keychain."); | ||
| } else { | ||
| NSLog(@"Error retrieving item from keychain. Status code: %d", (int)status); |
There was a problem hiding this comment.
Consider handling specific error codes in getItemFromKeychain to provide more detailed diagnostics and error handling.
} else {
+ NSLog(@"Error retrieving item from keychain. Status code: %d, Service: %@, Key: %@", (int)status, [NSString stringWithCString:kServiceName encoding:NSUTF8StringEncoding], [NSString stringWithCString:key encoding:NSUTF8StringEncoding]);
}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.
| NSLog(@"Error retrieving item from keychain. Status code: %d", (int)status); | |
| NSLog(@"Error retrieving item from keychain. Status code: %d, Service: %@, Key: %@", (int)status, [NSString stringWithCString:kServiceName encoding:NSUTF8StringEncoding], [NSString stringWithCString:key encoding:NSUTF8StringEncoding]); |
| } else if (status == errSecItemNotFound) { | ||
| NSLog(@"No matching item found in the keychain."); | ||
| } else { | ||
| NSLog(@"Error deleting item from keychain. Status code: %d", (int)status); |
There was a problem hiding this comment.
Consider handling specific error codes in deleteItemFromKeychain to provide more detailed diagnostics and error handling.
} else {
+ NSLog(@"Error deleting item from keychain. Status code: %d, Service: %@, Key: %@", (int)status, [NSString stringWithCString:kServiceName encoding:NSUTF8StringEncoding], [NSString stringWithCString:key encoding:NSUTF8StringEncoding]);
}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.
| NSLog(@"Error deleting item from keychain. Status code: %d", (int)status); | |
| NSLog(@"Error deleting item from keychain. Status code: %d, Service: %@, Key: %@", (int)status, [NSString stringWithCString:kServiceName encoding:NSUTF8StringEncoding], [NSString stringWithCString:key encoding:NSUTF8StringEncoding]); |
|
Discarding this, as a JNI approach is preferred over this JNA approach. |
Summary by CodeRabbit