mirror of
https://github.com/neon443/ShhShell.git
synced 2026-03-11 13:26:16 +00:00
redid hostkey checking system
fix hostkey checking just not happening :skulk: - moved logic into handler
This commit is contained in:
@@ -36,6 +36,7 @@ class SSHHandler: @unchecked Sendable, ObservableObject {
|
||||
@Published var bell: Bool = false
|
||||
|
||||
@Published var host: Host
|
||||
@Published var hostkeyChanged: Bool = false
|
||||
|
||||
private let userDefaults = NSUbiquitousKeyValueStore.default
|
||||
private let logger = Logger(subsystem: "xy", category: "sshHandler")
|
||||
@@ -64,12 +65,15 @@ class SSHHandler: @unchecked Sendable, ObservableObject {
|
||||
return
|
||||
}
|
||||
|
||||
checkHostkey(recieved: getHostkey())
|
||||
guard hostkeyChanged == false else { return }
|
||||
|
||||
do {
|
||||
try authWithNone()
|
||||
} catch { print("auth with none is not authed") }
|
||||
guard state != .authorized else { return }
|
||||
|
||||
//TODO: check hostkey
|
||||
|
||||
|
||||
for method in getAuthMethods() {
|
||||
guard state != .authorized else { break }
|
||||
@@ -164,8 +168,11 @@ class SSHHandler: @unchecked Sendable, ObservableObject {
|
||||
self.session = nil
|
||||
}
|
||||
|
||||
func checkHostkey() {
|
||||
|
||||
func checkHostkey(recieved: String?) {
|
||||
guard host.key == recieved else {
|
||||
self.hostkeyChanged = true
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func ring() {
|
||||
|
||||
@@ -60,6 +60,7 @@ struct FontManagerView: View {
|
||||
|
||||
Section("Test String") {
|
||||
TextEditor(text: $testLine)
|
||||
.fixedSize()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,6 @@ struct ConnectionView: View {
|
||||
|
||||
@State var showTerminal: Bool = false
|
||||
|
||||
@State var hostKeyChangedAlert: Bool = false
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
hostsManager.selectedTheme.background.suiColor.opacity(0.7)
|
||||
@@ -110,28 +108,36 @@ struct ConnectionView: View {
|
||||
}
|
||||
.scrollContentBackground(.hidden)
|
||||
.transition(.opacity)
|
||||
.onChange(of: handler.host.key) { _ in
|
||||
guard let previousKnownHost = hostsManager.getHostMatching(handler.host) else { return }
|
||||
guard handler.host.key == previousKnownHost.key else {
|
||||
hostKeyChangedAlert = true
|
||||
return
|
||||
}
|
||||
}
|
||||
.onDisappear {
|
||||
hostsManager.updateHost(handler.host)
|
||||
}
|
||||
.alert("Hostkey changed", isPresented: $hostKeyChangedAlert) {
|
||||
Button("Accept New Hostkey", role: .destructive) {
|
||||
.alert("Hostkey changed", isPresented: $handler.hostkeyChanged) {
|
||||
Button(role: .destructive) {
|
||||
handler.host.key = handler.getHostkey()
|
||||
hostsManager.updateHost(handler.host)
|
||||
handler.go()
|
||||
} label: {
|
||||
Text("Accept Hostkey")
|
||||
}
|
||||
|
||||
Button("Disconnect", role: .cancel) {
|
||||
Button(role: .cancel) {
|
||||
handler.disconnect()
|
||||
handler.host.key = hostsManager.getHostMatching(handler.host)?.key
|
||||
} label: {
|
||||
Text("Disconnect")
|
||||
.tint(.blue)
|
||||
.foregroundStyle(.blue)
|
||||
}
|
||||
.tint(.blue)
|
||||
.foregroundStyle(.blue)
|
||||
} message: {
|
||||
Text("Expected \(handler.host.key ?? "nil")\nbut recieved \(handler.getHostkey() ?? "nil") from the server")
|
||||
if let expectedKey = handler.host.key {
|
||||
Text("Expected \(expectedKey)\nbut recieved\n \(handler.getHostkey() ?? "nil") from server")
|
||||
} else {
|
||||
Text("""
|
||||
The authenticity of \(handler.host.description) can't be established.
|
||||
Hostkey fingerprint is \(handler.getHostkey() ?? "nil")
|
||||
""")
|
||||
}
|
||||
}
|
||||
.toolbar {
|
||||
ToolbarItem() {
|
||||
|
||||
@@ -56,6 +56,7 @@ struct KeyManagerView: View {
|
||||
let comment = UIDevice().model + " at " + Date().formatted(date: .numeric, time: .omitted)
|
||||
keyManager.generateKey(type: .ed25519, comment: comment)
|
||||
}
|
||||
.listRowSeparator(.hidden)
|
||||
|
||||
CenteredLabel(title: "Import a key", systemName: "square.and.arrow.down")
|
||||
.onTapGesture {
|
||||
|
||||
Reference in New Issue
Block a user