From 2ddd72ce4980333c318630c3518e6d74c066e922 Mon Sep 17 00:00:00 2001 From: Himanshu-Sharma-ODC Date: Tue, 23 Oct 2018 20:57:15 +0530 Subject: [PATCH 1/4] Added support to inject ssl certificate as a blob data --- Sources/ScClient/client.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sources/ScClient/client.swift b/Sources/ScClient/client.swift index e5d949a..765fcb6 100644 --- a/Sources/ScClient/client.swift +++ b/Sources/ScClient/client.swift @@ -196,5 +196,11 @@ public class ScClient : Listener, WebSocketDelegate { public func disableSSLVerification(value : Bool) { socket.disableSSLCertValidation = value } + + // The usePublicKeys bool is whether to use the certificates for validation or the public keys. The public keys will be extracted from the certificates automatically if usePublicKeys is choosen. + public func loadSSLCertificateFromData(data : Data, usePublicKeys : Bool = false) { + socket.security = SSLSecurity(certs: [SSLCert(data: data)], usePublicKeys: usePublicKeys) + } + } From 4443a9c6fc7387bf1c05055b9f7cd1f7e2d6e605 Mon Sep 17 00:00:00 2001 From: Himanshu-Sharma-ODC Date: Tue, 23 Oct 2018 20:58:06 +0530 Subject: [PATCH 2/4] Added support to load .cert file from bundle --- Sources/ScClient/client.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sources/ScClient/client.swift b/Sources/ScClient/client.swift index 765fcb6..4788525 100644 --- a/Sources/ScClient/client.swift +++ b/Sources/ScClient/client.swift @@ -197,6 +197,11 @@ public class ScClient : Listener, WebSocketDelegate { socket.disableSSLCertValidation = value } + // uses the .cer files in your app's bundle + public func useSSLCertificate() { + socket.security = SSLSecurity() + } + // The usePublicKeys bool is whether to use the certificates for validation or the public keys. The public keys will be extracted from the certificates automatically if usePublicKeys is choosen. public func loadSSLCertificateFromData(data : Data, usePublicKeys : Bool = false) { socket.security = SSLSecurity(certs: [SSLCert(data: data)], usePublicKeys: usePublicKeys) From b1a12c02315ec3466377a115a564ef8010ebe11a Mon Sep 17 00:00:00 2001 From: Himanshu-Sharma-ODC Date: Tue, 23 Oct 2018 21:31:05 +0530 Subject: [PATCH 3/4] Added documentation for SSL pinning methods --- Sources/ScClient/client.swift | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Sources/ScClient/client.swift b/Sources/ScClient/client.swift index 4788525..34bcc48 100644 --- a/Sources/ScClient/client.swift +++ b/Sources/ScClient/client.swift @@ -197,12 +197,19 @@ public class ScClient : Listener, WebSocketDelegate { socket.disableSSLCertValidation = value } - // uses the .cer files in your app's bundle + /** + Uses the .cer files in your app's bundle + */ public func useSSLCertificate() { socket.security = SSLSecurity() } - // The usePublicKeys bool is whether to use the certificates for validation or the public keys. The public keys will be extracted from the certificates automatically if usePublicKeys is choosen. + /** + You load either a Data blob of your certificate or you can use a SecKeyRef if you have a public key you want to use. + - Parameters: + - data: Data blob of your certificate. + - usePublicKeys: The usePublicKeys bool is whether to use the certificates for validation or the public keys. + */ public func loadSSLCertificateFromData(data : Data, usePublicKeys : Bool = false) { socket.security = SSLSecurity(certs: [SSLCert(data: data)], usePublicKeys: usePublicKeys) } From 9f44469886f357afd3d203f3cee01f44f0856b76 Mon Sep 17 00:00:00 2001 From: Himanshu-Sharma-ODC Date: Tue, 23 Oct 2018 21:43:17 +0530 Subject: [PATCH 4/4] added method to use selected CipherSuites for SSL encryption --- Sources/ScClient/client.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Sources/ScClient/client.swift b/Sources/ScClient/client.swift index 34bcc48..0024aec 100644 --- a/Sources/ScClient/client.swift +++ b/Sources/ScClient/client.swift @@ -213,6 +213,16 @@ public class ScClient : Listener, WebSocketDelegate { public func loadSSLCertificateFromData(data : Data, usePublicKeys : Bool = false) { socket.security = SSLSecurity(certs: [SSLCert(data: data)], usePublicKeys: usePublicKeys) } + + /** + To use an SSL encrypted connection, you need to tell Starscream about the cipher suites your server supports. + If you don't know which cipher suites are supported by your server, you can try pointing SSL Labs at it and checking the results. + - Parameters: + - cipherSuites: list of ciphersuites that will be chosen by client to select encryption algorithm + */ + public func useCipherSuites(cipherSuites : [SSLCipherSuite]) { + socket.enabledSSLCipherSuites = cipherSuites; + } }