|
@@ -3,6 +3,8 @@ package org.cryptomator.ui.keyloading.hub;
|
|
|
import com.google.common.base.Preconditions;
|
|
|
import com.nimbusds.jose.JWEObject;
|
|
|
import dagger.Lazy;
|
|
|
+import org.cryptomator.common.keychain.KeychainManager;
|
|
|
+import org.cryptomator.common.keychain.NoKeychainAccessProviderException;
|
|
|
import org.cryptomator.common.settings.DeviceKey;
|
|
|
import org.cryptomator.cryptolib.api.Masterkey;
|
|
|
import org.cryptomator.cryptolib.api.MasterkeyLoadingFailedException;
|
|
@@ -31,15 +33,19 @@ public class HubKeyLoadingStrategy implements KeyLoadingStrategy {
|
|
|
static final String SCHEME_HUB_HTTPS = SCHEME_PREFIX + "https";
|
|
|
|
|
|
private final Stage window;
|
|
|
+ private final KeychainManager keychainManager;
|
|
|
private final Lazy<Scene> authFlowScene;
|
|
|
+ private final Lazy<Scene> noKeychainScene;
|
|
|
private final CompletableFuture<JWEObject> result;
|
|
|
private final DeviceKey deviceKey;
|
|
|
|
|
|
@Inject
|
|
|
- public HubKeyLoadingStrategy(@KeyLoading Stage window, @FxmlScene(FxmlFile.HUB_AUTH_FLOW) Lazy<Scene> authFlowScene, CompletableFuture<JWEObject> result, DeviceKey deviceKey, @Named("windowTitle") String windowTitle) {
|
|
|
+ public HubKeyLoadingStrategy(@KeyLoading Stage window, @FxmlScene(FxmlFile.HUB_AUTH_FLOW) Lazy<Scene> authFlowScene, @FxmlScene(FxmlFile.HUB_NO_KEYCHAIN) Lazy<Scene> noKeychainScene, CompletableFuture<JWEObject> result, DeviceKey deviceKey, KeychainManager keychainManager, @Named("windowTitle") String windowTitle) {
|
|
|
this.window = window;
|
|
|
+ this.keychainManager = keychainManager;
|
|
|
window.setTitle(windowTitle);
|
|
|
this.authFlowScene = authFlowScene;
|
|
|
+ this.noKeychainScene = noKeychainScene;
|
|
|
this.result = result;
|
|
|
this.deviceKey = deviceKey;
|
|
|
}
|
|
@@ -48,10 +54,16 @@ public class HubKeyLoadingStrategy implements KeyLoadingStrategy {
|
|
|
public Masterkey loadKey(URI keyId) throws MasterkeyLoadingFailedException {
|
|
|
Preconditions.checkArgument(keyId.getScheme().startsWith(SCHEME_PREFIX));
|
|
|
try {
|
|
|
+ if (!keychainManager.isSupported()) {
|
|
|
+ throw new NoKeychainAccessProviderException();
|
|
|
+ }
|
|
|
var keypair = deviceKey.get();
|
|
|
- startAuthFlow();
|
|
|
+ showWindow(authFlowScene);
|
|
|
var jwe = result.get();
|
|
|
return JWEHelper.decrypt(jwe, keypair.getPrivate());
|
|
|
+ } catch (NoKeychainAccessProviderException e) {
|
|
|
+ showWindow(noKeychainScene);
|
|
|
+ throw new UnlockCancelledException("Unlock canceled due to missing prerequisites", e);
|
|
|
} catch (DeviceKey.DeviceKeyRetrievalException e) {
|
|
|
throw new MasterkeyLoadingFailedException("Failed to load keypair", e);
|
|
|
} catch (CancellationException e) {
|
|
@@ -64,9 +76,9 @@ public class HubKeyLoadingStrategy implements KeyLoadingStrategy {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void startAuthFlow() {
|
|
|
+ private void showWindow(Lazy<Scene> scene) {
|
|
|
Platform.runLater(() -> {
|
|
|
- window.setScene(authFlowScene.get());
|
|
|
+ window.setScene(scene.get());
|
|
|
window.show();
|
|
|
Window owner = window.getOwner();
|
|
|
if (owner != null) {
|