feat: SSH Authentication Keys v2 (#113)

* feat: add SSH authentication keys v2 for Git operations

Add comprehensive SSH key authentication support for Git operations including:
- SSH host key verification with user approval flow
- Encrypted SSH key storage with passphrase support
- SSH connection testing endpoint
- Real-time host key change warnings

Backend changes:
- New SSHHostKeyHandler for managing host key verification via IPC
- Add passphrase handler for locked SSH keys
- Add SSH key manager utilities (key writing, validation, cleanup)
- Add crypto utilities for secure key/secret encryption
- Add SSH validation utilities for key format checking
- Add SSH routes for host key response handling
- Enhance GitAuthService with SSH setup and environment methods
- Update GitService to handle SSH authentication for push/fetch/pull
- Update OpenCode server to support SSH keys with SSH config generation
- Add database migration for trusted_ssh_hosts table
- Add settings endpoint for SSH connection testing

Frontend changes:
- Add SSHHostKeyDialog for host key verification UI
- Add PassphraseModal for SSH key passphrase input
- Update GitCredentialDialog with SSH key type and testing
- Update GitSettings to manage SSH keys
- Add SSH API client and hooks (useSSH, usePassphraseHandler)

Shared changes:
- Add SSH schemas and types

Test coverage:
- Integration tests for SSH flow
- IPC handler tests for host key and passphrase
- SSH route tests
- SSH utility validation tests
- Updated existing tests for SSH-aware changes
This commit is contained in:
Chris Scott authored and GitHub committed 2026-02-08 00:06:44 -05:00
1 parent 3d5ee463d7
commit 414f39b809
54 files changed
+4051 -214

No files matched your search

+48
View File
@@ -0,0 +1,48 @@
import { promises as fs } from 'fs'
import { tmpdir } from 'os'
import { join } from 'path'
import { executeCommand } from './process'
async function removeFile(filePath: string): Promise<void> {
await fs.unlink(filePath).catch(() => {})
}
export async function validateSSHPrivateKey(key: string): Promise<{ valid: boolean; hasPassphrase: boolean; error?: string }> {
if (!key || typeof key !== 'string') {
return { valid: false, hasPassphrase: false, error: 'SSH key is required' }
}
const trimmedKey = key.trim()
if (!trimmedKey) {
return { valid: false, hasPassphrase: false, error: 'SSH key cannot be empty' }
}
let tempKeyPath: string | null = null
try {
tempKeyPath = join(tmpdir(), `temp-ssh-key-${Date.now()}-${Math.random().toString(36).slice(2)}`)
await fs.writeFile(tempKeyPath, trimmedKey + '\n', { mode: 0o600 })
try {
await executeCommand(['ssh-keygen', '-y', '-P', '', '-f', tempKeyPath], { silent: true })
return { valid: true, hasPassphrase: false }
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error)
const passphrasePatterns = ['incorrect passphrase', 'bad passphrase', 'passphrase failed']
const isPassphraseError = passphrasePatterns.some(pattern => errorMessage.toLowerCase().includes(pattern))
if (isPassphraseError) {
return { valid: true, hasPassphrase: true }
}
throw error
}
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error)
return { valid: false, hasPassphrase: false, error: `Invalid SSH key: ${errorMessage}` }
} finally {
if (tempKeyPath) {
await removeFile(tempKeyPath)
}
}
}