Skip to content

Commit

Permalink
agent auth
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugeny committed Aug 15, 2024
1 parent c42ea8a commit a1e54b8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 35 deletions.
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions app/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
69 changes: 39 additions & 30 deletions tabby-ssh/src/session/ssh.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
Expand Down Expand Up @@ -90,7 +90,6 @@ export class SSHSession {
private hostApp: HostAppService

Check failure on line 90 in tabby-ssh/src/session/ssh.ts

View workflow job for this annotation

GitHub Actions / build

'hostApp' is declared but its value is never read.

Check failure on line 90 in tabby-ssh/src/session/ssh.ts

View workflow job for this annotation

GitHub Actions / Lint

'hostApp' is declared but its value is never read.

Check failure on line 90 in tabby-ssh/src/session/ssh.ts

View workflow job for this annotation

GitHub Actions / macOS-Build (x86_64, x86_64-apple-darwin)

'hostApp' is declared but its value is never read.

Check failure on line 90 in tabby-ssh/src/session/ssh.ts

View workflow job for this annotation

GitHub Actions / macOS-Build (arm64, aarch64-apple-darwin)

'hostApp' is declared but its value is never read.

Check failure on line 90 in tabby-ssh/src/session/ssh.ts

View workflow job for this annotation

GitHub Actions / Windows-Build (x64, x86_64-pc-windows-msvc)

'hostApp' is declared but its value is never read.

Check failure on line 90 in tabby-ssh/src/session/ssh.ts

View workflow job for this annotation

GitHub Actions / Linux-Build (x64, amd64, x86_64-unknown-linux-gnu)

'hostApp' is declared but its value is never read.

Check failure on line 90 in tabby-ssh/src/session/ssh.ts

View workflow job for this annotation

GitHub Actions / Windows-Build (arm64, aarch64-pc-windows-msvc)

'hostApp' is declared but its value is never read.

Check failure on line 90 in tabby-ssh/src/session/ssh.ts

View workflow job for this annotation

GitHub Actions / Linux-Build (arm64, arm64, aarch64-unknown-linux-gnu, aarch64-linux-gnu-)

'hostApp' is declared but its value is never read.

Check failure on line 90 in tabby-ssh/src/session/ssh.ts

View workflow job for this annotation

GitHub Actions / Linux-Build (arm, armhf, arm-unknown-linux-gnueabihf, arm-linux-gnueabihf-)

'hostApp' is declared but its value is never read.
private platform: PlatformService

Check failure on line 91 in tabby-ssh/src/session/ssh.ts

View workflow job for this annotation

GitHub Actions / build

'platform' is declared but its value is never read.

Check failure on line 91 in tabby-ssh/src/session/ssh.ts

View workflow job for this annotation

GitHub Actions / Lint

'platform' is declared but its value is never read.

Check failure on line 91 in tabby-ssh/src/session/ssh.ts

View workflow job for this annotation

GitHub Actions / macOS-Build (x86_64, x86_64-apple-darwin)

'platform' is declared but its value is never read.

Check failure on line 91 in tabby-ssh/src/session/ssh.ts

View workflow job for this annotation

GitHub Actions / macOS-Build (arm64, aarch64-apple-darwin)

'platform' is declared but its value is never read.

Check failure on line 91 in tabby-ssh/src/session/ssh.ts

View workflow job for this annotation

GitHub Actions / Windows-Build (x64, x86_64-pc-windows-msvc)

'platform' is declared but its value is never read.

Check failure on line 91 in tabby-ssh/src/session/ssh.ts

View workflow job for this annotation

GitHub Actions / Linux-Build (x64, amd64, x86_64-unknown-linux-gnu)

'platform' is declared but its value is never read.

Check failure on line 91 in tabby-ssh/src/session/ssh.ts

View workflow job for this annotation

GitHub Actions / Windows-Build (arm64, aarch64-pc-windows-msvc)

'platform' is declared but its value is never read.

Check failure on line 91 in tabby-ssh/src/session/ssh.ts

View workflow job for this annotation

GitHub Actions / Linux-Build (arm64, arm64, aarch64-unknown-linux-gnu, aarch64-linux-gnu-)

'platform' is declared but its value is never read.

Check failure on line 91 in tabby-ssh/src/session/ssh.ts

View workflow job for this annotation

GitHub Actions / Linux-Build (arm, armhf, arm-unknown-linux-gnueabihf, arm-linux-gnueabihf-)

'platform' is declared but its value is never read.
private notifications: NotificationsService
// private zone: NgZone
private fileProviders: FileProvidersService
private config: ConfigService
private translate: TranslateService
Expand All @@ -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)
Expand All @@ -123,26 +121,26 @@ export class SSHSession {
}

async init (): Promise<void> {
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') {
Expand Down Expand Up @@ -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' })
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit a1e54b8

Please sign in to comment.