From 7ecc6ee0d8d88d5adbdf4c21804dd6de45e609e3 Mon Sep 17 00:00:00 2001 From: Zoe <124623481+ZoeWithTheE@users.noreply.github.com> Date: Mon, 20 Oct 2025 12:11:02 -0700 Subject: [PATCH] Update SSHServerSetup.java add handling for null path errors --- .../online/connections/SSHServerSetup.java | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/osiris/autoplug/client/network/online/connections/SSHServerSetup.java b/src/main/java/com/osiris/autoplug/client/network/online/connections/SSHServerSetup.java index a449dc30..6ddf6bef 100644 --- a/src/main/java/com/osiris/autoplug/client/network/online/connections/SSHServerSetup.java +++ b/src/main/java/com/osiris/autoplug/client/network/online/connections/SSHServerSetup.java @@ -35,23 +35,38 @@ public static void start() throws Exception { AL.warn("SSH server is already running."); return; } - + sshd = SshServer.setUpDefaultServer(); SSHConfig sshConfig = new SSHConfig(); - + int port = sshConfig.port.asInt(); String authMethod = sshConfig.auth_method.asString(); - Path allowedKeysPath = new File(sshConfig.allowed_keys_path.asString()).toPath(); - Path serverPrivateKeyPath = new File(sshConfig.server_private_key.asString()).toPath(); + String allowedKeysRaw = sshConfig.allowed_keys_path.asString(); + String privateKeyRaw = sshConfig.server_private_key.asString(); String username = sshConfig.username.asString(); String password = sshConfig.password.asString(); - + + // === Defensive checks === + if (allowedKeysRaw == null || allowedKeysRaw.trim().isEmpty()) { + AL.warn("SSH config error: 'allowed-keys-path' is missing or empty!"); + throw new IllegalArgumentException("Missing 'allowed-keys-path' in SSH config"); + } + if (privateKeyRaw == null || privateKeyRaw.trim().isEmpty()) { + AL.warn("SSH config error: 'server-private-key' is missing or empty! " + + "AutoPlug cannot start SSH without a valid key path.\n" + + "Example fix:\n server-private-key: ./autoplug/server_host_key.ser"); + throw new IllegalArgumentException("Missing 'server-private-key' in SSH config"); + } + + Path allowedKeysPath = new File(allowedKeysRaw).toPath(); + Path serverPrivateKeyPath = new File(privateKeyRaw).toPath(); + try { setupServer(port, authMethod, allowedKeysPath, serverPrivateKeyPath, username, password); sshd.start(); AL.info("SSH server started on port " + port + " with auth method: " + authMethod); } catch (Exception e) { - AL.warn("Failed to start SSH server!", e); + AL.warn("Failed to start SSH server! Reason: " + e.getMessage(), e); stop(); // Ensure any partial initialization is cleaned up } }