mirror of
https://github.com/neon443/ShhShell.git
synced 2026-03-11 13:26:16 +00:00
Hostkey changed warning
rewrote hostkey cahnged checker hostkeys sync as well, and the app syncs icloud on launch
This commit is contained in:
@@ -41,6 +41,7 @@ class HostsManager: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func loadSavedHosts() {
|
func loadSavedHosts() {
|
||||||
|
userDefaults.synchronize()
|
||||||
let decoder = JSONDecoder()
|
let decoder = JSONDecoder()
|
||||||
guard let data = userDefaults.data(forKey: "savedHosts") else { return }
|
guard let data = userDefaults.data(forKey: "savedHosts") else { return }
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ struct ConnectionView: View {
|
|||||||
@State var privPickerPresented: Bool = false
|
@State var privPickerPresented: Bool = false
|
||||||
@State var pubPickerPresented: Bool = false
|
@State var pubPickerPresented: Bool = false
|
||||||
|
|
||||||
|
@State var hostKeyChangedAlert: Bool = false
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationStack {
|
NavigationStack {
|
||||||
List {
|
List {
|
||||||
@@ -108,12 +110,10 @@ struct ConnectionView: View {
|
|||||||
if handler.host.key != nil {
|
if handler.host.key != nil {
|
||||||
Text("Hostkey: \(handler.host.key!.base64EncodedString())")
|
Text("Hostkey: \(handler.host.key!.base64EncodedString())")
|
||||||
.onChange(of: handler.host.key) { _ in
|
.onChange(of: handler.host.key) { _ in
|
||||||
guard let matchedIndex = hostsManager.getHostIndexMatching(handler.host) else { return }
|
guard let previousKnownHost = hostsManager.getHostMatching(handler.host) else { return }
|
||||||
guard handler.host.key == hostsManager.savedHosts[matchedIndex].key else {
|
guard handler.host.key == previousKnownHost.key else {
|
||||||
let hostkeyBefore = hostsManager.savedHosts[matchedIndex].key
|
hostKeyChangedAlert = true
|
||||||
let currentHostkey = handler.host.key
|
return
|
||||||
print("hiiii")
|
|
||||||
fatalError()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -129,13 +129,28 @@ struct ConnectionView: View {
|
|||||||
withAnimation { handler.testExec() }
|
withAnimation { handler.testExec() }
|
||||||
} label: {
|
} label: {
|
||||||
if let testResult = handler.testSuceeded {
|
if let testResult = handler.testSuceeded {
|
||||||
Image(systemName: testResult ? "checkmark.circle" : "xmark.circle")
|
Image(systemName: testResult ? "checkmark.circle" : "xmark.circle")
|
||||||
.modifier(foregroundColorStyle(testResult ? .green : .red))
|
.modifier(foregroundColorStyle(testResult ? .green : .red))
|
||||||
} else {
|
} else {
|
||||||
Label("Test Connection", systemImage: "checkmark")
|
Label("Test Connection", systemImage: "checkmark")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.alert("Hostkey changed", isPresented: $hostKeyChangedAlert) {
|
||||||
|
Button("Accept New Hostkey", role: .destructive) {
|
||||||
|
hostsManager.updateHost(handler.host)
|
||||||
|
}
|
||||||
|
|
||||||
|
Button("Disconnect", role: .cancel) {
|
||||||
|
handler.disconnect()
|
||||||
|
handler.host.key = hostsManager.getHostMatching(handler.host)?.key
|
||||||
|
}
|
||||||
|
} message: {
|
||||||
|
Text("""
|
||||||
|
Expected \(hostsManager.getHostMatching(handler.host)!.key!.base64EncodedString())
|
||||||
|
but recieved \(handler.host.key!.base64EncodedString()) from the server
|
||||||
|
""")
|
||||||
|
}
|
||||||
.transition(.opacity)
|
.transition(.opacity)
|
||||||
.toolbar {
|
.toolbar {
|
||||||
ToolbarItem() {
|
ToolbarItem() {
|
||||||
@@ -166,8 +181,9 @@ struct ConnectionView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onDisappear {
|
.onDisappear {
|
||||||
if hostsManager.getHostMatching(handler.host) != handler.host {
|
guard hostsManager.getHostMatching(handler.host) == handler.host else {
|
||||||
hostsManager.updateHost(handler.host)
|
hostsManager.updateHost(handler.host)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user