为了在macOS上信任自签名证书,我实现了以下URLSessionDelegate
处理程序:
func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
// trust certificate
let cred = challenge.protectionSpace.serverTrust.map { URLCredential(trust: $0) }
completionHandler(.useCredential, cred)
}
在Linux上编译时,我发现serverTrust
is not available:
/package/Sources/ResterCore/Request.swift:255:38: error: value of type 'URLProtectionSpace' has no member 'serverTrust'
我希望可以在没有serverTrust
的情况下创建所需的凭据,但是希望以其他方式创建URLCredential
are also unvailable:
// TODO: We have no implementation for Security.framework primitive types SecIdentity and SecTrust yet
有人知道在Linux上解决此问题的方法吗?即是否可以通过URLSession
在Linux上接受自签名证书?