我正在努力尝试手动添加可信证书。我已经保存了证书(使用Wireshark),但是我不确定如何告诉NWConnection信任它。
到目前为止,我有...
let cert = FileManager().contents(atPath: "path/to/cert.cert")
let certArray = [cert]
let policy = SecPolicyCreateSSL(false, nil)
var optionalTrust: SecTrust?
let trust = SecTrustCreateWithCertificates(certArray as AnyObject,
policy,
&optionalTrust)
//Not really sure how to get from "trust" to something I could pass to NWConnection?
let my_host = NWEndpoint.hostPort(host: "192.168.0.1", port: 4444)
let connection = NWConnection(to: my_host, using: .tls)
connection.stateUpdateHandler = { (newState) in
switch(newState) {
case .ready:
print("ready")
// Handle connection established
case .waiting(let error):
print("waiting: ", error)
// Handle connection waiting for network
case .failed(let error):
print("failed", error)
// Handle fatal connection error
default:
print("default")
}
}
let myQ = DispatchQueue.init(label: "connQ")
connection.start(queue: myQ)