moozzyk / SignalR-Client-Swift

Swift SignalR Client for Asp.Net Core SignalR server
MIT License
356 stars 136 forks source link

SSL/TLS pinning from WebsocketsTransport #275

Closed Gyyone closed 1 year ago

Gyyone commented 1 year ago

After Implement following code, Still facing SSL/TLS Issue from WebsocketTranspot. let challangeDelegate: (( session: URLSession, challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) -> Void)? = { , challenge, completionHandler in

guard let trust = challenge.protectionSpace.serverTrust, SecTrustGetCertificateCount(trust) > 0 else {
    completionHandler(.cancelAuthenticationChallenge, nil)
    return
}

if let serverCertificate = SecTrustGetCertificateAtIndex(trust, 0) {
    // pinnedCertificate = .....
    if serverCertificate == pinnedCertificate {
        completionHandler(.useCredential, URLCredential(trust: trust))
        return
    }
}

completionHandler(.cancelAuthenticationChallenge, nil)

}

let connection = HubConnectionBuilder(url: url) .withHttpConnectionOptions() { options in options.accessTokenProvider = { ....accessToken.... } options.authenticationChallengeHandler = challangeDelegate options.headers += ...... } .build() connection.delegate = self connection.start()

moozzyk commented 1 year ago

This should be fixed in: 5af700d13f6e926c6e6e8fc36ab99c7d18728688. The auth challenge handler should now be invoked by both - the HTTP client and the WebSocket transport.

Gyyone commented 1 year ago

Thanks . Have verified It work now.

moozzyk commented 1 year ago

Thanks for confirming. I am glad to hear it now works as expected.