Update Meshtastic/Helpers/Mqtt/MqttClientProxyManager.swift

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Ben Meadors 2025-04-19 07:06:56 -05:00 committed by GitHub
parent dc00d8d118
commit 5e6486b8d4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -131,8 +131,24 @@ extension MqttClientProxyManager: CocoaMQTTDelegate {
}
}
func mqtt(_ mqtt: CocoaMQTT, didReceive trust: SecTrust, completionHandler: @escaping (Bool) -> Void) {
completionHandler(true)
var isValid = false
#if canImport(Security)
if #available(macOS 10.15, iOS 13.0, *) {
isValid = SecTrustEvaluateWithError(trust, nil)
} else {
var result: SecTrustResultType = .invalid
let status = SecTrustEvaluate(trust, &result)
isValid = (status == errSecSuccess) && (result == .unspecified || result == .proceed)
}
#endif
if isValid {
Logger.mqtt.info("📲 [MQTT Client Proxy] TLS validation succeeded.")
completionHandler(true)
} else {
Logger.mqtt.error("📲 [MQTT Client Proxy] TLS validation failed.")
completionHandler(false)
}
}
func mqttDidDisconnect(_ mqtt: CocoaMQTT, withError err: Error?) {
Logger.mqtt.debug("📲 [MQTT Client Proxy] disconnected: \(err?.localizedDescription ?? "", privacy: .public)")
if let error = err {