mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 21:04:23 +01:00
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:
1 parent
3d5ee463d7
commit
414f39b809
54 files changed
+4051
-214
No files matched your search
@@ -0,0 +1,70 @@
|
||||
import { useState, useEffect, useCallback } from 'react'
|
||||
|
||||
interface PassphraseRequest {
|
||||
type: 'passphrase-request'
|
||||
credentialName: string
|
||||
host: string
|
||||
}
|
||||
|
||||
interface UsePassphraseHandlerProps {
|
||||
enabled?: boolean
|
||||
onSubmit?: (passphrase: string) => void
|
||||
}
|
||||
|
||||
export function usePassphraseHandler({ enabled = true, onSubmit }: UsePassphraseHandlerProps = {}) {
|
||||
const [isOpen, setIsOpen] = useState(false)
|
||||
const [credentialName, setCredentialName] = useState<string>('SSH key')
|
||||
const [host, setHost] = useState<string>('')
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
if (!enabled) return
|
||||
|
||||
const handlePassphraseRequest = (event: MessageEvent) => {
|
||||
const data = event.data as PassphraseRequest
|
||||
if (data.type === 'passphrase-request') {
|
||||
setCredentialName(data.credentialName)
|
||||
setHost(data.host)
|
||||
setIsOpen(true)
|
||||
setError(null)
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('message', handlePassphraseRequest)
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('message', handlePassphraseRequest)
|
||||
}
|
||||
}, [enabled])
|
||||
|
||||
const handleSubmitPassphrase = useCallback((passphrase: string) => {
|
||||
try {
|
||||
onSubmit?.(passphrase)
|
||||
setIsOpen(false)
|
||||
setError(null)
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Failed to submit passphrase')
|
||||
}
|
||||
}, [onSubmit])
|
||||
|
||||
const sendPassphraseResponse = useCallback((passphrase: string) => {
|
||||
window.postMessage({
|
||||
type: 'passphrase-response',
|
||||
passphrase
|
||||
}, '*')
|
||||
}, [])
|
||||
|
||||
const handleSubmit = useCallback((passphrase: string) => {
|
||||
sendPassphraseResponse(passphrase)
|
||||
handleSubmitPassphrase(passphrase)
|
||||
}, [sendPassphraseResponse, handleSubmitPassphrase])
|
||||
|
||||
return {
|
||||
isOpen,
|
||||
credentialName,
|
||||
host,
|
||||
error,
|
||||
onSubmit: handleSubmit,
|
||||
onOpenChange: setIsOpen
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { useEventContext } from '@/contexts/EventContext'
|
||||
|
||||
export function useSSH() {
|
||||
const { sshHostKey } = useEventContext()
|
||||
return sshHostKey
|
||||
}
|
||||
@@ -18,7 +18,7 @@ export function useSettingsDialogUrl(): UseSettingsDialogUrlReturn {
|
||||
|
||||
const searchParams = new URLSearchParams(location.search)
|
||||
const isOpen = searchParams.get('settings') === 'open'
|
||||
const activeTab = (searchParams.get('tab') as Tab) || 'menu'
|
||||
const activeTab = (searchParams.get('tab') as Tab) || 'account'
|
||||
|
||||
const open = useCallback(() => {
|
||||
const newParams = new URLSearchParams(location.search)
|
||||
|
||||
Reference in new issue
Block a user