From d76aecb34dd5d51bd93d5768bc131aae24201b65 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Mon, 13 Dec 2021 14:27:35 +0200 Subject: [PATCH] handle quotes in connected device passphrase on windows --- src/main/java/com/sparrowwallet/sparrow/io/Hwi.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/io/Hwi.java b/src/main/java/com/sparrowwallet/sparrow/io/Hwi.java index 487beab0..1dc4dcb6 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/Hwi.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/Hwi.java @@ -43,7 +43,7 @@ public class Hwi { try { List command; if(passphrase != null && !passphrase.isEmpty()) { - command = List.of(getHwiExecutable(Command.ENUMERATE).getAbsolutePath(), "--password", passphrase, Command.ENUMERATE.toString()); + command = List.of(getHwiExecutable(Command.ENUMERATE).getAbsolutePath(), "--password", escape(passphrase), Command.ENUMERATE.toString()); } else { command = List.of(getHwiExecutable(Command.ENUMERATE).getAbsolutePath(), Command.ENUMERATE.toString()); } @@ -414,7 +414,7 @@ public class Hwi { } private List getDeviceCommand(Device device, String passphrase, Command command, String... commandData) throws IOException { - List elements = new ArrayList<>(List.of(getHwiExecutable(command).getAbsolutePath(), "--device-path", device.getPath(), "--device-type", device.getType(), "--password", passphrase, command.toString())); + List elements = new ArrayList<>(List.of(getHwiExecutable(command).getAbsolutePath(), "--device-path", device.getPath(), "--device-type", device.getType(), "--password", escape(passphrase), command.toString())); addChainType(elements); elements.addAll(Arrays.stream(commandData).filter(Objects::nonNull).collect(Collectors.toList())); return elements; @@ -437,6 +437,15 @@ public class Hwi { return network.toString(); } + private String escape(String passphrase) { + Platform platform = Platform.getCurrent(); + if(platform == Platform.WINDOWS) { + return passphrase.replace("\"", "\\\""); + } + + return passphrase; + } + public static class EnumerateService extends Service> { private final String passphrase;