mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
* fix: prevent delete button click when card is not swiped open * refactor: improve CreateRepoInput type safety * security: require AUTH_SECRET and use secure random generation * fix: SSH key path validation, async passphrase stripping, and port handling * fix: use correct console methods for logger levels * Add error handling to DB update functions and improve migration logging * Add error handling for session lookup in auth middleware * Add structured git error handling with user-friendly messages - Parse git errors with specific error codes (AUTH_FAILED, REPO_NOT_FOUND, PUSH_REJECTED, MERGE_CONFLICT, etc.) and appropriate HTTP status codes - Return structured error responses with summary and detail from backend - Add GitErrorBanner component for better error display in UI - Add optional onError callback to useGit hook for external error handling * Make IPC server initialization/disposal async and fix SSH host key handler * add try-catch error handling in frontend lib utilities * remove unresolved promise handlers in speech synthesizer callbacks * Extract error types to shared package * Import GitErrorCode from shared package * Refactor API layer to use shared FetchError and fetchWrapper * Update prompt parser and source control components * Extract MCP server list to separate component with improved badge menu UX * merge useSettingsDialogUrl into useSettingsDialog and extract getRepoDisplayName utility * add separate loading state for passkey sign in * refactor hooks: use fetchWrapper, improve error handling, add proper types * replace browser confirm() with DeleteDialog component in settings * fix: add missing variables parameter in React Query onError callbacks * Refactor message parts to use separate Zustand store * Update QuestionPrompt styling for light/dark mode
50 lines
1.7 KiB
TypeScript
50 lines
1.7 KiB
TypeScript
import { promises as fs } from 'fs'
|
|
import { tmpdir } from 'os'
|
|
import { join } from 'path'
|
|
import { randomBytes } from 'crypto'
|
|
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()}-${randomBytes(8).toString('hex')}`)
|
|
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)
|
|
}
|
|
}
|
|
}
|