Ssh key file fixes

This commit is contained in:
crschnick committed 2023-12-19 15:31:06 +00:00
1 parent 09a419f628
commit aa71a72f58
7 files changed
+35 -35

No files matched your search

@@ -165,7 +165,7 @@ public class SentryErrorHandler implements ErrorHandler {
atts.forEach(attachment -> s.addAttachment(attachment));
}
s.setTag("hasLicense", String.valueOf(LicenseProvider.get().hasLicense()));
s.setTag("hasLicense", String.valueOf(LicenseProvider.get().hasPaidLicense()));
s.setTag("updatesEnabled", AppPrefs.get() != null ? AppPrefs.get().automaticallyUpdate().getValue().toString() : "unknown");
s.setTag("initError", String.valueOf(OperationMode.isInStartup()));
s.setTag(
@@ -1,7 +1,7 @@
package io.xpipe.app.storage;
import io.xpipe.app.prefs.AppPrefs;
import io.xpipe.core.process.OsType;
import io.xpipe.core.process.ShellControl;
import io.xpipe.core.store.FileNames;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
@@ -42,17 +42,23 @@ public class ContextualFileReference {
}
var ns = normalized(s.trim());
// Replacement order is important
var replaced = ns.replace("<DATA>", getDataDir())
.replace("~", normalized(System.getProperty("user.home")));
String replaced;
var withHomeResolved = ns.replace("~", normalized(System.getProperty("user.home")));
// Only replace ~ if it is part of data dir, otherwise keep it raw
if (withHomeResolved.startsWith(getDataDir())) {
replaced = withHomeResolved.replace("<DATA>", getDataDir());
} else {
replaced = ns.replace("<DATA>", getDataDir());
}
return new ContextualFileReference(normalized(replaced));
}
@NonNull
private final String path;
public String toString() {
return path.replaceAll("/", Matcher.quoteReplacement(OsType.getLocal().getFileSystemSeparator()));
public String toFilePath(ShellControl sc) {
return path.replaceAll("/", Matcher.quoteReplacement(sc != null ? sc.getOsType().getFileSystemSeparator() : "/"));
}
public String serialize() {
@@ -46,4 +46,6 @@ public abstract class LicenseProvider {
public abstract void init();
public abstract Comp<?> overviewPage();
public abstract boolean hasPaidLicense();
}
@@ -124,12 +124,12 @@ public class ScriptHelper {
return file;
}
public static String createAskPassScript(SecretValue pass, ShellControl parent, boolean forceExecutable)
public static String createAskpassScript(SecretValue pass, ShellControl parent, boolean forceExecutable, String errorMessage)
throws Exception {
return createAskPassScript(pass != null ? List.of(pass) : List.of(), parent, forceExecutable);
return createAskpassScript(pass != null ? List.of(pass) : List.of(), parent, forceExecutable, errorMessage);
}
public static String createAskPassScript(List<SecretValue> pass, ShellControl parent, boolean forceExecutable)
public static String createAskpassScript(List<SecretValue> pass, ShellControl parent, boolean forceExecutable, String errorMessage)
throws Exception {
var scriptType = parent.getShellDialect();
@@ -138,10 +138,10 @@ public class ScriptHelper {
scriptType = parent.getOsType().equals(OsType.WINDOWS) ? ShellDialects.CMD : ShellDialects.SH;
}
return createAskPassScript(pass, parent, scriptType);
return createAskpassScript(pass, parent, scriptType, errorMessage);
}
private static String createAskPassScript(List<SecretValue> pass, ShellControl parent, ShellDialect type)
private static String createAskpassScript(List<SecretValue> pass, ShellControl parent, ShellDialect type, String errorMessage)
throws Exception {
var fileName = "exec-" + getScriptId() + "." + type.getScriptFileEnding();
var temp = parent.getSubTemporaryDirectory();
@@ -154,7 +154,7 @@ public class ScriptHelper {
file,
pass.stream()
.map(secretValue -> secretValue.getSecretValue())
.toList());
.toList(), errorMessage);
return createExecScript(sub.getShellDialect(), sub, file, content);
}
} else {
@@ -164,7 +164,7 @@ public class ScriptHelper {
file,
pass.stream()
.map(secretValue -> secretValue.getSecretValue())
.toList());
.toList(), errorMessage);
return createExecScript(parent.getShellDialect(), parent, file, content);
}
}
@@ -44,7 +44,7 @@ public interface SecretRetrievalStrategy {
@Override
public boolean isLocalAskpassCompatible() {
return false;
return true;
}
@Override
@@ -125,25 +125,6 @@ public interface SecretRetrievalStrategy {
}
}
@JsonTypeName("dynamicPrompt")
class DynamicPrompt implements SecretRetrievalStrategy {
@Override
public SecretValue retrieve(String displayName, UUID id, int sub) {
return AskpassAlert.query(displayName, UUID.randomUUID(), id, sub);
}
@Override
public boolean shouldCache() {
return false;
}
@Override
public boolean isLocalAskpassCompatible() {
return true;
}
}
@JsonTypeName("passwordManager")
@Builder
@Jacksonized