Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored User Keys #282

Merged
merged 18 commits into from
Jun 6, 2024
Merged

Refactored User Keys #282

merged 18 commits into from
Jun 6, 2024

Conversation

overheadhunter
Copy link
Member

@overheadhunter overheadhunter commented May 30, 2024

This PR has changes in three areas:

  1. It changes the data model in order to store an ECDH key (same as before) as well as an ECDSA key (new). New columns are added in our database for the ECDSA public key. No separate column is required for the private key, as it will be added in the JWE that already holds the ECDH key in its payload (existing columns user.privatekeys and device.user_privatekeys; just renamed those).
  2. With userdata.ts, it adds a new facade object to the frontend. The purpose of this object is to channel all requests to /api/me as well as access to user keys and browser keys through a single place. This not only deduplicates some code and allows us to memoize seldom changing objects, it also makes sure we have a single entry point to inspect and interact with the user's key material.
  3. Building upon (2.), if the user DTO doesn't contain any ECDSA key yet, it is created and all objects that contain the user's key material are updated (i.e. the user itself and the user's devices)

One of the sequence diagrams generated by coderabbit was actually quite good. I fetched it from its edit history:

sequenceDiagram
    participant User as User
    participant Frontend as Frontend
    participant UserData as UserData
    participant Backend as Backend

    User ->> Frontend: Create Vault
    Frontend ->> UserData: Get User Data
    UserData ->> Backend: Fetch User Information
    Backend -->> UserData: UserDto
    UserData -->> Frontend: UserDto
    Frontend ->> UserData: Get ECDH Public Key
    UserData -->> Frontend: ECDH Public Key
    Frontend ->> Backend: Create Vault with ECDH Public Key
    Backend -->> Frontend: Vault Created

    User ->> Frontend: Recover Vault
    Frontend ->> UserData: Get User Data
    UserData ->> Backend: Fetch User Information
    Backend -->> UserData: UserDto
    UserData -->> Frontend: UserDto
    Frontend ->> UserData: Decrypt User Keys with Browser
    UserData -->> Frontend: Decrypted User Keys
    Frontend ->> Backend: Recover Vault with User Keys
    Backend -->> Frontend: Vault Recovered
Loading

Copy link

coderabbitai bot commented May 30, 2024

Walkthrough

The recent changes introduce a UserData class in the frontend, centralizing user data management and key handling. This class provides methods for fetching user information, creating browser keys, and decrypting user keys. The frontend components have been refactored to utilize this new class instead of directly interacting with the backend. Additionally, the backend has been updated to use more specific cryptographic key names, enhancing clarity and security.

Changes

Files/Paths Change Summaries
frontend/src/common/userdata.ts Introduced UserData class for managing user data and keys, added several methods for key operations.
frontend/src/components/VaultDetails.vue Refactored to use UserData for fetching user data and decrypting user keys.
frontend/src/components/CreateVault.vue Updated to retrieve user's ECDH public key from UserData instead of directly from the backend.
frontend/src/components/RecoverVaultDialog.vue Changed to use UserData for accessing the ECDH public key during vault recovery.
backend/src/main/java/.../UsersResource.java Renamed cryptographic key variables and updated method calls accordingly. Added updateDevices method.

Poem

In code's vast realm, a rabbit hops with glee,
Refactoring keys with utmost clarity.
From UserData springs a new dawn,
Where vaults are safe and secrets drawn.
Backend whispers, "ECDH, ECDSA,"
While frontend dances, simplifying the way.
Together they weave a secure, bright day. 🌟


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 testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @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.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@overheadhunter overheadhunter requested a review from SailReal May 30, 2024 18:18
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 10

Outside diff range and nitpick comments (8)
frontend/src/router/index.ts (1)

Line range hint 152-152: Consider removing the delete operator to improve performance.

- delete to.query.sync_me;
+ Reflect.deleteProperty(to.query, 'sync_me');
frontend/src/common/backend.ts (6)

Line range hint 164-164: Use template literals for better readability and consistency.

- return axiosAuth.put(`/vaults/${vaultId}/users/${userId}` + (role ? `?role=${role}` : ''))
+ return axiosAuth.put(`/vaults/${vaultId}/users/${userId}${role ? `?role=${role}` : ''}`)
- return axiosAuth.put(`/vaults/${vaultId}/groups/${groupId}` + (role ? `?role=${role}` : ''))
+ return axiosAuth.put(`/vaults/${vaultId}/groups/${groupId}${role ? `?role=${role}` : ''}`)

Also applies to: 169-169


Line range hint 220-220: Specify a more precise type instead of any to enhance type safety.

Please replace any with a more specific type where possible to ensure type safety and better code maintainability.

Also applies to: 225-225, 374-374


Line range hint 235-235: Remove unnecessary type annotation.

The type annotation on this variable is redundant and can be inferred from its initialization.


Line range hint 264-273: Simplify control flow by removing unnecessary else clauses.

- if (condition) {
-   // code
- } else {
-   return;
- }
+ if (condition) {
+   // code
+ }
+ return;

Also applies to: 377-379


Line range hint 1-1: Remove unused imports to clean up the code.

Please remove the unused imports to keep the codebase clean and maintainable.

Also applies to: 1-2, 5-6


Line range hint 152-152: Avoid unnecessary variable reassignments.

Consider initializing these variables directly with their intended values to avoid unnecessary reassignments.

Also applies to: 265-265

backend/src/main/java/org/cryptomator/hub/api/VaultResource.java (1)

Line range hint 339-339: Optimize the process of granting access.

-  const vaultKeyJwe = keys.encryptForUser(base64.parse(me.value.ecdhPublicKey));
-  try {
-    await backend.vaults.grantAccess(props.vaultId, { userId: me.value.id, token: await vaultKeyJwe });
-  } catch (error) {
-    if (error instanceof ConflictError) {
-      console.debug('User already member of this vault.');
-    } else {
-      console.error('Failed to grant access to self.', error);
-    }
-  }
+  try {
+    const vaultKeyJwe = await keys.encryptForUserAndGrantAccess(me.value.ecdhPublicKey, props.vaultId, me.value.id);
+  } catch (error) {
+    console.error('Failed to grant access to self.', error);
+  }

This refactor simplifies the process by moving the encryption and grant access logic into a single method, reducing complexity and potential for errors.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between bc9ab13 and a3196af.

Files ignored due to path filters (1)
  • backend/src/main/resources/org/cryptomator/hub/flyway/ERM.png is excluded by !**/*.png
Files selected for processing (25)
  • backend/src/main/java/org/cryptomator/hub/api/DeviceResource.java (3 hunks)
  • backend/src/main/java/org/cryptomator/hub/api/UserDto.java (1 hunks)
  • backend/src/main/java/org/cryptomator/hub/api/UsersResource.java (4 hunks)
  • backend/src/main/java/org/cryptomator/hub/api/VaultResource.java (1 hunks)
  • backend/src/main/java/org/cryptomator/hub/entities/Device.java (4 hunks)
  • backend/src/main/java/org/cryptomator/hub/entities/User.java (4 hunks)
  • backend/src/main/resources/org/cryptomator/hub/flyway/V15__User_ECDSA.sql (1 hunks)
  • backend/src/test/java/org/cryptomator/hub/api/VaultResourceIT.java (5 hunks)
  • backend/src/test/resources/org/cryptomator/hub/flyway/V9999__Test_Data.sql (2 hunks)
  • frontend/src/common/backend.ts (1 hunks)
  • frontend/src/common/crypto.ts (6 hunks)
  • frontend/src/common/userdata.ts (1 hunks)
  • frontend/src/components/AuthenticatedMain.vue (2 hunks)
  • frontend/src/components/CreateVault.vue (2 hunks)
  • frontend/src/components/DeviceList.vue (2 hunks)
  • frontend/src/components/GrantPermissionDialog.vue (2 hunks)
  • frontend/src/components/InitialSetup.vue (6 hunks)
  • frontend/src/components/ManageSetupCode.vue (2 hunks)
  • frontend/src/components/RecoverVaultDialog.vue (1 hunks)
  • frontend/src/components/RegenerateSetupCodeDialog.vue (2 hunks)
  • frontend/src/components/UnlockSuccess.vue (6 hunks)
  • frontend/src/components/UserProfile.vue (3 hunks)
  • frontend/src/components/VaultDetails.vue (4 hunks)
  • frontend/src/router/index.ts (2 hunks)
  • frontend/test/common/crypto.spec.ts (4 hunks)
Additional context used
Biome
frontend/src/common/userdata.ts

[error] 32-35: This else clause can be omitted because previous branches break early.


[error] 34-34: Use === instead of ==.
== is only allowed when comparing against null


[error] 1-2: Some named imports are only used as types.


[error] 95-95: This let declares a variable that is only assigned once.

frontend/src/router/index.ts

[error] 136-136: The computed expression can be simplified without the use of a string literal.


[error] 152-152: Avoid the delete operator which can impact performance.


[error] 1-1: Some named imports are only used as types.

frontend/src/common/backend.ts

[error] 27-27: The computed expression can be simplified without the use of a string literal.


[error] 164-164: Template literals are preferred over string concatenation.


[error] 169-169: Template literals are preferred over string concatenation.


[error] 220-220: Unexpected any. Specify a different type.


[error] 225-225: Unexpected any. Specify a different type.


[error] 235-235: This type annotation is trivially inferred from its initialization.


[error] 264-273: This else clause can be omitted because previous branches break early.


[error] 374-374: Unexpected any. Specify a different type.


[error] 377-379: This else clause can be omitted because previous branches break early.


[error] 1-1: Some named imports are only used as types.


[error] 1-2: Some named imports are only used as types.


[error] 5-6: All these imports are only used as types.


[error] 152-152: This let declares a variable that is only assigned once.


[error] 265-265: This let declares a variable that is only assigned once.

frontend/test/common/crypto.spec.ts

[error] 34-34: Declare variables separately


[error] 74-74: The computed expression can be simplified without the use of a string literal.


[error] 147-147: The computed expression can be simplified without the use of a string literal.


[error] 244-246: This constructor is unnecessary.


[error] 268-270: This constructor is unnecessary.


[error] 43-43: This let declares a variable that is only assigned once.


[error] 44-44: This let declares a variable that is only assigned once.


[error] 64-64: This let declares a variable that is only assigned once.

frontend/src/common/crypto.ts

[error] 6-6: Unexpected any. Specify a different type.


[error] 8-8: Unexpected any. Specify a different type.


[error] 198-198: Template literals are preferred over string concatenation.


[error] 205-205: Template literals are preferred over string concatenation.


[error] 420-422: This else clause can be omitted because previous branches break early.


[error] 462-464: This else clause can be omitted because previous branches break early.

Additional comments not posted (63)
backend/src/main/resources/org/cryptomator/hub/flyway/V15__User_ECDSA.sql (4)

1-1: Renaming publickey to ecdh_publickey aligns with the new data model requirements.


2-2: Renaming privatekey to privatekeys correctly reflects the storage of multiple keys.


3-3: Adding the ecdsa_publickey column is essential for supporting the new cryptographic functionality.


4-4: Renaming user_privatekey to user_privatekeys in the device table ensures consistency across the database schema.

frontend/src/components/AuthenticatedMain.vue (2)

24-25: Updated imports to use the centralized userdata module enhance maintainability and reduce redundancy.


39-39: Using userdata.me for fetching user data centralizes and simplifies data management in the frontend.

backend/src/main/java/org/cryptomator/hub/api/UserDto.java (3)

17-22: The addition of ecdhPublicKey, ecdsaPublicKey, and the renaming of privateKey to privateKeys are well-annotated and correctly reflect the new cryptographic architecture.


26-28: Maintaining a deprecated publicKey for backward compatibility while transitioning to new key structures is a prudent approach.


31-41: The constructor's update to support new cryptographic fields while maintaining backward compatibility is well-implemented.

backend/src/main/java/org/cryptomator/hub/entities/Device.java (4)

59-60: Updating the field name to userPrivateKeys aligns with the new cryptographic key management approach.


105-110: The updated getter and setter methods for userPrivateKeys ensure consistency with the database schema changes.


129-129: Including userPrivateKeys in the toString method ensures comprehensive logging and debugging capabilities.


144-144: Updating the equals method to include userPrivateKeys ensures accurate equality checks.

frontend/src/components/ManageSetupCode.vue (2)

52-52: Using the centralized userdata module for managing setup codes enhances consistency and maintainability in the frontend architecture.


71-76: Centralizing the retrieval of setup codes through userdata simplifies the management of sensitive data and enhances security.

backend/src/main/java/org/cryptomator/hub/entities/User.java (4)

29-29: Ensure the query condition is correctly updated to use ecdhPublicKey.


52-59: The addition of ecdhPublicKey, ecdsaPublicKey, and privateKeys columns aligns with the PR's objective to handle multiple key types.


80-101: The getter and setter methods for ecdhPublicKey, ecdsaPublicKey, and privateKeys are correctly implemented.


142-150: The equals and hashCode methods have been updated to include the new key fields, ensuring consistency in entity comparison and hash-based collections.

frontend/src/components/UnlockSuccess.vue (4)

2-2: The conditional rendering based on accountState and hasBrowserKeys ensures that the appropriate navigation bar is displayed.


41-41: The router link conditionally displayed based on hasBrowserKeys provides a direct way for users to access their account key if available.


71-71: Importing userdata from ../common/userdata is essential for accessing user-specific data, aligning with the frontend changes described in the PR.


Line range hint 84-132: The computed properties and the fetchData function are well-implemented to handle user setup states and fetch necessary data.

frontend/src/components/UserProfile.vue (2)

57-57: The UserkeyFingerprint component is correctly receiving the ecdhPublicKey as a prop, reflecting the backend changes to user key handling.


71-71: The use of userdata for fetching user details and the correct handling of potential errors in fetchData are in line with the PR's objectives to centralize user data management.

Also applies to: 94-94

frontend/src/router/index.ts (2)

5-5: The import of userdata is crucial for the new user data management strategy described in the PR.


165-174: The new routing guards use userdata to check for user setup and browser keys, ensuring that users are redirected to setup if necessary.

backend/src/main/java/org/cryptomator/hub/api/UsersResource.java (3)

73-75: The update methods for ecdhPublicKey, ecdsaPublicKey, and privateKeys in putMe are correctly implemented to reflect the new key management strategy.


120-122: The getMe method correctly maps device details and includes the new key fields in the UserDto.


134-135: The resetMe method correctly handles the nullification of keys, aligning with security best practices for account resets.

frontend/src/components/RecoverVaultDialog.vue (1)

108-109: The recoverVault method correctly uses the ecdhPublicKey for encryption, aligning with the updated key management system.

frontend/src/components/DeviceList.vue (3)

88-88: Refactored to use userdata for fetching user data.

This change centralizes the data fetching logic, which should help in maintaining and updating the code in the future.


105-106: Refactored to use userdata for fetching user and device data.

This change simplifies the data fetching process by using the userdata module, which is consistent with the PR's objective to centralize user data handling.


117-117: Added call to userdata.reload() after removing a device.

This ensures that the UI is updated with the latest data after a device is removed, maintaining the integrity of the displayed information.

frontend/src/components/GrantPermissionDialog.vue (2)

104-104: Updated to fetch fingerprints using the new ecdhPublicKey.

This change aligns with the updated data model where ecdhPublicKey is used instead of the deprecated publicKey.


127-128: Updated encryption logic to use ecdhPublicKey.

This ensures that the encryption process uses the correct public key format as per the new data model, enhancing security and compatibility.

backend/src/main/java/org/cryptomator/hub/api/DeviceResource.java (2)

104-104: Updated to store userPrivateKeys in the device.

This change is necessary to accommodate the new key management strategy that involves handling multiple keys, aligning with the PR's objectives.


175-180: Refactored DeviceDto to use new key fields.

This update ensures that the device data transfer objects are consistent with the new database schema and the updated key management system.

frontend/src/components/RegenerateSetupCodeDialog.vue (2)

106-106: Refactored to use userdata for user data operations.

This change centralizes user data handling, making the code cleaner and more maintainable.


153-157: Updated to use userdata for key decryption and setup code regeneration.

This ensures that all user key handling is centralized and uses the updated data model, which is crucial for maintaining security and data integrity.

backend/src/test/resources/org/cryptomator/hub/flyway/V9999__Test_Data.sql (2)

17-20: Updated test data to include new key fields (ecdh_publickey, ecdsa_publickey, privatekeys).

This update is necessary to ensure that the test environment reflects the new data model, allowing for accurate testing of the system with the updated key management.


55-55: Updated device test data to include user_privatekeys.

This change aligns the test data with the new database schema, ensuring that tests will accurately reflect the production environment.

frontend/src/common/backend.ts (1)

75-76: Update to UserDto to include ECDSA keys aligns with backend changes.

frontend/test/common/crypto.spec.ts (1)

44-44: Consider using const instead of let for ecdhP384 and ecdsaP384 since these variables are not reassigned.
[REFACTOR_SUGGESTion]

- let ecdhP384: EcKeyImportParams = { name: 'ECDH', namedCurve: 'P-384' };
- let ecdsaP384: EcKeyImportParams = { name: 'ECDSA', namedCurve: 'P-384' };
+ const ecdhP384: EcKeyImportParams = { name: 'ECDH', namedCurve: 'P-384' };
+ const ecdsaP384: EcKeyImportParams = { name: 'ECDSA', namedCurve: 'P-384' };

Also applies to: 43-43

frontend/src/components/InitialSetup.vue (5)

196-196: Refactor to use userdata module for user data management.

This change centralizes user data handling, improving maintainability and consistency across the application.


242-246: Ensure proper handling of user setup states.

The logic correctly handles different states based on the user's setup status, which enhances the user experience by providing clear state management.


261-269: Update user key handling to use new ECDSA keys.

This update aligns with the backend changes for ECDSA key management, ensuring that the frontend correctly handles the new key types.


285-288: Refactor to use userdata for key recovery.

This change simplifies the key recovery process by utilizing the userdata module, which centralizes key management logic.


310-310: Trigger a reload of user data after updating.

Reloading the user data after updates ensures that the UI reflects the most current state, which is crucial for user experience.

frontend/src/common/crypto.ts (6)

36-43: Introduce UserKeyPayload interface with deprecation notice.

This interface update is necessary for transitioning to the new key structure while maintaining backward compatibility.


231-232: Refactor encryption method to support new key types.

This method now supports encryption using either ECDH or ECDSA keys, aligning with the new cryptographic requirements.


263-325: Enhance key management with support for ECDSA.

These changes introduce support for ECDSA keys, which are essential for the new security features in the application.


353-355: Improve encryption with setup code.

This method provides enhanced security by allowing encryption of private keys using a setup code, which is crucial for secure key management.


370-381: Prepare keys for encryption with added security measures.

This method prepares keys for encryption while ensuring that sensitive data is securely handled, which is critical for maintaining data integrity.


459-465: Refactor key import function for clarity and efficiency.

This refactoring improves the clarity and efficiency of the key import process, making the code easier to maintain and understand.

backend/src/main/java/org/cryptomator/hub/api/VaultResource.java (1)

Line range hint 323-323: Validate user initialization before generating JWT.

frontend/src/components/VaultDetails.vue (3)

219-219: Use userdata consistently for user data management.

This line correctly uses the userdata module for managing user data, aligning with the frontend changes described in the PR.


217-217: Ensure VaultKeys is used correctly throughout the component.

Verification successful

The VaultKeys import appears to be used correctly and consistently throughout the VaultDetails.vue component. Here are the relevant usages:

  • Import statement: import { VaultKeys } from '../common/crypto';
  • Declaration: const vaultKeys = ref<VaultKeys>();
  • Assignment: vaultKeys.value = await loadVaultKeys(vaultKeyJwe);
  • Function return type: async function loadVaultKeys(vaultKeyJwe: string): Promise<VaultKeys> {
  • Method call: return VaultKeys.decryptWithUserKey(vaultKeyJwe, userKeys.ecdhKeyPair.privateKey);
  • Function parameter: async function provedOwnership(keys: VaultKeys, ownerKeyPair: CryptoKeyPair) {

These usages indicate that VaultKeys is being utilized as expected within the component.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that `VaultKeys` is used correctly and consistently throughout the component.

# Test: Search for `VaultKeys` usage. Expect: Consistent and correct usage patterns.
rg --type vue $'VaultKeys' ./frontend/src/components/VaultDetails.vue

Length of output: 96



Script:

#!/bin/bash
# Description: Verify that `VaultKeys` is used correctly and consistently throughout the component.

# Test: Search for `VaultKeys` usage. Expect: Consistent and correct usage patterns.
rg 'VaultKeys' ./frontend/src/components/VaultDetails.vue

Length of output: 431


323-323: Check user initialization before generating JWT.

backend/src/test/java/org/cryptomator/hub/api/VaultResourceIT.java (4)

449-449: Update SQL query to reflect new column names.

The SQL update statement correctly reflects the new column names (ecdh_publickey, ecdsa_publickey, privatekeys) as per the PR's objectives to handle cryptographic keys more securely.


562-562: Insert test data to simulate user and group membership.

The SQL insert statement correctly adds test data for user999 with the necessary cryptographic details. This setup is essential for testing the new cryptographic key management features introduced in the PR.


503-503: Ensure proper cleanup of test modifications.

This script checks if the cleanup SQL query effectively removes all test modifications related to user2. It's crucial to ensure that test data does not persist in the database after tests are completed.

Verification successful

The occurrences of 'user2' in the V9999__Test_Data.sql file are part of the initial test data setup and do not indicate a failure in the cleanup process.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the cleanup SQL query correctly resets the changes made for testing.

# Test: Search for any remaining test data that should have been cleaned up. Expect: No occurrences of test data.
rg --type sql $'user2'

Length of output: 2448


461-461: Ensure proper cleanup of test modifications.

This script checks if the cleanup SQL query effectively removes all test modifications related to user2. It's crucial to ensure that test data does not persist in the database after tests are completed.

frontend/test/common/crypto.spec.ts Show resolved Hide resolved
frontend/test/common/crypto.spec.ts Outdated Show resolved Hide resolved
frontend/src/components/CreateVault.vue Show resolved Hide resolved
frontend/src/components/VaultDetails.vue Outdated Show resolved Hide resolved
frontend/src/components/VaultDetails.vue Show resolved Hide resolved
frontend/src/common/userdata.ts Outdated Show resolved Hide resolved
frontend/src/common/userdata.ts Outdated Show resolved Hide resolved
frontend/src/common/userdata.ts Show resolved Hide resolved
Copy link
Member

@SailReal SailReal left a comment

Choose a reason for hiding this comment

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

LGTM 👍, just a minor change.

frontend/test/common/crypto.spec.ts Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 7

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a3196af and e757bdd.

Files selected for processing (2)
  • frontend/src/common/userdata.ts (1 hunks)
  • frontend/test/common/crypto.spec.ts (4 hunks)
Files not reviewed due to errors (1)
  • frontend/test/common/crypto.spec.ts (no review received)
Additional context used
Biome
frontend/src/common/userdata.ts

[error] 32-35: This else clause can be omitted because previous branches break early.


[error] 1-2: Some named imports are only used as types.

frontend/test/common/crypto.spec.ts

[error] 34-34: Declare variables separately


[error] 74-74: The computed expression can be simplified without the use of a string literal.


[error] 147-147: The computed expression can be simplified without the use of a string literal.


[error] 244-246: This constructor is unnecessary.


[error] 268-270: This constructor is unnecessary.


[error] 43-43: This let declares a variable that is only assigned once.


[error] 44-44: This let declares a variable that is only assigned once.


[error] 64-64: This let declares a variable that is only assigned once.

Additional comments not posted (3)
frontend/src/common/userdata.ts (3)

104-105: Ensure correct usage of default exports.

Verify that the default export of the UserData instance is correctly used throughout the project to maintain consistency and avoid potential issues with module resolution.


11-16: Ensure proper error handling in me method.

Consider adding error handling for the backend call in the me method to manage scenarios where the user data cannot be fetched due to network issues or server errors.


52-62: Enhance security in decryptUserKeysWithSetupCode method.

Ensure that the decryptUserKeysWithSetupCode method securely handles the setup code and does not expose it in logs or error messages.

Verification successful

The decryptUserKeysWithSetupCode method does not appear to log or expose the setup code directly. However, to ensure comprehensive security practices, it is important to verify that the setup code is not logged or exposed elsewhere in the codebase.


The search results indicate that the setupCode is used in various parts of the codebase, but there is no evidence of it being logged or exposed in error messages. The setupCode is primarily used for encryption and decryption purposes, which is appropriate.

  • frontend/src/common/userdata.ts: The setupCode is used in the decryptUserKeysWithSetupCode method and other related methods without being logged.
  • frontend/src/common/crypto.ts: The setupCode is used in encryption and decryption methods without being logged.

Based on the gathered information, the setupCode is handled securely and is not exposed in logs or error messages.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify security handling in `decryptUserKeysWithSetupCode` method.

# Test: Search for security practices in the `decryptUserKeysWithSetupCode` method. Expect: Security code.
rg --type typescript $'decryptUserKeysWithSetupCode\\(\\) {'

Length of output: 191



Script:

#!/bin/bash
# Description: Verify security handling in `decryptUserKeysWithSetupCode` method.

# Test: Search for security practices in the `decryptUserKeysWithSetupCode` method. Expect: Security code.
rg --type typescript 'decryptUserKeysWithSetupCode\(\) {'

Length of output: 191



Script:

#!/bin/bash
# Description: Verify security handling in `decryptUserKeysWithSetupCode` method.

# Test: Search for security practices in the `decryptUserKeysWithSetupCode` method. Expect: Security code.
rg --type typescript 'decryptUserKeysWithSetupCode' --context 10

Length of output: 99



Script:

#!/bin/bash
# Description: Verify security handling in `decryptUserKeysWithSetupCode` method.

# Test: Search for security practices in the `decryptUserKeysWithSetupCode` method. Expect: Security code.
rg --type ts 'decryptUserKeysWithSetupCode' --context 10

Length of output: 1532



Script:

#!/bin/bash
# Description: Verify that the setup code is not logged or exposed elsewhere in the codebase.

# Test: Search for any logging or error handling that might expose the setup code.
rg 'setupCode' --type ts --context 5

Length of output: 6614

frontend/src/common/userdata.ts Outdated Show resolved Hide resolved
frontend/src/common/userdata.ts Show resolved Hide resolved
frontend/src/common/userdata.ts Outdated Show resolved Hide resolved
frontend/src/common/userdata.ts Outdated Show resolved Hide resolved
frontend/src/common/userdata.ts Outdated Show resolved Hide resolved
frontend/src/common/userdata.ts Show resolved Hide resolved
frontend/src/common/userdata.ts Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e757bdd and a4aa396.

Files selected for processing (4)
  • frontend/src/common/userdata.ts (1 hunks)
  • frontend/src/components/CreateVault.vue (2 hunks)
  • frontend/src/components/RecoverVaultDialog.vue (3 hunks)
  • frontend/src/components/VaultDetails.vue (4 hunks)
Files skipped from review as they are similar to previous changes (3)
  • frontend/src/components/CreateVault.vue
  • frontend/src/components/RecoverVaultDialog.vue
  • frontend/src/components/VaultDetails.vue
Additional context used
Biome
frontend/src/common/userdata.ts

[error] 67-69: This else clause can be omitted because previous branches break early.


[error] 1-2: Some named imports are only used as types.

Additional comments not posted (6)
frontend/src/common/userdata.ts (6)

67-69: Simplify the ecdsaPublicKey getter by removing unnecessary else clause.
[REFACTOR_SUGGESTion]

-      } else {
-        return undefined;
-      }

14-18: The implementation of caching in the me getter method looks good.


24-29: The caching logic in the browserKeys getter method is correctly implemented.


36-41: The implementation of the browser getter method correctly handles asynchronous operations and potential undefined values.


76-79: The reload method correctly handles the invalidation and reloading of cached data. The concerns about synchronization were addressed in previous discussions.


86-92: The createBrowserKeys method is implemented correctly, and the decision to let consumers handle errors is justified given the context.

frontend/src/common/userdata.ts Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a4aa396 and 4341910.

Files selected for processing (2)
  • backend/src/main/java/org/cryptomator/hub/api/UsersResource.java (4 hunks)
  • frontend/src/common/userdata.ts (1 hunks)
Additional context used
Biome
frontend/src/common/userdata.ts

[error] 67-69: This else clause can be omitted because previous branches break early.


[error] 1-2: Some named imports are only used as types.

Additional comments not posted (1)
backend/src/main/java/org/cryptomator/hub/api/UsersResource.java (1)

73-75: Ensure that the new ECDSA key handling is secure and correctly implemented.

Given the sensitivity of cryptographic key handling, it's crucial to ensure that the implementation adheres to best practices for security, such as avoiding logging sensitive data and ensuring keys are transmitted securely.

frontend/src/common/userdata.ts Outdated Show resolved Hide resolved
frontend/src/common/userdata.ts Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4341910 and 6da692e.

Files selected for processing (2)
  • backend/src/main/java/org/cryptomator/hub/api/UsersResource.java (4 hunks)
  • frontend/src/common/userdata.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • backend/src/main/java/org/cryptomator/hub/api/UsersResource.java
Additional context used
Biome
frontend/src/common/userdata.ts

[error] 1-2: Some named imports are only used as types.

Additional comments not posted (1)
frontend/src/common/userdata.ts (1)

1-2: Use explicit type imports for TypeScript.

To clarify that certain imports are only used for type information, which can help during the TypeScript compilation process.

- import backend, { DeviceDto, UserDto } from './backend';
+ import backend from './backend';
+ import type { DeviceDto, UserDto } from './backend';

Likely invalid or redundant comment.

frontend/src/common/userdata.ts Show resolved Hide resolved
frontend/src/common/userdata.ts Show resolved Hide resolved
frontend/src/common/userdata.ts Show resolved Hide resolved
frontend/src/common/userdata.ts Show resolved Hide resolved
frontend/src/common/userdata.ts Show resolved Hide resolved
@overheadhunter overheadhunter requested a review from SailReal June 1, 2024 16:12
Copy link
Member

@SailReal SailReal left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@overheadhunter overheadhunter merged commit 645c013 into develop Jun 6, 2024
4 checks passed
@overheadhunter overheadhunter deleted the feature/refactored-user-keys branch June 6, 2024 07:34
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.

2 participants