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

Hub 1.2.x → Hub 1.3.x Legacy Device Migration #3291

Merged
merged 9 commits into from
Feb 2, 2024

Conversation

overheadhunter
Copy link
Member

@overheadhunter overheadhunter commented Jan 20, 2024

This adds a new subroutine during Device Registration, which attempts to migrate existing access tokens by re-encrypting them for the authenticated user.

Legacy Device Migration

Summary by CodeRabbit

  • New Features

    • Enhanced key loading process with new encryption and decryption capabilities.
    • Implemented a more efficient URI resolving system for internal API calls.
  • Bug Fixes

    • Replaced deprecated encoding method with a standard Base64 decoder for better reliability.
  • Refactor

    • Streamlined URI construction across different modules for consistency.
  • Tests

    • Added comprehensive tests for new encryption and decryption methods.
  • Documentation

    • Updated method documentation to reflect new encryption and decryption processes.

Copy link

coderabbitai bot commented Jan 20, 2024

Walkthrough

The updates across several Java classes in the Cryptomator project focus on enhancing the key loading mechanism. The changes include improved URI handling, a shift from Google's BaseEncoding to Java's Base64 for encoding, the introduction of new methods for key encryption and decryption, and the addition of exception handling for key decoding failures. Additionally, the handling of API paths has been centralized, and there is a new approach to device registration and legacy device migration.

Changes

File Path Change Summary
.../ui/keyloading/hub/HubConfig.java
.../ui/keyloading/hub/ReceiveKeyController.java
Added URIProcessors for path resolution, centralized API path handling, and updated URI constructions.
.../ui/keyloading/hub/JWEHelper.java Switched to Java's Base64, added crypto methods, introduced key decoding exception handling, and modified encryption/decryption methods.
.../ui/keyloading/hub/RegisterDeviceController.java Added methods for registration and legacy device migration, updated imports for exception and crypto handling, and introduced VaultDto record.

Poem

In the realm of code, where secrets hide,
A rabbit hopped, with keys inside.
With a flip and a hop, encryption's tight,
Safe in the burrow, locked up right. 🐇🔐

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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

CodeRabbit Commands (invoked as PR comments)

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

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

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

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

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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 24293b3 and 693299a.
Files selected for processing (5)
  • src/main/java/org/cryptomator/ui/keyloading/hub/HubConfig.java (3 hunks)
  • src/main/java/org/cryptomator/ui/keyloading/hub/JWEHelper.java (7 hunks)
  • src/main/java/org/cryptomator/ui/keyloading/hub/ReceiveKeyController.java (6 hunks)
  • src/main/java/org/cryptomator/ui/keyloading/hub/RegisterDeviceController.java (5 hunks)
  • src/test/java/org/cryptomator/ui/keyloading/hub/JWEHelperTest.java (3 hunks)
Additional comments: 21
src/main/java/org/cryptomator/ui/keyloading/hub/HubConfig.java (3)
  • 3-3: The import of com.fasterxml.jackson.annotation.JsonIgnore is correctly added to support the new @JsonIgnore annotation on the URIs field.
  • 22-26: The addition of the URIs field with the @JsonIgnore annotation is consistent with the summary stating that this field should not be included in JSON serialization/deserialization processes.
  • 50-61: The nested class URIProcessors with the API method is added as described in the summary. This method is used to resolve paths relative to the /api/ endpoint, which is a logical change for centralizing URI construction.
src/main/java/org/cryptomator/ui/keyloading/hub/JWEHelper.java (7)
  • 15-15: The import of org.cryptomator.cryptolib.api.CryptoException is correctly added to support the new exception handling in the encryption and decryption methods.
  • 55-77: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [71-84]

The method decodeECPrivateKey is added to decode a DER-encoded EC private key. It correctly throws a KeyDecodeFailedException if the key cannot be decoded, which aligns with the summary.

  • 94-107: The method decodeECPublicKey is added to decode a DER-encoded EC public key. It correctly throws a KeyDecodeFailedException if the key cannot be decoded, which aligns with the summary.
  • 110-112: The method encryptVaultKey is added to encrypt a Masterkey with a user's ECPublicKey. This method is part of the new functionality for handling encryption of vault keys.
  • 114-125: The encryptKey method is refactored to use Base64.getEncoder() instead of BaseEncoding.base64(), which is consistent with the summary stating that BaseEncoding.base64() usage has been replaced.
  • 148-153: The readKey method is updated to use Base64.getDecoder() instead of BaseEncoding.base64(). This change is consistent with the summary and the overall refactoring to remove the BaseEncoding import.
  • 168-172: The new exception class KeyDecodeFailedException is added as a subclass of CryptoException, providing a more specific exception for key decoding failures.
src/main/java/org/cryptomator/ui/keyloading/hub/ReceiveKeyController.java (4)
  • 91-91: The usage of hubConfig.URIs.API to construct the configUri is consistent with the changes in HubConfig.java and the summary provided.
  • 125-125: The usage of hubConfig.URIs.API to construct the deviceUri is consistent with the changes in HubConfig.java and the summary provided.
  • 165-165: The usage of hubConfig.URIs.API to construct the vaultKeyUri is consistent with the changes in HubConfig.java and the summary provided.
  • 208-208: The usage of hubConfig.URIs.API to construct the legacyAccessTokenUri is consistent with the changes in HubConfig.java and the summary provided.
src/main/java/org/cryptomator/ui/keyloading/hub/RegisterDeviceController.java (3)
  • 34-46: The addition of new imports (InterruptedIOException, UncheckedIOException, ECPublicKey, Base64, List) is consistent with the new methods added for handling user and device registration and migration of legacy devices.
  • 130-148: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [117-138]

The modifications to the register method, including the retrieval of user data and the migration of legacy devices, are consistent with the PR objectives to support legacy device migration.

  • 262-263: The introduction of the VaultDto record for parsing JSON responses is consistent with the summary and the new functionality for handling JSON responses during the migration process.
src/test/java/org/cryptomator/ui/keyloading/hub/JWEHelperTest.java (4)
  • 4-4: The addition of the Masterkey import is necessary for the new test methods that involve encryption and decryption of vault keys.
  • 8-10: The addition of BeforeAll and Nested imports is necessary for setting up the nested test class structure and initializing shared test data.
  • 36-62: The new nested class Decoders with methods for DER decoding is added, which is consistent with the changes in JWEHelper.java and the summary provided.
  • 175-200: New test methods for encryption and decryption of vault and user keys have been included, which is necessary to ensure the new functionality works as expected.

@overheadhunter overheadhunter marked this pull request as ready for review January 26, 2024 15:50
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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 693299a and d66cfe0.
Files selected for processing (1)
  • src/main/java/org/cryptomator/ui/keyloading/hub/RegisterDeviceController.java (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/main/java/org/cryptomator/ui/keyloading/hub/RegisterDeviceController.java

Copy link
Member

@infeo infeo left a comment

Choose a reason for hiding this comment

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

Looks good.

@overheadhunter overheadhunter added this to the 1.12.0 milestone Feb 2, 2024
@overheadhunter overheadhunter merged commit ee5a5c6 into develop Feb 2, 2024
5 checks passed
@overheadhunter overheadhunter deleted the feature/legacy-device-migration branch February 2, 2024 13:59
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.

None yet

2 participants