Skip to content

Commit 649625e

Browse files
committed
refactor(ssh): remove TODO in server initialization
1 parent 095d2a2 commit 649625e

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

src/proxy/ssh/server.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as ssh2 from 'ssh2';
2-
import * as fs from 'fs';
32
import * as bcrypt from 'bcryptjs';
43
import { getSSHConfig, getMaxPackSizeBytes, getDomains } from '../../config';
54
import { serverConfig } from '../../config/env';
@@ -15,6 +14,7 @@ import {
1514
import { ClientWithUser } from './types';
1615
import { createMockResponse } from './sshHelpers';
1716
import { processGitUrl } from '../routes/helper';
17+
import { ensureHostKey } from './hostKeyManager';
1818

1919
export class SSHServer {
2020
private server: ssh2.Server;
@@ -23,16 +23,22 @@ export class SSHServer {
2323
const sshConfig = getSSHConfig();
2424
const privateKeys: Buffer[] = [];
2525

26+
// Ensure the SSH host key exists (generates automatically if needed)
27+
// This key identifies the PROXY SERVER to connecting clients, similar to an SSL certificate.
28+
// It is NOT used for authenticating to remote Git servers - agent forwarding handles that.
2629
try {
27-
privateKeys.push(fs.readFileSync(sshConfig.hostKey.privateKeyPath));
30+
const hostKey = ensureHostKey(sshConfig.hostKey);
31+
privateKeys.push(hostKey);
2832
} catch (error) {
33+
console.error('[SSH] Failed to initialize proxy host key');
2934
console.error(
30-
`Error reading private key at ${sshConfig.hostKey.privateKeyPath}. Check your SSH host key configuration or disbale SSH.`,
35+
`[SSH] ${error instanceof Error ? error.message : String(error)}`,
3136
);
37+
console.error('[SSH] Cannot start SSH server without a valid host key.');
3238
process.exit(1);
3339
}
3440

35-
// TODO: Server config could go to config file
41+
// Initialize SSH server with secure defaults
3642
this.server = new ssh2.Server(
3743
{
3844
hostKeys: privateKeys,

0 commit comments

Comments
 (0)