Skip to content

Commit

Permalink
avoid infinite loop on incorrect private key passphrase
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugeny committed Feb 4, 2023
1 parent 85bb7a2 commit e018197
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions tabby-ssh/src/session/ssh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,16 +616,9 @@ export class SSHSession {

async loadPrivateKey (name: string, privateKeyContents: Buffer): Promise<string|null> {
this.emitServiceMessage(`Loading private key: ${name}`)
try {
const parsedKey = await this.parsePrivateKey(privateKeyContents.toString())
this.activePrivateKey = parsedKey.toString('openssh')
return this.activePrivateKey
} catch (error) {
this.emitServiceMessage(colors.bgRed.black(' X ') + ' Could not read the private key file')
this.emitServiceMessage(colors.bgRed.black(' X ') + ` ${error}`)
this.notifications.error('Could not read the private key file')
return null
}
const parsedKey = await this.parsePrivateKey(privateKeyContents.toString())
this.activePrivateKey = parsedKey.toString('openssh')
return this.activePrivateKey
}

async parsePrivateKey (privateKey: string): Promise<any> {
Expand All @@ -649,7 +642,10 @@ export class SSHSession {
modal.componentInstance.password = true
modal.componentInstance.showRememberCheckbox = true

const result = await modal.result
const result = await modal.result.catch(() => {
throw new Error('Passphrase prompt cancelled')
})

passphrase = result?.value
if (passphrase && result.remember) {
this.passwordStorage.savePrivateKeyPassword(keyHash, passphrase)
Expand Down

0 comments on commit e018197

Please sign in to comment.