From 8593ad89c6936718e104f7572ba812309ccb0cf1 Mon Sep 17 00:00:00 2001 From: Artur Date: Mon, 19 Sep 2022 17:18:46 +0300 Subject: [PATCH 1/4] Support private key forwarding to winscp --- tabby-ssh/package.json | 4 ++- tabby-ssh/src/services/ssh.service.ts | 16 ++++++++-- tabby-ssh/yarn.lock | 45 +++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 3 deletions(-) diff --git a/tabby-ssh/package.json b/tabby-ssh/package.json index 9683b5ef..a3e2932d 100644 --- a/tabby-ssh/package.json +++ b/tabby-ssh/package.json @@ -28,8 +28,10 @@ "strip-ansi": "^7.0.0" }, "dependencies": { + "@luminati-io/socksv5": "^0.0.7", + "node-forge": "^1.3.1", "run-script-os": "^1.1.3", - "@luminati-io/socksv5": "^0.0.7" + "tmp-promise": "^3.0.3" }, "peerDependencies": { "@angular/animations": "^9.1.9", diff --git a/tabby-ssh/src/services/ssh.service.ts b/tabby-ssh/src/services/ssh.service.ts index 4b99769a..4944850d 100644 --- a/tabby-ssh/src/services/ssh.service.ts +++ b/tabby-ssh/src/services/ssh.service.ts @@ -1,5 +1,9 @@ import * as shellQuote from 'shell-quote' import * as net from 'net' +import * as fs from 'fs/promises' +import * as tmp from 'tmp-promise' +import * as sshpk from 'sshpk' +import * as forge from 'node-forge' import socksv5 from '@luminati-io/socksv5' import { Duplex } from 'stream' import { Injectable } from '@angular/core' @@ -45,9 +49,17 @@ export class SSHService { return } const args = [await this.getWinSCPURI(session.profile, undefined, session.authUsername ?? undefined)] + if (session.activePrivateKey) { - args.push('/privatekey') - args.push(session.activePrivateKey) + const tmpFile = await tmp.file() + const privateKey = await sshpk.parsePrivateKey(session.activePrivateKey, 'auto')/* .toString('putty') */ + const forgePrivateKey = forge.pki.decryptRsaPrivateKey(privateKey.toString('pem')) + const ppk = forge.ssh.privateKeyToPutty(forgePrivateKey) + await fs.writeFile(tmpFile.path, ppk) + args.push(`/privatekey=${tmpFile.path}`) + setTimeout(() => { + tmpFile.cleanup() + }, 5000) } this.platform.exec(path, args) } diff --git a/tabby-ssh/yarn.lock b/tabby-ssh/yarn.lock index bc0fdb4e..0f98010f 100644 --- a/tabby-ssh/yarn.lock +++ b/tabby-ssh/yarn.lock @@ -156,6 +156,18 @@ getpass@^0.1.1: once "^1.3.0" path-is-absolute "^1.0.0" +glob@^7.1.3: + version "7.2.3" + resolved "https://registry.yarnpkg.com/glob/-/glob-7.2.3.tgz#b8df0fb802bbfa8e89bd1d938b4e16578ed44f2b" + integrity sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q== + dependencies: + fs.realpath "^1.0.0" + inflight "^1.0.4" + inherits "2" + minimatch "^3.1.1" + once "^1.3.0" + path-is-absolute "^1.0.0" + inflight@^1.0.4: version "1.0.6" resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9" @@ -195,6 +207,18 @@ minimatch@^3.0.4: dependencies: brace-expansion "^1.1.7" +minimatch@^3.1.1: + version "3.1.2" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b" + integrity sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw== + dependencies: + brace-expansion "^1.1.7" + +node-forge@^1.3.1: + version "1.3.1" + resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-1.3.1.tgz#be8da2af243b2417d5f646a770663a92b7e9ded3" + integrity sha512-dPEtOeMvF9VMcYV/1Wb8CPoVAXtp6MKMlcbAt4ddqmGqUJ6fQZFXkNZNkNlfevtNkGtaSoXf/vNNNSvgrdXwtA== + once@^1.3.0: version "1.4.0" resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" @@ -212,6 +236,13 @@ pkginfo@0.3.x: resolved "https://registry.yarnpkg.com/pkginfo/-/pkginfo-0.3.1.tgz#5b29f6a81f70717142e09e765bbeab97b4f81e21" integrity sha1-Wyn2qB9wcXFC4J52W76rl7T4HiE= +rimraf@^3.0.0: + version "3.0.2" + resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-3.0.2.tgz#f1a5402ba6220ad52cc1282bac1ae3aa49fd061a" + integrity sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA== + 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" @@ -253,6 +284,20 @@ strip-ansi@^7.0.0: dependencies: ansi-regex "^6.0.0" +tmp-promise@^3.0.3: + version "3.0.3" + resolved "https://registry.yarnpkg.com/tmp-promise/-/tmp-promise-3.0.3.tgz#60a1a1cc98c988674fcbfd23b6e3367bdeac4ce7" + integrity sha512-RwM7MoPojPxsOBYnyd2hy0bxtIlVrihNs9pj5SUvY8Zz1sQcQG2tG1hSr8PDxfgEB8RNKDhqbIlroIarSNDNsQ== + dependencies: + tmp "^0.2.0" + +tmp@^0.2.0: + version "0.2.1" + resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.2.1.tgz#8457fc3037dcf4719c251367a1af6500ee1ccf14" + integrity sha512-76SUhtfqR2Ijn+xllcI5P1oyannHNHByD80W1q447gU3mp9G9PSpGdWmjUOHRDPiHYacIk66W7ubDTuPF3BEtQ== + dependencies: + rimraf "^3.0.0" + tweetnacl@^0.14.3, tweetnacl@~0.14.0: version "0.14.5" resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64" From d97e0e19467df7eb70787c371c32137c8ead8713 Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Tue, 27 Sep 2022 23:07:14 +0200 Subject: [PATCH 2/4] Update decorator.ts --- tabby-linkifier/src/decorator.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/tabby-linkifier/src/decorator.ts b/tabby-linkifier/src/decorator.ts index e4e2debb..29278683 100644 --- a/tabby-linkifier/src/decorator.ts +++ b/tabby-linkifier/src/decorator.ts @@ -34,7 +34,6 @@ export class LinkHighlighterDecorator extends TerminalDecorator { const openLink = async uri => handler.handle(await getLink(uri), tab) const addon = new WebLinksAddon( - this.onClick.bind(this), async (event, uri) => { if (!this.willHandleEvent(event)) { return From 5f86e101dfd108975a27d9812862686021970d72 Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Tue, 27 Sep 2022 23:07:26 +0200 Subject: [PATCH 3/4] make Platform.exec async --- tabby-core/src/api/platform.ts | 2 +- tabby-electron/src/services/platform.service.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tabby-core/src/api/platform.ts b/tabby-core/src/api/platform.ts index 79362cb0..73b081ba 100644 --- a/tabby-core/src/api/platform.ts +++ b/tabby-core/src/api/platform.ts @@ -145,7 +145,7 @@ export abstract class PlatformService { throw new Error('Not implemented') } - exec (app: string, argv: string[]): void { + async exec (app: string, argv: string[]): Promise { throw new Error('Not implemented') } diff --git a/tabby-electron/src/services/platform.service.ts b/tabby-electron/src/services/platform.service.ts index 806a15dd..7f655fb1 100644 --- a/tabby-electron/src/services/platform.service.ts +++ b/tabby-electron/src/services/platform.service.ts @@ -80,8 +80,8 @@ export class ElectronPlatformService extends PlatformService { return null } - exec (app: string, argv: string[]): void { - execFile(app, argv) + async exec (app: string, argv: string[]): Promise { + await execFile(app, argv) } isShellIntegrationSupported (): boolean { From 4675b7521ea55444708eca4b6ef3680bad9d8e8f Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Tue, 27 Sep 2022 23:12:59 +0200 Subject: [PATCH 4/4] defer tempfile cleanup --- tabby-ssh/src/services/ssh.service.ts | 9 ++++----- web/polyfills.ts | 3 ++- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tabby-ssh/src/services/ssh.service.ts b/tabby-ssh/src/services/ssh.service.ts index 4944850d..5189a1e1 100644 --- a/tabby-ssh/src/services/ssh.service.ts +++ b/tabby-ssh/src/services/ssh.service.ts @@ -50,18 +50,17 @@ export class SSHService { } const args = [await this.getWinSCPURI(session.profile, undefined, session.authUsername ?? undefined)] + let tmpFile: tmp.FileResult|null = null if (session.activePrivateKey) { - const tmpFile = await tmp.file() + tmpFile = await tmp.file() const privateKey = await sshpk.parsePrivateKey(session.activePrivateKey, 'auto')/* .toString('putty') */ const forgePrivateKey = forge.pki.decryptRsaPrivateKey(privateKey.toString('pem')) const ppk = forge.ssh.privateKeyToPutty(forgePrivateKey) await fs.writeFile(tmpFile.path, ppk) args.push(`/privatekey=${tmpFile.path}`) - setTimeout(() => { - tmpFile.cleanup() - }, 5000) } - this.platform.exec(path, args) + await this.platform.exec(path, args) + tmpFile?.cleanup() } } diff --git a/web/polyfills.ts b/web/polyfills.ts index 404d34c7..1aa5e2b2 100644 --- a/web/polyfills.ts +++ b/web/polyfills.ts @@ -48,7 +48,7 @@ Tabby.registerMock('fs', { appendFile: () => null, constants: {}, }) -Tabby.registerMock('any-promise', Promise) +Tabby.registerMock('fs/promises', {}) Tabby.registerMock('tls', {}) Tabby.registerMock('module', { globalPaths: [], @@ -92,6 +92,7 @@ Tabby.registerMock('keytar', { }) Tabby.registerMock('@serialport/bindings', {}) Tabby.registerMock('@serialport/bindings-cpp', {}) +Tabby.registerMock('tmp', {}) Tabby.registerModule('net', { Socket: SocketProxy,