@@ -37,7 +37,7 @@ export function ensureHostKey(config: HostKeyConfig): Buffer {
3737
3838 // Validate paths to prevent command injection
3939 // Only allow alphanumeric, dots, slashes, underscores, hyphens
40- const safePathRegex = / ^ [ a - z A - Z 0 - 9 . _ \- \ /] + $ / ;
40+ const safePathRegex = / ^ [ a - z A - Z 0 - 9 . _ \- / ] + $ / ;
4141 if ( ! safePathRegex . test ( privateKeyPath ) || ! safePathRegex . test ( publicKeyPath ) ) {
4242 throw new Error (
4343 `Invalid SSH host key path: paths must contain only alphanumeric characters, dots, slashes, underscores, and hyphens` ,
@@ -59,7 +59,9 @@ export function ensureHostKey(config: HostKeyConfig): Buffer {
5959 // Generate a new host key
6060 console . log ( `[SSH] Proxy host key not found at ${ privateKeyPath } ` ) ;
6161 console . log ( '[SSH] Generating new SSH host key for the proxy server...' ) ;
62- console . log ( '[SSH] Note: This key identifies the proxy to connecting clients (like an SSL certificate)' ) ;
62+ console . log (
63+ '[SSH] Note: This key identifies the proxy to connecting clients (like an SSL certificate)' ,
64+ ) ;
6365
6466 try {
6567 // Create directory if it doesn't exist
@@ -75,13 +77,10 @@ export function ensureHostKey(config: HostKeyConfig): Buffer {
7577 // - Faster key generation
7678 // - Better security properties
7779 console . log ( '[SSH] Generating Ed25519 host key...' ) ;
78- execSync (
79- `ssh-keygen -t ed25519 -f "${ privateKeyPath } " -N "" -C "git-proxy-host-key"` ,
80- {
81- stdio : 'pipe' , // Suppress ssh-keygen output
82- timeout : 10000 , // 10 second timeout
83- } ,
84- ) ;
80+ execSync ( `ssh-keygen -t ed25519 -f "${ privateKeyPath } " -N "" -C "git-proxy-host-key"` , {
81+ stdio : 'pipe' , // Suppress ssh-keygen output
82+ timeout : 10000 , // 10 second timeout
83+ } ) ;
8584
8685 console . log ( `[SSH] ✓ Successfully generated proxy host key` ) ;
8786 console . log ( `[SSH] Private key: ${ privateKeyPath } ` ) ;
@@ -99,23 +98,20 @@ export function ensureHostKey(config: HostKeyConfig): Buffer {
9998 return fs . readFileSync ( privateKeyPath ) ;
10099 } catch ( error ) {
101100 // If generation fails, provide helpful error message
102- const errorMessage =
103- error instanceof Error
104- ? error . message
105- : String ( error ) ;
101+ const errorMessage = error instanceof Error ? error . message : String ( error ) ;
106102
107103 console . error ( '[SSH] Failed to generate host key' ) ;
108104 console . error ( `[SSH] Error: ${ errorMessage } ` ) ;
109105 console . error ( '[SSH]' ) ;
110106 console . error ( '[SSH] To fix this, you can either:' ) ;
111107 console . error ( '[SSH] 1. Install ssh-keygen (usually part of OpenSSH)' ) ;
112108 console . error ( '[SSH] 2. Manually generate a key:' ) ;
113- console . error ( `[SSH] ssh-keygen -t ed25519 -f "${ privateKeyPath } " -N "" -C "git-proxy-host-key"` ) ;
109+ console . error (
110+ `[SSH] ssh-keygen -t ed25519 -f "${ privateKeyPath } " -N "" -C "git-proxy-host-key"` ,
111+ ) ;
114112 console . error ( '[SSH] 3. Disable SSH in proxy.config.json: "ssh": { "enabled": false }' ) ;
115113
116- throw new Error (
117- `Failed to generate SSH host key: ${ errorMessage } . See console for details.` ,
118- ) ;
114+ throw new Error ( `Failed to generate SSH host key: ${ errorMessage } . See console for details.` ) ;
119115 }
120116}
121117
0 commit comments