Repository navigation
Feature: Vault Recovery Enhancements - #3821
Conversation
auto restore when bkup exists added new VaultStates
…se dir and restore
dialog fix
infeo
left a comment
There was a problem hiding this comment.
first half of the review. There is definitively work ahead to improve code organization.
remove is hub vault dialog
infeo
left a comment
There was a problem hiding this comment.
The rest of the classes will be reviewed once we are done with the model.
There was a problem hiding this comment.
Actionable comments posted: 0
♻️ Duplicate comments (2)
src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java (1)
278-286: Enhance user feedback in the default case.The
defaultcase only logs a warning without informing the user. If the vault is in an unexpected state (e.g.,ERROR,MISSING,UNLOCKED,PROCESSING), the user receives no feedback about what happened or why the recovery didn't proceed.Consider showing an error dialog to inform the user:
switch (preparedVault.getState()) { case VAULT_CONFIG_MISSING -> recoveryKeyWindow.create(preparedVault, mainWindow, new SimpleObjectProperty<>(RecoveryActionType.RESTORE_VAULT_CONFIG)).showOnboardingDialogWindow(); case ALL_MISSING -> recoveryKeyWindow.create(preparedVault, mainWindow, new SimpleObjectProperty<>(RecoveryActionType.RESTORE_ALL)).showOnboardingDialogWindow(); case LOCKED, NEEDS_MIGRATION -> { vaultListManager.addVault(preparedVault); dialogs.prepareRecoveryVaultAdded(mainWindow, preparedVault.getDisplayName()).setOkAction(Stage::close).build().showAndWait(); } - default -> LOG.warn("Unhandled vault state during recovery: {}", preparedVault.getState()); + default -> { + LOG.warn("Unhandled vault state during recovery: {}", preparedVault.getState()); + dialogs.prepareErrorDialog(mainWindow) + .setMessageKey("recovery.unexpectedState") + .build().showAndWait(); + } }Note: You'll need to add the corresponding i18n key
recovery.unexpectedStateto your strings.properties file.src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyResetPasswordController.java (1)
132-134: Handle potential null cipher scheme before initializing CryptoFS.
cipherCombo.get()may be null at this point, which would causeCryptoFsInitializer.initto fail. Detect and set the scheme if missing, using the already-loaded masterkey.Apply this diff:
try (Masterkey masterkey = MasterkeyService.load(masterkeyFileAccess, recoveryPath.resolve(MASTERKEY_FILENAME), newPasswordController.passwordField.getCharacters())) { - CryptoFsInitializer.init(recoveryPath, masterkey, shorteningThreshold.get(), cipherCombo.get()); + CryptorProvider.Scheme scheme = cipherCombo.get(); + if (scheme == null) { + java.util.Optional<CryptorProvider.Scheme> detected = MasterkeyService.detect(masterkey, vault.getPath()); + if (detected.isEmpty()) { + throw new IllegalStateException("Unable to detect crypto scheme from vault contents"); + } + scheme = detected.get(); + cipherCombo.set(scheme); + } + CryptoFsInitializer.init(recoveryPath, masterkey, shorteningThreshold.get(), scheme); }Also widen the catch to handle IllegalStateException:
-} catch (IOException | CryptoException e) { +} catch (IOException | CryptoException | IllegalStateException e) { LOG.error("Recovery process failed", e); appWindows.showErrorWindow(e, window, null); }Based on past review comments and relevant code snippets showing that MasterkeyService.detect() can determine the scheme from a masterkey and vault path.
🧹 Nitpick comments (4)
src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyOnboardingController.java (3)
92-98: Improve default case handling for window title.The default case sets an empty window title, which degrades the user experience if an unexpected recovery type is encountered. Consider logging a warning or throwing an exception to catch unsupported recovery types during development.
Apply this diff to add logging:
switch (recoverType.get()) { case RESTORE_MASTERKEY -> window.setTitle(resourceBundle.getString("recover.recoverMasterkey.title")); case RESTORE_ALL, RESTORE_VAULT_CONFIG -> window.setTitle(resourceBundle.getString("recover.recoverVaultConfig.title")); - default -> window.setTitle(""); + default -> { + LOG.warn("Unexpected recovery action type: {}", recoverType.get()); + window.setTitle(resourceBundle.getString("recover.recoverVaultConfig.title")); + } }Add the logger import and field:
+import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + @RecoveryKeyScoped public class RecoveryKeyOnboardingController implements FxController { + + private static final Logger LOG = LoggerFactory.getLogger(RecoveryKeyOnboardingController.class);
115-126: Handle unexpected recovery types in secondTextDesc binding.The default case returns an empty string, which could confuse users if an unexpected recovery type is encountered. Consider adding logging to help diagnose issues.
Apply this diff:
secondTextDesc.textProperty().bind(Bindings.createStringBinding(() -> { RecoveryActionType type = recoverType.get(); Toggle sel = methodToggleGroup.getSelectedToggle(); return switch (type) { case RESTORE_VAULT_CONFIG -> resourceBundle.getString(sel == passwordRadio ? "recover.onBoarding.intro.password" : "recover.onBoarding.intro.recoveryKey"); case RESTORE_MASTERKEY -> resourceBundle.getString("recover.onBoarding.intro.masterkey.recoveryKey"); case RESTORE_ALL -> resourceBundle.getString("recover.onBoarding.intro.recoveryKey"); - default -> ""; + default -> { + LOG.warn("Unexpected recovery action type: {}", type); + return ""; + } }; }, recoverType, methodToggleGroup.selectedToggleProperty()));
144-153: Use proper type for selectedToggle.The variable is declared as
Objectbut is used in comparisons with specificRadioButtoninstances. UseTogglefor better type safety.Apply this diff:
case RESTORE_VAULT_CONFIG, RESTORE_ALL -> { - Object selectedToggle = methodToggleGroup.getSelectedToggle(); + Toggle selectedToggle = methodToggleGroup.getSelectedToggle(); if (selectedToggle == recoveryKeyRadio) { recoverType.set(RESTORE_ALL); window.setScene(recoverykeyRecoverScene.get()); } else if (selectedToggle == passwordRadio) { recoverType.set(RESTORE_VAULT_CONFIG); window.setScene(recoverykeyExpertSettingsScene.get()); } else { window.setScene(recoverykeyRecoverScene.get()); } }src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyResetPasswordController.java (1)
184-186: Consider removing redundant failure handler.The
ResetPasswordTaskconstructor sets anonFailedhandler that logs the exception, but the outerresetPassword()method also sets anonFailedhandler (line 172) that both logs and displays an error window. This results in the exception being logged twice with slightly different messages.Remove the inner failure handler since the outer one provides more comprehensive error handling:
private class ResetPasswordTask extends Task<Void> { private static final Logger LOG = LoggerFactory.getLogger(ResetPasswordTask.class); - public ResetPasswordTask() { - setOnFailed(_ -> LOG.error("Failed to reset password", getException())); - } + // Constructor removed - failure handling is done in resetPassword() method @Override protected Void call() throws IOException, IllegalArgumentException { recoveryKeyFactory.newMasterkeyFileWithPassphrase(vault.getPath(), recoveryKey.get(), newPasswordController.passwordField.getCharacters()); return null; } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java(9 hunks)src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyOnboardingController.java(1 hunks)src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyResetPasswordController.java(2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2024-11-21T16:57:58.292Z
Learnt from: infeo
PR: cryptomator/cryptomator#3618
File: src/main/java/org/cryptomator/ui/fxapp/FxApplicationWindows.java:151-165
Timestamp: 2024-11-21T16:57:58.292Z
Learning: In the file `src/main/java/org/cryptomator/ui/fxapp/FxApplicationWindows.java`, when reviewing the method `showDokanySupportEndWindow`, suggestions to add error handling to asynchronous dialog creation (e.g., `CompletableFuture`) may be considered out of scope for certain pull requests.
Applied to files:
src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java
🧬 Code graph analysis (3)
src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java (1)
src/main/java/org/cryptomator/common/recovery/VaultPreparator.java (1)
VaultPreparator(20-54)
src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyOnboardingController.java (2)
src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyRecoverController.java (1)
RecoveryKeyScoped(20-111)src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyExpertSettingsController.java (1)
RecoveryKeyScoped(25-123)
src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyResetPasswordController.java (4)
src/main/java/org/cryptomator/common/recovery/CryptoFsInitializer.java (1)
CryptoFsInitializer(15-33)src/main/java/org/cryptomator/common/recovery/MasterkeyService.java (1)
MasterkeyService(30-101)src/main/java/org/cryptomator/common/recovery/RecoveryDirectory.java (1)
RecoveryDirectory(12-56)src/main/java/org/cryptomator/ui/changepassword/NewPasswordController.java (1)
NewPasswordController(19-100)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Compile and Test
🔇 Additional comments (2)
src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java (2)
229-247: LGTM! Past review comments properly addressed.The method correctly refactors the previous
while(true)loop into a clearerdo-whilestructure and usesConstants.DATA_DIR_NAMEinstead of the hardcoded"d"string. TheFiletoPathconversion is appropriate sinceDirectoryChooser.showDialog()returnsFile.
292-292: LGTM! Appropriate extension of removable vault states.Adding
ALL_MISSINGandVAULT_CONFIG_MISSINGto the set of states that permit vault removal is appropriate, as these recovery states indicate the vault is not operational (similar toMISSINGandERROR).
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (4)
src/main/resources/i18n/strings.properties (4)
439-442: Avoid “VaultConfig”; prefer “vault configuration”Use the natural language term used elsewhere.
-main.vaultDetail.missingVaultConfig.info=VaultConfig is missing. -main.vaultDetail.missingVaultConfig.restore=Restore vault config +main.vaultDetail.missingVaultConfig.info=Vault configuration is missing. +main.vaultDetail.missingVaultConfig.restore=Restore vault configuration
132-132: Placeholder removed; suggest ellipsis and minor wording tweakGood fix. For consistency with other actions that open dialogs, append an ellipsis.
-unlock.chooseMasterkey.restoreInstead=Restore the masterkey file instead +unlock.chooseMasterkey.restoreInstead=Restore masterkey file instead…
539-543: LGTM — matches agreed wording“The selected folder must be a valid Cryptomator vault.” aligns with earlier discussion.
550-552: Prefer “Vault Configuration” over “Vault Config” in titlesAligns with prior guidance to avoid “VaultConfig/config”.
-recover.recoverVaultConfig.title=Recover Vault Config +recover.recoverVaultConfig.title=Recover Vault Configuration recover.recoverMasterkey.title=Recover Masterkey
🧹 Nitpick comments (3)
src/main/resources/i18n/strings.properties (3)
399-401: Align wording with wizard: use “Add Existing Vault…” instead of “Open Existing Vault…”“Open” may be confused with unlocking. Wizard title says “Add Existing Vault”. Suggest:
-main.vaultlist.addVaultBtn.menuItemExisting=Open Existing Vault… +main.vaultlist.addVaultBtn.menuItemExisting=Add Existing Vault…
506-506: Use “vault configuration” and consider “restore” vs “recover”For clarity and consistency:
-recoveryKey.recover.description=Enter the password for "%s" to recover the vault config. +recoveryKey.recover.description=Enter the password for "%s" to restore the vault configuration.
523-527: Use “restored successfully” instead of “reset” for files“Reset” fits passwords; for files, “restore” is clearer.
-recoveryKey.recover.resetVaultConfigSuccess.message=Vault config reset successful -recoveryKey.recover.resetMasterkeyFileSuccess.message=Masterkey file reset successful -recoveryKey.recover.resetMasterkeyFileSuccess.description=You can unlock your vault with your password now. +recoveryKey.recover.resetVaultConfigSuccess.message=Vault configuration restored successfully +recoveryKey.recover.resetMasterkeyFileSuccess.message=Masterkey file restored successfully +recoveryKey.recover.resetMasterkeyFileSuccess.description=You can unlock your vault with your password now.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/main/resources/i18n/strings.properties(6 hunks)
🔇 Additional comments (8)
src/main/resources/i18n/strings.properties (8)
100-100: LGTM on adding “Restore…” entryLooks consistent with action labels opening dialogs.
519-519: LGTMButton label is concise and clear.
528-533: LGTMWording (“No recovery process was necessary.”) is clear and matches prior feedback.
535-538: LGTMConcise and user-friendly.
545-548: LGTMClear guidance for Hub-managed vaults.
554-561: LGTMOnboarding copy is succinct; checkbox text mirrors existing patterns.
563-567: LGTMRequirements are clear for each method.
569-569: LGTMExpert setting note is precise and actionable.
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/main/resources/i18n/strings.properties(6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Compile and Test
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/main/resources/fxml/convertvault_hubtopassword_convert.fxml (2)
25-33: Consider adding explicit accessibility semantics to the decorative icon.The Group containing the key icon is purely decorative and doesn't convey essential information. For better accessibility, consider adding
aria-hidden="true"or wrapping it in a container withfocusTraversable="false"to ensure screen readers don't unnecessarily announce it.
17-21: Fixed dimensions may limit flexibility.The HBox specifies fixed
minWidth="400"andmaxWidth="400", which works for standard dialog sizes but may not adapt well if content grows (e.g., localized strings, different font sizes). If this dialog is always modal with controlled content, the fixed dimensions are acceptable. Otherwise, consider using preferred width instead of maxWidth for better responsiveness.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/main/resources/fxml/convertvault_hubtopassword_convert.fxml(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Compile and Test
🔇 Additional comments (1)
src/main/resources/fxml/convertvault_hubtopassword_convert.fxml (1)
1-52: LGTM! Two-column layout enhances UX.The restructure from VBox to HBox with a decorative key icon on the left and content on the right improves visual hierarchy and aligns with the recovery-related UI patterns introduced in this PR. The FXML syntax is correct, imports are appropriate, and the layout properties are well-configured.
There was a problem hiding this comment.
Actionable comments posted: 4
♻️ Duplicate comments (1)
src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyResetPasswordController.java (1)
132-134: Null cipher scheme can cause failure during CryptoFS initialization.At line 133,
cipherCombo.get()is passed directly toCryptoFsInitializer.initwithout null checking. If the cipher scheme is not set, this will cause initialization to fail.Apply this diff to detect and set the scheme if missing:
try (Masterkey masterkey = MasterkeyService.load(masterkeyFileAccess, recoveryPath.resolve(MASTERKEY_FILENAME), newPasswordController.passwordField.getCharacters())) { - CryptoFsInitializer.init(recoveryPath, masterkey, shorteningThreshold.get(), cipherCombo.get()); + CryptorProvider.Scheme scheme = cipherCombo.get(); + if (scheme == null) { + java.util.Optional<CryptorProvider.Scheme> detected = MasterkeyService.detect(masterkey, vault.getPath()); + if (detected.isEmpty()) { + throw new IllegalStateException("Unable to detect Crypto scheme from *.c9r"); + } + scheme = detected.get(); + cipherCombo.set(scheme); + } + CryptoFsInitializer.init(recoveryPath, masterkey, shorteningThreshold.get(), scheme); }Also widen the catch clause to handle the
IllegalStateException:-} catch (IOException | CryptoException e) { +} catch (IOException | CryptoException | IllegalStateException e) {
🧹 Nitpick comments (1)
src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyCreationController.java (1)
98-109: Consider adding a default case or else clause.The initialize() method only handles
SHOW_KEYandRESTORE_VAULT_CONFIGcases. If additionalRecoveryActionTypeenum values are introduced and used, the UI may not be properly configured.Consider adding a default case or documenting that only these two types are expected:
@FXML public void initialize() { if (recoverType.get() == RecoveryActionType.SHOW_KEY) { window.setTitle(resourceBundle.getString("recoveryKey.display.title")); } else if (recoverType.get() == RecoveryActionType.RESTORE_VAULT_CONFIG) { window.setTitle(resourceBundle.getString("recover.recoverVaultConfig.title")); descriptionLabel.formatProperty().set(resourceBundle.getString("recoveryKey.recover.description")); cancelButton.setOnAction((_) -> back()); cancelButton.setText(resourceBundle.getString("generic.button.back")); nextButton.setOnAction((_) -> restoreWithPassword()); + } else { + // Document: Only SHOW_KEY and RESTORE_VAULT_CONFIG are supported in this controller + throw new IllegalStateException("Unsupported recovery type: " + recoverType.get()); } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyCreationController.java(2 hunks)src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyResetPasswordController.java(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyCreationController.java (7)
src/main/java/org/cryptomator/common/recovery/CryptoFsInitializer.java (1)
CryptoFsInitializer(15-33)src/main/java/org/cryptomator/common/recovery/MasterkeyService.java (1)
MasterkeyService(30-101)src/main/java/org/cryptomator/common/recovery/RecoveryDirectory.java (1)
RecoveryDirectory(12-56)src/main/java/org/cryptomator/ui/controls/FormattedLabel.java (1)
FormattedLabel(11-80)src/main/java/org/cryptomator/ui/controls/NiceSecurePasswordField.java (1)
NiceSecurePasswordField(14-106)src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyResetPasswordController.java (1)
RecoveryKeyScoped(42-205)src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyExpertSettingsController.java (1)
RecoveryKeyScoped(25-123)
src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyResetPasswordController.java (4)
src/main/java/org/cryptomator/common/recovery/CryptoFsInitializer.java (1)
CryptoFsInitializer(15-33)src/main/java/org/cryptomator/common/recovery/MasterkeyService.java (1)
MasterkeyService(30-101)src/main/java/org/cryptomator/common/recovery/RecoveryDirectory.java (1)
RecoveryDirectory(12-56)src/main/java/org/cryptomator/ui/changepassword/NewPasswordController.java (1)
NewPasswordController(19-100)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Compile and Test
🔇 Additional comments (8)
src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyResetPasswordController.java (8)
1-64: LGTM: Dependency injection setup and field declarations are correct.The expanded constructor dependencies and new fields properly support the multi-path recovery flow. All imports are used, and the public
nextButtonfield enables UI wiring for dynamic label updates.
66-97: LGTM: Constructor properly wires all dependencies.All injected dependencies are correctly assigned to fields. The Dagger annotations and named qualifiers are appropriately used for disambiguation.
99-106: LGTM: Dynamic button labeling based on recovery action type.The
initialize()method correctly sets thenextButtontext according to the selectedrecoverType, with a sensible default fallback.
108-115: LGTM: Scene navigation logic is clear and correct.The
close()method appropriately routes to different scenes based onrecoverType, with a safe default to close the window.
117-124: LGTM: Dispatcher correctly routes to recovery methods.The
next()method cleanly dispatches to the appropriate recovery method based onrecoverType.
162-170: LGTM: Duplicate window.close() issue has been fixed.The previous duplicate
window.close()call has been properly removed. The window now closes once before displaying the success dialog, which is correct.
180-193: LGTM: ResetPasswordTask implementation is correct.The inner class properly extends
Task<Void>, has its own logger, and correctly implements the password reset logic incall(). The constructor sets up error handling appropriately.
195-205: LGTM: Property delegation is correct.The getter methods properly delegate to
newPasswordControllerto expose password validation state.
| @FXML | ||
| public void restoreWithPassword() { | ||
|
|
||
| try (RecoveryDirectory recoveryDirectory = RecoveryDirectory.create(vault.getPath())) { | ||
| Path recoveryPath = recoveryDirectory.getRecoveryPath(); | ||
|
|
||
| Path masterkeyFilePath = vault.getPath().resolve(MASTERKEY_FILENAME); | ||
|
|
||
| try (Masterkey masterkey = MasterkeyService.load(masterkeyFileAccess, masterkeyFilePath, passwordField.getCharacters())) { | ||
| var combo = MasterkeyService.detect(masterkey, vault.getPath()) | ||
| .orElseThrow(() -> new IllegalStateException("Could not detect combo for vault path: " + vault.getPath())); | ||
|
|
||
| CryptoFsInitializer.init(recoveryPath, masterkey, shorteningThreshold.get(), combo); | ||
| } | ||
|
|
||
| recoveryDirectory.moveRecoveredFile(VAULTCONFIG_FILENAME); | ||
|
|
||
| if (!vaultListManager.isAlreadyAdded(vault.getPath())) { | ||
| vaultListManager.add(vault.getPath()); | ||
| } | ||
| window.close(); | ||
| dialogs.prepareRecoverPasswordSuccess((Stage)window.getOwner()) // | ||
| .setTitleKey("recover.recoverVaultConfig.title") // | ||
| .setMessageKey("recoveryKey.recover.resetVaultConfigSuccess.message") // | ||
| .setDescriptionKey("recoveryKey.recover.resetMasterkeyFileSuccess.description") | ||
| .build().showAndWait(); | ||
|
|
||
| } catch (InvalidPassphraseException e) { | ||
| LOG.info("Password invalid", e); | ||
| Animations.createShakeWindowAnimation(window).play(); | ||
| } catch (IOException | CryptoException e) { | ||
| LOG.error("Recovery process failed", e); | ||
| appWindows.showErrorWindow(e, window, null); | ||
| } | ||
| } |
There was a problem hiding this comment.
Move blocking I/O operations off the JavaFX application thread.
The restoreWithPassword() method performs extensive blocking I/O operations (file system access, cryptographic operations, filesystem initialization) directly on the JavaFX application thread. This will freeze the UI during execution and degrade user experience.
Follow the pattern used in createRecoveryKey() (line 118): wrap the restoration logic in a Task and submit it to the executor thread:
@FXML
public void restoreWithPassword() {
+ Task<Void> task = new RestoreVaultConfigTask();
+ task.setOnScheduled(_ -> {
+ LOG.debug("Restoring vault config for {}.", vault.getDisplayablePath());
+ });
+ task.setOnSucceeded(_ -> {
+ LOG.debug("Vault config restored for {}.", vault.getDisplayablePath());
+ window.close();
+ dialogs.prepareRecoverPasswordSuccess((Stage)window.getOwner())
+ .setTitleKey("recover.recoverVaultConfig.title")
+ .setMessageKey("recoveryKey.recover.resetVaultConfigSuccess.message")
+ .setDescriptionKey("recoveryKey.recover.resetMasterkeyFileSuccess.description")
+ .build().showAndWait();
+ });
+ task.setOnFailed(_ -> {
+ if (task.getException() instanceof InvalidPassphraseException) {
+ Animations.createShakeWindowAnimation(window).play();
+ } else {
+ LOG.error("Recovery process failed", task.getException());
+ appWindows.showErrorWindow(task.getException(), window, null);
+ }
+ });
+ executor.submit(task);
+}
+
+private class RestoreVaultConfigTask extends Task<Void> {
+
+ @Override
+ protected Void call() throws IOException, CryptoException {
+ try (RecoveryDirectory recoveryDirectory = RecoveryDirectory.create(vault.getPath())) {
+ Path recoveryPath = recoveryDirectory.getRecoveryPath();
+ Path masterkeyFilePath = vault.getPath().resolve(MASTERKEY_FILENAME);
- try (RecoveryDirectory recoveryDirectory = RecoveryDirectory.create(vault.getPath())) {
- Path recoveryPath = recoveryDirectory.getRecoveryPath();
-
- Path masterkeyFilePath = vault.getPath().resolve(MASTERKEY_FILENAME);
-
- try (Masterkey masterkey = MasterkeyService.load(masterkeyFileAccess, masterkeyFilePath, passwordField.getCharacters())) {
- var combo = MasterkeyService.detect(masterkey, vault.getPath())
- .orElseThrow(() -> new IllegalStateException("Could not detect combo for vault path: " + vault.getPath()));
-
- CryptoFsInitializer.init(recoveryPath, masterkey, shorteningThreshold.get(), combo);
- }
-
- recoveryDirectory.moveRecoveredFile(VAULTCONFIG_FILENAME);
-
- if (!vaultListManager.isAlreadyAdded(vault.getPath())) {
- vaultListManager.add(vault.getPath());
- }
- window.close();
- dialogs.prepareRecoverPasswordSuccess((Stage)window.getOwner()) //
- .setTitleKey("recover.recoverVaultConfig.title") //
- .setMessageKey("recoveryKey.recover.resetVaultConfigSuccess.message") //
- .setDescriptionKey("recoveryKey.recover.resetMasterkeyFileSuccess.description")
- .build().showAndWait();
-
- } catch (InvalidPassphraseException e) {
- LOG.info("Password invalid", e);
- Animations.createShakeWindowAnimation(window).play();
- } catch (IOException | CryptoException e) {
- LOG.error("Recovery process failed", e);
- appWindows.showErrorWindow(e, window, null);
+ try (Masterkey masterkey = MasterkeyService.load(masterkeyFileAccess, masterkeyFilePath, passwordField.getCharacters())) {
+ var combo = MasterkeyService.detect(masterkey, vault.getPath())
+ .orElseThrow(() -> new IllegalStateException("Could not detect combo for vault path: " + vault.getPath()));
+
+ CryptoFsInitializer.init(recoveryPath, masterkey, shorteningThreshold.get(), combo);
+ }
+
+ recoveryDirectory.moveRecoveredFile(VAULTCONFIG_FILENAME);
+
+ if (!vaultListManager.isAlreadyAdded(vault.getPath())) {
+ vaultListManager.add(vault.getPath());
+ }
+ }
+ return null;
}
}Committable suggestion skipped: line range outside the PR's diff.
| @FXML | ||
| public void restorePassword() { | ||
| try (RecoveryDirectory recoveryDirectory = RecoveryDirectory.create(vault.getPath())) { | ||
| Path recoveryPath = recoveryDirectory.getRecoveryPath(); | ||
| MasterkeyService.recoverFromRecoveryKey(recoveryKey.get(), recoveryKeyFactory, recoveryPath, newPasswordController.passwordField.getCharacters()); | ||
|
|
||
| try (Masterkey masterkey = MasterkeyService.load(masterkeyFileAccess, recoveryPath.resolve(MASTERKEY_FILENAME), newPasswordController.passwordField.getCharacters())) { | ||
| CryptoFsInitializer.init(recoveryPath, masterkey, shorteningThreshold.get(), cipherCombo.get()); | ||
| } | ||
|
|
||
| recoveryDirectory.moveRecoveredFile(MASTERKEY_FILENAME); | ||
| recoveryDirectory.moveRecoveredFile(VAULTCONFIG_FILENAME); | ||
|
|
||
| if (!vaultListManager.isAlreadyAdded(vault.getPath())) { | ||
| vaultListManager.add(vault.getPath()); | ||
| } | ||
| window.close(); | ||
| dialogs.prepareRecoverPasswordSuccess((Stage)window.getOwner()) // | ||
| .setTitleKey("recover.recoverVaultConfig.title") // | ||
| .setMessageKey("recoveryKey.recover.resetVaultConfigSuccess.message") // | ||
| .build().showAndWait(); | ||
|
|
||
| } catch (IOException | CryptoException e) { | ||
| LOG.error("Recovery process failed", e); | ||
| appWindows.showErrorWindow(e, window, null); | ||
| } | ||
| } |
There was a problem hiding this comment.
Heavy I/O operations on the FX thread will freeze the UI.
The restorePassword() method performs multiple blocking I/O operations (temp directory creation, masterkey recovery, CryptoFS initialization, file moves) synchronously on the FX application thread. This will cause the UI to freeze during recovery, degrading user experience.
Refactor to use a background task similar to resetPassword():
@FXML
public void restorePassword() {
+ Task<Void> task = new RestorePasswordTask();
+
+ task.setOnScheduled(_ -> {
+ LOG.debug("Starting full restore for {}.", vault.getDisplayablePath());
+ });
+
+ task.setOnSucceeded(_ -> {
+ LOG.debug("Full restore completed for {}.", vault.getDisplayablePath());
+ window.close();
+ dialogs.prepareRecoverPasswordSuccess((Stage)window.getOwner())
+ .setTitleKey("recover.recoverVaultConfig.title")
+ .setMessageKey("recoveryKey.recover.resetVaultConfigSuccess.message")
+ .build().showAndWait();
+ });
+
+ task.setOnFailed(_ -> {
+ LOG.error("Full restore failed.", task.getException());
+ appWindows.showErrorWindow(task.getException(), window, null);
+ });
+
+ executor.submit(task);
+}
+
+private class RestorePasswordTask extends Task<Void> {
+
+ @Override
+ protected Void call() throws IOException, CryptoException {
- try (RecoveryDirectory recoveryDirectory = RecoveryDirectory.create(vault.getPath())) {
- Path recoveryPath = recoveryDirectory.getRecoveryPath();
- MasterkeyService.recoverFromRecoveryKey(recoveryKey.get(), recoveryKeyFactory, recoveryPath, newPasswordController.passwordField.getCharacters());
-
- try (Masterkey masterkey = MasterkeyService.load(masterkeyFileAccess, recoveryPath.resolve(MASTERKEY_FILENAME), newPasswordController.passwordField.getCharacters())) {
- CryptoFsInitializer.init(recoveryPath, masterkey, shorteningThreshold.get(), cipherCombo.get());
- }
-
- recoveryDirectory.moveRecoveredFile(MASTERKEY_FILENAME);
- recoveryDirectory.moveRecoveredFile(VAULTCONFIG_FILENAME);
-
- if (!vaultListManager.isAlreadyAdded(vault.getPath())) {
- vaultListManager.add(vault.getPath());
- }
- window.close();
- dialogs.prepareRecoverPasswordSuccess((Stage)window.getOwner())
- .setTitleKey("recover.recoverVaultConfig.title")
- .setMessageKey("recoveryKey.recover.resetVaultConfigSuccess.message")
- .build().showAndWait();
-
- } catch (IOException | CryptoException e) {
- LOG.error("Recovery process failed", e);
- appWindows.showErrorWindow(e, window, null);
- }
+ try (RecoveryDirectory recoveryDirectory = RecoveryDirectory.create(vault.getPath())) {
+ Path recoveryPath = recoveryDirectory.getRecoveryPath();
+ MasterkeyService.recoverFromRecoveryKey(recoveryKey.get(), recoveryKeyFactory, recoveryPath, newPasswordController.passwordField.getCharacters());
+
+ try (Masterkey masterkey = MasterkeyService.load(masterkeyFileAccess, recoveryPath.resolve(MASTERKEY_FILENAME), newPasswordController.passwordField.getCharacters())) {
+ CryptoFsInitializer.init(recoveryPath, masterkey, shorteningThreshold.get(), cipherCombo.get());
+ }
+
+ recoveryDirectory.moveRecoveredFile(MASTERKEY_FILENAME);
+ recoveryDirectory.moveRecoveredFile(VAULTCONFIG_FILENAME);
+
+ if (!vaultListManager.isAlreadyAdded(vault.getPath())) {
+ vaultListManager.add(vault.getPath());
+ }
+ }
+ return null;
+ }
}🤖 Prompt for AI Agents
In
src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyResetPasswordController.java
around lines 126 to 152, restorePassword() performs heavy blocking I/O on the FX
thread; move the entire recovery flow (RecoveryDirectory.create,
MasterkeyService.recoverFromRecoveryKey, MasterkeyService.load,
CryptoFsInitializer.init, recoveryDirectory.moveRecoveredFile,
vaultListManager.add, dialogs.show) into a background Task or Service (same
pattern as resetPassword()), run the Task via an Executor or new Thread, update
UI state (disable controls, show progress, close window, and show success
dialog) on the FX thread using Platform.runLater, and propagate exceptions from
the Task to be logged and shown on the FX thread so the UI does not freeze
during recovery.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (6)
src/main/resources/i18n/strings.properties (6)
132-132: Add ellipsis to indicate a follow-up dialog.Action likely opens a flow; align with other labels by adding “…”.
-unlock.chooseMasterkey.restoreInstead=Restore the masterkey file instead +unlock.chooseMasterkey.restoreInstead=Restore the masterkey file instead…
441-443: Prefer “vault configuration” for clarity and consistency.Small copy tweak to match phrasing used elsewhere.
-main.vaultDetail.missingVaultConfig.info=Vault config is missing. +main.vaultDetail.missingVaultConfig.info=Vault configuration is missing. -main.vaultDetail.missingVaultConfig.restore=Restore vault config +main.vaultDetail.missingVaultConfig.restore=Restore vault configuration
525-527: Standardize success wording: use “restored” instead of “reset” for files.Aligns with other “Restore …” strings and avoids conflating with password reset.
-recoveryKey.recover.resetVaultConfigSuccess.message=Vault config reset successful +recoveryKey.recover.resetVaultConfigSuccess.message=Vault configuration restored successfully -recoveryKey.recover.resetMasterkeyFileSuccess.message=Masterkey file reset successful +recoveryKey.recover.resetMasterkeyFileSuccess.message=Masterkey file restored successfully
545-549: Clarify which items are missing in Hub flow.Be explicit that one or more vault files may be missing.
-contactHubVaultOwner.description=Please reach out to the vault owner to restore the missing file. They can download the vault template from Cryptomator Hub. +contactHubVaultOwner.description=Please reach out to the vault owner to restore the missing vault files. They can download the vault template from Cryptomator Hub.
551-553: Title consistency: clarify “Masterkey” and prefer “Restore” for file operations.Matches other strings (“Restore vault configuration”, “Masterkey file”).
-recover.recoverVaultConfig.title=Recover Vault Config +recover.recoverVaultConfig.title=Restore Vault Configuration -recover.recoverMasterkey.title=Recover Masterkey +recover.recoverMasterkey.title=Recover Masterkey File
555-570: Minor copy polish for onboarding and expert setting title.Improves clarity and tone; optional.
-recover.onBoarding.intro.ensure=All files are fully synced. +recover.onBoarding.intro.ensure=All vault files are fully synced across all devices. -recover.onBoarding.intro.recoveryKey=You have the recovery key and know if expert settings were used. +recover.onBoarding.intro.recoveryKey=You have the recovery key and know if expert settings were applied. -recover.onBoarding.intro.password=You have the vault password and know if expert settings were used. +recover.onBoarding.intro.password=You have the vault password and know if expert settings were applied. -recover.onBoarding.intro.masterkey.recoveryKey=You have the vault recovery key. +recover.onBoarding.intro.masterkey.recoveryKey=You have the recovery key for this vault. -recover.expertSettings.shorteningThreshold.title=This value must match the one used before recovery to ensure compatibility with previously encrypted data. +recover.expertSettings.shorteningThreshold.title=Shortening threshold must match previous settingAlso applies to: 572-572
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/main/java/org/cryptomator/ui/fxapp/FxApplicationTerminator.java(1 hunks)src/main/java/org/cryptomator/ui/mainwindow/VaultListContextMenuController.java(2 hunks)src/main/resources/i18n/strings.properties(6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: Build Debian Package
- GitHub Check: Build .msi Installer (x64, windows-latest, zulu, 24.0.1+9, jdk)
- GitHub Check: Build Cryptomator.app for arm64
- GitHub Check: Compile and Test
🔇 Additional comments (5)
src/main/java/org/cryptomator/ui/fxapp/FxApplicationTerminator.java (1)
31-31: LGTM! Correct extension of termination logic for new vault states.The addition of
VAULT_CONFIG_MISSINGandALL_MISSINGto the termination-allowing states is appropriate. Like the existing states (LOCKED,MISSING,ERROR), these represent inactive vaults with no mounted resources requiring cleanup during shutdown. This correctly enables sudden termination when all vaults are in non-operational states.src/main/java/org/cryptomator/ui/mainwindow/VaultListContextMenuController.java (2)
23-23: LGTM! Import additions follow existing patterns.The static imports for
ALL_MISSINGandVAULT_CONFIG_MISSINGare consistent with the existing VaultState.Value imports and properly ordered.Also applies to: 29-29
68-68: Code changes are consistent and properly integrated across controllers.Verification confirms the EnumSet update is already synchronized in
VaultListController(line 292) with identical states. The removal dialog inDialogs.javais generic and handles all vault states without special casing. Additionally,FxApplicationTerminatoralready accounts forALL_MISSINGandVAULT_CONFIG_MISSINGstates, indicating these transitions were previously anticipated in the codebase design. No other controllers require updates, and no state-specific conflicts or race conditions exist in the removal path.src/main/resources/i18n/strings.properties (2)
100-100: Good: Consistent ellipsis in action labels.Labels correctly use the ellipsis character (…) and clear wording. No change needed.
Also applies to: 400-402
529-544: LGTM: Recovery result dialogs read well.Clear outcomes and improved phrasing (“No recovery process was necessary.”). No change needed.
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyCreationController.java (1)
139-173: Critical: Move blocking I/O off the JavaFX application thread.This method performs extensive blocking operations (file I/O, cryptographic operations, filesystem initialization) directly on the JavaFX thread, which will freeze the UI. This issue was previously flagged (lines 139-173 in earlier review) but remains unaddressed.
Wrap the restoration logic in a
Taskand submit to the executor, following the pattern increateRecoveryKey()(line 118):@FXML public void restoreWithPassword() { + Task<Void> task = new RestoreVaultConfigTask(); + task.setOnScheduled(_ -> { + LOG.debug("Restoring vault config for {}.", vault.getDisplayablePath()); + }); + task.setOnSucceeded(_ -> { + LOG.debug("Vault config restored for {}.", vault.getDisplayablePath()); + window.close(); + dialogs.prepareRecoverPasswordSuccess((Stage)window.getOwner()) + .setTitleKey("recover.recoverVaultConfig.title") + .setMessageKey("recoveryKey.recover.resetVaultConfigSuccess.message") + .setDescriptionKey("recoveryKey.recover.resetMasterkeyFileSuccess.description") + .build().showAndWait(); + }); + task.setOnFailed(_ -> { + if (task.getException() instanceof InvalidPassphraseException) { + Animations.createShakeWindowAnimation(window).play(); + } else { + LOG.error("Recovery process failed", task.getException()); + appWindows.showErrorWindow(task.getException(), window, null); + } + }); + executor.submit(task); +} + +private class RestoreVaultConfigTask extends Task<Void> { + + @Override + protected Void call() throws IOException, CryptoException { + try (RecoveryDirectory recoveryDirectory = RecoveryDirectory.create(vault.getPath())) { + Path recoveryPath = recoveryDirectory.getRecoveryPath(); + Path masterkeyFilePath = vault.getPath().resolve(MASTERKEY_FILENAME); - try (RecoveryDirectory recoveryDirectory = RecoveryDirectory.create(vault.getPath())) { - Path recoveryPath = recoveryDirectory.getRecoveryPath(); - - Path masterkeyFilePath = vault.getPath().resolve(MASTERKEY_FILENAME); - - try (Masterkey masterkey = MasterkeyService.load(masterkeyFileAccess, masterkeyFilePath, passwordField.getCharacters())) { - var combo = MasterkeyService.detect(masterkey, vault.getPath()) - .orElseThrow(() -> new IllegalStateException("Could not detect combo for vault path: " + vault.getPath())); - - CryptoFsInitializer.init(recoveryPath, masterkey, shorteningThreshold.get(), combo); - } - - recoveryDirectory.moveRecoveredFile(VAULTCONFIG_FILENAME); - - if (!vaultListManager.isAlreadyAdded(vault.getPath())) { - vaultListManager.add(vault.getPath()); - } - window.close(); - dialogs.prepareRecoverPasswordSuccess((Stage)window.getOwner()) // - .setTitleKey("recover.recoverVaultConfig.title") // - .setMessageKey("recoveryKey.recover.resetVaultConfigSuccess.message") // - .setDescriptionKey("recoveryKey.recover.resetMasterkeyFileSuccess.description") - .build().showAndWait(); - - } catch (InvalidPassphraseException e) { - LOG.info("Password invalid", e); - Animations.createShakeWindowAnimation(window).play(); - } catch (IOException | CryptoException | IllegalStateException e) { - LOG.error("Recovery process failed", e); - appWindows.showErrorWindow(e, window, null); + try (Masterkey masterkey = MasterkeyService.load(masterkeyFileAccess, masterkeyFilePath, passwordField.getCharacters())) { + var combo = MasterkeyService.detect(masterkey, vault.getPath()) + .orElseThrow(() -> new IllegalStateException("Could not detect combo for vault path: " + vault.getPath())); + + CryptoFsInitializer.init(recoveryPath, masterkey, shorteningThreshold.get(), combo); + } + + recoveryDirectory.moveRecoveredFile(VAULTCONFIG_FILENAME); + + if (!vaultListManager.isAlreadyAdded(vault.getPath())) { + vaultListManager.add(vault.getPath()); + } + } + return null; } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyCreationController.java(2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2024-11-21T16:57:58.292Z
Learnt from: infeo
PR: cryptomator/cryptomator#3618
File: src/main/java/org/cryptomator/ui/fxapp/FxApplicationWindows.java:151-165
Timestamp: 2024-11-21T16:57:58.292Z
Learning: In the file `src/main/java/org/cryptomator/ui/fxapp/FxApplicationWindows.java`, when reviewing the method `showDokanySupportEndWindow`, suggestions to add error handling to asynchronous dialog creation (e.g., `CompletableFuture`) may be considered out of scope for certain pull requests.
Applied to files:
src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyCreationController.java
🧬 Code graph analysis (1)
src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyCreationController.java (6)
src/main/java/org/cryptomator/common/recovery/CryptoFsInitializer.java (1)
CryptoFsInitializer(15-33)src/main/java/org/cryptomator/common/recovery/MasterkeyService.java (1)
MasterkeyService(30-101)src/main/java/org/cryptomator/common/recovery/RecoveryDirectory.java (1)
RecoveryDirectory(12-56)src/main/java/org/cryptomator/ui/controls/FormattedLabel.java (1)
FormattedLabel(11-80)src/main/java/org/cryptomator/ui/controls/NiceSecurePasswordField.java (1)
NiceSecurePasswordField(14-106)src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyResetPasswordController.java (1)
RecoveryKeyScoped(42-205)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Compile and Test
🔇 Additional comments (4)
src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyCreationController.java (4)
4-65: LGTM: Imports and field declarations support dual-mode functionality.The new imports and fields appropriately support both recovery key display and vault configuration restoration workflows.
68-96: LGTM: Constructor properly injects all required dependencies.The expanded constructor correctly initializes all fields needed for the dual-mode recovery workflow.
98-109: LGTM: Clean mode-based UI configuration with correct enum comparison.The initialize method appropriately configures the UI for SHOW_KEY vs RESTORE_VAULT_CONFIG modes. Correctly uses
==for enum comparison as per learnings.Based on learnings
111-115: LGTM: Navigation logic is correct.The back method appropriately returns to the expert settings scene and re-centers the window.
This PR enhances the recovery functionality. The following is an overview of the key modifications and improvements:
1. Recovery Utility
A new utility class has been introduced with methods to detect the encryption scheme (using a .c9r file), restore missing configuration and master key files from backups, and perform recovery tasks.
Cipher Scheme Detection: Uses a provided master key and a sample file to determine if the vault employs one of the supported cipher schemes (e.g., SIV_GCM or SIV_CTRMAC).
Backup Restoration: Automatically searches for backup files for missing vault configuration or master key files and restores them if available.
Recovery Directory Handling: Creates a temporary recovery directory, generates a new master key file using the recovery key, initialises the crypto file system, moves the recovered files back to the vault directory, and then cleans up the temporary directory.
2. Enhancements to Vault and VaultState
In addition to the previous status values, new states have been added for missing vault configuration (VAULT_CONFIG_MISSING) and for scenarios where both the configuration and master key are missing (ALL_MISSING).
3. UI/UX Enhancements and Recovery Key Workflow
New Controllers and Dialogs:
Several new UI components have been added under the org.cryptomator.ui.recoverykey package to support the recovery key flow:
4. Module and Dependency Injection Updates
Dependency Injection:
Modules such as ConvertVaultModule, RecoveryKeyModule, and MainWindowModule have been updated to integrate the new recovery key components into the DI graph.