import React, { useState } from "react"; import { Button } from "@/components/button.tsx"; import { Shield, AlertTriangle, Copy, Check } from "lucide-react"; import { useTranslation } from "react-i18next"; import { copyToClipboard } from "@/lib/clipboard"; interface HostKeyVerificationDialogProps { isOpen: boolean; scenario: "new" | "changed"; ip: string; port: number; hostname?: string; fingerprint: string; oldFingerprint?: string; keyType: string; oldKeyType?: string; algorithm: string; onAccept: () => void; onReject: () => void; backgroundColor?: string; } export function HostKeyVerificationDialog({ isOpen, scenario, ip, port, hostname, fingerprint, oldFingerprint, algorithm, onAccept, onReject, backgroundColor, }: HostKeyVerificationDialogProps) { const { t } = useTranslation(); const [copiedFingerprint, setCopiedFingerprint] = useState(false); const [copiedOldFingerprint, setCopiedOldFingerprint] = useState(false); if (!isOpen) return null; const copyFingerprint = (text: string, isOld: boolean = false) => { copyToClipboard(text); if (isOld) { setCopiedOldFingerprint(true); setTimeout(() => setCopiedOldFingerprint(false), 2000); } else { setCopiedFingerprint(true); setTimeout(() => setCopiedFingerprint(false), 2000); } }; const formatFingerprint = (fp: string) => fp.match(/.{1,2}/g)?.join(":") || fp; return (
{hostname || ip}:{port}
{t("hostKey.firstConnectionTitle")}
{t("hostKey.firstConnectionDescription")}
{t("hostKey.fingerprint")} ({algorithm.toUpperCase()})
{t("hostKey.verifyInstructions")}
> ) : ( <>{t("hostKey.securityWarning")}
{t("hostKey.keyChangedDescription")}
{t("hostKey.previousKey")}
{t("hostKey.newFingerprint")}