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