From e36a627e000620a5d1f0a395d391089aa0f5722f Mon Sep 17 00:00:00 2001 From: mikera Date: Thu, 12 Dec 2024 18:27:36 +0000 Subject: [PATCH] Block non-interactive password input. Fixes #518 --- convex-cli/src/main/java/convex/cli/ACommand.java | 2 ++ convex-cli/src/main/java/convex/cli/Constants.java | 4 +++- .../src/main/java/convex/cli/mixins/RemotePeerMixin.java | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/convex-cli/src/main/java/convex/cli/ACommand.java b/convex-cli/src/main/java/convex/cli/ACommand.java index 9fd3a1ac1..784a6f82a 100644 --- a/convex-cli/src/main/java/convex/cli/ACommand.java +++ b/convex-cli/src/main/java/convex/cli/ACommand.java @@ -120,6 +120,8 @@ public String prompt(String message) { } public char[] readPassword(String prompt) { + if (!isInteractive()) throw new CLIError("Can't prompt for password in non-interactive mode: "+prompt); + // For some reason using this stops CTRL-C from being subsequently handled :-( Console c = System.console(); if (c == null) { diff --git a/convex-cli/src/main/java/convex/cli/Constants.java b/convex-cli/src/main/java/convex/cli/Constants.java index c2d9a333a..ff9754e33 100644 --- a/convex-cli/src/main/java/convex/cli/Constants.java +++ b/convex-cli/src/main/java/convex/cli/Constants.java @@ -10,7 +10,6 @@ public class Constants { public static final String HOSTNAME_REMOTE = "convex.world"; - public static final String HOSTNAME_PEER = "localhost"; public static final String KEYSTORE_FILENAME = convex.core.Constants.DEFAULT_KEYSTORE_FILENAME; @@ -28,6 +27,9 @@ public class Constants { public static final int DEFAULT_PEER_PORT = convex.core.Constants.DEFAULT_PEER_PORT; + public static final String DEFAULT_PEER_HOSTNAME = "localhost"; + + public static final int DEFAULT_VERBOSE_LEVEL = 2; } diff --git a/convex-cli/src/main/java/convex/cli/mixins/RemotePeerMixin.java b/convex-cli/src/main/java/convex/cli/mixins/RemotePeerMixin.java index 68a1804f0..1a7dbed2b 100644 --- a/convex-cli/src/main/java/convex/cli/mixins/RemotePeerMixin.java +++ b/convex-cli/src/main/java/convex/cli/mixins/RemotePeerMixin.java @@ -19,7 +19,7 @@ public class RemotePeerMixin extends AMixin { private Integer port; @Option(names={"--host"}, - defaultValue="${env:CONVEX_HOST:-"+Constants.HOSTNAME_PEER+"}", + defaultValue="${env:CONVEX_HOST:-"+Constants.DEFAULT_PEER_HOSTNAME+"}", description="Hostname for remote peer connection. Can specify with CONVEX_HOST. Defaulting to: ${DEFAULT-VALUE}") private String hostname; @@ -30,7 +30,7 @@ public class RemotePeerMixin extends AMixin { */ public Convex connect() { if (port==null) port=convex.core.Constants.DEFAULT_PEER_PORT; - if (hostname==null) hostname=convex.cli.Constants.HOSTNAME_PEER; + if (hostname==null) hostname=convex.cli.Constants.DEFAULT_PEER_HOSTNAME; InetSocketAddress sa=IPUtils.parseAddress(hostname,port); try { Convex c;