mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
* 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
57 lines
1.7 KiB
TypeScript
57 lines
1.7 KiB
TypeScript
import { Hono } from 'hono'
|
|
import { z } from 'zod'
|
|
import { logger } from '../utils/logger'
|
|
import { GitAuthService } from '../services/git-auth'
|
|
|
|
const SSHHostKeyResponseSchema = z.object({
|
|
requestId: z.string(),
|
|
response: z.enum(['accept', 'reject'])
|
|
})
|
|
|
|
interface SSHHostKeyResponse {
|
|
success: boolean
|
|
error?: string
|
|
}
|
|
|
|
export function createSSHRoutes(gitAuthService: GitAuthService) {
|
|
const app = new Hono()
|
|
|
|
app.post('/host-key/respond', async (c) => {
|
|
try {
|
|
const body = await c.req.json()
|
|
const validated = SSHHostKeyResponseSchema.parse(body)
|
|
|
|
const handler = gitAuthService.sshHostKeyHandler
|
|
if (!handler) {
|
|
return c.json<SSHHostKeyResponse>({ success: false, error: 'SSH host key handler not found' }, 404)
|
|
}
|
|
|
|
const result = await handler.respond(validated)
|
|
return c.json<SSHHostKeyResponse>(result)
|
|
} catch (error) {
|
|
logger.error('Error responding to SSH host key request:', error)
|
|
if (error instanceof z.ZodError) {
|
|
return c.json<SSHHostKeyResponse>({ success: false, error: 'Invalid request body' }, 400)
|
|
}
|
|
return c.json<SSHHostKeyResponse>({ success: false, error: 'Internal server error' }, 500)
|
|
}
|
|
})
|
|
|
|
app.get('/host-key/status', (c) => {
|
|
try {
|
|
const handler = gitAuthService.sshHostKeyHandler
|
|
if (!handler) {
|
|
return c.json({ success: false, error: 'SSH host key handler not found' }, 404)
|
|
}
|
|
|
|
const pendingCount = handler.getPendingCount()
|
|
return c.json({ success: true, pendingCount })
|
|
} catch (error) {
|
|
logger.error('Error getting SSH host key status:', error)
|
|
return c.json({ success: false, error: 'Internal server error' }, 500)
|
|
}
|
|
})
|
|
|
|
return app
|
|
}
|