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

+8
View File
@@ -181,6 +181,14 @@ export const settingsApi = {
})
},
testSSHConnection: async (host: string, sshPrivateKey: string, passphrase?: string): Promise<{ success: boolean; message: string }> => {
return fetchWrapper(`${API_BASE_URL}/api/settings/test-ssh`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ host, sshPrivateKey, passphrase }),
})
},
getAgentsMd: async (): Promise<{ content: string }> => {
return fetchWrapper(`${API_BASE_URL}/api/settings/agents-md`)
},
+14
View File
@@ -0,0 +1,14 @@
import { API_BASE_URL } from '@/config'
import { fetchWrapper } from './fetchWrapper'
export function respondSSHHostKey(requestId: string, approved: boolean): Promise<{ success: boolean; error?: string }> {
return fetchWrapper(`${API_BASE_URL}/api/ssh/host-key/respond`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ requestId, response: approved ? 'accept' : 'reject' }),
})
}
export function getSSHHostKeyStatus(): Promise<{ success: boolean; pendingCount?: number; error?: string }> {
return fetchWrapper(`${API_BASE_URL}/api/ssh/host-key/status`)
}
+20
View File
@@ -179,6 +179,11 @@ export interface SSESessionErrorEvent {
}
}
export interface SSESSHHostKeyRequestEvent {
type: 'ssh.host-key-request'
properties: SSHHostKeyRequest
}
export type SSEEvent =
| SSEMessagePartUpdatedEvent
| SSEMessageUpdatedEvent
@@ -198,6 +203,7 @@ export type SSEEvent =
| SSEQuestionRejectedEvent
| SSEInstallationUpdatedEvent
| SSEInstallationUpdateAvailableEvent
| SSESSHHostKeyRequestEvent
export type ContentPart =
| { type: 'text', content: string }
@@ -216,3 +222,17 @@ export interface ImageAttachment {
mime: string
dataUrl: string
}
export interface SSHHostKeyRequest {
id: string
requestId: string
host: string
ip?: string
keyType: string
fingerprint: string
isKeyChanged?: boolean
timestamp: number
action: 'verify'
}
export type SSHHostKeyResponse = 'accept' | 'reject'
+6 -1
View File
@@ -28,8 +28,13 @@ export interface CustomAgent {
export interface GitCredential {
name: string
host: string
token: string
type: 'pat' | 'ssh'
token?: string
sshPrivateKey?: string
sshPrivateKeyEncrypted?: string
hasPassphrase?: boolean
username?: string
passphrase?: string
}
export interface GitIdentity {