From f8b56ab774647190bf9bc93ec83146ece3b0f68f Mon Sep 17 00:00:00 2001 From: crschnick Date: Sun, 6 Aug 2023 15:00:40 +0000 Subject: [PATCH] Ssh secret input rework --- app/build.gradle | 2 +- .../java/io/xpipe/app/util/AskpassAlert.java | 23 +++++++++++-------- .../java/io/xpipe/app/util/SecretCache.java | 4 ++++ .../xpipe/ext/base/browser/RenameAction.java | 8 ++++++- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 356113c5..57e2ec8f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -144,7 +144,7 @@ application { run { systemProperty 'io.xpipe.app.useVirtualThreads', 'false' systemProperty 'io.xpipe.app.mode', 'gui' - // systemProperty 'io.xpipe.app.dataDir', "$projectDir/local7/" + systemProperty 'io.xpipe.app.dataDir', "$projectDir/local7/" systemProperty 'io.xpipe.app.writeLogs', "true" systemProperty 'io.xpipe.app.writeSysOut', "true" systemProperty 'io.xpipe.app.developerMode', "true" diff --git a/app/src/main/java/io/xpipe/app/util/AskpassAlert.java b/app/src/main/java/io/xpipe/app/util/AskpassAlert.java index 5fe5b504..d5fa4b11 100644 --- a/app/src/main/java/io/xpipe/app/util/AskpassAlert.java +++ b/app/src/main/java/io/xpipe/app/util/AskpassAlert.java @@ -8,18 +8,20 @@ import javafx.beans.property.SimpleObjectProperty; import javafx.scene.control.Alert; import javafx.scene.layout.StackPane; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; +import java.util.*; public class AskpassAlert { - private static final Map requestToId = new HashMap<>(); + private static final Set cancelledRequests = new HashSet<>(); + private static final Set requests = new HashSet<>(); public static SecretValue query(String prompt, UUID requestId, UUID secretId) { - if (requestToId.containsKey(requestId)) { - var id = requestToId.remove(requestId); - SecretCache.clear(id); + if (cancelledRequests.contains(requestId)) { + return null; + } + + if (SecretCache.get(secretId).isPresent() && requests.contains(requestId)) { + SecretCache.clear(secretId); } var found = SecretCache.get(secretId); @@ -40,15 +42,16 @@ public class AskpassAlert { }) .filter(b -> b.getButtonData().isDefaultButton() && prop.getValue() != null) .map(t -> { - // AppCache.update(msg.getId(), prop.getValue()); - return prop.getValue(); + return prop.getValue() != null ? prop.getValue() : SecretHelper.encryptInPlace(""); }) .orElse(null); // If the result is null, assume that the operation was aborted by the user if (r != null) { - requestToId.put(requestId, secretId); + requests.add(requestId); SecretCache.set(secretId, r); + } else { + cancelledRequests.add(requestId); } return r; diff --git a/app/src/main/java/io/xpipe/app/util/SecretCache.java b/app/src/main/java/io/xpipe/app/util/SecretCache.java index 53b22d9c..da37f11f 100644 --- a/app/src/main/java/io/xpipe/app/util/SecretCache.java +++ b/app/src/main/java/io/xpipe/app/util/SecretCache.java @@ -23,6 +23,10 @@ public class SecretCache { } var pass = strategy.retrieve(prompt, id); + if (pass == null) { + return null; + } + passwords.put(id, pass); return pass; } diff --git a/ext/base/src/main/java/io/xpipe/ext/base/browser/RenameAction.java b/ext/base/src/main/java/io/xpipe/ext/base/browser/RenameAction.java index 1fb8cf89..b2bf50dd 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/browser/RenameAction.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/browser/RenameAction.java @@ -3,6 +3,7 @@ package io.xpipe.ext.base.browser; import io.xpipe.app.browser.BrowserEntry; import io.xpipe.app.browser.OpenFileSystemModel; import io.xpipe.app.browser.action.LeafAction; +import io.xpipe.core.store.FileKind; import javafx.scene.Node; import javafx.scene.input.KeyCode; import javafx.scene.input.KeyCodeCombination; @@ -18,6 +19,11 @@ public class RenameAction implements LeafAction { model.getFileList().getEditing().setValue(entries.get(0)); } + @Override + public boolean automaticallyResolveLinks() { + return false; + } + @Override public Category getCategory() { return Category.MUTATION; @@ -30,7 +36,7 @@ public class RenameAction implements LeafAction { @Override public boolean isApplicable(OpenFileSystemModel model, List entries) { - return entries.size() == 1; + return entries.size() == 1 && entries.get(0).getRawFileEntry().getKind() != FileKind.LINK; } @Override