@@ -8,6 +8,7 @@ import { ToolkitError } from '../../shared/errors'
88import { tryRun } from '../../shared/utilities/pathFind'
99import { Timeout } from '../../shared/utilities/timeoutUtils'
1010import { findAsync } from '../../shared/utilities/collectionUtils'
11+ import { RunParameterContext } from '../../shared/utilities/processUtils'
1112
1213type sshKeyType = 'rsa' | 'ed25519'
1314
@@ -17,7 +18,7 @@ export class SshKeyPair {
1718 private deleted : boolean = false
1819
1920 private constructor (
20- private keyPath : string ,
21+ private readonly keyPath : string ,
2122 lifetime : number
2223 ) {
2324 this . publicKeyPath = `${ keyPath } .pub`
@@ -29,10 +30,6 @@ export class SshKeyPair {
2930 }
3031
3132 public static async getSshKeyPair ( keyPath : string , lifetime : number ) {
32- // Overwrite key if already exists
33- if ( await fs . existsFile ( keyPath ) ) {
34- await fs . delete ( keyPath )
35- }
3633 await SshKeyPair . generateSshKeyPair ( keyPath )
3734 return new SshKeyPair ( keyPath , lifetime )
3835 }
@@ -50,7 +47,12 @@ export class SshKeyPair {
5047 * @param keyType type of key to generate.
5148 */
5249 public static async tryKeyGen ( keyPath : string , keyType : sshKeyType ) : Promise < boolean > {
53- return ! ( await tryRun ( 'ssh-keygen' , [ '-t' , keyType , '-N' , '' , '-q' , '-f' , keyPath ] , 'yes' , 'unknown key type' ) )
50+ const overrideKeys = async ( _t : string , proc : RunParameterContext ) => {
51+ await proc . send ( 'yes' )
52+ }
53+ return ! ( await tryRun ( 'ssh-keygen' , [ '-t' , keyType , '-N' , '' , '-q' , '-f' , keyPath ] , 'yes' , 'unknown key type' , {
54+ onStdout : overrideKeys ,
55+ } ) )
5456 }
5557
5658 public static async tryKeyTypes ( keyPath : string , keyTypes : sshKeyType [ ] ) : Promise < boolean > {
0 commit comments