Askpass fixes

This commit is contained in:
crschnick 2023-04-13 20:34:30 +00:00
parent f777604573
commit 8abc82971a
3 changed files with 37 additions and 18 deletions

View file

@ -4,6 +4,7 @@ import io.xpipe.app.ext.PrefsChoiceValue;
import io.xpipe.app.issue.ErrorEvent;
import io.xpipe.app.util.ApplicationHelper;
import io.xpipe.app.util.MacOsPermissions;
import io.xpipe.app.util.ScriptHelper;
import io.xpipe.core.impl.FileNames;
import io.xpipe.core.impl.LocalStore;
import io.xpipe.core.process.OsType;
@ -43,19 +44,20 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
}
};
public static final ExternalTerminalType PWSH =
new SimpleType("pwsh", "pwsh", "PowerShell Core") {
public static final ExternalTerminalType PWSH = new SimpleType("pwsh", "pwsh", "PowerShell Core") {
@Override
protected String toCommand(String name, String file) {
return "-ExecutionPolicy Bypass -Command cmd /C '" + file + "'";
}
@Override
protected String toCommand(String name, String file) {
// Fix for https://github.com/PowerShell/PowerShell/issues/18530#issuecomment-1325691850
var script = ScriptHelper.createLocalExecScript("set \"PSModulePath=\"\r\n\"" + file + "\"\npause");
return "-ExecutionPolicy Bypass -Command cmd /C '" +script + "'";
}
@Override
public boolean isSelectable() {
return OsType.getLocal().equals(OsType.WINDOWS);
}
};
@Override
public boolean isSelectable() {
return OsType.getLocal().equals(OsType.WINDOWS);
}
};
public static final ExternalTerminalType WINDOWS_TERMINAL =
new SimpleType("windowsTerminal", "wt.exe", "Windows Terminal") {

View file

@ -6,9 +6,11 @@ import io.xpipe.core.impl.LocalStore;
import io.xpipe.core.process.OsType;
import io.xpipe.core.process.ShellControl;
import io.xpipe.core.process.ShellDialect;
import io.xpipe.core.process.ShellDialects;
import io.xpipe.core.util.SecretValue;
import lombok.SneakyThrows;
import java.util.Collections;
import java.util.List;
import java.util.Random;
@ -105,15 +107,32 @@ public class ScriptHelper {
return file;
}
public static String createAskPassScript(SecretValue pass, ShellControl parent) throws Exception {
public static String createAskPassScript(SecretValue pass, ShellControl parent, boolean forceExecutable) throws Exception {
var scriptType = parent.getShellDialect();
// Fix for powershell as there are permission issues when executing a powershell askpass script
if (forceExecutable && parent.getShellDialect().equals(ShellDialects.POWERSHELL)) {
scriptType = parent.getOsType().equals(OsType.WINDOWS) ? ShellDialects.CMD : ShellDialects.SH;
}
return createAskPassScript(pass, parent, scriptType);
}
private static String createAskPassScript(SecretValue pass, ShellControl parent, ShellDialect type) throws Exception {
var content = type.getSelfdeleteEchoScriptContent(pass.getSecretValue());
var fileName = "askpass-" + getScriptId() + "." + type.getScriptFileEnding();
var temp = parent.getTemporaryDirectory();
var file = FileNames.join(temp, "askpass-" + getScriptId() + "." + type.getScriptFileEnding());
return createExecScript(parent, file, content);
var file = FileNames.join(temp, fileName);
if (type != parent.getShellDialect()) {
try (var sub = parent.subShell(type)) {
var content = sub.getShellDialect().prepareAskpassContent(sub, file, Collections.singletonList(pass.getSecretValue()));
var exec = createExecScript(sub, file, content);
return exec;
}
} else {
var content = parent.getShellDialect().prepareAskpassContent(parent, file, Collections.singletonList(pass.getSecretValue()));
var exec = createExecScript(parent, file, content);
return exec;
}
}
}

View file

@ -79,9 +79,7 @@ public interface ShellDialect {
String getMakeExecutableCommand(String file);
default String getSelfdeleteEchoScriptContent(String s) {
return getEchoCommand(s, false);
}
String prepareAskpassContent(ShellControl sc, String fileName, List<String> s) throws Exception;
String getSetEnvironmentVariableCommand(String variable, String value);