updated gethostkey to work with strings, and the rest of the ui had been updated to reflect this

This commit is contained in:
neon443 committed 2025-06-25 14:07:27 +01:00
1 parent 43b407b038
commit 548beca410
3 files changed
+14 -11

No files matched your search

+3 -3
View File
@@ -16,7 +16,7 @@ protocol HostPr: Codable, Identifiable, Equatable {
var publicKey: Data? { get set }
var privateKey: Data? { get set }
var passphrase: String { get set }
var key: Data? { get set }
var key: String? { get set }
}
struct Host: HostPr {
@@ -28,7 +28,7 @@ struct Host: HostPr {
var publicKey: Data?
var privateKey: Data?
var passphrase: String = ""
var key: Data?
var key: String?
init(
address: String,
@@ -38,7 +38,7 @@ struct Host: HostPr {
publicKey: Data? = nil,
privateKey: Data? = nil,
passphrase: String = "",
hostkey: Data? = nil
hostkey: String? = nil
) {
self.address = address
self.port = port
+7 -3
View File
@@ -33,7 +33,7 @@ class SSHHandler: @unchecked Sendable, ObservableObject {
self.host = host
}
func getHostkey() -> Data? {
func getHostkey() -> String? {
var hostkey: ssh_key?
ssh_get_server_publickey(session, &hostkey)
@@ -41,7 +41,7 @@ class SSHHandler: @unchecked Sendable, ObservableObject {
let status = ssh_pki_export_pubkey_base64(hostkey, &hostkeyB64)
guard status == SSH_OK, let cString = hostkeyB64 else { return nil }
return String(cString: cString).data(using: .utf8)
return String(cString: cString)
}
func go() {
@@ -60,7 +60,11 @@ class SSHHandler: @unchecked Sendable, ObservableObject {
try? authWithNone()
getAuthMethods()
self.host.key = getHostkey()
if self.host.key != getHostkey() {
self.host.key = getHostkey()
return
}
if !host.password.isEmpty {
do { try authWithPw() } catch {
+4 -5
View File
@@ -76,10 +76,9 @@ struct ConnectionView: View {
TextField("", text: $passphrase, prompt: Text("Passphrase (Optional)"))
}
if handler.host.key != nil,
let hostkeyString = String(data: handler.host.key!, encoding: .utf8) {
Text("Hostkey: "+hostkeyString)
.onChange(of: handler.host.key) { _ in
if handler.host.key != nil {
Text("Hostkey: \(handler.getHostkey() ?? hostsManager.getHostMatching(handler.host)?.key ?? "nil")")
.onChange(of: handler.host.key) { _ in
guard let previousKnownHost = hostsManager.getHostMatching(handler.host) else { return }
guard handler.host.key == previousKnownHost.key else {
hostKeyChangedAlert = true
@@ -116,7 +115,7 @@ struct ConnectionView: View {
handler.host.key = hostsManager.getHostMatching(handler.host)?.key
}
} message: {
Text("Expected \(hostsManager.getHostMatching(handler.host)?.key?.base64EncodedString() ?? "null")\nbut recieved \(handler.host.key?.base64EncodedString() ?? "null" ) from the server")
Text("Expected \(handler.host.key ?? "nil")\nbut recieved \(handler.getHostkey() ?? "nil") from the server")
}
.transition(.opacity)
.toolbar {
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.