Skip to content

Commit 49a4c85

Browse files
authored
Merge pull request #274 from ZoeWithTheE/patch-1
Update SSHServerSetup.java
2 parents 79a65b9 + 7ecc6ee commit 49a4c85

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/main/java/com/osiris/autoplug/client/network/online/connections/SSHServerSetup.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,38 @@ public static void start() throws Exception {
3535
AL.warn("SSH server is already running.");
3636
return;
3737
}
38-
38+
3939
sshd = SshServer.setUpDefaultServer();
4040
SSHConfig sshConfig = new SSHConfig();
41-
41+
4242
int port = sshConfig.port.asInt();
4343
String authMethod = sshConfig.auth_method.asString();
44-
Path allowedKeysPath = new File(sshConfig.allowed_keys_path.asString()).toPath();
45-
Path serverPrivateKeyPath = new File(sshConfig.server_private_key.asString()).toPath();
44+
String allowedKeysRaw = sshConfig.allowed_keys_path.asString();
45+
String privateKeyRaw = sshConfig.server_private_key.asString();
4646
String username = sshConfig.username.asString();
4747
String password = sshConfig.password.asString();
48-
48+
49+
// === Defensive checks ===
50+
if (allowedKeysRaw == null || allowedKeysRaw.trim().isEmpty()) {
51+
AL.warn("SSH config error: 'allowed-keys-path' is missing or empty!");
52+
throw new IllegalArgumentException("Missing 'allowed-keys-path' in SSH config");
53+
}
54+
if (privateKeyRaw == null || privateKeyRaw.trim().isEmpty()) {
55+
AL.warn("SSH config error: 'server-private-key' is missing or empty! "
56+
+ "AutoPlug cannot start SSH without a valid key path.\n"
57+
+ "Example fix:\n server-private-key: ./autoplug/server_host_key.ser");
58+
throw new IllegalArgumentException("Missing 'server-private-key' in SSH config");
59+
}
60+
61+
Path allowedKeysPath = new File(allowedKeysRaw).toPath();
62+
Path serverPrivateKeyPath = new File(privateKeyRaw).toPath();
63+
4964
try {
5065
setupServer(port, authMethod, allowedKeysPath, serverPrivateKeyPath, username, password);
5166
sshd.start();
5267
AL.info("SSH server started on port " + port + " with auth method: " + authMethod);
5368
} catch (Exception e) {
54-
AL.warn("Failed to start SSH server!", e);
69+
AL.warn("Failed to start SSH server! Reason: " + e.getMessage(), e);
5570
stop(); // Ensure any partial initialization is cleaned up
5671
}
5772
}

0 commit comments

Comments
 (0)