From a1e54b8410c8e38f636babe41ce0d012d6e6a533 Mon Sep 17 00:00:00 2001 From: Eugene Date: Thu, 15 Aug 2024 21:52:58 +0200 Subject: [PATCH] agent auth --- app/package.json | 2 +- app/yarn.lock | 8 ++--- tabby-ssh/src/session/ssh.ts | 69 ++++++++++++++++++++---------------- 3 files changed, 44 insertions(+), 35 deletions(-) diff --git a/app/package.json b/app/package.json index 5b8f23ed..2038a1e8 100644 --- a/app/package.json +++ b/app/package.json @@ -30,7 +30,7 @@ "native-process-working-directory": "^1.0.2", "npm": "6", "rxjs": "^7.5.7", - "russh": "^0.0.1-alpha.9", + "russh": "^0.0.1-alpha.10", "source-map-support": "^0.5.20", "v8-compile-cache": "^2.3.0", "yargs": "^17.7.2" diff --git a/app/yarn.lock b/app/yarn.lock index 4e5a8bd3..f9bf07ff 100644 --- a/app/yarn.lock +++ b/app/yarn.lock @@ -3613,10 +3613,10 @@ run-queue@^1.0.0, run-queue@^1.0.3: dependencies: aproba "^1.1.1" -russh@^0.0.1-alpha.9: - version "0.0.1-alpha.9" - resolved "https://registry.yarnpkg.com/russh/-/russh-0.0.1-alpha.9.tgz#d7b11f70bcdbd54caa13cf0a4f3748a185cb0b08" - integrity sha512-CfA6T7YsIvPdT1fgtCMqoLkiJnNbjI1V5xsq8aZLe8SevIiIJSMgg8jUl8hJgQX7hR9pUNhG646BPuv/I/1OCA== +russh@^0.0.1-alpha.10: + version "0.0.1-alpha.10" + resolved "https://registry.yarnpkg.com/russh/-/russh-0.0.1-alpha.10.tgz#5d90ca214be37ef6b527dcee66ef72ca04744c84" + integrity sha512-yi7te2CcasiD16RpDKVUIEbvnJ4o66z4+BGg+fQjMGw378AWJ+6e0z+JXccgrKPsEOGDzvSTR5DwPCfea7X3CA== dependencies: "@napi-rs/cli" "^2.18.3" diff --git a/tabby-ssh/src/session/ssh.ts b/tabby-ssh/src/session/ssh.ts index 85a95490..f5534934 100644 --- a/tabby-ssh/src/session/ssh.ts +++ b/tabby-ssh/src/session/ssh.ts @@ -1,11 +1,11 @@ -import * as fs from 'mz/fs' +// import * as fs from 'mz/fs' import * as crypto from 'crypto' import colors from 'ansi-colors' import stripAnsi from 'strip-ansi' import * as shellQuote from 'shell-quote' import { Injector } from '@angular/core' import { NgbModal } from '@ng-bootstrap/ng-bootstrap' -import { ConfigService, FileProvidersService, HostAppService, NotificationsService, Platform, PlatformService, PromptModalComponent, LogService, Logger, TranslateService } from 'tabby-core' +import { ConfigService, FileProvidersService, HostAppService, NotificationsService, PlatformService, PromptModalComponent, LogService, Logger, TranslateService } from 'tabby-core' import { Socket } from 'net' import { Subject, Observable } from 'rxjs' import { HostKeyPromptModalComponent } from '../components/hostKeyPromptModal.component' @@ -19,7 +19,7 @@ import { X11Socket } from './x11' import { supportedAlgorithms } from '../algorithms' import * as russh from 'russh' -const WINDOWS_OPENSSH_AGENT_PIPE = '\\\\.\\pipe\\openssh-ssh-agent' +// const WINDOWS_OPENSSH_AGENT_PIPE = '\\\\.\\pipe\\openssh-ssh-agent' export interface Prompt { prompt: string @@ -90,7 +90,6 @@ export class SSHSession { private hostApp: HostAppService private platform: PlatformService private notifications: NotificationsService - // private zone: NgZone private fileProviders: FileProvidersService private config: ConfigService private translate: TranslateService @@ -108,7 +107,6 @@ export class SSHSession { this.hostApp = injector.get(HostAppService) this.platform = injector.get(PlatformService) this.notifications = injector.get(NotificationsService) - // this.zone = injector.get(NgZone) this.fileProviders = injector.get(FileProvidersService) this.config = injector.get(ConfigService) this.translate = injector.get(TranslateService) @@ -123,26 +121,26 @@ export class SSHSession { } async init (): Promise { - if (this.hostApp.platform === Platform.Windows) { - if (this.config.store.ssh.agentType === 'auto') { - if (await fs.exists(WINDOWS_OPENSSH_AGENT_PIPE)) { - this.agentPath = WINDOWS_OPENSSH_AGENT_PIPE - } else { - if ( - await this.platform.isProcessRunning('pageant.exe') || - await this.platform.isProcessRunning('gpg-agent.exe') - ) { - this.agentPath = 'pageant' - } - } - } else if (this.config.store.ssh.agentType === 'pageant') { - this.agentPath = 'pageant' - } else { - this.agentPath = this.config.store.ssh.agentPath || WINDOWS_OPENSSH_AGENT_PIPE - } - } else { - this.agentPath = process.env.SSH_AUTH_SOCK! - } + // TODO if (this.hostApp.platform === Platform.Windows) { + // if (this.config.store.ssh.agentType === 'auto') { + // if (await fs.exists(WINDOWS_OPENSSH_AGENT_PIPE)) { + // this.agentPath = WINDOWS_OPENSSH_AGENT_PIPE + // } else { + // if ( + // await this.platform.isProcessRunning('pageant.exe') || + // await this.platform.isProcessRunning('gpg-agent.exe') + // ) { + // this.agentPath = 'pageant' + // } + // } + // } else if (this.config.store.ssh.agentType === 'pageant') { + // this.agentPath = 'pageant' + // } else { + // this.agentPath = this.config.store.ssh.agentPath || WINDOWS_OPENSSH_AGENT_PIPE + // } + // } else { + // this.agentPath = process.env.SSH_AUTH_SOCK! + // } this.remainingAuthMethods = [{ type: 'none' }] if (!this.profile.options.auth || this.profile.options.auth === 'publicKey') { @@ -171,11 +169,11 @@ export class SSHSession { } } if (!this.profile.options.auth || this.profile.options.auth === 'agent') { - if (!this.agentPath) { - this.emitServiceMessage(colors.bgYellow.yellow.black(' ! ') + ` Agent auth selected, but no running agent is detected`) - } else { - this.remainingAuthMethods.push({ type: 'agent' }) - } + // if (!this.agentPath) { + // this.emitServiceMessage(colors.bgYellow.yellow.black(' ! ') + ` Agent auth selected, but no running agent is detected`) + // } else { + this.remainingAuthMethods.push({ type: 'agent' }) + // } } if (!this.profile.options.auth || this.profile.options.auth === 'password') { this.remainingAuthMethods.push({ type: 'password' }) @@ -545,6 +543,17 @@ export class SSHSession { } } } + if (method.type === 'agent') { + try { + const result = await this.ssh.authenticateWithAgent(this.authUsername) + if (result) { + return result + } + } catch (e) { + this.emitServiceMessage(colors.bgYellow.yellow.black(' ! ') + ` Failed to authenticate using agent: ${e}`) + continue + } + } } return null }