@@ -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 { ChildProcess } from '../../shared/utilities/childProcess'
1112
1213type sshKeyType = 'rsa' | 'ed25519'
1314
@@ -29,12 +30,6 @@ export class SshKeyPair {
2930 }
3031
3132 public static async getSshKeyPair ( keyPath : string , lifetime : number , overwrite : boolean = true ) {
32- // Overwrite key if already exists
33- if ( overwrite ) {
34- await fs . delete ( keyPath , { force : true } )
35- await fs . delete ( `${ keyPath } .pub` , { force : true } )
36- }
37-
3833 await SshKeyPair . generateSshKeyPair ( keyPath )
3934 return new SshKeyPair ( keyPath , lifetime )
4035 }
@@ -52,7 +47,16 @@ export class SshKeyPair {
5247 * @param keyType type of key to generate.
5348 */
5449 public static async tryKeyGen ( keyPath : string , keyType : sshKeyType ) : Promise < boolean > {
55- return ! ( await tryRun ( 'ssh-keygen' , [ '-t' , keyType , '-N' , '' , '-q' , '-f' , keyPath ] , 'yes' , 'unknown key type' ) )
50+ const overrideKeys = async ( proc : ChildProcess , text : string ) => {
51+ await proc . send ( 'yes' )
52+ }
53+ return ! ( await tryRun (
54+ 'ssh-keygen' ,
55+ [ '-t' , keyType , '-N' , '' , '-q' , '-f' , keyPath ] ,
56+ 'yes' ,
57+ 'unknown key type' ,
58+ overrideKeys
59+ ) )
5660 }
5761
5862 public static async tryKeyTypes ( keyPath : string , keyTypes : sshKeyType [ ] ) : Promise < boolean > {
0 commit comments