Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set SNI when enabling CertificatePinning with WSEngine with TCPTransport #1024

Open
dourgulf opened this issue May 14, 2024 · 0 comments
Open

Comments

@dourgulf
Copy link

dourgulf commented May 14, 2024

What do you want to happen?

I want to do DNS resolve by myself, and connect to wss server with IP, I set Host header and implement CertificatePinning.

public class HostCertificatePinning: CertificatePinning {
    let host: String
    init(host: String) {
        self.host = host
    }

    public func evaluateTrust(trust: SecTrust, domain: String?, completion: (PinningState) -> Void) {
        SecTrustSetPolicies(trust, SecPolicyCreateSSL(true, host as NSString))
        var error: CFError?
        if SecTrustEvaluateWithError(trust, &error) {
            completion(.success)
        } else {
            completion(.failed(error))
        }
    }
}
        let testUrl = URL(string: "wss://xx.xx.xx.xx")!
        var request = URLRequest(url: testUrl)
        let host = "host.app.com"
        request.addValue(host, forHTTPHeaderField: "Host")
        webcoket = WebSocket(request: request, certPinner: HostCertificatePinning(host: host))

What happens now?

I must set host to CDN host other than our host name to verify certification.
I thinks it because the WebSocket connect do not set SNI, so server return default host certification.

Demo Code

RT

Describe alternatives you've considered

Additional context

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant