1

I had a couple of tries to make a connection with SSL via Starscream but I got the same error for some reasons. Here are simples of connection and response

client = WebSocket(url: URL(string: "wss://XXXXXXXX:443/")!)
    client?.enabledSSLCipherSuites = [TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256]
    let certificateData = try Data(contentsOf:Bundle.main.url(forResource: "certificate", withExtension: "cer")!)
    let cert = SSLCert(data: certificateData)

    let security = SSLSecurity(certs: [cert], usePublicKeys: true)
    security.validatedDN = false
    security.validateEntireChain = false
    client?.security = security
    client?.delegate = self
    client?.connect()

2nd one

 do
    {
        client = WebSocket(url: URL(string: "wss://XXXXXXXX:443/")!)
        let urlPath     = Bundle.main.path(forResource: "certificate", ofType: "der")
        let url         = NSURL.fileURL(withPath: urlPath!)
        let certificateData = try Data(contentsOf: url)
        let certificate: SecCertificate =
            SecCertificateCreateWithData(kCFAllocatorDefault, certificateData as CFData)!

        var trust: SecTrust?
        let policy = SecPolicyCreateBasicX509()
        let status = SecTrustCreateWithCertificates(certificate, policy, &trust)
        if status == errSecSuccess {
            let key = SecTrustCopyPublicKey(trust!)!;
            let ssl =  SSLCert(key: key)
            let security = SSLSecurity(certs: [ssl], usePublicKeys: false)
            security.validateEntireChain = false
            client?.security = security
            client?.delegate = self
            client?.connect()
        }

    }catch let error as NSError
    {
        print(error)
    }

And Logs

CFNetwork SSLHandshake failed (-9807)

0 TCP Conn 0x600003119c80 SSLHandshake failed (-9807)

ERROR - %@ Optional("The operation couldn’t be completed. (OSStatus error -9807.)")

0 Answers0