socket.io-client-swift
socket.io-client-swift copied to clipboard
SSL / TLS client certificate authentication
I'd like to implement the above mentioned feature in socket.io-client-swift. It was requested in various issues, e.g. #687, #936.
It was recently added to Starscream (https://github.com/daltoniam/Starscream/pull/481) and just needs to be propagated into socket.io-client-swift. The main question is what would be the best place to add this feature.
The client certificate would need to be passed to the Starscream WebSocket in createWebSocketAndConnect
. One option to pass id down that way would be extend SocketIO.SSLSecurity with an sslClientCertificate property. Any guidance would be appreciated.
This comment helped me. So, i make a note of the sample source for SSL client certificate.
It seems that the StarScream library needs to be modified. (This is not a good example, so please use it as a reference purposes)
private func createWebSocketAndConnect() {
var req = URLRequest(url: urlWebSocketWithSid)
addHeaders(to: &req, includingCookies: session?.configuration.httpCookieStorage?.cookies(for: urlPollingWithSid))
let stream = FoundationStream()
stream.enableSOCKSProxy = enableSOCKSProxy
ws = WebSocket(request: req, stream: stream)
ws?.callbackQueue = engineQueue
ws?.enableCompression = compress
ws?.disableSSLCertValidation = selfSigned
ws?.security = security?.security
// [SSLクライアント認証 暫定対応] start
let password = "hogehoge"
let path = Bundle.main.path(forResource: "client-cert", ofType: "pfx")
let sslClientCertificate = try! SSLClientCertificate(pkcs12Path: path!, password: password)
ws?.sslClientCertificate = sslClientCertificate
// [SSLクライアント認証 暫定対応] end
ws?.onConnect = {[weak self] in
nice!
good job!
That's the low level implementation where every user wanting to use client certificates would have to modify the code of socket.io-client-swift, which is a good starting point to get it done but a solution where you can pass an identity down when creating the socketio connection would be much better. And there the question remains how to pass down the certificate to createWebSocketAndConnect()
?