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

@@ -0,0 +1,102 @@
import { useState, useEffect, useRef } from 'react'
import { Button } from '@/components/ui/button'
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog'
import { Input } from '@/components/ui/input'
import { Label } from '@/components/ui/label'
import { Lock, AlertCircle } from 'lucide-react'
interface PassphraseModalProps {
open: boolean
onOpenChange: (open: boolean) => void
onSubmit: (passphrase: string) => void
credentialName?: string
}
export function PassphraseModal({ open, onOpenChange, onSubmit, credentialName = 'SSH key' }: PassphraseModalProps) {
const [passphrase, setPassphrase] = useState('')
const [error, setError] = useState<string | null>(null)
const inputRef = useRef<HTMLInputElement>(null)
useEffect(() => {
if (open) {
setPassphrase('')
setError(null)
setTimeout(() => inputRef.current?.focus(), 100)
}
}, [open])
const handleSubmit = () => {
if (!passphrase.trim()) {
setError('Passphrase is required')
return
}
onSubmit(passphrase)
setPassphrase('')
setError(null)
}
const handleKeyDown = (e: React.KeyboardEvent) => {
if (e.key === 'Enter') {
e.preventDefault()
handleSubmit()
}
}
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="max-w-[90%] sm:max-w-md">
<DialogHeader>
<DialogTitle className="flex items-center gap-2">
<Lock className="h-5 w-5" />
SSH Key Passphrase Required
</DialogTitle>
<DialogDescription>
Enter the passphrase for your <span className="font-medium">{credentialName}</span>
</DialogDescription>
</DialogHeader>
<div className="space-y-4 py-2">
<div className="space-y-2">
<Label htmlFor="passphrase">Passphrase</Label>
<div className="relative">
<Input
id="passphrase"
type="password"
ref={inputRef}
value={passphrase}
onChange={(e) => {
setPassphrase(e.target.value)
setError(null)
}}
onKeyDown={handleKeyDown}
placeholder="Enter your passphrase"
className={error ? 'border-destructive' : ''}
autoComplete="current-password"
/>
</div>
{error && (
<p className="text-sm text-destructive flex items-center gap-1">
<AlertCircle className="h-4 w-4" />
{error}
</p>
)}
</div>
<p className="text-xs text-muted-foreground">
This passphrase is NOT stored and will be required each time you access this SSH key.
</p>
</div>
<DialogFooter>
<Button variant="outline" onClick={() => onOpenChange(false)}>
Cancel
</Button>
<Button onClick={handleSubmit} disabled={!passphrase.trim()}>
Submit
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
)
}
@@ -1,9 +1,11 @@
import { useState, useEffect } from 'react'
import { Loader2 } from 'lucide-react'
import { Loader2, Key, Lock, AlertTriangle } from 'lucide-react'
import { Button } from '@/components/ui/button'
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog'
import { Input } from '@/components/ui/input'
import { Label } from '@/components/ui/label'
import { Textarea } from '@/components/ui/textarea'
import { Alert } from '@/components/ui/alert'
import { showToast } from '@/lib/toast'
import type { GitCredential } from '@/api/types/settings'
@@ -19,10 +21,16 @@ export function GitCredentialDialog({ open, onOpenChange, onSave, credential, is
const [formData, setFormData] = useState<GitCredential>({
name: '',
host: '',
type: 'pat',
token: '',
username: '',
sshPrivateKey: '',
passphrase: '',
})
const [tokenEdited, setTokenEdited] = useState(false)
const [isTesting, setIsTesting] = useState(false)
const [showPassphraseInput, setShowPassphraseInput] = useState(false)
const [testPassphrase, setTestPassphrase] = useState('')
const maskToken = (token: string) => {
if (!token) return ''
@@ -33,13 +41,16 @@ export function GitCredentialDialog({ open, onOpenChange, onSave, credential, is
useEffect(() => {
if (open) {
setTokenEdited(false)
setShowPassphraseInput(false)
setTestPassphrase('')
if (credential) {
setFormData({
...credential,
token: ''
sshPrivateKey: '',
token: credential.type === 'pat' ? '' : credential.token
})
} else {
setFormData({ name: '', host: 'https://github.com', token: '', username: '' })
setFormData({ name: '', host: '', type: 'pat', token: '', username: '', sshPrivateKey: '', passphrase: '' })
}
}
}, [open, credential])
@@ -47,35 +58,77 @@ export function GitCredentialDialog({ open, onOpenChange, onSave, credential, is
const handleSubmit = async (event?: React.MouseEvent) => {
event?.preventDefault()
event?.stopPropagation()
const isEditing = !!credential
const tokenRequired = isEditing ? tokenEdited : true
if (!formData.name.trim() || !formData.host.trim() || (tokenRequired && !formData.token.trim())) {
showToast.error('Please fill in all required fields')
if (!formData.name.trim() || !formData.host.trim()) {
showToast.error('Name and host are required')
return
}
if (formData.type === 'pat') {
if (!formData.token?.trim()) {
showToast.error('Token is required for PAT type')
return
}
} else if (formData.type === 'ssh') {
if (!formData.sshPrivateKey?.trim()) {
showToast.error('SSH key is required for SSH type')
return
}
}
try {
const dataToSave: GitCredential = {
...formData,
token: (isEditing && !tokenEdited) ? credential.token : formData.token
hasPassphrase: formData.type === 'ssh' ? Boolean(formData.passphrase?.trim()) : false
}
if (formData.type === 'pat' && credential?.token && !tokenEdited) {
dataToSave.token = credential.token
}
await onSave(dataToSave)
setFormData({ name: '', host: '', token: '', username: '' })
setFormData({ name: '', host: '', type: 'pat', token: '', username: '', sshPrivateKey: '', passphrase: '' })
onOpenChange(false)
} catch {
showToast.error('Failed to save credential')
}
}
const handleTestConnection = async () => {
if (!formData.sshPrivateKey?.trim()) {
showToast.error('Please enter an SSH key first')
return
}
setIsTesting(true)
try {
const host = formData.host.replace(/^https?:\/\//, '').replace(/\/$/, '')
const settingsApi = (await import('@/api/settings')).settingsApi
const result = await settingsApi.testSSHConnection(
host,
formData.sshPrivateKey,
testPassphrase || undefined
)
if (result.success) {
showToast.success(result.message)
} else {
showToast.error(result.message)
}
} catch (error) {
const message = error instanceof Error ? error.message : 'Failed to test SSH connection'
showToast.error(message)
} finally {
setIsTesting(false)
}
}
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="max-w-md">
<DialogContent className="max-w-lg z-[150]" overlayClassName="z-[140]">
<DialogHeader>
<DialogTitle>{credential ? 'Edit Git Credential' : 'Add Git Credential'}</DialogTitle>
</DialogHeader>
<form onSubmit={(e) => { e.preventDefault(); handleSubmit(); }} className="space-y-4">
<div className="space-y-2">
<Label htmlFor="cred-name">Name *</Label>
@@ -85,52 +138,166 @@ export function GitCredentialDialog({ open, onOpenChange, onSave, credential, is
value={formData.name}
onChange={(e) => setFormData({ ...formData, name: e.target.value })}
disabled={isSaving}
autoComplete="off"
/>
</div>
<div className="space-y-2">
<Label htmlFor="cred-host">Host URL *</Label>
<Label htmlFor="cred-type">Authentication Type</Label>
<div className="flex gap-2">
<Button
type="button"
variant={formData.type === 'pat' ? 'default' : 'outline'}
onClick={() => setFormData({ ...formData, type: 'pat', sshPrivateKey: '', passphrase: '' })}
disabled={isSaving}
className="flex-1"
>
<Key className="h-4 w-4 mr-2" />
PAT
</Button>
<Button
type="button"
variant={formData.type === 'ssh' ? 'default' : 'outline'}
onClick={() => setFormData({ ...formData, type: 'ssh', token: '' })}
disabled={isSaving}
className="flex-1"
>
<Lock className="h-4 w-4 mr-2" />
SSH Key
</Button>
</div>
</div>
<div className="space-y-2">
<Label htmlFor="cred-host">Host *</Label>
<Input
id="cred-host"
placeholder="https://github.com/"
placeholder="github.com or git@github.com"
value={formData.host}
onChange={(e) => setFormData({ ...formData, host: e.target.value })}
disabled={isSaving}
autoComplete="off"
/>
</div>
<div className="space-y-2">
<Label htmlFor="cred-token">
Access Token {credential && !tokenEdited ? '(unchanged)' : '*'}
</Label>
<Input
id="cred-token"
type="password"
placeholder={credential ? maskToken(credential.token) : 'Personal access token'}
value={formData.token}
onChange={(e) => {
setTokenEdited(true)
setFormData({ ...formData, token: e.target.value })
}}
disabled={isSaving}
/>
{credential && !tokenEdited && (
<p className="text-xs text-muted-foreground">
Leave empty to keep existing token
</p>
)}
</div>
{formData.type === 'pat' ? (
<>
<div className="space-y-2">
<Label htmlFor="cred-token">
Access Token {credential?.token && !tokenEdited ? '(unchanged)' : '*'}
</Label>
<Input
id="cred-token"
type="password"
placeholder={credential?.token ? maskToken(credential.token) : 'Personal access token'}
value={formData.token || ''}
onChange={(e) => {
setTokenEdited(true)
setFormData({ ...formData, token: e.target.value })
}}
disabled={isSaving}
autoComplete="new-password"
/>
{credential?.token && !tokenEdited && (
<p className="text-xs text-muted-foreground">
Leave empty to keep existing token
</p>
)}
</div>
<div className="space-y-2">
<Label htmlFor="cred-username">Username (optional)</Label>
<Input
id="cred-username"
placeholder="Auto-detected if empty"
value={formData.username || ''}
onChange={(e) => setFormData({ ...formData, username: e.target.value })}
disabled={isSaving}
/>
</div>
<div className="space-y-2">
<Label htmlFor="cred-pat-username">Username (optional)</Label>
<Input
id="cred-pat-username"
placeholder="Auto-detected if empty"
value={formData.username || ''}
onChange={(e) => setFormData({ ...formData, username: e.target.value })}
disabled={isSaving}
autoComplete="off"
/>
</div>
</>
) : (
<>
<div className="space-y-2">
<Label htmlFor="cred-ssh-key">SSH Private Key *</Label>
<Textarea
id="cred-ssh-key"
placeholder="-----BEGIN OPENSSH PRIVATE KEY-----"
value={formData.sshPrivateKey || ''}
onChange={(e) => setFormData({ ...formData, sshPrivateKey: e.target.value })}
disabled={isSaving}
rows={8}
className="font-mono"
/>
<p className="text-xs text-muted-foreground">
Paste your private key content here
</p>
</div>
<div className="space-y-2">
<Button
type="button"
variant="outline"
onClick={() => setShowPassphraseInput(!showPassphraseInput)}
disabled={isSaving}
className="w-full"
>
{showPassphraseInput ? 'Remove' : 'Add'} Passphrase
</Button>
</div>
{showPassphraseInput && (
<div className="space-y-2">
<Label htmlFor="cred-passphrase">Passphrase</Label>
<Input
id="cred-passphrase"
type="password"
placeholder="Enter passphrase for SSH key"
value={formData.passphrase || ''}
onChange={(e) => setFormData({ ...formData, passphrase: e.target.value })}
disabled={isSaving}
autoComplete="new-password"
/>
<p className="text-xs text-muted-foreground">
This passphrase will be required for each git operation
</p>
</div>
)}
<div className="space-y-2">
<Label htmlFor="test-passphrase">Passphrase for Test (if protected)</Label>
<Input
id="test-passphrase"
type="password"
placeholder="Enter passphrase to test connection"
value={testPassphrase}
onChange={(e) => setTestPassphrase(e.target.value)}
disabled={isTesting || isSaving}
autoComplete="new-password"
/>
</div>
<Button
type="button"
variant="outline"
onClick={handleTestConnection}
disabled={isTesting || isSaving || !formData.sshPrivateKey?.trim()}
className="w-full"
>
{isTesting && <Loader2 className="h-4 w-4 mr-2 animate-spin" />}
Test Connection
</Button>
<Alert>
<AlertTriangle className="h-4 w-4" />
<p className="text-sm font-medium">Security Notice</p>
<p className="text-xs mt-1">
Your private key will be encrypted at rest. Never share it with anyone.
</p>
</Alert>
</>
)}
<div className="flex justify-end gap-2 pt-4">
<Button
@@ -143,7 +310,9 @@ export function GitCredentialDialog({ open, onOpenChange, onSave, credential, is
</Button>
<Button
type="submit"
disabled={isSaving || !formData.name.trim() || !formData.host.trim() || (!credential && !formData.token.trim())}
disabled={isSaving || !formData.name.trim() || !formData.host.trim() ||
(formData.type === 'pat' && !formData.token?.trim()) ||
(formData.type === 'ssh' && !formData.sshPrivateKey?.trim())}
>
{isSaving && <Loader2 className="h-4 w-4 mr-2 animate-spin" />}
{credential ? 'Update' : 'Add'}
@@ -45,6 +45,18 @@ export function GitSettings() {
setIsCredentialDialogOpen(true)
}
const handleEditClick = (e: React.MouseEvent, index: number) => {
e.preventDefault()
e.stopPropagation()
openEditCredentialDialog(index)
}
const handleDeleteClick = (e: React.MouseEvent, index: number) => {
e.preventDefault()
e.stopPropagation()
removeCredential(index)
}
const saveCredential = async (credential: GitCredential) => {
let newCredentials: GitCredential[]
@@ -216,10 +228,11 @@ export function GitSettings() {
) : (
<div className="border border-border rounded-lg overflow-hidden">
<table className="w-full text-sm">
<thead className="bg-muted/50">
<thead className="bg-muted/50">
<tr>
<th className="px-3 py-2 text-left font-medium text-muted-foreground">Name</th>
<th className="px-3 py-2 text-left font-medium text-muted-foreground hidden sm:table-cell">Host</th>
<th className="px-3 py-2 text-left font-medium text-muted-foreground hidden sm:table-cell">Type</th>
<th className="px-3 py-2 text-right font-medium text-muted-foreground">Actions</th>
</tr>
</thead>
@@ -235,32 +248,37 @@ export function GitSettings() {
<td className="px-3 py-2 text-muted-foreground hidden sm:table-cell">
{cred.host}
</td>
<td className="px-3 py-2">
<div className="flex items-center justify-end gap-1">
<td className="px-3 py-2 text-muted-foreground hidden sm:table-cell">
<span className="text-xs px-1.5 py-0.5 rounded bg-muted">
{cred.type === 'ssh' ? 'SSH' : 'PAT'}
</span>
</td>
<td className="px-3 py-2">
<div className="flex items-center justify-end gap-1">
<Button
type="button"
variant="ghost"
size="sm"
className="h-7 w-7 p-0"
onClick={(e) => handleEditClick(e, index)}
disabled={isSaving}
title="Edit"
>
<Pencil className="h-3.5 w-3.5" />
</Button>
<Button
type="button"
variant="ghost"
size="sm"
className="h-7 w-7 p-0"
onClick={() => openEditCredentialDialog(index)}
className="h-7 w-7 p-0 text-destructive hover:text-destructive"
onClick={(e) => handleDeleteClick(e, index)}
disabled={isSaving}
title="Edit"
title="Delete"
>
<Pencil className="h-3.5 w-3.5" />
<Trash2 className="h-3.5 w-3.5" />
</Button>
<Button
type="button"
variant="ghost"
size="sm"
className="h-7 w-7 p-0 text-destructive hover:text-destructive"
onClick={() => removeCredential(index)}
disabled={isSaving}
title="Delete"
>
<Trash2 className="h-3.5 w-3.5" />
</Button>
</div>
</td>
</div>
</td>
</tr>
))}
</tbody>
@@ -41,7 +41,10 @@ export function SettingsDialog() {
useEffect(() => {
if (!isOpen) return
const handleKeyDown = (e: KeyboardEvent) => {
if (e.key === 'Escape') close()
if (e.key === 'Escape') {
e.stopPropagation()
close()
}
}
document.addEventListener('keydown', handleKeyDown)
return () => document.removeEventListener('keydown', handleKeyDown)
@@ -116,14 +119,14 @@ export function SettingsDialog() {
<div className="flex-1 overflow-y-auto">
<div className="px-6 pb-6">
<TabsContent value="account" className="mt-0"><AccountSettings /></TabsContent>
<TabsContent value="general" className="mt-0"><GeneralSettings /></TabsContent>
<TabsContent value="notifications" className="mt-0"><NotificationSettings /></TabsContent>
<TabsContent value="voice" className="mt-0"><VoiceSettings /></TabsContent>
<TabsContent value="git" className="mt-0"><GitSettings /></TabsContent>
<TabsContent value="shortcuts" className="mt-0"><KeyboardShortcuts /></TabsContent>
<TabsContent value="opencode" className="mt-0"><OpenCodeConfigManager /></TabsContent>
<TabsContent value="providers" className="mt-0"><ProviderSettings /></TabsContent>
<TabsContent key="account" value="account" className="mt-0"><AccountSettings /></TabsContent>
<TabsContent key="general" value="general" className="mt-0"><GeneralSettings /></TabsContent>
<TabsContent key="notifications" value="notifications" className="mt-0"><NotificationSettings /></TabsContent>
<TabsContent key="voice" value="voice" className="mt-0"><VoiceSettings /></TabsContent>
<TabsContent key="git" value="git" className="mt-0"><GitSettings /></TabsContent>
<TabsContent key="shortcuts" value="shortcuts" className="mt-0"><KeyboardShortcuts /></TabsContent>
<TabsContent key="opencode" value="opencode" className="mt-0"><OpenCodeConfigManager /></TabsContent>
<TabsContent key="providers" value="providers" className="mt-0"><ProviderSettings /></TabsContent>
</div>
</div>
</Tabs>
@@ -156,41 +159,41 @@ export function SettingsDialog() {
</Button>
</div>
<div className="flex-1 min-h-0 overflow-y-auto p-4 pb-32">
{mobileView === 'menu' && (
<div className="space-y-3">
{menuItems.map((item) => (
<button
key={item.id}
onClick={() => {
setMobileView(item.id as SettingsView)
setActiveTab(item.id as SettingsView)
}}
className="w-full bg-gradient-to-br from-card to-card-hover border border-border rounded-xl p-4 hover:border-border transition-all duration-200 text-left"
>
<div className="flex items-center gap-4">
<div className="p-3 bg-accent rounded-lg">
<item.icon className="w-6 h-6 text-blue-600 dark:text-blue-400" />
</div>
<div className="flex-1 min-w-0">
<h3 className="font-semibold text-foreground mb-1">{item.label}</h3>
<p className="text-sm text-muted-foreground">{item.description}</p>
</div>
</div>
</button>
))}
</div>
)}
<div className="flex-1 min-h-0 overflow-y-auto p-4 pb-32">
{mobileView === 'menu' && (
<div className="space-y-3">
{menuItems.map((item) => (
<button
key={item.id}
onClick={() => {
setMobileView(item.id as SettingsView)
setActiveTab(item.id as SettingsView)
}}
className="w-full bg-gradient-to-br from-card to-card-hover border border-border rounded-xl p-4 hover:border-border transition-all duration-200 text-left"
>
<div className="flex items-center gap-4">
<div className="p-3 bg-accent rounded-lg">
<item.icon className="w-6 h-6 text-blue-600 dark:text-blue-400" />
</div>
<div className="flex-1 min-w-0">
<h3 className="font-semibold text-foreground mb-1">{item.label}</h3>
<p className="text-sm text-muted-foreground">{item.description}</p>
</div>
</div>
</button>
))}
</div>
)}
{mobileView === 'account' && <AccountSettings />}
{mobileView === 'general' && <GeneralSettings />}
{mobileView === 'notifications' && <NotificationSettings />}
{mobileView === 'voice' && <VoiceSettings />}
{mobileView === 'git' && <GitSettings />}
{mobileView === 'shortcuts' && <KeyboardShortcuts />}
{mobileView === 'opencode' && <OpenCodeConfigManager />}
{mobileView === 'providers' && <ProviderSettings />}
</div>
{mobileView === 'account' && <div key="account"><AccountSettings /></div>}
{mobileView === 'general' && <div key="general"><GeneralSettings /></div>}
{mobileView === 'notifications' && <div key="notifications"><NotificationSettings /></div>}
{mobileView === 'voice' && <div key="voice"><VoiceSettings /></div>}
{mobileView === 'git' && <div key="git"><GitSettings /></div>}
{mobileView === 'shortcuts' && <div key="shortcuts"><KeyboardShortcuts /></div>}
{mobileView === 'opencode' && <div key="opencode"><OpenCodeConfigManager /></div>}
{mobileView === 'providers' && <div key="providers"><ProviderSettings /></div>}
</div>
</div>
</DialogContent>
</Dialog>
@@ -0,0 +1,166 @@
import { useState, useEffect } from 'react'
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle
} from '@/components/ui/dialog'
import { Button } from '@/components/ui/button'
import { Alert, AlertDescription } from '@/components/ui/alert'
import { CopyButton } from '@/components/ui/copy-button'
import { Shield, ShieldAlert } from 'lucide-react'
import { cn } from '@/lib/utils'
import type { SSHHostKeyRequest, SSHHostKeyResponse } from '@/api/types'
import { showToast } from '@/lib/toast'
interface SSHHostKeyDialogProps {
request: SSHHostKeyRequest | null
onRespond: (requestId: string, response: SSHHostKeyResponse) => Promise<void>
open?: boolean
onOpenChange?: (open: boolean) => void
timeoutMs?: number
}
export function SSHHostKeyDialog({
request,
onRespond,
open: parentOpen,
onOpenChange,
timeoutMs = 120_000
}: SSHHostKeyDialogProps) {
const [isLoading, setIsLoading] = useState(false)
const [timeRemaining, setTimeRemaining] = useState(0)
useEffect(() => {
if (!request) {
setTimeRemaining(0)
return
}
const elapsed = Date.now() - request.timestamp
const remaining = Math.max(0, timeoutMs - elapsed)
setTimeRemaining(Math.ceil(remaining / 1000))
const interval = setInterval(() => {
const currentElapsed = Date.now() - request.timestamp
const currentRemaining = Math.max(0, timeoutMs - currentElapsed)
setTimeRemaining(Math.ceil(currentRemaining / 1000))
if (currentRemaining <= 0) {
clearInterval(interval)
}
}, 1000)
return () => clearInterval(interval)
}, [request, timeoutMs])
if (!request) return null
if (parentOpen === false) return null
const handleResponse = async (response: SSHHostKeyResponse) => {
setIsLoading(true)
try {
await onRespond(request.id, response)
if (response === 'accept') {
showToast.success('Host key accepted')
}
} catch {
showToast.error('Failed to respond to host key request. Please try again.')
} finally {
setIsLoading(false)
}
}
const formatTime = (seconds: number): string => {
const mins = Math.floor(seconds / 60)
const secs = seconds % 60
return `${mins}:${secs.toString().padStart(2, '0')}`
}
const isExpired = timeRemaining === 0
const WarningIcon = request.isKeyChanged ? ShieldAlert : Shield
return (
<Dialog open={parentOpen ?? true} onOpenChange={onOpenChange ?? (() => {})}>
<DialogContent className="max-w-[calc(100vw-2rem)] sm:max-w-md p-4 sm:p-6">
<DialogHeader>
<DialogTitle className="flex items-center gap-2 flex-wrap">
<WarningIcon className={cn(
"h-5 w-5",
request.isKeyChanged ? "text-red-500" : "text-amber-500"
)} />
<span>{request.isKeyChanged ? 'Host Key Changed' : 'Verify SSH Host Key'}</span>
</DialogTitle>
<DialogDescription>
{request.isKeyChanged
? 'WARNING: The host key for this server has changed!'
: 'Verify the authenticity of this SSH server before connecting.'}
</DialogDescription>
</DialogHeader>
<div className="space-y-3">
{request.isKeyChanged && (
<Alert variant="destructive">
<AlertDescription className="text-sm">
<strong>Security Warning:</strong> This could indicate a man-in-the-middle attack.
Only proceed if you are certain the server is legitimate.
</AlertDescription>
</Alert>
)}
<div className="space-y-2 text-sm">
<div className="flex justify-between items-start">
<span className="text-muted-foreground">Host:</span>
<span className="font-mono font-medium">{request.host}</span>
</div>
<div className="flex justify-between items-start">
<span className="text-muted-foreground">IP Address:</span>
<span className="font-mono font-medium">{request.ip}</span>
</div>
<div className="flex justify-between items-start">
<span className="text-muted-foreground">Key Type:</span>
<span className="font-mono font-medium">{request.keyType}</span>
</div>
<div className="flex justify-between items-start gap-4">
<span className="text-muted-foreground">Fingerprint:</span>
<div className="flex items-center gap-2 flex-1 justify-end">
<span className="font-mono text-xs break-all">{request.fingerprint}</span>
<CopyButton content={request.fingerprint} variant="ghost" iconSize="sm" />
</div>
</div>
</div>
<div className="text-xs text-muted-foreground">
<div className="flex justify-between">
<span>Auto-reject in:</span>
<span className={cn("font-mono", isExpired && "text-red-500")}>
{isExpired ? 'Expired' : formatTime(timeRemaining)}
</span>
</div>
</div>
</div>
<DialogFooter className="flex-col-reverse gap-2 sm:flex-row sm:gap-2 mt-2">
<Button
variant="outline"
onClick={() => handleResponse('reject')}
disabled={isLoading || isExpired}
className="w-full sm:flex-1 text-sm h-9 sm:h-10"
>
{isLoading ? 'Processing...' : 'Reject'}
</Button>
<Button
variant={request.isKeyChanged ? 'destructive' : 'default'}
onClick={() => handleResponse('accept')}
disabled={isLoading || isExpired}
className="w-full sm:flex-1 text-sm h-9 sm:h-10"
>
{isLoading ? 'Processing...' : 'Accept'}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
)
}
+3 -2
View File
@@ -32,17 +32,18 @@ interface DialogContentProps
hideCloseButton?: boolean
fullscreen?: boolean
mobileFullscreen?: boolean
overlayClassName?: string
}
const DialogContent = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Content>,
DialogContentProps
>(({ className, children, hideCloseButton, fullscreen, mobileFullscreen, ...props }, ref) => {
>(({ className, children, hideCloseButton, fullscreen, mobileFullscreen, overlayClassName, ...props }, ref) => {
const isMobileFullscreenMode = fullscreen || mobileFullscreen
return (
<DialogPortal>
{!fullscreen && <DialogOverlay />}
{!fullscreen && <DialogOverlay className={overlayClassName} />}
<DialogPrimitive.Content
ref={ref}
aria-describedby={undefined}