1
1
mirror of https://github.com/Eugeny/tabby.git synced 2024-12-22 18:11:43 +03:00

ppk key support

This commit is contained in:
Eugene Pankov 2021-05-15 18:51:53 +02:00
parent c7bee48199
commit edb07e155c
No known key found for this signature in database
GPG Key ID: 5896FCBBDD1CF4F4
5 changed files with 10 additions and 69 deletions

Binary file not shown.

Binary file not shown.

View File

@ -28,9 +28,8 @@
"clone-deep": "^4.0.1",
"ssh2": "^0.8.9",
"ssh2-streams": "Eugeny/ssh2-streams#75f6d3425d071ac73a18fd46e2f5e738bfe897c5",
"sshpk": "^1.16.1",
"strip-ansi": "^7.0.0",
"temp": "^0.9.1"
"sshpk": "Eugeny/node-sshpk#89ed17dfae425a8b629873c8337e77d26838c04f",
"strip-ansi": "^7.0.0"
},
"dependencies": {
"run-script-os": "^1.1.3",

View File

@ -1,18 +1,16 @@
import colors from 'ansi-colors'
import { Duplex } from 'stream'
import * as crypto from 'crypto'
import { open as openTemp } from 'temp'
import { Injectable, NgZone } from '@angular/core'
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
import { Client } from 'ssh2'
import { SSH2Stream } from 'ssh2-streams'
import * as fs from 'mz/fs'
import { execFile } from 'mz/child_process'
import { exec } from 'child_process'
import * as path from 'path'
import * as sshpk from 'sshpk'
import { Subject, Observable } from 'rxjs'
import { HostAppService, Platform, Logger, LogService, ElectronService, AppService, SelectorOption, ConfigService, NotificationsService } from 'terminus-core'
import { HostAppService, Platform, Logger, LogService, AppService, SelectorOption, ConfigService, NotificationsService } from 'terminus-core'
import { SettingsTabComponent } from 'terminus-settings'
import { ALGORITHM_BLACKLIST, ForwardedPort, SSHConnection, SSHSession } from '../api'
import { PromptModalComponent } from '../components/promptModal.component'
@ -37,7 +35,6 @@ export class SSHService {
private constructor (
private log: LogService,
private electron: ElectronService,
private zone: NgZone,
private ngbModal: NgbModal,
private hostApp: HostAppService,
@ -72,41 +69,14 @@ export class SSHService {
try {
privateKey = (await fs.readFile(privateKeyPath)).toString()
} catch (error) {
session.emitServiceMessage(colors.bgRed.black(' X ') + 'Could not read the private key file')
session.emitServiceMessage(colors.bgRed.black(' X ') + ' Could not read the private key file')
session.emitServiceMessage(colors.bgRed.black(' X ') + ` ${error}`)
this.notifications.error('Could not read the private key file')
}
if (privateKey) {
const parsedKey = await this.parsePrivateKey(privateKey)
const sshFormatKey = parsedKey.toString('openssh')
const temp = await openTemp()
fs.close(temp.fd)
await fs.writeFile(temp.path, sshFormatKey)
let sshKeygenPath = 'ssh-keygen'
if (this.hostApp.platform === Platform.Windows) {
sshKeygenPath = path.join(
path.dirname(this.electron.app.getPath('exe')),
'resources',
'extras',
'ssh-keygen',
'ssh-keygen.exe',
)
await execFile('icacls', [temp.path, '/inheritance:r'])
let sid = await execFile('whoami', ['/user', '/nh', '/fo', 'csv'])
sid = sid[0].split(',')[0]
sid = sid.substring(1, sid.length - 1)
await execFile('icacls', [temp.path, '/grant:r', `${sid}:(R,W)`])
}
await execFile(sshKeygenPath, [
'-p', '-P', '', '-N', '', '-m', 'PEM', '-f',
temp.path,
])
privateKey = await fs.readFile(temp.path, { encoding: 'utf-8' })
fs.unlink(temp.path)
privateKey = parsedKey.toString('openssh')
}
}
return privateKey
@ -119,7 +89,6 @@ export class SSHService {
try {
return sshpk.parsePrivateKey(privateKey, 'auto', { passphrase })
} catch (e) {
this.notifications.error('Could not read the private key', e.toString())
if (e instanceof sshpk.KeyEncryptedError || e instanceof sshpk.KeyParseError) {
await this.passwordStorage.deletePrivateKeyPassword(keyHash)
@ -138,6 +107,7 @@ export class SSHService {
throw e
}
} else {
this.notifications.error('Could not read the private key', e.toString())
throw e
}
}

View File

@ -151,7 +151,7 @@ getpass@^0.1.1:
dependencies:
assert-plus "^1.0.0"
"glob@>= 3.1.4", glob@^7.1.3:
"glob@>= 3.1.4":
version "7.1.6"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.6.tgz#141f33b81a7c2492e125594307480c46679278a6"
integrity sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==
@ -219,18 +219,6 @@ minimatch@^3.0.4:
dependencies:
brace-expansion "^1.1.7"
minimist@^1.2.5:
version "1.2.5"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602"
integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==
mkdirp@^0.5.1:
version "0.5.5"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.5.tgz#d91cefd62d1436ca0f41620e251288d420099def"
integrity sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==
dependencies:
minimist "^1.2.5"
once@^1.3.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1"
@ -248,13 +236,6 @@ pkginfo@0.3.x:
resolved "https://registry.yarnpkg.com/pkginfo/-/pkginfo-0.3.1.tgz#5b29f6a81f70717142e09e765bbeab97b4f81e21"
integrity sha1-Wyn2qB9wcXFC4J52W76rl7T4HiE=
rimraf@~2.6.2:
version "2.6.3"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.3.tgz#b2d104fe0d8fb27cf9e0a1cda8262dd3833c6cab"
integrity sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==
dependencies:
glob "^7.1.3"
run-script-os@^1.1.3:
version "1.1.6"
resolved "https://registry.yarnpkg.com/run-script-os/-/run-script-os-1.1.6.tgz#8b0177fb1b54c99a670f95c7fdc54f18b9c72347"
@ -308,10 +289,9 @@ ssh2@^0.8.9:
dependencies:
ssh2-streams "~0.4.10"
sshpk@^1.16.1:
sshpk@Eugeny/node-sshpk#89ed17dfae425a8b629873c8337e77d26838c04f:
version "1.16.1"
resolved "https://registry.yarnpkg.com/sshpk/-/sshpk-1.16.1.tgz#fb661c0bef29b39db40769ee39fa70093d6f6877"
integrity sha512-HXXqVUq7+pcKeLqqZj6mHFUMvXtOJt1uoUx09pFW6011inTMxqI8BA8PM95myrIyyKwdnzjdFjLiE6KBPVtJIg==
resolved "https://codeload.github.com/Eugeny/node-sshpk/tar.gz/89ed17dfae425a8b629873c8337e77d26838c04f"
dependencies:
asn1 "~0.2.3"
assert-plus "^1.0.0"
@ -340,14 +320,6 @@ strip-ansi@^7.0.0:
dependencies:
ansi-regex "^6.0.0"
temp@^0.9.1:
version "0.9.4"
resolved "https://registry.yarnpkg.com/temp/-/temp-0.9.4.tgz#cd20a8580cb63635d0e4e9d4bd989d44286e7620"
integrity sha512-yYrrsWnrXMcdsnu/7YMYAofM1ktpL5By7vZhf15CrXijWWrEYZks5AXBudalfSWJLlnen/QUJUB5aoB0kqZUGA==
dependencies:
mkdirp "^0.5.1"
rimraf "~2.6.2"
tweetnacl@^0.14.3, tweetnacl@~0.14.0:
version "0.14.5"
resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64"