Host-Key-Popup mit Fingerprint + ctty-run-Helper (Ctty fuer ssh-Prompts), Doku
This commit is contained in:
@@ -11,6 +11,9 @@ struct EmbeddedTerminalView: View {
|
||||
@State private var input = ""
|
||||
@State private var secureInput = false
|
||||
@State private var checking = false
|
||||
@State private var hostKeyInfo: HostKeyInfo?
|
||||
@State private var hostKeyChange = false
|
||||
@State private var showingHostKey = false
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 0) {
|
||||
@@ -98,6 +101,18 @@ struct EmbeddedTerminalView: View {
|
||||
connect() // Auto-Connect beim Öffnen des Tabs
|
||||
}
|
||||
}
|
||||
.sheet(isPresented: $showingHostKey) {
|
||||
if let info = hostKeyInfo {
|
||||
HostKeySheet(info: info, isChange: hostKeyChange,
|
||||
onAccept: acceptHostKey,
|
||||
onCancel: {
|
||||
showingHostKey = false
|
||||
checking = false
|
||||
hostKeyInfo = nil
|
||||
term.fail("Host-Key nicht akzeptiert — Verbindung abgebrochen.")
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func connect() {
|
||||
@@ -105,16 +120,47 @@ struct EmbeddedTerminalView: View {
|
||||
checking = true
|
||||
TCPCheck.check(host: profile.host, port: profile.port) { message in
|
||||
DispatchQueue.main.async {
|
||||
checking = false
|
||||
if let message {
|
||||
checking = false
|
||||
term.fail("Vorab-Check: \(message)")
|
||||
} else {
|
||||
return
|
||||
}
|
||||
// Host-Key vorab per keyscan prüfen (Yes/No-Prompt käme ohne Ctty nicht an)
|
||||
let hk = HostKeyService.status(host: profile.host, port: profile.port)
|
||||
switch hk {
|
||||
case .known, .unreachable:
|
||||
checking = false
|
||||
term.start()
|
||||
case .unknown(let info):
|
||||
hostKeyInfo = info
|
||||
hostKeyChange = false
|
||||
showingHostKey = true
|
||||
case .changed(let info):
|
||||
hostKeyInfo = info
|
||||
hostKeyChange = true
|
||||
showingHostKey = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func acceptHostKey() {
|
||||
guard let info = hostKeyInfo else { return }
|
||||
showingHostKey = false
|
||||
if hostKeyChange {
|
||||
_ = HostKeyService.revoke(host: profile.host, port: profile.port)
|
||||
}
|
||||
if HostKeyService.accept(info) {
|
||||
checking = false
|
||||
term.note("Host-Key akzeptiert (\(info.keyType), \(info.fingerprintSHA256.prefix(19))…).")
|
||||
term.start()
|
||||
} else {
|
||||
checking = false
|
||||
term.fail("Host-Key konnte nicht in known_hosts gespeichert werden.")
|
||||
}
|
||||
hostKeyInfo = nil
|
||||
}
|
||||
|
||||
func diagnose() {
|
||||
guard !checking else { return }
|
||||
checking = true
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import SwiftUI
|
||||
|
||||
/// Popup bei unbekanntem/geändertem Host-Key: Fingerprint prüfen, dann
|
||||
/// akzeptieren (→ known_hosts + verbinden) oder abbrechen.
|
||||
struct HostKeySheet: View {
|
||||
var info: HostKeyInfo
|
||||
var isChange: Bool
|
||||
var onAccept: () -> Void
|
||||
var onCancel: () -> Void
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
HStack(spacing: 10) {
|
||||
Image(systemName: isChange ? "exclamationmark.octagon.fill" : "key.fill")
|
||||
.font(.title)
|
||||
.foregroundStyle(isChange ? Dracula.red : Dracula.orange)
|
||||
VStack(alignment: .leading) {
|
||||
Text(isChange ? "Host-Key GEÄNDERT" : "Neuer Host-Key")
|
||||
.font(.headline)
|
||||
Text("\(info.host):\(info.port) · \(info.keyType)")
|
||||
.font(.subheadline).foregroundStyle(.secondary)
|
||||
}
|
||||
}
|
||||
|
||||
if isChange {
|
||||
Text("Warnung: Der gespeicherte Schlüssel passt NICHT zum Server. Das kann ein neu aufgesetzter Server sein — oder ein Angriff (MITM). Nur fortfahren, wenn du die Änderung erwartest!")
|
||||
.font(.callout).foregroundStyle(Dracula.red)
|
||||
} else {
|
||||
Text("Erstverbindung: Dieser Server ist noch unbekannt. Fingerprint prüfen (z. B. mit dem Server-Admin oder einer Terminal-Verbindung vergleichen), dann akzeptieren.")
|
||||
.font(.callout).foregroundStyle(.secondary)
|
||||
}
|
||||
|
||||
GroupBox("SHA256-Fingerprint") {
|
||||
Text(info.fingerprintSHA256)
|
||||
.font(.system(.body, design: .monospaced))
|
||||
.textSelection(.enabled)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
GroupBox("MD5-Fingerprint") {
|
||||
Text(info.fingerprintMD5)
|
||||
.font(.system(.callout, design: .monospaced))
|
||||
.foregroundStyle(.secondary)
|
||||
.textSelection(.enabled)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
|
||||
HStack {
|
||||
Button("Abbrechen", role: .cancel, action: onCancel)
|
||||
Spacer()
|
||||
Button(isChange ? "Trotzdem ersetzen & verbinden" : "Akzeptieren & verbinden", action: onAccept)
|
||||
.keyboardShortcut(.defaultAction)
|
||||
}
|
||||
}
|
||||
.padding(20)
|
||||
.frame(width: 480)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user