Handling self-signed certificates in URLAuthenticationChallenge on Linux

In order to trust a self-signed certificate on macOS I've implemented the following URLSessionDelegate handler:

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)

When compiling for Linux, I found that serverTrust is not available:

/package/Sources/ResterCore/Request.swift:255:38: error: value of type 'URLProtectionSpace' has no member 'serverTrust'

I was hoping to perhaps create the required credential without serverTrust but other ways to create a URLCredential are also unvailable:

// TODO: We have no implementation for Security.framework primitive types SecIdentity and SecTrust yet

Does anyone know of a way to work around this on Linux? I.e. is there a way to accept a self-signed certificate on Linux via URLSession?

Any pointers greatly appreciated!

Terms of Service

Privacy Policy

Cookie Policy