Add host lookup xpc service (#826)

* Add host lookup xpc service

* Remove restriction that snuck in

* Test fixes
This commit is contained in:
Max Goedjen authored and GitHub committed 2026-09-07 04:32:51 +00:00
1 parent e9a0ff31d3
commit 70e32dcf99
21 files changed
+1126 -42

No files matched your search

@@ -0,0 +1,25 @@
import Foundation
import OSLog
import XPCWrappers
import SSHProtocolKit
final class SecretAgentHostsfileReader: NSObject, XPCProtocol {
private let logger = Logger(subsystem: "com.maxgoedjen.secretive.SecretAgentHostsfileReader", category: "SecretAgentHostsfileReader")
func process(_ data: Data) async throws -> [Data: String] {
logger.log("Parsing hostsfile")
var result: [Data: String] = [:]
for try await line in URL(filePath: NSHomeDirectory().appending("/.ssh/known_hosts")).lines {
let split = line.split(separator: " ").map(String.init)
guard split.count == 3 else { continue }
guard let decoded = Data(base64Encoded: split[2]) else { continue }
let reader = OpenSSHReader(data: decoded)
_ = try reader.readNextChunk()
let key = try reader.readNextChunk()
result[key] = split[0]
}
return result
}
}