Wi-Fi WSS / TLS Connection

SOLVED (next answer)

I use the Starcream library to create a secure websocket wss on a test server, we have a self-signed certificate, and I find it impossible to do this.

var socket = WebSocket(url: NSURL(scheme: "wss", host: "selfsignedserver.com", path: "/")!) 

Magazine

 2014-12-16 10:38:10.260 pruebasignin[2135:363455] CFNetwork SSLHandshake failed (-9807) websocket is disconnected: The operation couldn't be completed. (OSStatus error -9807.) 

, and when I try to connect to the server certificate, the unsolvable connection also fails

 var socket = WebSocket(url: NSURL(scheme: "wss", host: "production.com", path: "/")!) 

Magazine

 websocket is disconnected: Invalid HTTP upgrade 
+7
ios ssl swift websocket wss
source share
2 answers

I solved the problem by allowing Starscream self-signed certificates that modify the library. To this, add the following code to arcivo WebSocket.swift:

 if url.scheme == "wss" || url.scheme == "https" { inputStream!.setProperty(NSStreamSocketSecurityLevelNegotiatedSSL, forKey: NSStreamSocketSecurityLevelKey) outputStream!.setProperty(NSStreamSocketSecurityLevelNegotiatedSSL, forKey: NSStreamSocketSecurityLevelKey) /* My code */ var settings = Dictionary<NSObject, NSObject>() settings[kCFStreamSSLValidatesCertificateChain] = NSNumber(bool:false) settings[kCFStreamSSLPeerName] = kCFNull CFReadStreamSetProperty(self.inputStream, kCFStreamPropertySSLSettings, settings) CFWriteStreamSetProperty(self.outputStream, kCFStreamPropertySSLSettings, settings) /* End my code*/ } 
+2
source share

Starscream now supports the flag so you can use self-signed certificates: https://github.com/daltoniam/Starscream#self-signed-ssl-and-voip

+3
source share

All Articles