Skip to content

Add Touch ID - #36

Closed
purejava wants to merge 5 commits into
cryptomator:developfrom
purejava:2ndfactor-SecItem
Closed

purejava wants to merge 5 commits into
cryptomator:developfrom
purejava:2ndfactor-SecItem

Conversation

@purejava

@purejava purejava commented Feb 15, 2024 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features
    • Introduced macOS keychain integration for securely managing passphrases.
    • Added functionality to add, retrieve, and delete items from the macOS keychain.
  • Refactor
    • Improved macOS keychain operations with enhanced logging and internal method optimizations.
  • Tests
    • Updated tests for macOS keychain access to use direct assertions.

@coderabbitai

coderabbitai Bot commented Feb 15, 2024 •

Copy link
Copy Markdown
Contributor

Walkthrough

This 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 com.sun.jna library, developing a new interface and its implementation for keychain interactions, adjusting the native Xcode project settings, and refining the testing approach to align with these changes.

Changes

File Path Change Summary
module-info.java Added requires com.sun.jna directive.
.../macos/keychain/MacSystemKeychain.java New interface for macOS keychain interactions.
.../macos/keychain/MacSystemKeychainAccess.java Enhanced keychain operations using NATIVELIB, added logging and constants.
.../native/Integrations.xcodeproj/project.pbxproj Removed reference to org_cryptomator_macos_keychain_MacKeychain_Native.m.
.../native/MacSystemKeychain.xcodeproj/... Introduced Xcode project and workspace for MacSystemKeychain library.
.../native/MacSystemKeychain/MacSystemKeychain.entitlements Defined keychain access groups.
.../native/MacSystemKeychain/MacSystemKeychain.h, MacSystemKeychain.m Functions for keychain item management.
.../macos/keychain/MacSystemKeychainAccessTest.java Refactored tests to use Assertions, adjusted for direct interaction with MacSystemKeychainAccess.

🐰✨

In the land of code and digital keys,
A rabbit hopped with grace and ease.
It twirled and leaped through macOS gates,
Securing secrets, sealing fates.
With every hop, a passphrase set,
In keychain's keep, no need to fret.
🌟🔐 "Safe and sound," it softly said,
As moonlit bytes danced overhead.
🐰✨

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>.
    • Generate unit-tests for this file.
  • 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 tests 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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 8

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 9afdcad and 129a122.
Files ignored due to path filters (1)
  • pom.xml is 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.jna as 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.m from 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.

Comment on lines +41 to +43
var errorCode = NATIVELIB.addItemToKeychain(SERVICE_NAME, key, passphrase.toString());
if (errorCode != OSSTATUS_SUCCESS) {
throw new KeychainAccessException("Failed to store password. Error code " + errorCode);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Suggested change
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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Suggested change
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());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Suggested change
Assertions.assertSame(e, thrown.getMessage());
Assertions.assertEquals(e.getMessage(), thrown.getMessage());

});
Assertions.assertSame(thrown, e);

Assertions.assertSame(e, thrown.getMessage());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Suggested change
Assertions.assertSame(e, thrown.getMessage());
Assertions.assertEquals(e.getMessage(), thrown.getMessage());

keychainAccess.changePassphrase("key", "newpass");
keychainAccess.changePassphrase("key", "displayName", "newpass");
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Suggested change

if (status == errSecSuccess) {
NSLog(@"Item added to keychain successfully.");
} else {
NSLog(@"Error adding item to keychain. Status code: %d", (int)status);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Suggested change
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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Suggested change
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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Suggested change
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]);

@purejava

Copy link
Copy Markdown
Contributor Author

Discarding this, as a JNI approach is preferred over this JNA approach.

@purejava purejava closed this May 26, 2024
@purejava
purejava deleted the 2ndfactor-SecItem branch May 26, 2024 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant