From f7630c28d61c40cafc560fcf922ede0d8d035585 Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Tue, 8 Oct 2019 16:26:57 +0200 Subject: [PATCH] Generate recovery key during vault creation --- .../ui/addvaultwizard/AddVaultModule.java | 20 ++++++++ .../CreateNewVaultLocationController.java | 3 +- .../CreateNewVaultNameController.java | 3 +- .../CreateNewVaultPasswordController.java | 46 +++++++++++-------- .../CreateNewVaultRecoveryKeyController.java | 42 +++++++++++++++++ .../org/cryptomator/ui/common/FxmlFile.java | 1 + .../resources/fxml/addvault_new_password.fxml | 4 +- .../fxml/addvault_new_recoverykey.fxml | 39 ++++++++++++++++ .../main/resources/i18n/strings.properties | 3 +- 9 files changed, 135 insertions(+), 26 deletions(-) create mode 100644 main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultRecoveryKeyController.java create mode 100644 main/ui/src/main/resources/fxml/addvault_new_recoverykey.fxml diff --git a/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultModule.java b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultModule.java index 2e92a5345..f89a2473b 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultModule.java +++ b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultModule.java @@ -65,6 +65,7 @@ public abstract class AddVaultModule { } @Provides + @Named("vaultName") @AddVaultWizardScoped static StringProperty provideVaultName() { return new SimpleStringProperty(""); @@ -77,6 +78,13 @@ public abstract class AddVaultModule { return new SimpleObjectProperty<>(); } + @Provides + @Named("recoveryKey") + @AddVaultWizardScoped + static StringProperty provideRecoveryKey() { + return new SimpleStringProperty(); + } + // ------------------ @Provides @@ -114,6 +122,13 @@ public abstract class AddVaultModule { return fxmlLoaders.createScene("/fxml/addvault_new_password.fxml"); } + @Provides + @FxmlScene(FxmlFile.ADDVAULT_NEW_RECOVERYKEY) + @AddVaultWizardScoped + static Scene provideCreateNewVaultRecoveryKeyScene(@AddVaultWizardWindow FXMLLoaderFactory fxmlLoaders) { + return fxmlLoaders.createScene("/fxml/addvault_new_recoverykey.fxml"); + } + @Provides @FxmlScene(FxmlFile.ADDVAULT_SUCCESS) @AddVaultWizardScoped @@ -152,4 +167,9 @@ public abstract class AddVaultModule { @IntoMap @FxControllerKey(AddVaultSuccessController.class) abstract FxController bindAddVaultSuccessController(AddVaultSuccessController controller); + + @Binds + @IntoMap + @FxControllerKey(CreateNewVaultRecoveryKeyController.class) + abstract FxController bindCreateNewVaultRecoveryKeyController(CreateNewVaultRecoveryKeyController controller); } diff --git a/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultLocationController.java b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultLocationController.java index f766d2fce..5d40dbeb8 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultLocationController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultLocationController.java @@ -23,6 +23,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.inject.Inject; +import javax.inject.Named; import java.io.File; import java.io.IOException; import java.nio.file.DirectoryNotEmptyException; @@ -58,7 +59,7 @@ public class CreateNewVaultLocationController implements FxController { public RadioButton customRadioButton; @Inject - CreateNewVaultLocationController(@AddVaultWizardWindow Stage window, @FxmlScene(FxmlFile.ADDVAULT_NEW_NAME) Lazy chooseNameScene, @FxmlScene(FxmlFile.ADDVAULT_NEW_PASSWORD) Lazy choosePasswordScene, LocationPresets locationPresets, ObjectProperty vaultPath, StringProperty vaultName, ResourceBundle resourceBundle) { + CreateNewVaultLocationController(@AddVaultWizardWindow Stage window, @FxmlScene(FxmlFile.ADDVAULT_NEW_NAME) Lazy chooseNameScene, @FxmlScene(FxmlFile.ADDVAULT_NEW_PASSWORD) Lazy choosePasswordScene, LocationPresets locationPresets, ObjectProperty vaultPath, @Named("vaultName") StringProperty vaultName, ResourceBundle resourceBundle) { this.window = window; this.chooseNameScene = chooseNameScene; this.choosePasswordScene = choosePasswordScene; diff --git a/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultNameController.java b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultNameController.java index 8cc8fa9a2..57b8bed04 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultNameController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultNameController.java @@ -16,6 +16,7 @@ import org.cryptomator.ui.common.FxmlFile; import org.cryptomator.ui.common.FxmlScene; import javax.inject.Inject; +import javax.inject.Named; import java.nio.file.Path; import java.util.ResourceBundle; import java.util.regex.Pattern; @@ -36,7 +37,7 @@ public class CreateNewVaultNameController implements FxController { private final StringBinding warningText; @Inject - CreateNewVaultNameController(@AddVaultWizardWindow Stage window, @FxmlScene(FxmlFile.ADDVAULT_WELCOME) Lazy welcomeScene, @FxmlScene(FxmlFile.ADDVAULT_NEW_LOCATION) Lazy chooseLocationScene, ObjectProperty vaultPath, StringProperty vaultName, ResourceBundle resourceBundle) { + CreateNewVaultNameController(@AddVaultWizardWindow Stage window, @FxmlScene(FxmlFile.ADDVAULT_WELCOME) Lazy welcomeScene, @FxmlScene(FxmlFile.ADDVAULT_NEW_LOCATION) Lazy chooseLocationScene, ObjectProperty vaultPath, @Named("vaultName") StringProperty vaultName, ResourceBundle resourceBundle) { this.window = window; this.welcomeScene = welcomeScene; this.chooseLocationScene = chooseLocationScene; diff --git a/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultPasswordController.java b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultPasswordController.java index 26091ec73..ab2fe27a0 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultPasswordController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultPasswordController.java @@ -12,7 +12,6 @@ import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.StringProperty; import javafx.fxml.FXML; import javafx.scene.Scene; -import javafx.scene.control.CheckBox; import javafx.scene.control.ContentDisplay; import javafx.scene.control.Label; import javafx.scene.layout.HBox; @@ -28,11 +27,13 @@ import org.cryptomator.ui.common.Tasks; import org.cryptomator.ui.controls.FontAwesome5IconView; import org.cryptomator.ui.controls.NiceSecurePasswordField; import org.cryptomator.ui.common.PasswordStrengthUtil; +import org.cryptomator.ui.recoverykey.RecoveryKeyFactory; import org.fxmisc.easybind.EasyBind; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.inject.Inject; +import javax.inject.Named; import java.io.IOException; import java.io.UncheckedIOException; import java.nio.channels.WritableByteChannel; @@ -56,11 +57,13 @@ public class CreateNewVaultPasswordController implements FxController { private final Stage window; private final Lazy chooseLocationScene; - private final Lazy successScene; + private final Lazy recoveryKeyScene; private final ExecutorService executor; - private final StringProperty vaultName; - private final ObjectProperty vaultPath; - private final ObjectProperty vault; + private final RecoveryKeyFactory recoveryKeyFactory; + private final StringProperty vaultNameProperty; + private final ObjectProperty vaultPathProperty; + private final ObjectProperty vaultProperty; + private final StringProperty recoveryKeyProperty; private final VaultListManager vaultListManager; private final ResourceBundle resourceBundle; private final PasswordStrengthUtil strengthRater; @@ -77,17 +80,18 @@ public class CreateNewVaultPasswordController implements FxController { public FontAwesome5IconView checkmark; public FontAwesome5IconView cross; public Label passwordMatchLabel; - public CheckBox finalConfirmationCheckbox; @Inject - CreateNewVaultPasswordController(@AddVaultWizardWindow Stage window, @FxmlScene(FxmlFile.ADDVAULT_NEW_LOCATION) Lazy chooseLocationScene, @FxmlScene(FxmlFile.ADDVAULT_SUCCESS) Lazy successScene, ExecutorService executor, StringProperty vaultName, ObjectProperty vaultPath, @AddVaultWizardWindow ObjectProperty vault, VaultListManager vaultListManager, ResourceBundle resourceBundle, PasswordStrengthUtil strengthRater, ReadmeGenerator readmeGenerator) { + CreateNewVaultPasswordController(@AddVaultWizardWindow Stage window, @FxmlScene(FxmlFile.ADDVAULT_NEW_LOCATION) Lazy chooseLocationScene, @FxmlScene(FxmlFile.ADDVAULT_NEW_RECOVERYKEY) Lazy recoveryKeyScene, ExecutorService executor, RecoveryKeyFactory recoveryKeyFactory, @Named("vaultName") StringProperty vaultName, ObjectProperty vaultPath, @AddVaultWizardWindow ObjectProperty vault, @Named("recoveryKey") StringProperty recoveryKey, VaultListManager vaultListManager, ResourceBundle resourceBundle, PasswordStrengthUtil strengthRater, ReadmeGenerator readmeGenerator) { this.window = window; this.chooseLocationScene = chooseLocationScene; - this.successScene = successScene; + this.recoveryKeyScene = recoveryKeyScene; this.executor = executor; - this.vaultName = vaultName; - this.vaultPath = vaultPath; - this.vault = vault; + this.recoveryKeyFactory = recoveryKeyFactory; + this.vaultNameProperty = vaultName; + this.vaultPathProperty = vaultPath; + this.vaultProperty = vault; + this.recoveryKeyProperty = recoveryKey; this.vaultListManager = vaultListManager; this.resourceBundle = resourceBundle; this.strengthRater = strengthRater; @@ -105,7 +109,7 @@ public class CreateNewVaultPasswordController implements FxController { //binding indicating if the passwords not match BooleanBinding passwordsMatch = Bindings.createBooleanBinding(() -> CharSequence.compare(passwordField.getCharacters(), reenterField.getCharacters()) == 0, passwordField.textProperty(), reenterField.textProperty()); BooleanBinding reenterFieldNotEmpty = reenterField.textProperty().isNotEmpty(); - readyToCreateVault.bind(reenterFieldNotEmpty.and(passwordsMatch).and(finalConfirmationCheckbox.selectedProperty()).and(processing.not())); + readyToCreateVault.bind(reenterFieldNotEmpty.and(passwordsMatch).and(processing.not())); //make match indicator invisible when passwords do not match or one is empty passwordMatchBox.visibleProperty().bind(reenterFieldNotEmpty); checkmark.visibleProperty().bind(passwordsMatch.and(reenterFieldNotEmpty)); @@ -125,7 +129,7 @@ public class CreateNewVaultPasswordController implements FxController { @FXML public void next() { - Path pathToVault = vaultPath.get(); + Path pathToVault = vaultPathProperty.get(); try { Files.createDirectory(pathToVault); @@ -140,8 +144,9 @@ public class CreateNewVaultPasswordController implements FxController { processing.set(true); Tasks.create(() -> { initializeVault(pathToVault, passwordField.getCharacters()); - }).onSuccess(() -> { - initializationSucceeded(pathToVault); + return recoveryKeyFactory.createRecoveryKey(pathToVault, passwordField.getCharacters()); + }).onSuccess(recoveryKey -> { + initializationSucceeded(pathToVault, recoveryKey); }).onError(IOException.class, e -> { // TODO show generic error screen LOG.error("", e); @@ -171,11 +176,12 @@ public class CreateNewVaultPasswordController implements FxController { LOG.info("Created vault at {}", path); } - private void initializationSucceeded(Path pathToVault) { + private void initializationSucceeded(Path pathToVault, String recoveryKey) { try { Vault newVault = vaultListManager.add(pathToVault); - vault.set(newVault); - window.setScene(successScene.get()); + vaultProperty.set(newVault); + recoveryKeyProperty.set(recoveryKey); + window.setScene(recoveryKeyScene.get()); } catch (NoSuchFileException e) { throw new UncheckedIOException(e); } @@ -184,11 +190,11 @@ public class CreateNewVaultPasswordController implements FxController { /* Getter/Setter */ public String getVaultName() { - return vaultName.get(); + return vaultNameProperty.get(); } public StringProperty vaultNameProperty() { - return vaultName; + return vaultNameProperty; } public IntegerProperty passwordStrengthProperty() { diff --git a/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultRecoveryKeyController.java b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultRecoveryKeyController.java new file mode 100644 index 000000000..4c38f1250 --- /dev/null +++ b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultRecoveryKeyController.java @@ -0,0 +1,42 @@ +package org.cryptomator.ui.addvaultwizard; + +import dagger.Lazy; +import javafx.beans.property.StringProperty; +import javafx.fxml.FXML; +import javafx.scene.Scene; +import javafx.stage.Stage; +import org.cryptomator.ui.common.FxController; +import org.cryptomator.ui.common.FxmlFile; +import org.cryptomator.ui.common.FxmlScene; + +import javax.inject.Inject; +import javax.inject.Named; + +public class CreateNewVaultRecoveryKeyController implements FxController { + + private final Stage window; + private final Lazy successScene; + private final StringProperty recoveryKeyProperty; + + @Inject + CreateNewVaultRecoveryKeyController(@AddVaultWizardWindow Stage window, @FxmlScene(FxmlFile.ADDVAULT_SUCCESS) Lazy successScene, @Named("recoveryKey")StringProperty recoveryKey) { + this.window = window; + this.successScene = successScene; + this.recoveryKeyProperty = recoveryKey; + } + + @FXML + public void next() { + window.setScene(successScene.get()); + } + + /* Getter/Setter */ + + public String getRecoveryKey() { + return recoveryKeyProperty.get(); + } + + public StringProperty recoveryKeyProperty() { + return recoveryKeyProperty; + } +} diff --git a/main/ui/src/main/java/org/cryptomator/ui/common/FxmlFile.java b/main/ui/src/main/java/org/cryptomator/ui/common/FxmlFile.java index 87a979a5c..aab0bd01a 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/common/FxmlFile.java +++ b/main/ui/src/main/java/org/cryptomator/ui/common/FxmlFile.java @@ -6,6 +6,7 @@ public enum FxmlFile { ADDVAULT_NEW_NAME("/fxml/addvault_new_name.fxml"), // ADDVAULT_NEW_LOCATION("/fxml/addvault_new_location.fxml"), // ADDVAULT_NEW_PASSWORD("/fxml/addvault_new_password.fxml"), // + ADDVAULT_NEW_RECOVERYKEY("/fxml/addvault_new_recoverykey.fxml"), // ADDVAULT_SUCCESS("/fxml/addvault_success.fxml"), // CHANGEPASSWORD("/fxml/changepassword.fxml"), // FORGET_PASSWORD("/fxml/forget_password.fxml"), // diff --git a/main/ui/src/main/resources/fxml/addvault_new_password.fxml b/main/ui/src/main/resources/fxml/addvault_new_password.fxml index a0cdbad64..52651cda6 100644 --- a/main/ui/src/main/resources/fxml/addvault_new_password.fxml +++ b/main/ui/src/main/resources/fxml/addvault_new_password.fxml @@ -10,9 +10,8 @@ - - + - diff --git a/main/ui/src/main/resources/fxml/addvault_new_recoverykey.fxml b/main/ui/src/main/resources/fxml/addvault_new_recoverykey.fxml new file mode 100644 index 000000000..c58436e69 --- /dev/null +++ b/main/ui/src/main/resources/fxml/addvault_new_recoverykey.fxml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + +