Skip to content

Commit 1ccae5f

Browse files
committed
fix: add validation for private key file before SSH server init
1 parent e9af0aa commit 1ccae5f

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/proxy/ssh/server.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,21 @@ export class SSHServer {
3939

4040
constructor() {
4141
const sshConfig = getSSHConfig();
42+
const privateKeys: Buffer[] = [];
43+
44+
try {
45+
privateKeys.push(fs.readFileSync(sshConfig.hostKey.privateKeyPath));
46+
} catch (error) {
47+
console.error(
48+
`Error reading private key at ${sshConfig.hostKey.privateKeyPath}. Check your SSH host key configuration or disbale SSH.`,
49+
);
50+
process.exit(1);
51+
}
52+
4253
// TODO: Server config could go to config file
4354
this.server = new ssh2.Server(
4455
{
45-
hostKeys: [fs.readFileSync(sshConfig.hostKey.privateKeyPath)],
56+
hostKeys: privateKeys,
4657
authMethods: ['publickey', 'password'] as any,
4758
keepaliveInterval: 20000, // 20 seconds is recommended for SSH connections
4859
keepaliveCountMax: 5, // Recommended for SSH connections is 3-5 attempts

0 commit comments

Comments
 (0)