iclouddriveLocationProperty() {
diff --git a/src/main/java/org/cryptomator/ui/common/AutoAnimator.java b/src/main/java/org/cryptomator/ui/common/AutoAnimator.java
index b5398339c..9b53dc318 100644
--- a/src/main/java/org/cryptomator/ui/common/AutoAnimator.java
+++ b/src/main/java/org/cryptomator/ui/common/AutoAnimator.java
@@ -12,15 +12,15 @@ import javafx.beans.value.ObservableValue;
*
* During creation the consumer can optionally define actions to be executed everytime before the animation starts and after it stops.
*/
-public class AutoAnimator {
+public class AutoAnimator {
- private final T animation;
+ private final Animation animation;
private final ObservableValue condition;
private final Runnable beforeStart;
private final Runnable afterStop;
private final Subscription sub;
- AutoAnimator(T animation, ObservableValue condition, Runnable beforeStart, Runnable afterStop) {
+ AutoAnimator(Animation animation, ObservableValue condition, Runnable beforeStart, Runnable afterStop) {
this.animation = animation;
this.condition = condition;
this.beforeStart = beforeStart;
@@ -52,7 +52,7 @@ public class AutoAnimator {
public static class Builder {
- private Animation animation;
+ private final Animation animation;
private ObservableValue condition = new SimpleBooleanProperty(true);
private Runnable beforeStart = () -> {};
private Runnable afterStop = () -> {};
diff --git a/src/main/java/org/cryptomator/ui/common/ErrorController.java b/src/main/java/org/cryptomator/ui/common/ErrorController.java
index a2204fae3..3b5e08ffb 100644
--- a/src/main/java/org/cryptomator/ui/common/ErrorController.java
+++ b/src/main/java/org/cryptomator/ui/common/ErrorController.java
@@ -77,7 +77,7 @@ public class ErrorController implements FxController {
var enhancedTemplate = String.format(REPORT_BODY_TEMPLATE, //
System.getProperty("os.name"), //
System.getProperty("os.version"), //
- environment.getAppVersion().orElse("undefined"), //
+ environment.getAppVersion(), //
environment.getBuildNumber().orElse("undefined"));
var body = URLEncoder.encode(enhancedTemplate, StandardCharsets.UTF_8);
application.getHostServices().showDocument(REPORT_URL_FORMAT.formatted(title, body));
diff --git a/src/main/java/org/cryptomator/ui/common/FxmlFile.java b/src/main/java/org/cryptomator/ui/common/FxmlFile.java
index bc952f9d1..73e805273 100644
--- a/src/main/java/org/cryptomator/ui/common/FxmlFile.java
+++ b/src/main/java/org/cryptomator/ui/common/FxmlFile.java
@@ -13,6 +13,13 @@ public enum FxmlFile {
FORGET_PASSWORD("/fxml/forget_password.fxml"), //
HEALTH_START("/fxml/health_start.fxml"), //
HEALTH_CHECK_LIST("/fxml/health_check_list.fxml"), //
+ HUB_AUTH_FLOW("/fxml/hub_auth_flow.fxml"), //
+ HUB_LICENSE_EXCEEDED("/fxml/hub_license_exceeded.fxml"), //
+ HUB_RECEIVE_KEY("/fxml/hub_receive_key.fxml"), //
+ HUB_REGISTER_DEVICE("/fxml/hub_register_device.fxml"), //
+ HUB_REGISTER_SUCCESS("/fxml/hub_register_success.fxml"), //
+ HUB_REGISTER_FAILED("/fxml/hub_register_failed.fxml"),
+ HUB_UNAUTHORIZED_DEVICE("/fxml/hub_unauthorized_device.fxml"), //
LOCK_FORCED("/fxml/lock_forced.fxml"), //
LOCK_FAILED("/fxml/lock_failed.fxml"), //
MAIN_WINDOW("/fxml/main_window.fxml"), //
@@ -23,9 +30,11 @@ public enum FxmlFile {
MIGRATION_SUCCESS("/fxml/migration_success.fxml"), //
PREFERENCES("/fxml/preferences.fxml"), //
QUIT("/fxml/quit.fxml"), //
+ QUIT_FORCED("/fxml/quit_forced.fxml"), //
RECOVERYKEY_CREATE("/fxml/recoverykey_create.fxml"), //
RECOVERYKEY_RECOVER("/fxml/recoverykey_recover.fxml"), //
RECOVERYKEY_RESET_PASSWORD("/fxml/recoverykey_reset_password.fxml"), //
+ RECOVERYKEY_RESET_PASSWORD_SUCCESS("/fxml/recoverykey_reset_password_success.fxml"), //
RECOVERYKEY_SUCCESS("/fxml/recoverykey_success.fxml"), //
REMOVE_VAULT("/fxml/remove_vault.fxml"), //
UNLOCK_ENTER_PASSWORD("/fxml/unlock_enter_password.fxml"),
diff --git a/src/main/java/org/cryptomator/ui/common/NewPasswordController.java b/src/main/java/org/cryptomator/ui/common/NewPasswordController.java
index caa0962f8..6f029efe1 100644
--- a/src/main/java/org/cryptomator/ui/common/NewPasswordController.java
+++ b/src/main/java/org/cryptomator/ui/common/NewPasswordController.java
@@ -1,6 +1,5 @@
package org.cryptomator.ui.common;
-import com.tobiasdiez.easybind.EasyBind;
import org.cryptomator.ui.controls.FontAwesome5IconView;
import org.cryptomator.ui.controls.NiceSecurePasswordField;
@@ -42,7 +41,7 @@ public class NewPasswordController implements FxController {
passwordStrength.bind(Bindings.createIntegerBinding(() -> strengthRater.computeRate(passwordField.getCharacters()), passwordField.textProperty()));
passwordStrengthLabel.graphicProperty().bind(Bindings.createObjectBinding(this::getIconViewForPasswordStrengthLabel, passwordField.textProperty(), passwordStrength));
- passwordStrengthLabel.textProperty().bind(EasyBind.map(passwordStrength, strengthRater::getStrengthDescription));
+ passwordStrengthLabel.textProperty().bind(passwordStrength.map(strengthRater::getStrengthDescription));
BooleanBinding passwordsMatch = Bindings.createBooleanBinding(this::passwordFieldsMatch, passwordField.textProperty(), reenterField.textProperty());
BooleanBinding reenterFieldNotEmpty = reenterField.textProperty().isNotEmpty();
diff --git a/src/main/java/org/cryptomator/ui/common/VaultService.java b/src/main/java/org/cryptomator/ui/common/VaultService.java
index a6486f35f..8486a09c0 100644
--- a/src/main/java/org/cryptomator/ui/common/VaultService.java
+++ b/src/main/java/org/cryptomator/ui/common/VaultService.java
@@ -86,7 +86,8 @@ public class VaultService {
}
/**
- * Creates but doesn't start a lock-all task.
+ * Creates a lock-all task.
+ * This task itself is _not started_, but its subtasks locking each vault will be already executed.
*
* @param vaults The list of vaults to be locked
* @param forced Whether to attempt a forced lock
diff --git a/src/main/java/org/cryptomator/ui/controls/NiceSecurePasswordField.java b/src/main/java/org/cryptomator/ui/controls/NiceSecurePasswordField.java
index 4d09707b9..e16c3ff21 100644
--- a/src/main/java/org/cryptomator/ui/controls/NiceSecurePasswordField.java
+++ b/src/main/java/org/cryptomator/ui/controls/NiceSecurePasswordField.java
@@ -46,7 +46,7 @@ public class NiceSecurePasswordField extends StackPane {
nonPrintableCharsIcon.managedProperty().bind(passwordField.containingNonPrintableCharsProperty());
revealPasswordIcon.setGlyph(FontAwesome5Icon.EYE);
- revealPasswordIcon.glyphProperty().bind(Bindings.createObjectBinding(this::getRevealPasswordGlyph, revealPasswordButton.selectedProperty()));
+ revealPasswordIcon.glyphProperty().bind(Bindings.when(revealPasswordButton.selectedProperty()).then(FontAwesome5Icon.EYE_SLASH).otherwise(FontAwesome5Icon.EYE));
revealPasswordIcon.setGlyphSize(ICON_SIZE);
revealPasswordButton.setContentDisplay(ContentDisplay.LEFT);
@@ -61,10 +61,6 @@ public class NiceSecurePasswordField extends StackPane {
disabledProperty().addListener(this::disabledChanged);
}
- private FontAwesome5Icon getRevealPasswordGlyph() {
- return revealPasswordButton.isSelected() ? FontAwesome5Icon.EYE_SLASH : FontAwesome5Icon.EYE;
- }
-
private void disabledChanged(@SuppressWarnings("unused") Observable observable) {
revealPasswordButton.setSelected(false);
}
diff --git a/src/main/java/org/cryptomator/ui/controls/SecurePasswordField.java b/src/main/java/org/cryptomator/ui/controls/SecurePasswordField.java
index 66df79394..a7ec9df6a 100644
--- a/src/main/java/org/cryptomator/ui/controls/SecurePasswordField.java
+++ b/src/main/java/org/cryptomator/ui/controls/SecurePasswordField.java
@@ -71,9 +71,11 @@ public class SecurePasswordField extends TextField {
}
public void cut() {
+ //not implemented by design
}
public void copy() {
+ //not implemented by design
}
public Object queryAccessibleAttribute(AccessibleAttribute attribute, Object... parameters) {
diff --git a/src/main/java/org/cryptomator/ui/forgetPassword/ForgetPasswordController.java b/src/main/java/org/cryptomator/ui/forgetPassword/ForgetPasswordController.java
index 81d28f682..8cd43ae22 100644
--- a/src/main/java/org/cryptomator/ui/forgetPassword/ForgetPasswordController.java
+++ b/src/main/java/org/cryptomator/ui/forgetPassword/ForgetPasswordController.java
@@ -43,9 +43,11 @@ public class ForgetPasswordController implements FxController {
LOG.debug("Forgot password for vault {}.", vault.getDisplayName());
confirmedResult.setValue(true);
} catch (KeychainAccessException e) {
- LOG.error("Failed to remove entry from system keychain.", e);
+ LOG.error("Failed to delete passphrase from system keychain.", e);
confirmedResult.setValue(false);
}
+ } else {
+ LOG.warn("Keychain not supported. Doing nothing.");
}
window.close();
}
diff --git a/src/main/java/org/cryptomator/ui/fxapp/AutoUnlocker.java b/src/main/java/org/cryptomator/ui/fxapp/AutoUnlocker.java
index 9d6a73fa0..973d919fc 100644
--- a/src/main/java/org/cryptomator/ui/fxapp/AutoUnlocker.java
+++ b/src/main/java/org/cryptomator/ui/fxapp/AutoUnlocker.java
@@ -4,6 +4,8 @@ import org.cryptomator.common.vaults.Vault;
import javax.inject.Inject;
import javafx.collections.ObservableList;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionStage;
@FxApplicationScoped
public class AutoUnlocker {
@@ -18,9 +20,11 @@ public class AutoUnlocker {
}
public void unlock() {
- vaults.stream().filter(Vault::isLocked).filter(v -> v.getVaultSettings().unlockAfterStartup().get()).forEach(v -> {
- appWindows.startUnlockWorkflow(v, null);
- });
+ vaults.stream().filter(Vault::isLocked) //
+ .filter(v -> v.getVaultSettings().unlockAfterStartup().get()) //
+ .>reduce(CompletableFuture.completedFuture(null), //
+ (unlockFlow, v) -> unlockFlow.handle((voit, ex) -> appWindows.startUnlockWorkflow(v, null)).thenCompose(stage -> stage), //we don't care here about the exception, logged elsewhere
+ (unlockChain1, unlockChain2) -> unlockChain1.handle((voit, ex) -> unlockChain2).thenCompose(stage -> stage));
}
}
diff --git a/src/main/java/org/cryptomator/ui/fxapp/FxApplicationModule.java b/src/main/java/org/cryptomator/ui/fxapp/FxApplicationModule.java
index 85e46dffa..cdeb764be 100644
--- a/src/main/java/org/cryptomator/ui/fxapp/FxApplicationModule.java
+++ b/src/main/java/org/cryptomator/ui/fxapp/FxApplicationModule.java
@@ -14,6 +14,7 @@ import org.cryptomator.ui.lock.LockComponent;
import org.cryptomator.ui.mainwindow.MainWindowComponent;
import org.cryptomator.ui.preferences.PreferencesComponent;
import org.cryptomator.ui.quit.QuitComponent;
+
import org.cryptomator.ui.traymenu.TrayMenuComponent;
import org.cryptomator.ui.unlock.UnlockComponent;
@@ -57,4 +58,4 @@ abstract class FxApplicationModule {
static QuitComponent provideQuitComponent(QuitComponent.Builder builder) {
return builder.build();
}
-}
+}
\ No newline at end of file
diff --git a/src/main/java/org/cryptomator/ui/fxapp/FxApplicationStyle.java b/src/main/java/org/cryptomator/ui/fxapp/FxApplicationStyle.java
index 711da7948..b6681f728 100644
--- a/src/main/java/org/cryptomator/ui/fxapp/FxApplicationStyle.java
+++ b/src/main/java/org/cryptomator/ui/fxapp/FxApplicationStyle.java
@@ -12,6 +12,8 @@ import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javafx.application.Application;
+import javafx.beans.property.ObjectProperty;
+import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.value.ObservableValue;
import java.util.Optional;
@@ -24,9 +26,10 @@ public class FxApplicationStyle {
private final Optional appearanceProvider;
private final LicenseHolder licenseHolder;
private final UiAppearanceListener systemInterfaceThemeListener = this::systemInterfaceThemeChanged;
+ private final ObjectProperty appliedTheme = new SimpleObjectProperty<>(Theme.LIGHT);
@Inject
- public FxApplicationStyle(Settings settings, Optional appearanceProvider, LicenseHolder licenseHolder){
+ public FxApplicationStyle(Settings settings, Optional appearanceProvider, LicenseHolder licenseHolder) {
this.settings = settings;
this.appearanceProvider = appearanceProvider;
this.licenseHolder = licenseHolder;
@@ -91,6 +94,7 @@ public class FxApplicationStyle {
} else {
Application.setUserAgentStylesheet(stylesheet.toString());
appearanceProvider.ifPresent(provider -> provider.adjustToTheme(Theme.LIGHT));
+ appliedTheme.set(Theme.LIGHT);
}
}
@@ -103,6 +107,11 @@ public class FxApplicationStyle {
} else {
Application.setUserAgentStylesheet(stylesheet.toString());
appearanceProvider.ifPresent(provider -> provider.adjustToTheme(Theme.DARK));
+ appliedTheme.set(Theme.DARK);
}
}
+
+ public ObjectProperty appliedThemeProperty() {
+ return appliedTheme;
+ }
}
diff --git a/src/main/java/org/cryptomator/ui/fxapp/FxApplicationTerminator.java b/src/main/java/org/cryptomator/ui/fxapp/FxApplicationTerminator.java
index 7c7b07c1e..569a3674a 100644
--- a/src/main/java/org/cryptomator/ui/fxapp/FxApplicationTerminator.java
+++ b/src/main/java/org/cryptomator/ui/fxapp/FxApplicationTerminator.java
@@ -2,10 +2,12 @@ package org.cryptomator.ui.fxapp;
import com.google.common.base.Preconditions;
import org.cryptomator.common.ShutdownHook;
+import org.cryptomator.common.settings.Settings;
import org.cryptomator.common.vaults.LockNotCompletedException;
import org.cryptomator.common.vaults.Vault;
import org.cryptomator.common.vaults.VaultState;
import org.cryptomator.common.vaults.Volume;
+import org.cryptomator.ui.common.VaultService;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -27,18 +29,24 @@ import static org.cryptomator.common.vaults.VaultState.Value.*;
public class FxApplicationTerminator {
private static final Set STATES_ALLOWING_TERMINATION = EnumSet.of(LOCKED, NEEDS_MIGRATION, MISSING, ERROR);
+ private static final Set STATES_PREVENT_TERMINATION = EnumSet.of(PROCESSING);
private static final Logger LOG = LoggerFactory.getLogger(FxApplicationTerminator.class);
private final ObservableList vaults;
private final ShutdownHook shutdownHook;
private final FxApplicationWindows appWindows;
private final AtomicBoolean allowQuitWithoutPrompt = new AtomicBoolean();
+ private final AtomicBoolean preventQuitWithGracefulLock = new AtomicBoolean();
+ private final Settings settings;
+ private final VaultService vaultService;
@Inject
- public FxApplicationTerminator(ObservableList vaults, ShutdownHook shutdownHook, FxApplicationWindows appWindows) {
+ public FxApplicationTerminator(ObservableList vaults, ShutdownHook shutdownHook, FxApplicationWindows appWindows, Settings settings, VaultService vaultService) {
this.vaults = vaults;
this.shutdownHook = shutdownHook;
this.appWindows = appWindows;
+ this.settings = settings;
+ this.vaultService = vaultService;
}
public void initialize() {
@@ -72,6 +80,10 @@ public class FxApplicationTerminator {
private void vaultListChanged(@SuppressWarnings("unused") Observable observable) {
boolean allowSuddenTermination = vaults.stream().map(Vault::getState).allMatch(STATES_ALLOWING_TERMINATION::contains);
boolean stateChanged = allowQuitWithoutPrompt.compareAndSet(!allowSuddenTermination, allowSuddenTermination);
+
+ boolean preventGracefulTermination = vaults.stream().map(Vault::getState).anyMatch(STATES_PREVENT_TERMINATION::contains);
+ preventQuitWithGracefulLock.set(preventGracefulTermination);
+
Desktop desktop = Desktop.getDesktop();
if (stateChanged && desktop.isSupported(Desktop.Action.APP_SUDDEN_TERMINATION)) {
if (allowSuddenTermination) {
@@ -92,10 +104,22 @@ public class FxApplicationTerminator {
*/
private void handleQuitRequest(@SuppressWarnings("unused") @Nullable EventObject e, QuitResponse response) {
var exitingResponse = new ExitingQuitResponse(response);
+
if (allowQuitWithoutPrompt.get()) {
exitingResponse.performQuit();
+ } else if (settings.autoCloseVaults().get() && !preventQuitWithGracefulLock.get()) {
+ var lockAllTask = vaultService.createLockAllTask(vaults.filtered(Vault::isUnlocked), false);
+ lockAllTask.setOnSucceeded(event -> {
+ LOG.info("Locked remaining vaults was succesful.");
+ exitingResponse.performQuit();
+ });
+ lockAllTask.setOnFailed(event -> {
+ LOG.warn("Unable to lock all vaults.");
+ appWindows.showQuitWindow(exitingResponse, true);
+ });
+ lockAllTask.run();
} else {
- appWindows.showQuitWindow(exitingResponse);
+ appWindows.showQuitWindow(exitingResponse, false);
}
}
@@ -115,7 +139,7 @@ public class FxApplicationTerminator {
/**
* A dummy QuitResponse that ignores the response.
- *
+ *
* To be used with {@link #handleQuitRequest(EventObject, QuitResponse)} if the invoking method is not interested in the response.
*/
private static class NoopQuitResponse implements QuitResponse {
diff --git a/src/main/java/org/cryptomator/ui/fxapp/FxApplicationWindows.java b/src/main/java/org/cryptomator/ui/fxapp/FxApplicationWindows.java
index ba28f9bc4..5d38a9017 100644
--- a/src/main/java/org/cryptomator/ui/fxapp/FxApplicationWindows.java
+++ b/src/main/java/org/cryptomator/ui/fxapp/FxApplicationWindows.java
@@ -40,7 +40,7 @@ public class FxApplicationWindows {
private final Optional trayIntegration;
private final Lazy mainWindow;
private final Lazy preferencesWindow;
- private final Lazy quitWindow;
+ private final QuitComponent.Builder quitWindowBuilder;
private final UnlockComponent.Factory unlockWorkflowFactory;
private final LockComponent.Factory lockWorkflowFactory;
private final ErrorComponent.Factory errorWindowFactory;
@@ -48,12 +48,12 @@ public class FxApplicationWindows {
private final FilteredList visibleWindows;
@Inject
- public FxApplicationWindows(@PrimaryStage Stage primaryStage, Optional trayIntegration, Lazy mainWindow, Lazy preferencesWindow, Lazy quitWindow, UnlockComponent.Factory unlockWorkflowFactory, LockComponent.Factory lockWorkflowFactory, ErrorComponent.Factory errorWindowFactory, ExecutorService executor) {
+ public FxApplicationWindows(@PrimaryStage Stage primaryStage, Optional trayIntegration, Lazy mainWindow, Lazy preferencesWindow, QuitComponent.Builder quitWindowBuilder, UnlockComponent.Factory unlockWorkflowFactory, LockComponent.Factory lockWorkflowFactory, ErrorComponent.Factory errorWindowFactory, ExecutorService executor) {
this.primaryStage = primaryStage;
this.trayIntegration = trayIntegration;
this.mainWindow = mainWindow;
this.preferencesWindow = preferencesWindow;
- this.quitWindow = quitWindow;
+ this.quitWindowBuilder = quitWindowBuilder;
this.unlockWorkflowFactory = unlockWorkflowFactory;
this.lockWorkflowFactory = lockWorkflowFactory;
this.errorWindowFactory = errorWindowFactory;
@@ -104,8 +104,8 @@ public class FxApplicationWindows {
return CompletableFuture.supplyAsync(() -> preferencesWindow.get().showPreferencesWindow(selectedTab), Platform::runLater).whenComplete(this::reportErrors);
}
- public CompletionStage showQuitWindow(QuitResponse response) {
- return CompletableFuture.supplyAsync(() -> quitWindow.get().showQuitWindow(response), Platform::runLater).whenComplete(this::reportErrors);
+ public void showQuitWindow(QuitResponse response, boolean forced) {
+ CompletableFuture.runAsync(() -> quitWindowBuilder.build().showQuitWindow(response,forced), Platform::runLater);
}
public CompletionStage startUnlockWorkflow(Vault vault, @Nullable Stage owner) {
diff --git a/src/main/java/org/cryptomator/ui/fxapp/UpdateChecker.java b/src/main/java/org/cryptomator/ui/fxapp/UpdateChecker.java
index 729791356..b83fe8515 100644
--- a/src/main/java/org/cryptomator/ui/fxapp/UpdateChecker.java
+++ b/src/main/java/org/cryptomator/ui/fxapp/UpdateChecker.java
@@ -9,14 +9,12 @@ import javax.inject.Inject;
import javax.inject.Named;
import javafx.beans.binding.BooleanBinding;
import javafx.beans.property.ReadOnlyStringProperty;
-import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.concurrent.ScheduledService;
import javafx.concurrent.Worker;
import javafx.concurrent.WorkerStateEvent;
import javafx.util.Duration;
import java.util.Comparator;
-import java.util.Optional;
@FxApplicationScoped
public class UpdateChecker {
@@ -25,8 +23,7 @@ public class UpdateChecker {
private static final Duration AUTOCHECK_DELAY = Duration.seconds(5);
private final Settings settings;
- private final Optional applicationVersion;
- private final StringProperty currentVersionProperty;
+ private final String currentVersion;
private final StringProperty latestVersionProperty;
private final Comparator semVerComparator;
private final ScheduledService updateCheckerService;
@@ -34,11 +31,10 @@ public class UpdateChecker {
@Inject
UpdateChecker(Settings settings, Environment env, @Named("latestVersion") StringProperty latestVersionProperty, @Named("SemVer") Comparator semVerComparator, ScheduledService updateCheckerService) {
this.settings = settings;
- this.applicationVersion = env.getAppVersion();
this.latestVersionProperty = latestVersionProperty;
this.semVerComparator = semVerComparator;
this.updateCheckerService = updateCheckerService;
- this.currentVersionProperty = new SimpleStringProperty(applicationVersion.orElse("SNAPSHOT"));
+ this.currentVersion = env.getAppVersion();
}
public void automaticallyCheckForUpdatesIfEnabled() {
@@ -66,11 +62,10 @@ public class UpdateChecker {
}
private void checkSucceeded(WorkerStateEvent event) {
- String currentVersion = applicationVersion.orElse(null);
String latestVersion = updateCheckerService.getValue();
LOG.info("Current version: {}, lastest version: {}", currentVersion, latestVersion);
- if (currentVersion == null || semVerComparator.compare(currentVersion, latestVersion) < 0) {
+ if (semVerComparator.compare(currentVersion, latestVersion) < 0) {
// update is available
latestVersionProperty.set(latestVersion);
} else {
@@ -92,8 +87,8 @@ public class UpdateChecker {
return latestVersionProperty;
}
- public ReadOnlyStringProperty currentVersionProperty() {
- return currentVersionProperty;
+ public String getCurrentVersion() {
+ return currentVersion;
}
}
diff --git a/src/main/java/org/cryptomator/ui/fxapp/UpdateCheckerModule.java b/src/main/java/org/cryptomator/ui/fxapp/UpdateCheckerModule.java
index 8c9f7fb20..dd7c5bf77 100644
--- a/src/main/java/org/cryptomator/ui/fxapp/UpdateCheckerModule.java
+++ b/src/main/java/org/cryptomator/ui/fxapp/UpdateCheckerModule.java
@@ -43,7 +43,9 @@ public abstract class UpdateCheckerModule {
@FxApplicationScoped
static Optional provideHttpClient() {
try {
- return Optional.of(HttpClient.newHttpClient());
+ return Optional.of(HttpClient.newBuilder() //
+ .followRedirects(HttpClient.Redirect.NORMAL) // from version 1.6.11 onwards, Cryptomator can follow redirects, in case this URL ever changes
+ .build());
} catch (UncheckedIOException e) {
LOG.error("HttpClient for update check cannot be created.", e);
return Optional.empty();
@@ -54,7 +56,7 @@ public abstract class UpdateCheckerModule {
@FxApplicationScoped
static HttpRequest provideCheckForUpdatesRequest(Environment env) {
String userAgent = String.format("Cryptomator VersionChecker/%s %s %s (%s)", //
- env.getAppVersion().orElse("SNAPSHOT"), //
+ env.getAppVersion(), //
SystemUtils.OS_NAME, //
SystemUtils.OS_VERSION, //
SystemUtils.OS_ARCH); //
diff --git a/src/main/java/org/cryptomator/ui/health/CheckDetailController.java b/src/main/java/org/cryptomator/ui/health/CheckDetailController.java
index 66f2e9bf5..c467a5328 100644
--- a/src/main/java/org/cryptomator/ui/health/CheckDetailController.java
+++ b/src/main/java/org/cryptomator/ui/health/CheckDetailController.java
@@ -3,12 +3,12 @@ package org.cryptomator.ui.health;
import com.tobiasdiez.easybind.EasyBind;
import com.tobiasdiez.easybind.EasyObservableList;
import com.tobiasdiez.easybind.Subscription;
-import com.tobiasdiez.easybind.optional.OptionalBinding;
import org.cryptomator.cryptofs.health.api.DiagnosticResult;
import org.cryptomator.ui.common.FxController;
import javax.inject.Inject;
import javafx.beans.binding.Binding;
+import javafx.beans.binding.BooleanExpression;
import javafx.beans.property.ObjectProperty;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
@@ -22,15 +22,15 @@ public class CheckDetailController implements FxController {
private final EasyObservableList results;
private final ObjectProperty check;
- private final OptionalBinding checkState;
- private final Binding checkName;
- private final Binding checkRunning;
- private final Binding checkScheduled;
- private final Binding checkFinished;
- private final Binding checkSkipped;
- private final Binding checkSucceeded;
- private final Binding checkFailed;
- private final Binding checkCancelled;
+ private final ObservableValue checkState;
+ private final ObservableValue checkName;
+ private final BooleanExpression checkRunning;
+ private final BooleanExpression checkScheduled;
+ private final BooleanExpression checkFinished;
+ private final BooleanExpression checkSkipped;
+ private final BooleanExpression checkSucceeded;
+ private final BooleanExpression checkFailed;
+ private final BooleanExpression checkCancelled;
private final Binding countOfWarnSeverity;
private final Binding countOfCritSeverity;
private final Binding warnOrCritsExist;
@@ -44,15 +44,15 @@ public class CheckDetailController implements FxController {
this.resultListCellFactory = resultListCellFactory;
this.results = EasyBind.wrapList(FXCollections.observableArrayList());
this.check = selectedTask;
- this.checkState = EasyBind.wrapNullable(selectedTask).mapObservable(Check::stateProperty);
- this.checkName = EasyBind.wrapNullable(selectedTask).map(Check::getName).orElse("");
- this.checkRunning = checkState.map(Check.CheckState.RUNNING::equals).orElse(false);
- this.checkScheduled = checkState.map(Check.CheckState.SCHEDULED::equals).orElse(false);
- this.checkSkipped = checkState.map(Check.CheckState.SKIPPED::equals).orElse(false);
- this.checkSucceeded = checkState.map(Check.CheckState.SUCCEEDED::equals).orElse(false);
- this.checkFailed = checkState.map(Check.CheckState.ERROR::equals).orElse(false);
- this.checkCancelled = checkState.map(Check.CheckState.CANCELLED::equals).orElse(false);
- this.checkFinished = EasyBind.combine(checkSucceeded, checkFailed, checkCancelled, (a, b, c) -> a || b || c);
+ this.checkState = selectedTask.flatMap(Check::stateProperty);
+ this.checkName = selectedTask.map(Check::getName).orElse("");
+ this.checkRunning = BooleanExpression.booleanExpression(checkState.map(Check.CheckState.RUNNING::equals).orElse(false));
+ this.checkScheduled = BooleanExpression.booleanExpression(checkState.map(Check.CheckState.SCHEDULED::equals).orElse(false));
+ this.checkSkipped =BooleanExpression.booleanExpression(checkState.map(Check.CheckState.SKIPPED::equals).orElse(false));
+ this.checkSucceeded = BooleanExpression.booleanExpression(checkState.map(Check.CheckState.SUCCEEDED::equals).orElse(false));
+ this.checkFailed = BooleanExpression.booleanExpression(checkState.map(Check.CheckState.ERROR::equals).orElse(false));
+ this.checkCancelled = BooleanExpression.booleanExpression(checkState.map(Check.CheckState.CANCELLED::equals).orElse(false));
+ this.checkFinished = checkSucceeded.or(checkFailed).or(checkCancelled);
this.countOfWarnSeverity = results.reduce(countSeverity(DiagnosticResult.Severity.WARN));
this.countOfCritSeverity = results.reduce(countSeverity(DiagnosticResult.Severity.CRITICAL));
this.warnOrCritsExist = EasyBind.combine(checkSucceeded, countOfWarnSeverity, countOfCritSeverity, (suceeded, warns, crits) -> suceeded && (warns.longValue() > 0 || crits.longValue() > 0) );
@@ -84,7 +84,7 @@ public class CheckDetailController implements FxController {
return checkName.getValue();
}
- public Binding checkNameProperty() {
+ public ObservableValue checkNameProperty() {
return checkName;
}
@@ -108,7 +108,7 @@ public class CheckDetailController implements FxController {
return checkRunning.getValue();
}
- public Binding checkRunningProperty() {
+ public BooleanExpression checkRunningProperty() {
return checkRunning;
}
@@ -116,7 +116,7 @@ public class CheckDetailController implements FxController {
return checkFinished.getValue();
}
- public Binding checkFinishedProperty() {
+ public BooleanExpression checkFinishedProperty() {
return checkFinished;
}
@@ -124,7 +124,7 @@ public class CheckDetailController implements FxController {
return checkScheduled.getValue();
}
- public Binding checkScheduledProperty() {
+ public BooleanExpression checkScheduledProperty() {
return checkScheduled;
}
@@ -132,7 +132,7 @@ public class CheckDetailController implements FxController {
return checkSkipped.getValue();
}
- public Binding checkSkippedProperty() {
+ public BooleanExpression checkSkippedProperty() {
return checkSkipped;
}
@@ -140,7 +140,7 @@ public class CheckDetailController implements FxController {
return checkSucceeded.getValue();
}
- public Binding checkSucceededProperty() {
+ public BooleanExpression checkSucceededProperty() {
return checkSucceeded;
}
@@ -148,7 +148,7 @@ public class CheckDetailController implements FxController {
return checkFailed.getValue();
}
- public Binding checkFailedProperty() {
+ public BooleanExpression checkFailedProperty() {
return checkFailed;
}
@@ -164,7 +164,7 @@ public class CheckDetailController implements FxController {
return warnOrCritsExist.getValue();
}
- public Binding checkCancelledProperty() {
+ public BooleanExpression checkCancelledProperty() {
return checkCancelled;
}
diff --git a/src/main/java/org/cryptomator/ui/health/CheckListCellController.java b/src/main/java/org/cryptomator/ui/health/CheckListCellController.java
index 5ef2926ef..6357be558 100644
--- a/src/main/java/org/cryptomator/ui/health/CheckListCellController.java
+++ b/src/main/java/org/cryptomator/ui/health/CheckListCellController.java
@@ -1,21 +1,20 @@
package org.cryptomator.ui.health;
-import com.tobiasdiez.easybind.EasyBind;
import org.cryptomator.ui.common.FxController;
import javax.inject.Inject;
-import javafx.beans.binding.Binding;
import javafx.beans.binding.Bindings;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
+import javafx.beans.value.ObservableValue;
import javafx.scene.control.CheckBox;
public class CheckListCellController implements FxController {
private final ObjectProperty check;
- private final Binding checkName;
- private final Binding checkRunnable;
+ private final ObservableValue checkRunnable;
+ private final ObservableValue checkName;
/* FXML */
public CheckBox checkbox;
@@ -23,8 +22,8 @@ public class CheckListCellController implements FxController {
@Inject
public CheckListCellController() {
check = new SimpleObjectProperty<>();
- checkRunnable = EasyBind.wrapNullable(check).mapObservable(Check::stateProperty).map(Check.CheckState.RUNNABLE::equals).orElse(false);
- checkName = EasyBind.wrapNullable(check).map(Check::getName).orElse("");
+ checkRunnable = check.flatMap(Check::stateProperty).map(Check.CheckState.RUNNABLE::equals).orElse(false);
+ checkName = check.map(Check::getName).orElse("");
}
public void initialize() {
@@ -50,7 +49,7 @@ public class CheckListCellController implements FxController {
check.set(c);
}
- public Binding checkNameProperty() {
+ public ObservableValue checkNameProperty() {
return checkName;
}
@@ -58,7 +57,7 @@ public class CheckListCellController implements FxController {
return checkName.getValue();
}
- public Binding checkRunnableProperty() {
+ public ObservableValue checkRunnableProperty() {
return checkRunnable;
}
diff --git a/src/main/java/org/cryptomator/ui/health/ResultListCellController.java b/src/main/java/org/cryptomator/ui/health/ResultListCellController.java
index 59ee2fa67..d655d0058 100644
--- a/src/main/java/org/cryptomator/ui/health/ResultListCellController.java
+++ b/src/main/java/org/cryptomator/ui/health/ResultListCellController.java
@@ -13,13 +13,12 @@ import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javafx.application.Platform;
-import javafx.beans.binding.Binding;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.BooleanBinding;
import javafx.beans.binding.ObjectBinding;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
-import javafx.beans.value.ObservableObjectValue;
+import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML;
import javafx.scene.control.Tooltip;
import javafx.util.Duration;
@@ -38,10 +37,10 @@ public class ResultListCellController implements FxController {
private final Logger LOG = LoggerFactory.getLogger(ResultListCellController.class);
private final ObjectProperty result;
- private final ObservableObjectValue severity;
- private final Binding description;
+ private final ObservableValue severity;
+ private final ObservableValue description;
private final ResultFixApplier fixApplier;
- private final ObservableObjectValue fixState;
+ private final ObservableValue fixState;
private final ObjectBinding severityGlyph;
private final ObjectBinding fixGlyph;
private final BooleanBinding fixable;
@@ -62,10 +61,10 @@ public class ResultListCellController implements FxController {
@Inject
public ResultListCellController(ResultFixApplier fixApplier, ResourceBundle resourceBundle) {
this.result = new SimpleObjectProperty<>(null);
- this.severity = EasyBind.wrapNullable(result).map(r -> r.diagnosis().getSeverity()).asOrdinary();
- this.description = EasyBind.wrapNullable(result).map(Result::getDescription).orElse("");
+ this.severity = result.map(Result::diagnosis).map(DiagnosticResult::getSeverity);
+ this.description = result.map(Result::getDescription).orElse("");
this.fixApplier = fixApplier;
- this.fixState = EasyBind.wrapNullable(result).mapObservable(Result::fixState).asOrdinary();
+ this.fixState = result.flatMap(Result::fixState);
this.severityGlyph = Bindings.createObjectBinding(this::getSeverityGlyph, result);
this.fixGlyph = Bindings.createObjectBinding(this::getFixGlyph, fixState);
this.fixable = Bindings.createBooleanBinding(this::isFixable, fixState);
@@ -83,14 +82,15 @@ public class ResultListCellController implements FxController {
@FXML
public void initialize() {
// see getGlyph() for relevant glyphs:
- subscriptions.addAll(List.of(EasyBind.includeWhen(severityView.getStyleClass(), "glyph-icon-muted", Bindings.equal(severity, DiagnosticResult.Severity.INFO)), //
- EasyBind.includeWhen(severityView.getStyleClass(), "glyph-icon-primary", Bindings.equal(severity, DiagnosticResult.Severity.GOOD)), //
- EasyBind.includeWhen(severityView.getStyleClass(), "glyph-icon-orange", Bindings.equal(severity, DiagnosticResult.Severity.WARN)), //
- EasyBind.includeWhen(severityView.getStyleClass(), "glyph-icon-red", Bindings.equal(severity, DiagnosticResult.Severity.CRITICAL)) //
+ subscriptions.addAll(List.of(EasyBind.includeWhen(severityView.getStyleClass(), "glyph-icon-muted", severity.map(DiagnosticResult.Severity.INFO::equals).orElse(false)), //
+ EasyBind.includeWhen(severityView.getStyleClass(), "glyph-icon-primary", severity.map(DiagnosticResult.Severity.GOOD::equals).orElse(false)), //
+ EasyBind.includeWhen(severityView.getStyleClass(), "glyph-icon-orange", severity.map(DiagnosticResult.Severity.WARN::equals).orElse(false)), //
+ EasyBind.includeWhen(severityView.getStyleClass(), "glyph-icon-red", severity.map(DiagnosticResult.Severity.CRITICAL::equals).orElse(false)) //
));
+
var animation = Animations.createDiscrete360Rotation(fixView);
this.fixRunningRotator = AutoAnimator.animate(animation) //
- .onCondition(Bindings.equal(fixState, Result.FixState.FIXING)) //
+ .onCondition(fixing) //
.afterStop(() -> fixView.setRotate(0)) //
.build();
}
@@ -127,7 +127,7 @@ public class ResultListCellController implements FxController {
return result;
}
- public Binding descriptionProperty() {
+ public ObservableValue descriptionProperty() {
return description;
}
@@ -173,7 +173,7 @@ public class ResultListCellController implements FxController {
}
public boolean isFixable() {
- return Result.FixState.FIXABLE.equals(fixState.get());
+ return Result.FixState.FIXABLE.equals(fixState.getValue());
}
public BooleanBinding fixingProperty() {
@@ -181,7 +181,7 @@ public class ResultListCellController implements FxController {
}
public boolean isFixing() {
- return Result.FixState.FIXING.equals(fixState.get());
+ return Result.FixState.FIXING.equals(fixState.getValue());
}
public BooleanBinding fixedProperty() {
@@ -189,7 +189,7 @@ public class ResultListCellController implements FxController {
}
public boolean isFixed() {
- return Result.FixState.FIXED.equals(fixState.get());
+ return Result.FixState.FIXED.equals(fixState.getValue());
}
public BooleanBinding fixFailedProperty() {
@@ -197,7 +197,7 @@ public class ResultListCellController implements FxController {
}
public Boolean isFixFailed() {
- return Result.FixState.FIX_FAILED.equals(fixState.get());
+ return Result.FixState.FIX_FAILED.equals(fixState.getValue());
}
public BooleanBinding fixRunningOrDoneProperty() {
diff --git a/src/main/java/org/cryptomator/ui/keyloading/KeyLoadingModule.java b/src/main/java/org/cryptomator/ui/keyloading/KeyLoadingModule.java
index 616e7e5e0..5dbb4adbd 100644
--- a/src/main/java/org/cryptomator/ui/keyloading/KeyLoadingModule.java
+++ b/src/main/java/org/cryptomator/ui/keyloading/KeyLoadingModule.java
@@ -6,6 +6,7 @@ import org.cryptomator.common.vaults.Vault;
import org.cryptomator.ui.common.DefaultSceneFactory;
import org.cryptomator.ui.common.FxController;
import org.cryptomator.ui.common.FxmlLoaderFactory;
+import org.cryptomator.ui.keyloading.hub.HubKeyLoadingModule;
import org.cryptomator.ui.keyloading.masterkeyfile.MasterkeyFileLoadingModule;
import javax.inject.Provider;
@@ -13,7 +14,7 @@ import java.io.IOException;
import java.util.Map;
import java.util.ResourceBundle;
-@Module(includes = {MasterkeyFileLoadingModule.class})
+@Module(includes = {MasterkeyFileLoadingModule.class, HubKeyLoadingModule.class})
abstract class KeyLoadingModule {
@Provides
diff --git a/src/main/java/org/cryptomator/ui/keyloading/hub/AuthFlowContext.java b/src/main/java/org/cryptomator/ui/keyloading/hub/AuthFlowContext.java
new file mode 100644
index 000000000..3ee2b55eb
--- /dev/null
+++ b/src/main/java/org/cryptomator/ui/keyloading/hub/AuthFlowContext.java
@@ -0,0 +1,5 @@
+package org.cryptomator.ui.keyloading.hub;
+
+record AuthFlowContext(String deviceId) {
+
+}
diff --git a/src/main/java/org/cryptomator/ui/keyloading/hub/AuthFlowController.java b/src/main/java/org/cryptomator/ui/keyloading/hub/AuthFlowController.java
new file mode 100644
index 000000000..5765f56e0
--- /dev/null
+++ b/src/main/java/org/cryptomator/ui/keyloading/hub/AuthFlowController.java
@@ -0,0 +1,101 @@
+package org.cryptomator.ui.keyloading.hub;
+
+import com.nimbusds.jose.JWEObject;
+import dagger.Lazy;
+import org.cryptomator.ui.common.FxController;
+import org.cryptomator.ui.common.FxmlFile;
+import org.cryptomator.ui.common.FxmlScene;
+import org.cryptomator.ui.keyloading.KeyLoading;
+import org.cryptomator.ui.keyloading.KeyLoadingScoped;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javafx.application.Application;
+import javafx.application.Platform;
+import javafx.beans.binding.Bindings;
+import javafx.beans.binding.StringBinding;
+import javafx.beans.property.ObjectProperty;
+import javafx.beans.property.SimpleObjectProperty;
+import javafx.concurrent.WorkerStateEvent;
+import javafx.fxml.FXML;
+import javafx.scene.Scene;
+import javafx.stage.Stage;
+import javafx.stage.WindowEvent;
+import java.net.URI;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.atomic.AtomicReference;
+
+@KeyLoadingScoped
+public class AuthFlowController implements FxController {
+
+ private final Application application;
+ private final Stage window;
+ private final ExecutorService executor;
+ private final String deviceId;
+ private final HubConfig hubConfig;
+ private final AtomicReference tokenRef;
+ private final CompletableFuture result;
+ private final Lazy receiveKeyScene;
+ private final ObjectProperty authUri;
+ private AuthFlowTask task;
+
+ @Inject
+ public AuthFlowController(Application application, @KeyLoading Stage window, ExecutorService executor, @Named("deviceId") String deviceId, HubConfig hubConfig, @Named("bearerToken") AtomicReference tokenRef, CompletableFuture result, @FxmlScene(FxmlFile.HUB_RECEIVE_KEY) Lazy receiveKeyScene) {
+ this.application = application;
+ this.window = window;
+ this.executor = executor;
+ this.deviceId = deviceId;
+ this.hubConfig = hubConfig;
+ this.tokenRef = tokenRef;
+ this.result = result;
+ this.receiveKeyScene = receiveKeyScene;
+ this.authUri = new SimpleObjectProperty<>();
+ this.window.addEventHandler(WindowEvent.WINDOW_HIDING, this::windowClosed);
+ }
+
+ @FXML
+ public void initialize() {
+ assert task == null;
+ task = new AuthFlowTask(hubConfig, new AuthFlowContext(deviceId), this::setAuthUri);
+ task.setOnFailed(this::authFailed);
+ task.setOnSucceeded(this::authSucceeded);
+ executor.submit(task);
+ }
+
+ @FXML
+ public void browse() {
+ application.getHostServices().showDocument(authUri.get().toString());
+ }
+
+ @FXML
+ public void cancel() {
+ window.close();
+ }
+
+ private void setAuthUri(URI uri) {
+ Platform.runLater(() -> {
+ authUri.set(uri);
+ browse();
+ });
+ }
+
+ private void windowClosed(WindowEvent windowEvent) {
+ // stop server, if it is still running
+ task.cancel();
+ result.cancel(true);
+ }
+
+ private void authSucceeded(WorkerStateEvent workerStateEvent) {
+ tokenRef.set(task.getValue());
+ window.requestFocus();
+ window.setScene(receiveKeyScene.get());
+ }
+
+ private void authFailed(WorkerStateEvent workerStateEvent) {
+ window.requestFocus();
+ var exception = workerStateEvent.getSource().getException();
+ result.completeExceptionally(exception);
+ }
+
+}
diff --git a/src/main/java/org/cryptomator/ui/keyloading/hub/AuthFlowTask.java b/src/main/java/org/cryptomator/ui/keyloading/hub/AuthFlowTask.java
new file mode 100644
index 000000000..c65256007
--- /dev/null
+++ b/src/main/java/org/cryptomator/ui/keyloading/hub/AuthFlowTask.java
@@ -0,0 +1,53 @@
+package org.cryptomator.ui.keyloading.hub;
+
+import com.google.gson.JsonParser;
+import io.github.coffeelibs.tinyoauth2client.AuthFlow;
+import io.github.coffeelibs.tinyoauth2client.TinyOAuth2;
+import io.github.coffeelibs.tinyoauth2client.http.response.Response;
+
+import javafx.concurrent.Task;
+import java.io.IOException;
+import java.net.URI;
+import java.util.function.Consumer;
+
+class AuthFlowTask extends Task {
+
+ private final HubConfig hubConfig;
+ private final AuthFlowContext authFlowContext;
+ private final Consumer redirectUriConsumer;
+
+ /**
+ * Spawns a server and waits for the redirectUri to be called.
+ *
+ * @param hubConfig Configuration object holding parameters required by {@link AuthFlow}
+ * @param redirectUriConsumer A callback invoked with the redirectUri, as soon as the server has started
+ */
+ public AuthFlowTask(HubConfig hubConfig, AuthFlowContext authFlowContext, Consumer redirectUriConsumer) {
+ this.hubConfig = hubConfig;
+ this.authFlowContext = authFlowContext;
+ this.redirectUriConsumer = redirectUriConsumer;
+ }
+
+ @Override
+ protected String call() throws IOException, InterruptedException {
+ var response = TinyOAuth2.client(hubConfig.clientId) //
+ .withTokenEndpoint(URI.create(hubConfig.tokenEndpoint)) //
+ .authFlow(URI.create(hubConfig.authEndpoint)) //
+ .setSuccessResponse(Response.redirect(URI.create(hubConfig.authSuccessUrl + "&device=" + authFlowContext.deviceId()))) //
+ .setErrorResponse(Response.redirect(URI.create(hubConfig.authErrorUrl + "&device=" + authFlowContext.deviceId()))) //
+ .authorize(redirectUriConsumer);
+ if (response.statusCode() != 200) {
+ throw new NotOkResponseException("Authorization returned status code " + response.statusCode());
+ }
+ var json = JsonParser.parseString(response.body());
+ return json.getAsJsonObject().get("access_token").getAsString();
+ }
+
+ public static class NotOkResponseException extends RuntimeException {
+
+ NotOkResponseException(String msg) {
+ super(msg);
+ }
+ }
+
+}
diff --git a/src/main/java/org/cryptomator/ui/keyloading/hub/CreateDeviceDto.java b/src/main/java/org/cryptomator/ui/keyloading/hub/CreateDeviceDto.java
new file mode 100644
index 000000000..71377a318
--- /dev/null
+++ b/src/main/java/org/cryptomator/ui/keyloading/hub/CreateDeviceDto.java
@@ -0,0 +1,9 @@
+package org.cryptomator.ui.keyloading.hub;
+
+class CreateDeviceDto {
+
+ public String id;
+ public String name;
+ public String publicKey;
+
+}
diff --git a/src/main/java/org/cryptomator/ui/keyloading/hub/HttpHelper.java b/src/main/java/org/cryptomator/ui/keyloading/hub/HttpHelper.java
new file mode 100644
index 000000000..51f3662a7
--- /dev/null
+++ b/src/main/java/org/cryptomator/ui/keyloading/hub/HttpHelper.java
@@ -0,0 +1,23 @@
+package org.cryptomator.ui.keyloading.hub;
+
+import com.google.common.io.CharStreams;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParseException;
+import com.google.gson.JsonParser;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.net.http.HttpResponse;
+import java.nio.charset.StandardCharsets;
+
+class HttpHelper {
+
+ public static String readBody(HttpResponse response) throws IOException {
+ try (var in = response.body(); var reader = new InputStreamReader(in, StandardCharsets.UTF_8)) {
+ return CharStreams.toString(reader);
+ }
+ }
+
+}
diff --git a/src/main/java/org/cryptomator/ui/keyloading/hub/HubConfig.java b/src/main/java/org/cryptomator/ui/keyloading/hub/HubConfig.java
new file mode 100644
index 000000000..7c2bc8be7
--- /dev/null
+++ b/src/main/java/org/cryptomator/ui/keyloading/hub/HubConfig.java
@@ -0,0 +1,13 @@
+package org.cryptomator.ui.keyloading.hub;
+
+// needs to be accessible by JSON decoder
+public class HubConfig {
+
+ public String clientId;
+ public String authEndpoint;
+ public String tokenEndpoint;
+ public String devicesResourceUrl;
+ public String authSuccessUrl;
+ public String authErrorUrl;
+
+}
diff --git a/src/main/java/org/cryptomator/ui/keyloading/hub/HubKeyLoadingModule.java b/src/main/java/org/cryptomator/ui/keyloading/hub/HubKeyLoadingModule.java
new file mode 100644
index 000000000..a23a5f1b3
--- /dev/null
+++ b/src/main/java/org/cryptomator/ui/keyloading/hub/HubKeyLoadingModule.java
@@ -0,0 +1,180 @@
+package org.cryptomator.ui.keyloading.hub;
+
+import com.google.common.io.BaseEncoding;
+import com.nimbusds.jose.JWEObject;
+import dagger.Binds;
+import dagger.Module;
+import dagger.Provides;
+import dagger.multibindings.IntoMap;
+import dagger.multibindings.StringKey;
+import org.cryptomator.common.settings.DeviceKey;
+import org.cryptomator.common.vaults.Vault;
+import org.cryptomator.cryptolib.common.MessageDigestSupplier;
+import org.cryptomator.ui.common.FxController;
+import org.cryptomator.ui.common.FxControllerKey;
+import org.cryptomator.ui.common.FxmlFile;
+import org.cryptomator.ui.common.FxmlLoaderFactory;
+import org.cryptomator.ui.common.FxmlScene;
+import org.cryptomator.ui.common.NewPasswordController;
+import org.cryptomator.ui.common.PasswordStrengthUtil;
+import org.cryptomator.ui.keyloading.KeyLoading;
+import org.cryptomator.ui.keyloading.KeyLoadingScoped;
+import org.cryptomator.ui.keyloading.KeyLoadingStrategy;
+
+import javax.inject.Named;
+import javafx.scene.Scene;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.util.Objects;
+import java.util.ResourceBundle;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicReference;
+
+@Module
+public abstract class HubKeyLoadingModule {
+
+ @Provides
+ @KeyLoadingScoped
+ static HubConfig provideHubConfig(@KeyLoading Vault vault) {
+ try {
+ return vault.getVaultConfigCache().get().getHeader("hub", HubConfig.class);
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
+ }
+
+ @Provides
+ @KeyLoadingScoped
+ @Named("windowTitle")
+ static String provideWindowTitle(@KeyLoading Vault vault, ResourceBundle resourceBundle) {
+ return String.format(resourceBundle.getString("unlock.title"), vault.getDisplayName());
+ }
+
+
+ @Provides
+ @KeyLoadingScoped
+ @Named("deviceId")
+ static String provideDeviceId(DeviceKey deviceKey) {
+ var publicKey = Objects.requireNonNull(deviceKey.get()).getPublic().getEncoded();
+ try (var instance = MessageDigestSupplier.SHA256.instance()) {
+ var hashedKey = instance.get().digest(publicKey);
+ return BaseEncoding.base16().encode(hashedKey);
+ }
+ }
+
+ @Provides
+ @Named("bearerToken")
+ @KeyLoadingScoped
+ static AtomicReference provideBearerTokenRef() {
+ return new AtomicReference<>();
+ }
+
+ @Provides
+ @KeyLoadingScoped
+ static CompletableFuture provideResult() {
+ return new CompletableFuture<>();
+ }
+
+ @Binds
+ @IntoMap
+ @KeyLoadingScoped
+ @StringKey(HubKeyLoadingStrategy.SCHEME_HUB_HTTP)
+ abstract KeyLoadingStrategy bindHubKeyLoadingStrategyToHubHttp(HubKeyLoadingStrategy strategy);
+
+ @Binds
+ @IntoMap
+ @KeyLoadingScoped
+ @StringKey(HubKeyLoadingStrategy.SCHEME_HUB_HTTPS)
+ abstract KeyLoadingStrategy bindHubKeyLoadingStrategyToHubHttps(HubKeyLoadingStrategy strategy);
+
+ @Provides
+ @FxmlScene(FxmlFile.HUB_AUTH_FLOW)
+ @KeyLoadingScoped
+ static Scene provideHubAuthFlowScene(@KeyLoading FxmlLoaderFactory fxmlLoaders) {
+ return fxmlLoaders.createScene(FxmlFile.HUB_AUTH_FLOW);
+ }
+
+ @Provides
+ @FxmlScene(FxmlFile.HUB_LICENSE_EXCEEDED)
+ @KeyLoadingScoped
+ static Scene provideLicenseExceededScene(@KeyLoading FxmlLoaderFactory fxmlLoaders) {
+ return fxmlLoaders.createScene(FxmlFile.HUB_LICENSE_EXCEEDED);
+ }
+
+ @Provides
+ @FxmlScene(FxmlFile.HUB_RECEIVE_KEY)
+ @KeyLoadingScoped
+ static Scene provideHubReceiveKeyScene(@KeyLoading FxmlLoaderFactory fxmlLoaders) {
+ return fxmlLoaders.createScene(FxmlFile.HUB_RECEIVE_KEY);
+ }
+
+ @Provides
+ @FxmlScene(FxmlFile.HUB_REGISTER_DEVICE)
+ @KeyLoadingScoped
+ static Scene provideHubRegisterDeviceScene(@KeyLoading FxmlLoaderFactory fxmlLoaders) {
+ return fxmlLoaders.createScene(FxmlFile.HUB_REGISTER_DEVICE);
+ }
+
+ @Provides
+ @FxmlScene(FxmlFile.HUB_REGISTER_SUCCESS)
+ @KeyLoadingScoped
+ static Scene provideHubRegisterSuccessScene(@KeyLoading FxmlLoaderFactory fxmlLoaders) {
+ return fxmlLoaders.createScene(FxmlFile.HUB_REGISTER_SUCCESS);
+ }
+
+ @Provides
+ @FxmlScene(FxmlFile.HUB_REGISTER_FAILED)
+ @KeyLoadingScoped
+ static Scene provideHubRegisterFailedScene(@KeyLoading FxmlLoaderFactory fxmlLoaders) {
+ return fxmlLoaders.createScene(FxmlFile.HUB_REGISTER_FAILED);
+ }
+
+ @Provides
+ @FxmlScene(FxmlFile.HUB_UNAUTHORIZED_DEVICE)
+ @KeyLoadingScoped
+ static Scene provideHubUnauthorizedDeviceScene(@KeyLoading FxmlLoaderFactory fxmlLoaders) {
+ return fxmlLoaders.createScene(FxmlFile.HUB_UNAUTHORIZED_DEVICE);
+ }
+
+ @Binds
+ @IntoMap
+ @FxControllerKey(AuthFlowController.class)
+ abstract FxController bindAuthFlowController(AuthFlowController controller);
+
+ @Provides
+ @IntoMap
+ @FxControllerKey(NewPasswordController.class)
+ static FxController provideNewPasswordController(ResourceBundle resourceBundle, PasswordStrengthUtil strengthRater) {
+ return new NewPasswordController(resourceBundle, strengthRater);
+ }
+
+ @Binds
+ @IntoMap
+ @FxControllerKey(LicenseExceededController.class)
+ abstract FxController bindLicenseExceededController(LicenseExceededController controller);
+
+ @Binds
+ @IntoMap
+ @FxControllerKey(ReceiveKeyController.class)
+ abstract FxController bindReceiveKeyController(ReceiveKeyController controller);
+
+ @Binds
+ @IntoMap
+ @FxControllerKey(RegisterDeviceController.class)
+ abstract FxController bindRegisterDeviceController(RegisterDeviceController controller);
+
+ @Binds
+ @IntoMap
+ @FxControllerKey(RegisterSuccessController.class)
+ abstract FxController bindRegisterSuccessController(RegisterSuccessController controller);
+
+ @Binds
+ @IntoMap
+ @FxControllerKey(RegisterFailedController.class)
+ abstract FxController bindRegisterFailedController(RegisterFailedController controller);
+
+ @Binds
+ @IntoMap
+ @FxControllerKey(UnauthorizedDeviceController.class)
+ abstract FxController bindUnauthorizedDeviceController(UnauthorizedDeviceController controller);
+}
diff --git a/src/main/java/org/cryptomator/ui/keyloading/hub/HubKeyLoadingStrategy.java b/src/main/java/org/cryptomator/ui/keyloading/hub/HubKeyLoadingStrategy.java
new file mode 100644
index 000000000..dcb5722d2
--- /dev/null
+++ b/src/main/java/org/cryptomator/ui/keyloading/hub/HubKeyLoadingStrategy.java
@@ -0,0 +1,80 @@
+package org.cryptomator.ui.keyloading.hub;
+
+import com.google.common.base.Preconditions;
+import com.nimbusds.jose.JWEObject;
+import dagger.Lazy;
+import org.cryptomator.common.settings.DeviceKey;
+import org.cryptomator.cryptolib.api.Masterkey;
+import org.cryptomator.cryptolib.api.MasterkeyLoadingFailedException;
+import org.cryptomator.ui.common.FxmlFile;
+import org.cryptomator.ui.common.FxmlScene;
+import org.cryptomator.ui.keyloading.KeyLoading;
+import org.cryptomator.ui.keyloading.KeyLoadingStrategy;
+import org.cryptomator.ui.unlock.UnlockCancelledException;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javafx.application.Platform;
+import javafx.scene.Scene;
+import javafx.stage.Stage;
+import javafx.stage.Window;
+import java.net.URI;
+import java.util.concurrent.CancellationException;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+
+@KeyLoading
+public class HubKeyLoadingStrategy implements KeyLoadingStrategy {
+
+ private static final String SCHEME_PREFIX = "hub+";
+ static final String SCHEME_HUB_HTTP = SCHEME_PREFIX + "http";
+ static final String SCHEME_HUB_HTTPS = SCHEME_PREFIX + "https";
+
+ private final Stage window;
+ private final Lazy authFlowScene;
+ private final CompletableFuture result;
+ private final DeviceKey deviceKey;
+
+ @Inject
+ public HubKeyLoadingStrategy(@KeyLoading Stage window, @FxmlScene(FxmlFile.HUB_AUTH_FLOW) Lazy authFlowScene, CompletableFuture result, DeviceKey deviceKey, @Named("windowTitle") String windowTitle) {
+ this.window = window;
+ window.setTitle(windowTitle);
+ this.authFlowScene = authFlowScene;
+ this.result = result;
+ this.deviceKey = deviceKey;
+ }
+
+ @Override
+ public Masterkey loadKey(URI keyId) throws MasterkeyLoadingFailedException {
+ Preconditions.checkArgument(keyId.getScheme().startsWith(SCHEME_PREFIX));
+ try {
+ startAuthFlow();
+ var jwe = result.get();
+ return JWEHelper.decrypt(jwe, deviceKey.get().getPrivate());
+ } catch (DeviceKey.DeviceKeyRetrievalException e) {
+ throw new MasterkeyLoadingFailedException("Failed to load keypair", e);
+ } catch (CancellationException e) {
+ throw new UnlockCancelledException("User cancelled auth workflow", e);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new UnlockCancelledException("Loading interrupted", e);
+ } catch (ExecutionException e) {
+ throw new MasterkeyLoadingFailedException("Failed to retrieve key", e);
+ }
+ }
+
+ private void startAuthFlow() {
+ Platform.runLater(() -> {
+ window.setScene(authFlowScene.get());
+ window.show();
+ Window owner = window.getOwner();
+ if (owner != null) {
+ window.setX(owner.getX() + (owner.getWidth() - window.getWidth()) / 2);
+ window.setY(owner.getY() + (owner.getHeight() - window.getHeight()) / 2);
+ } else {
+ window.centerOnScreen();
+ }
+ });
+ }
+
+}
diff --git a/src/main/java/org/cryptomator/ui/keyloading/hub/JWEHelper.java b/src/main/java/org/cryptomator/ui/keyloading/hub/JWEHelper.java
new file mode 100644
index 000000000..2c2b9baa4
--- /dev/null
+++ b/src/main/java/org/cryptomator/ui/keyloading/hub/JWEHelper.java
@@ -0,0 +1,55 @@
+package org.cryptomator.ui.keyloading.hub;
+
+import com.google.common.base.Preconditions;
+import com.google.common.io.BaseEncoding;
+import com.nimbusds.jose.JOSEException;
+import com.nimbusds.jose.JWEObject;
+import com.nimbusds.jose.crypto.ECDHDecrypter;
+import org.cryptomator.cryptolib.api.Masterkey;
+import org.cryptomator.cryptolib.api.MasterkeyLoadingFailedException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.security.interfaces.ECPrivateKey;
+import java.util.Arrays;
+
+class JWEHelper {
+
+ private static final Logger LOG = LoggerFactory.getLogger(JWEHelper.class);
+ private static final String JWE_PAYLOAD_MASTERKEY_FIELD = "key";
+
+ private JWEHelper(){}
+
+ public static Masterkey decrypt(JWEObject jwe, ECPrivateKey privateKey) throws MasterkeyLoadingFailedException {
+ try {
+ jwe.decrypt(new ECDHDecrypter(privateKey));
+ return readKey(jwe);
+ } catch (JOSEException e) {
+ LOG.warn("Failed to decrypt JWE: {}", jwe);
+ throw new MasterkeyLoadingFailedException("Failed to decrypt JWE", e);
+ }
+ }
+
+ private static Masterkey readKey(JWEObject jwe) throws MasterkeyLoadingFailedException {
+ Preconditions.checkArgument(jwe.getState() == JWEObject.State.DECRYPTED);
+ var fields = jwe.getPayload().toJSONObject();
+ if (fields == null) {
+ LOG.error("Expected JWE payload to be JSON: {}", jwe.getPayload());
+ throw new MasterkeyLoadingFailedException("Expected JWE payload to be JSON");
+ }
+ var keyBytes = new byte[0];
+ try {
+ if (fields.get(JWE_PAYLOAD_MASTERKEY_FIELD) instanceof String key) {
+ keyBytes = BaseEncoding.base64().decode(key);
+ return new Masterkey(keyBytes);
+ } else {
+ throw new IllegalArgumentException("JWE payload doesn't contain field " + JWE_PAYLOAD_MASTERKEY_FIELD);
+ }
+ } catch (IllegalArgumentException e) {
+ LOG.error("Unexpected JWE payload: {}", jwe.getPayload());
+ throw new MasterkeyLoadingFailedException("Unexpected JWE payload", e);
+ } finally {
+ Arrays.fill(keyBytes, (byte) 0x00);
+ }
+ }
+}
diff --git a/src/main/java/org/cryptomator/ui/keyloading/hub/LicenseExceededController.java b/src/main/java/org/cryptomator/ui/keyloading/hub/LicenseExceededController.java
new file mode 100644
index 000000000..115ba16b4
--- /dev/null
+++ b/src/main/java/org/cryptomator/ui/keyloading/hub/LicenseExceededController.java
@@ -0,0 +1,23 @@
+package org.cryptomator.ui.keyloading.hub;
+
+import org.cryptomator.ui.common.FxController;
+import org.cryptomator.ui.keyloading.KeyLoading;
+
+import javax.inject.Inject;
+import javafx.fxml.FXML;
+import javafx.stage.Stage;
+
+public class LicenseExceededController implements FxController {
+
+ private final Stage window;
+
+ @Inject
+ public LicenseExceededController(@KeyLoading Stage window) {
+ this.window = window;
+ }
+
+ @FXML
+ public void close() {
+ window.close();
+ }
+}
diff --git a/src/main/java/org/cryptomator/ui/keyloading/hub/ReceiveKeyController.java b/src/main/java/org/cryptomator/ui/keyloading/hub/ReceiveKeyController.java
new file mode 100644
index 000000000..44a09b988
--- /dev/null
+++ b/src/main/java/org/cryptomator/ui/keyloading/hub/ReceiveKeyController.java
@@ -0,0 +1,145 @@
+package org.cryptomator.ui.keyloading.hub;
+
+import com.nimbusds.jose.JWEObject;
+import dagger.Lazy;
+import org.cryptomator.common.vaults.Vault;
+import org.cryptomator.ui.common.FxController;
+import org.cryptomator.ui.common.FxmlFile;
+import org.cryptomator.ui.common.FxmlScene;
+import org.cryptomator.ui.keyloading.KeyLoading;
+import org.cryptomator.ui.keyloading.KeyLoadingScoped;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javafx.application.Platform;
+import javafx.fxml.FXML;
+import javafx.scene.Scene;
+import javafx.stage.Stage;
+import javafx.stage.WindowEvent;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UncheckedIOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.text.ParseException;
+import java.util.Objects;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.atomic.AtomicReference;
+
+@KeyLoadingScoped
+public class ReceiveKeyController implements FxController {
+
+ private static final String SCHEME_PREFIX = "hub+";
+
+ private final Stage window;
+ private final String deviceId;
+ private final String bearerToken;
+ private final CompletableFuture result;
+ private final Lazy registerDeviceScene;
+ private final Lazy unauthorizedScene;
+ private final URI vaultBaseUri;
+ private final Lazy licenseExceededScene;
+ private final HttpClient httpClient;
+
+ @Inject
+ public ReceiveKeyController(@KeyLoading Vault vault, ExecutorService executor, @KeyLoading Stage window, @Named("deviceId") String deviceId, @Named("bearerToken") AtomicReference tokenRef, CompletableFuture result, @FxmlScene(FxmlFile.HUB_REGISTER_DEVICE) Lazy registerDeviceScene, @FxmlScene(FxmlFile.HUB_UNAUTHORIZED_DEVICE) Lazy unauthorizedScene, @FxmlScene(FxmlFile.HUB_LICENSE_EXCEEDED) Lazy licenseExceededScene) {
+ this.window = window;
+ this.deviceId = deviceId;
+ this.bearerToken = Objects.requireNonNull(tokenRef.get());
+ this.result = result;
+ this.registerDeviceScene = registerDeviceScene;
+ this.unauthorizedScene = unauthorizedScene;
+ this.vaultBaseUri = getVaultBaseUri(vault);
+ this.licenseExceededScene = licenseExceededScene;
+ this.window.addEventHandler(WindowEvent.WINDOW_HIDING, this::windowClosed);
+ this.httpClient = HttpClient.newBuilder().version(HttpClient.Version.HTTP_1_1).executor(executor).build();
+ }
+
+ @FXML
+ public void initialize() {
+ var keyUri = appendPath(vaultBaseUri, "/keys/" + deviceId);
+ var request = HttpRequest.newBuilder(keyUri) //
+ .header("Authorization", "Bearer " + bearerToken) //
+ .GET() //
+ .build();
+ httpClient.sendAsync(request, HttpResponse.BodyHandlers.ofInputStream()) //
+ .thenAcceptAsync(this::loadedExistingKey, Platform::runLater) //
+ .exceptionally(this::retrievalFailed);
+ }
+
+ private void loadedExistingKey(HttpResponse response) {
+ try {
+ switch (response.statusCode()) {
+ case 200 -> retrievalSucceeded(response);
+ case 402 -> licenseExceeded();
+ case 403 -> accessNotGranted();
+ case 404 -> needsDeviceRegistration();
+ default -> throw new IOException("Unexpected response " + response.statusCode());
+ }
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
+ }
+
+ private void retrievalSucceeded(HttpResponse response) throws IOException {
+ try {
+ var string = HttpHelper.readBody(response);
+ result.complete(JWEObject.parse(string));
+ window.close();
+ } catch (ParseException e) {
+ throw new IOException("Failed to parse JWE", e);
+ }
+ }
+
+ private void licenseExceeded() {
+ window.setScene(licenseExceededScene.get());
+ }
+
+ private void needsDeviceRegistration() {
+ window.setScene(registerDeviceScene.get());
+ }
+
+ private void accessNotGranted() {
+ window.setScene(unauthorizedScene.get());
+ }
+
+ private Void retrievalFailed(Throwable cause) {
+ result.completeExceptionally(cause);
+ return null;
+ }
+
+ @FXML
+ public void cancel() {
+ window.close();
+ }
+
+ private void windowClosed(WindowEvent windowEvent) {
+ result.cancel(true);
+ }
+
+ private static URI appendPath(URI base, String path) {
+ try {
+ var newPath = base.getPath() + path;
+ return new URI(base.getScheme(), base.getAuthority(), newPath, base.getQuery(), base.getFragment());
+ } catch (URISyntaxException e) {
+ throw new IllegalArgumentException("Can't append '" + path + "' to URI: " + base, e);
+ }
+ }
+
+ private static URI getVaultBaseUri(Vault vault) {
+ try {
+ var kid = vault.getVaultConfigCache().get().getKeyId();
+ assert kid.getScheme().startsWith(SCHEME_PREFIX);
+ var hubUriScheme = kid.getScheme().substring(SCHEME_PREFIX.length());
+ return new URI(hubUriScheme, kid.getSchemeSpecificPart(), kid.getFragment());
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ } catch (URISyntaxException e) {
+ throw new IllegalStateException("URI constructed from params known to be valid", e);
+ }
+ }
+}
diff --git a/src/main/java/org/cryptomator/ui/keyloading/hub/RegisterDeviceController.java b/src/main/java/org/cryptomator/ui/keyloading/hub/RegisterDeviceController.java
new file mode 100644
index 000000000..4cf2d9fa2
--- /dev/null
+++ b/src/main/java/org/cryptomator/ui/keyloading/hub/RegisterDeviceController.java
@@ -0,0 +1,176 @@
+package org.cryptomator.ui.keyloading.hub;
+
+import com.auth0.jwt.JWT;
+import com.auth0.jwt.interfaces.DecodedJWT;
+import com.google.common.io.BaseEncoding;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.nimbusds.jose.JWEObject;
+import dagger.Lazy;
+import org.cryptomator.common.settings.DeviceKey;
+import org.cryptomator.cryptolib.common.P384KeyPair;
+import org.cryptomator.ui.common.FxController;
+import org.cryptomator.ui.common.FxmlFile;
+import org.cryptomator.ui.common.FxmlScene;
+import org.cryptomator.ui.keyloading.KeyLoading;
+import org.cryptomator.ui.keyloading.KeyLoadingScoped;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javafx.application.Platform;
+import javafx.beans.property.BooleanProperty;
+import javafx.beans.property.SimpleBooleanProperty;
+import javafx.fxml.FXML;
+import javafx.scene.Scene;
+import javafx.scene.control.Button;
+import javafx.scene.control.ContentDisplay;
+import javafx.scene.control.TextField;
+import javafx.stage.Stage;
+import javafx.stage.WindowEvent;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.URI;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.atomic.AtomicReference;
+
+@KeyLoadingScoped
+public class RegisterDeviceController implements FxController {
+
+ private static final Logger LOG = LoggerFactory.getLogger(RegisterDeviceController.class);
+ private static final Gson GSON = new GsonBuilder().setLenient().create();
+ private static final List EXPECTED_RESPONSE_CODES = List.of(201, 409);
+
+ private final Stage window;
+ private final HubConfig hubConfig;
+ private final String bearerToken;
+ private final Lazy registerSuccessScene;
+ private final Lazy registerFailedScene;
+ private final String deviceId;
+ private final P384KeyPair keyPair;
+ private final CompletableFuture result;
+ private final DecodedJWT jwt;
+ private final HttpClient httpClient;
+ private final BooleanProperty deviceNameAlreadyExists = new SimpleBooleanProperty(false);
+
+ public TextField deviceNameField;
+ public Button registerBtn;
+
+ @Inject
+ public RegisterDeviceController(@KeyLoading Stage window, ExecutorService executor, HubConfig hubConfig, @Named("deviceId") String deviceId, DeviceKey deviceKey, CompletableFuture result, @Named("bearerToken") AtomicReference bearerToken, @FxmlScene(FxmlFile.HUB_REGISTER_SUCCESS) Lazy registerSuccessScene, @FxmlScene(FxmlFile.HUB_REGISTER_FAILED) Lazy registerFailedScene) {
+ this.window = window;
+ this.hubConfig = hubConfig;
+ this.deviceId = deviceId;
+ this.keyPair = Objects.requireNonNull(deviceKey.get());
+ this.result = result;
+ this.bearerToken = Objects.requireNonNull(bearerToken.get());
+ this.registerSuccessScene = registerSuccessScene;
+ this.registerFailedScene = registerFailedScene;
+ this.jwt = JWT.decode(this.bearerToken);
+ this.window.addEventHandler(WindowEvent.WINDOW_HIDING, this::windowClosed);
+ this.httpClient = HttpClient.newBuilder().version(HttpClient.Version.HTTP_1_1).executor(executor).build();
+ }
+
+ public void initialize() {
+ deviceNameField.setText(determineHostname());
+ deviceNameField.textProperty().addListener(observable -> deviceNameAlreadyExists.set(false));
+ }
+
+ private String determineHostname() {
+ try {
+ var hostName = InetAddress.getLocalHost().getHostName();
+ return Objects.requireNonNullElse(hostName, "");
+ } catch (IOException e) {
+ return "";
+ }
+ }
+
+ @FXML
+ public void register() {
+ deviceNameAlreadyExists.set(false);
+ registerBtn.setContentDisplay(ContentDisplay.LEFT);
+ registerBtn.setDisable(true);
+
+ var keyUri = URI.create(hubConfig.devicesResourceUrl + deviceId);
+ var deviceKey = keyPair.getPublic().getEncoded();
+ var dto = new CreateDeviceDto();
+ dto.id = deviceId;
+ dto.name = deviceNameField.getText();
+ dto.publicKey = BaseEncoding.base64Url().omitPadding().encode(deviceKey);
+ var json = GSON.toJson(dto); // TODO: do we want to keep GSON? doesn't support records -.-
+ var request = HttpRequest.newBuilder(keyUri) //
+ .header("Authorization", "Bearer " + bearerToken) //
+ .header("Content-Type", "application/json").PUT(HttpRequest.BodyPublishers.ofString(json, StandardCharsets.UTF_8)) //
+ .build();
+ httpClient.sendAsync(request, HttpResponse.BodyHandlers.discarding()) //
+ .thenApply(response -> {
+ if (EXPECTED_RESPONSE_CODES.contains(response.statusCode())) {
+ return response;
+ } else {
+ throw new RuntimeException("Server answered with unexpected status code " + response.statusCode());
+ }
+ }).handleAsync((response, throwable) -> {
+ if (response != null) {
+ this.handleResponse(response);
+ } else {
+ this.registrationFailed(throwable);
+ }
+ return null;
+ }, Platform::runLater);
+ }
+
+ private void handleResponse(HttpResponse voidHttpResponse) {
+ assert EXPECTED_RESPONSE_CODES.contains(voidHttpResponse.statusCode());
+
+ if (voidHttpResponse.statusCode() == 409) {
+ deviceNameAlreadyExists.set(true);
+ registerBtn.setContentDisplay(ContentDisplay.TEXT_ONLY);
+ registerBtn.setDisable(false);
+ } else {
+ LOG.debug("Device registration for hub instance {} successful.", hubConfig.authSuccessUrl);
+ window.setScene(registerSuccessScene.get());
+ }
+ }
+
+ private void registrationFailed(Throwable cause) {
+ LOG.warn("Device registration failed.", cause);
+ window.setScene(registerFailedScene.get());
+ result.completeExceptionally(cause);
+ }
+
+ @FXML
+ public void close() {
+ window.close();
+ }
+
+ private void windowClosed(WindowEvent windowEvent) {
+ result.cancel(true);
+ }
+
+ /* Getter */
+
+ public String getUserName() {
+ return jwt.getClaim("email").asString();
+ }
+
+
+ //--- Getters & Setters
+
+ public BooleanProperty deviceNameAlreadyExistsProperty() {
+ return deviceNameAlreadyExists;
+ }
+
+ public boolean getDeviceNameAlreadyExists() {
+ return deviceNameAlreadyExists.get();
+ }
+
+
+}
diff --git a/src/main/java/org/cryptomator/ui/keyloading/hub/RegisterFailedController.java b/src/main/java/org/cryptomator/ui/keyloading/hub/RegisterFailedController.java
new file mode 100644
index 000000000..8a4278d72
--- /dev/null
+++ b/src/main/java/org/cryptomator/ui/keyloading/hub/RegisterFailedController.java
@@ -0,0 +1,29 @@
+package org.cryptomator.ui.keyloading.hub;
+
+import com.nimbusds.jose.JWEObject;
+import org.cryptomator.ui.common.FxController;
+import org.cryptomator.ui.keyloading.KeyLoading;
+
+import javax.inject.Inject;
+import javafx.fxml.FXML;
+import javafx.stage.Stage;
+import java.util.concurrent.CompletableFuture;
+
+public class RegisterFailedController implements FxController {
+
+ private final Stage window;
+ private final CompletableFuture result;
+
+ @Inject
+ public RegisterFailedController(@KeyLoading Stage window, CompletableFuture result) {
+ this.window = window;
+ this.result = result;
+ }
+
+ @FXML
+ public void close() {
+ window.close();
+ }
+
+
+}
diff --git a/src/main/java/org/cryptomator/ui/keyloading/hub/RegisterSuccessController.java b/src/main/java/org/cryptomator/ui/keyloading/hub/RegisterSuccessController.java
new file mode 100644
index 000000000..bba13516c
--- /dev/null
+++ b/src/main/java/org/cryptomator/ui/keyloading/hub/RegisterSuccessController.java
@@ -0,0 +1,24 @@
+package org.cryptomator.ui.keyloading.hub;
+
+import org.cryptomator.ui.common.FxController;
+import org.cryptomator.ui.keyloading.KeyLoading;
+
+import javax.inject.Inject;
+import javafx.fxml.FXML;
+import javafx.stage.Stage;
+
+public class RegisterSuccessController implements FxController {
+
+ private final Stage window;
+
+ @Inject
+ public RegisterSuccessController(@KeyLoading Stage window) {
+ this.window = window;
+ }
+
+ @FXML
+ public void close() {
+ window.close();
+ }
+
+}
diff --git a/src/main/java/org/cryptomator/ui/keyloading/hub/UnauthorizedDeviceController.java b/src/main/java/org/cryptomator/ui/keyloading/hub/UnauthorizedDeviceController.java
new file mode 100644
index 000000000..1a7cbab02
--- /dev/null
+++ b/src/main/java/org/cryptomator/ui/keyloading/hub/UnauthorizedDeviceController.java
@@ -0,0 +1,35 @@
+package org.cryptomator.ui.keyloading.hub;
+
+import com.nimbusds.jose.JWEObject;
+import org.cryptomator.ui.common.FxController;
+import org.cryptomator.ui.keyloading.KeyLoading;
+import org.cryptomator.ui.keyloading.KeyLoadingScoped;
+
+import javax.inject.Inject;
+import javafx.fxml.FXML;
+import javafx.stage.Stage;
+import javafx.stage.WindowEvent;
+import java.util.concurrent.CompletableFuture;
+
+@KeyLoadingScoped
+public class UnauthorizedDeviceController implements FxController {
+
+ private final Stage window;
+ private final CompletableFuture result;
+
+ @Inject
+ public UnauthorizedDeviceController(@KeyLoading Stage window, CompletableFuture result) {
+ this.window = window;
+ this.result = result;
+ this.window.addEventHandler(WindowEvent.WINDOW_HIDING, this::windowClosed);
+ }
+
+ @FXML
+ public void close() {
+ window.close();
+ }
+
+ private void windowClosed(WindowEvent windowEvent) {
+ result.cancel(true);
+ }
+}
diff --git a/src/main/java/org/cryptomator/ui/keyloading/hub/package-info.java b/src/main/java/org/cryptomator/ui/keyloading/hub/package-info.java
new file mode 100644
index 000000000..54bd6ae0e
--- /dev/null
+++ b/src/main/java/org/cryptomator/ui/keyloading/hub/package-info.java
@@ -0,0 +1,24 @@
+/**
+ * This {@link org.cryptomator.ui.keyloading.KeyLoadingStrategy strategy} retrieves the vault key from a web application, similar to
+ * RFC 8252 but with an encrypted masterkey instead of an authorization code.
+ *
+ * If the kid of the vault config starts with either {@value org.cryptomator.ui.keyloading.hub.HubKeyLoadingStrategy#SCHEME_HUB_HTTP}
+ * or {@value org.cryptomator.ui.keyloading.hub.HubKeyLoadingStrategy#SCHEME_HUB_HTTPS}, the included http address is amended by three parameters and opened
+ * in a browser. These parameters are:
+ *
+ * - A device-specific public key (generated by this application and stored among its settings
+ * - A unique device ID (stored in settings)
+ * - A loopback callback address
+ *
+ *
+ * The callback address points to a embedded web server waiting to receive the masterkey encrypted specifically for this device, using the device-specific public key.
+ *
+ * The vault key can be decrypted using this ECIES:
+ *
+ * - Generate shared secret using ECDH without cofactor
+ * - Derive 44 bytes using ANSI X9.63 KDF with SHA256
+ * - Decrypt payload via AES-GCM, using first 32 bytes as key, last 12 bytes as IV
+ * - No MAC check required, as AES-GCM includes a tag already
+ *
+ */
+package org.cryptomator.ui.keyloading.hub;
\ No newline at end of file
diff --git a/src/main/java/org/cryptomator/ui/keyloading/masterkeyfile/ChooseMasterkeyFileController.java b/src/main/java/org/cryptomator/ui/keyloading/masterkeyfile/ChooseMasterkeyFileController.java
index 11cf7bd6b..9b2231921 100644
--- a/src/main/java/org/cryptomator/ui/keyloading/masterkeyfile/ChooseMasterkeyFileController.java
+++ b/src/main/java/org/cryptomator/ui/keyloading/masterkeyfile/ChooseMasterkeyFileController.java
@@ -1,11 +1,13 @@
package org.cryptomator.ui.keyloading.masterkeyfile;
+import org.cryptomator.common.vaults.Vault;
import org.cryptomator.ui.common.FxController;
import org.cryptomator.ui.keyloading.KeyLoading;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
+import javafx.beans.binding.StringBinding;
import javafx.fxml.FXML;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
@@ -15,18 +17,22 @@ import java.nio.file.Path;
import java.util.ResourceBundle;
import java.util.concurrent.CompletableFuture;
+import static org.cryptomator.common.Constants.CRYPTOMATOR_FILENAME_GLOB;
+
@ChooseMasterkeyFileScoped
public class ChooseMasterkeyFileController implements FxController {
private static final Logger LOG = LoggerFactory.getLogger(ChooseMasterkeyFileController.class);
private final Stage window;
+ private final Vault vault;
private final CompletableFuture result;
private final ResourceBundle resourceBundle;
@Inject
- public ChooseMasterkeyFileController(@KeyLoading Stage window, CompletableFuture result, ResourceBundle resourceBundle) {
+ public ChooseMasterkeyFileController(@KeyLoading Stage window, @KeyLoading Vault vault, CompletableFuture result, ResourceBundle resourceBundle) {
this.window = window;
+ this.vault = vault;
this.result = result;
this.resourceBundle = resourceBundle;
this.window.setOnHiding(this::windowClosed);
@@ -46,7 +52,7 @@ public class ChooseMasterkeyFileController implements FxController {
LOG.trace("proceed()");
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle(resourceBundle.getString("unlock.chooseMasterkey.filePickerTitle"));
- fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Cryptomator Masterkey", "*.cryptomator"));
+ fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter(resourceBundle.getString("unlock.chooseMasterkey.filePickerMimeDesc"), CRYPTOMATOR_FILENAME_GLOB));
File masterkeyFile = fileChooser.showOpenDialog(window);
if (masterkeyFile != null) {
LOG.debug("Chose masterkey file: {}", masterkeyFile);
@@ -54,4 +60,10 @@ public class ChooseMasterkeyFileController implements FxController {
}
}
+ //--- Setter & Getter ---
+
+ public String getDisplayName(){
+ return vault.getDisplayName();
+ }
+
}
diff --git a/src/main/java/org/cryptomator/ui/keyloading/masterkeyfile/MasterkeyFileLoadingStrategy.java b/src/main/java/org/cryptomator/ui/keyloading/masterkeyfile/MasterkeyFileLoadingStrategy.java
index b4964f9a0..68877430a 100644
--- a/src/main/java/org/cryptomator/ui/keyloading/masterkeyfile/MasterkeyFileLoadingStrategy.java
+++ b/src/main/java/org/cryptomator/ui/keyloading/masterkeyfile/MasterkeyFileLoadingStrategy.java
@@ -61,6 +61,7 @@ public class MasterkeyFileLoadingStrategy implements KeyLoadingStrategy {
@Override
public Masterkey loadKey(URI keyId) throws MasterkeyLoadingFailedException {
+ window.setTitle(resourceBundle.getString("unlock.title").formatted(vault.getDisplayName()));
Preconditions.checkArgument(SCHEME.equalsIgnoreCase(keyId.getScheme()), "Only supports keys with scheme " + SCHEME);
try {
Path filePath = vault.getPath().resolve(keyId.getSchemeSpecificPart());
@@ -124,7 +125,6 @@ public class MasterkeyFileLoadingStrategy implements KeyLoadingStrategy {
var comp = masterkeyFileChoice.build();
Platform.runLater(() -> {
window.setScene(comp.chooseMasterkeyScene());
- window.setTitle(resourceBundle.getString("unlock.chooseMasterkey.title").formatted(vault.getDisplayName()));
window.show();
Window owner = window.getOwner();
if (owner != null) {
@@ -147,7 +147,6 @@ public class MasterkeyFileLoadingStrategy implements KeyLoadingStrategy {
var comp = passphraseEntry.savedPassword(passphrase).build();
Platform.runLater(() -> {
window.setScene(comp.passphraseEntryScene());
- window.setTitle(resourceBundle.getString("unlock.title").formatted(vault.getDisplayName()));
window.show();
Window owner = window.getOwner();
if (owner != null) {
diff --git a/src/main/java/org/cryptomator/ui/keyloading/masterkeyfile/PassphraseEntryController.java b/src/main/java/org/cryptomator/ui/keyloading/masterkeyfile/PassphraseEntryController.java
index 24afab78a..baadb9a12 100644
--- a/src/main/java/org/cryptomator/ui/keyloading/masterkeyfile/PassphraseEntryController.java
+++ b/src/main/java/org/cryptomator/ui/keyloading/masterkeyfile/PassphraseEntryController.java
@@ -1,10 +1,10 @@
package org.cryptomator.ui.keyloading.masterkeyfile;
import org.cryptomator.common.Nullable;
+import org.cryptomator.common.Passphrase;
import org.cryptomator.common.keychain.KeychainManager;
import org.cryptomator.common.vaults.Vault;
import org.cryptomator.ui.common.FxController;
-import org.cryptomator.common.Passphrase;
import org.cryptomator.ui.common.WeakBindings;
import org.cryptomator.ui.controls.NiceSecurePasswordField;
import org.cryptomator.ui.forgetPassword.ForgetPasswordComponent;
@@ -50,7 +50,7 @@ public class PassphraseEntryController implements FxController {
private final KeychainManager keychain;
private final StringBinding vaultName;
private final BooleanProperty unlockInProgress = new SimpleBooleanProperty();
- private final ObjectBinding unlockButtonContentDisplay = Bindings.createObjectBinding(this::getUnlockButtonContentDisplay, unlockInProgress);
+ private final ObjectBinding unlockButtonContentDisplay = Bindings.when(unlockInProgress).then(ContentDisplay.LEFT).otherwise(ContentDisplay.TEXT_ONLY);
private final BooleanProperty unlockButtonDisabled = new SimpleBooleanProperty();
/* FXML */
@@ -186,7 +186,7 @@ public class PassphraseEntryController implements FxController {
}
public ContentDisplay getUnlockButtonContentDisplay() {
- return unlockInProgress.get() ? ContentDisplay.LEFT : ContentDisplay.TEXT_ONLY;
+ return unlockButtonContentDisplay.get();
}
public ReadOnlyBooleanProperty userInteractionDisabledProperty() {
diff --git a/src/main/java/org/cryptomator/ui/mainwindow/ResizeController.java b/src/main/java/org/cryptomator/ui/mainwindow/ResizeController.java
index 448d54d91..11f035124 100644
--- a/src/main/java/org/cryptomator/ui/mainwindow/ResizeController.java
+++ b/src/main/java/org/cryptomator/ui/mainwindow/ResizeController.java
@@ -46,7 +46,7 @@ public class ResizeController implements FxController {
ResizeController(@MainWindow Stage window, Settings settings) {
this.window = window;
this.settings = settings;
- this.showResizingArrows = Bindings.createBooleanBinding(this::isShowResizingArrows, window.fullScreenProperty());
+ this.showResizingArrows = window.fullScreenProperty().not();
}
@FXML
@@ -181,8 +181,7 @@ public class ResizeController implements FxController {
}
public boolean isShowResizingArrows() {
- //If in fullscreen resizing is not be possible;
- return !window.isFullScreen();
+ return showResizingArrows.get();
}
}
\ No newline at end of file
diff --git a/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailController.java b/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailController.java
index b38710023..7e309fdaf 100644
--- a/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailController.java
+++ b/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailController.java
@@ -1,6 +1,5 @@
package org.cryptomator.ui.mainwindow;
-import com.tobiasdiez.easybind.EasyBind;
import org.cryptomator.common.vaults.Vault;
import org.cryptomator.common.vaults.VaultState;
import org.cryptomator.ui.common.Animations;
@@ -11,10 +10,10 @@ import org.cryptomator.ui.controls.FontAwesome5IconView;
import javax.inject.Inject;
import javafx.application.Application;
-import javafx.beans.binding.Binding;
import javafx.beans.binding.BooleanBinding;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.ReadOnlyObjectProperty;
+import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML;
@MainWindowScoped
@@ -22,7 +21,7 @@ public class VaultDetailController implements FxController {
private final ReadOnlyObjectProperty vault;
private final Application application;
- private final Binding glyph;
+ private final ObservableValue glyph;
private final BooleanBinding anyVaultSelected;
private AutoAnimator spinAnimation;
@@ -35,15 +34,13 @@ public class VaultDetailController implements FxController {
VaultDetailController(ObjectProperty vault, Application application) {
this.vault = vault;
this.application = application;
- this.glyph = EasyBind.select(vault) //
- .selectObject(Vault::stateProperty) //
- .map(this::getGlyphForVaultState);
+ this.glyph = vault.flatMap(Vault::stateProperty).map(this::getGlyphForVaultState);
this.anyVaultSelected = vault.isNotNull();
}
public void initialize() {
this.spinAnimation = AutoAnimator.animate(Animations.createDiscrete360Rotation(vaultStateView)) //
- .onCondition(EasyBind.select(vault).selectObject(Vault::stateProperty).map(VaultState.Value.PROCESSING::equals)) //
+ .onCondition(vault.flatMap(Vault::stateProperty).map(VaultState.Value.PROCESSING::equals).orElse(false)) //
.afterStop(() -> vaultStateView.setRotate(0)) //
.build();
}
@@ -77,7 +74,7 @@ public class VaultDetailController implements FxController {
return vault.get();
}
- public Binding