@@ -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