在Linux上的URLAuthenticationChallenge中处理自签名证书

时间:2019-04-03 09:12:05

标签: swift linux ssl foundation

为了在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上接受自签名证书?

0 个答案:

没有答案