beta2
This commit is contained in:
commit
36aa57e89c
@ -166,7 +166,7 @@ case ReconnectWait(Int) // Amount of time to wait between reconnects. Default is
|
||||
case SessionDelegate(NSURLSessionDelegate) // Sets an NSURLSessionDelegate for the underlying engine. Useful if you need to handle self-signed certs. Default is nil.
|
||||
case Secure(Bool) // If the connection should use TLS. Default is false.
|
||||
case Security(SSLSecurity) // Allows you to set which certs are valid. Useful for SSL pinning.
|
||||
case SelfSigned(Bool) // Sets WebSocket.selfSignedSSL (Don't do this, iOS will yell at you)
|
||||
case SelfSigned(Bool) // Sets WebSocket.selfSignedSSL. Use this if you're using self-signed certs.
|
||||
case VoipEnabled(Bool) // Only use this option if you're using the client with VoIP services. Changes the way the WebSocket is created. Default is false
|
||||
```
|
||||
Methods
|
||||
|
||||
@ -127,12 +127,9 @@
|
||||
74BC45AD1D0C6675008CC431 /* SocketClientManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74BC45AA1D0C6675008CC431 /* SocketClientManager.swift */; };
|
||||
74F124F01BC574CF002966F4 /* SocketBasicPacketTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74F124EF1BC574CF002966F4 /* SocketBasicPacketTest.swift */; };
|
||||
74F124F11BC574CF002966F4 /* SocketBasicPacketTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74F124EF1BC574CF002966F4 /* SocketBasicPacketTest.swift */; };
|
||||
CEBA56961CDA0B7700BA0389 /* NSCharacterSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEBA56951CDA0B7700BA0389 /* NSCharacterSet.swift */; };
|
||||
CEBA56971CDA0B7700BA0389 /* NSCharacterSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEBA56951CDA0B7700BA0389 /* NSCharacterSet.swift */; };
|
||||
CEBA56981CDA0B7700BA0389 /* NSCharacterSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEBA56951CDA0B7700BA0389 /* NSCharacterSet.swift */; };
|
||||
CEBA569A1CDA0B8200BA0389 /* String.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEBA56991CDA0B8200BA0389 /* String.swift */; };
|
||||
CEBA569B1CDA0B8200BA0389 /* String.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEBA56991CDA0B8200BA0389 /* String.swift */; };
|
||||
CEBA569C1CDA0B8200BA0389 /* String.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEBA56991CDA0B8200BA0389 /* String.swift */; };
|
||||
CEBA569A1CDA0B8200BA0389 /* SocketExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEBA56991CDA0B8200BA0389 /* SocketExtensions.swift */; };
|
||||
CEBA569B1CDA0B8200BA0389 /* SocketExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEBA56991CDA0B8200BA0389 /* SocketExtensions.swift */; };
|
||||
CEBA569C1CDA0B8200BA0389 /* SocketExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEBA56991CDA0B8200BA0389 /* SocketExtensions.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
@ -200,8 +197,7 @@
|
||||
74B4AD201D09A6190062A523 /* SSLSecurity.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SSLSecurity.swift; path = Source/WebSocket/SSLSecurity.swift; sourceTree = "<group>"; };
|
||||
74BC45AA1D0C6675008CC431 /* SocketClientManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketClientManager.swift; path = Source/SocketClientManager.swift; sourceTree = "<group>"; };
|
||||
74F124EF1BC574CF002966F4 /* SocketBasicPacketTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketBasicPacketTest.swift; sourceTree = "<group>"; };
|
||||
CEBA56951CDA0B7700BA0389 /* NSCharacterSet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = NSCharacterSet.swift; path = Source/NSCharacterSet.swift; sourceTree = "<group>"; };
|
||||
CEBA56991CDA0B8200BA0389 /* String.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = String.swift; path = Source/String.swift; sourceTree = "<group>"; };
|
||||
CEBA56991CDA0B8200BA0389 /* SocketExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketExtensions.swift; path = Source/SocketExtensions.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@ -348,6 +344,7 @@
|
||||
74171E561C10CD240062D398 /* SocketEngineSpec.swift */,
|
||||
740CA11F1C496EEB00CB98F4 /* SocketEngineWebsocket.swift */,
|
||||
74171E571C10CD240062D398 /* SocketEventHandler.swift */,
|
||||
CEBA56991CDA0B8200BA0389 /* SocketExtensions.swift */,
|
||||
74171E591C10CD240062D398 /* SocketIOClient.swift */,
|
||||
74171E5A1C10CD240062D398 /* SocketIOClientOption.swift */,
|
||||
74ABF7761C3991C10078C657 /* SocketIOClientSpec.swift */,
|
||||
@ -357,7 +354,6 @@
|
||||
74171E5E1C10CD240062D398 /* SocketParsable.swift */,
|
||||
74171E5F1C10CD240062D398 /* SocketStringReader.swift */,
|
||||
74171E601C10CD240062D398 /* SocketTypes.swift */,
|
||||
CEBA569E1CDA0C0C00BA0389 /* utils */,
|
||||
74B4AD1B1D09A5C30062A523 /* Websocket */,
|
||||
);
|
||||
name = Source;
|
||||
@ -372,15 +368,6 @@
|
||||
name = Websocket;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
CEBA569E1CDA0C0C00BA0389 /* utils */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
CEBA56951CDA0B7700BA0389 /* NSCharacterSet.swift */,
|
||||
CEBA56991CDA0B8200BA0389 /* String.swift */,
|
||||
);
|
||||
name = utils;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXHeadersBuildPhase section */
|
||||
@ -618,12 +605,11 @@
|
||||
files = (
|
||||
740CA1221C496EF700CB98F4 /* SocketEngineWebsocket.swift in Sources */,
|
||||
74171EA51C10CD240062D398 /* SocketIOClientStatus.swift in Sources */,
|
||||
CEBA569A1CDA0B8200BA0389 /* String.swift in Sources */,
|
||||
CEBA569A1CDA0B8200BA0389 /* SocketExtensions.swift in Sources */,
|
||||
74B4AD1D1D09A5D80062A523 /* WebSocket.swift in Sources */,
|
||||
74171E751C10CD240062D398 /* SocketEngine.swift in Sources */,
|
||||
74171E691C10CD240062D398 /* SocketAckManager.swift in Sources */,
|
||||
7420CB791C49629E00956AA4 /* SocketEnginePollable.swift in Sources */,
|
||||
CEBA56961CDA0B7700BA0389 /* NSCharacterSet.swift in Sources */,
|
||||
74ABF7771C3991C10078C657 /* SocketIOClientSpec.swift in Sources */,
|
||||
74171E871C10CD240062D398 /* SocketEngineSpec.swift in Sources */,
|
||||
74171E631C10CD240062D398 /* SocketAckEmitter.swift in Sources */,
|
||||
@ -677,11 +663,10 @@
|
||||
74B4AD241D09A6450062A523 /* WebSocket.swift in Sources */,
|
||||
740CA1211C496EF200CB98F4 /* SocketEngineWebsocket.swift in Sources */,
|
||||
7471CCEA1C39926300364B59 /* SocketIOClientSpec.swift in Sources */,
|
||||
CEBA569B1CDA0B8200BA0389 /* String.swift in Sources */,
|
||||
CEBA569B1CDA0B8200BA0389 /* SocketExtensions.swift in Sources */,
|
||||
74171EA71C10CD240062D398 /* SocketIOClientStatus.swift in Sources */,
|
||||
74171E771C10CD240062D398 /* SocketEngine.swift in Sources */,
|
||||
7420CB7A1C49629E00956AA4 /* SocketEnginePollable.swift in Sources */,
|
||||
CEBA56971CDA0B7700BA0389 /* NSCharacterSet.swift in Sources */,
|
||||
74171E6B1C10CD240062D398 /* SocketAckManager.swift in Sources */,
|
||||
74171E891C10CD240062D398 /* SocketEngineSpec.swift in Sources */,
|
||||
74171E651C10CD240062D398 /* SocketAckEmitter.swift in Sources */,
|
||||
@ -723,11 +708,10 @@
|
||||
74B4AD251D09A6490062A523 /* WebSocket.swift in Sources */,
|
||||
740CA1201C496EEB00CB98F4 /* SocketEngineWebsocket.swift in Sources */,
|
||||
7471CCEB1C39926C00364B59 /* SocketIOClientSpec.swift in Sources */,
|
||||
CEBA569C1CDA0B8200BA0389 /* String.swift in Sources */,
|
||||
CEBA569C1CDA0B8200BA0389 /* SocketExtensions.swift in Sources */,
|
||||
74171EA91C10CD240062D398 /* SocketIOClientStatus.swift in Sources */,
|
||||
74171E791C10CD240062D398 /* SocketEngine.swift in Sources */,
|
||||
7420CB7B1C49629E00956AA4 /* SocketEnginePollable.swift in Sources */,
|
||||
CEBA56981CDA0B7700BA0389 /* NSCharacterSet.swift in Sources */,
|
||||
74171E6D1C10CD240062D398 /* SocketAckManager.swift in Sources */,
|
||||
74171E8B1C10CD240062D398 /* SocketEngineSpec.swift in Sources */,
|
||||
74171E671C10CD240062D398 /* SocketAckEmitter.swift in Sources */,
|
||||
|
||||
@ -24,7 +24,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
private struct SocketAck : Hashable, Equatable {
|
||||
private struct SocketAck : Hashable {
|
||||
let ack: Int
|
||||
var callback: AckCallback!
|
||||
var hashValue: Int {
|
||||
|
||||
@ -131,21 +131,17 @@ public final class SocketEngine : NSObject, SocketEnginePollable, SocketEngineWe
|
||||
}
|
||||
|
||||
private func checkAndHandleEngineError(_ msg: String) {
|
||||
guard let stringData = msg.data(using: String.Encoding.utf8,
|
||||
allowLossyConversion: false) else { return }
|
||||
|
||||
do {
|
||||
if let dict = try JSONSerialization.jsonObject(with: stringData, options: .mutableContainers) as? NSDictionary {
|
||||
guard let error = dict["message"] as? String else { return }
|
||||
let dict = try msg.toNSDictionary()
|
||||
guard let error = dict["message"] as? String else { return }
|
||||
|
||||
/*
|
||||
0: Unknown transport
|
||||
1: Unknown sid
|
||||
2: Bad handshake request
|
||||
3: Bad request
|
||||
*/
|
||||
didError(reason: error)
|
||||
}
|
||||
/*
|
||||
0: Unknown transport
|
||||
1: Unknown sid
|
||||
2: Bad handshake request
|
||||
3: Bad request
|
||||
*/
|
||||
didError(reason: error)
|
||||
} catch {
|
||||
client?.engineDidError(reason: "Got unknown error from server \(msg)")
|
||||
}
|
||||
@ -360,24 +356,23 @@ public final class SocketEngine : NSObject, SocketEnginePollable, SocketEngineWe
|
||||
doPoll()
|
||||
}
|
||||
|
||||
private func handleOpen(_ openMessage: String) {
|
||||
let mesData = openMessage.data(using: String.Encoding.utf8, allowLossyConversion: false)!
|
||||
private func handleOpen(openData: String) {
|
||||
do {
|
||||
let json = try JSONSerialization.jsonObject(with: mesData,
|
||||
options: JSONSerialization.ReadingOptions.allowFragments) as? NSDictionary
|
||||
if let sid = json?["sid"] as? String {
|
||||
let json = try openData.toNSDictionary()
|
||||
|
||||
if let sid = json["sid"] as? String {
|
||||
let upgradeWs: Bool
|
||||
|
||||
self.sid = sid
|
||||
connected = true
|
||||
|
||||
if let upgrades = json?["upgrades"] as? [String] {
|
||||
if let upgrades = json["upgrades"] as? [String] {
|
||||
upgradeWs = upgrades.contains("websocket")
|
||||
} else {
|
||||
upgradeWs = false
|
||||
}
|
||||
|
||||
if let pingInterval = json?["pingInterval"] as? Double, pingTimeout = json?["pingTimeout"] as? Double {
|
||||
if let pingInterval = json["pingInterval"] as? Double, pingTimeout = json["pingTimeout"] as? Double {
|
||||
self.pingInterval = pingInterval / 1000.0
|
||||
self.pingTimeout = pingTimeout / 1000.0
|
||||
}
|
||||
@ -443,7 +438,7 @@ public final class SocketEngine : NSObject, SocketEnginePollable, SocketEngineWe
|
||||
case .pong:
|
||||
handlePong(fixedString)
|
||||
case .open:
|
||||
handleOpen(fixedString[fixedString.characters.index(after: fixedString.characters.startIndex)..<fixedString.endIndex])
|
||||
handleOpen(openData: fixedString[fixedString.characters.index(after: fixedString.characters.startIndex)..<fixedString.endIndex])
|
||||
case .close:
|
||||
handleClose(fixedString)
|
||||
default:
|
||||
@ -459,7 +454,7 @@ public final class SocketEngine : NSObject, SocketEnginePollable, SocketEngineWe
|
||||
polling = true
|
||||
probing = false
|
||||
invalidated = false
|
||||
session = URLSession(configuration: .default(),
|
||||
session = URLSession(configuration: .default,
|
||||
delegate: sessionDelegate,
|
||||
delegateQueue: OperationQueue())
|
||||
sid = ""
|
||||
|
||||
@ -45,7 +45,9 @@ public protocol SocketEnginePollable : SocketEngineSpec {
|
||||
|
||||
// Default polling methods
|
||||
extension SocketEnginePollable {
|
||||
private func addHeaders(for req: NSMutableURLRequest) {
|
||||
private func addHeaders(for req: URLRequest) -> URLRequest {
|
||||
var req = req
|
||||
|
||||
if cookies != nil {
|
||||
let headers = HTTPCookie.requestHeaderFields(with: cookies!)
|
||||
req.allHTTPHeaderFields = headers
|
||||
@ -56,9 +58,13 @@ extension SocketEnginePollable {
|
||||
req.setValue(value, forHTTPHeaderField: headerName)
|
||||
}
|
||||
}
|
||||
|
||||
return req
|
||||
}
|
||||
|
||||
func createRequestForPostWithPostWait() -> URLRequest {
|
||||
defer { postWait.removeAll(keepingCapacity: true) }
|
||||
|
||||
var postStr = ""
|
||||
|
||||
for packet in postWait {
|
||||
@ -69,18 +75,14 @@ extension SocketEnginePollable {
|
||||
|
||||
DefaultSocketLogger.Logger.log("Created POST string: %@", type: "SocketEnginePolling", args: postStr)
|
||||
|
||||
postWait.removeAll(keepingCapacity: false)
|
||||
var req = URLRequest(url: urlPollingWithSid)
|
||||
let postData = postStr.data(using: .utf8, allowLossyConversion: false)!
|
||||
|
||||
let req = NSMutableURLRequest(url: urlPollingWithSid as URL)
|
||||
|
||||
addHeaders(for: req)
|
||||
req = addHeaders(for: req)
|
||||
|
||||
req.httpMethod = "POST"
|
||||
req.setValue("text/plain; charset=UTF-8", forHTTPHeaderField: "Content-Type")
|
||||
|
||||
let postData = postStr.data(using: String.Encoding.utf8,
|
||||
allowLossyConversion: false)!
|
||||
|
||||
req.httpBody = postData
|
||||
req.setValue(String(postData.count), forHTTPHeaderField: "Content-Length")
|
||||
|
||||
@ -88,15 +90,14 @@ extension SocketEnginePollable {
|
||||
}
|
||||
|
||||
public func doPoll() {
|
||||
if websocket || waitingForPoll || !connected || closed {
|
||||
return
|
||||
}
|
||||
if websocket || waitingForPoll || !connected || closed { return }
|
||||
|
||||
waitingForPoll = true
|
||||
let req = NSMutableURLRequest(url: urlPollingWithSid as URL)
|
||||
|
||||
addHeaders(for: req)
|
||||
doLongPoll(for: req as URLRequest)
|
||||
var req = URLRequest(url: urlPollingWithSid)
|
||||
|
||||
req = addHeaders(for: req)
|
||||
doLongPoll(for: req )
|
||||
}
|
||||
|
||||
func doRequest(for req: URLRequest, callbackWith callback: (Data?, URLResponse?, NSError?) -> Void) {
|
||||
|
||||
@ -84,7 +84,7 @@ extension SocketEngineSpec {
|
||||
|
||||
return .left(mutData as Data)
|
||||
} else {
|
||||
let str = "b4" + data.base64EncodedString(Data.Base64EncodingOptions(rawValue: 0))
|
||||
let str = "b4" + data.base64EncodedString(options: Data.Base64EncodingOptions(rawValue: 0))
|
||||
|
||||
return .right(str)
|
||||
}
|
||||
|
||||
66
Source/SocketExtensions.swift
Normal file
66
Source/SocketExtensions.swift
Normal file
@ -0,0 +1,66 @@
|
||||
//
|
||||
// SocketExtensions.swift
|
||||
// Socket.IO-Client-Swift
|
||||
//
|
||||
// Created by Erik Little on 7/1/2016.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
import Foundation
|
||||
|
||||
enum JSONError : ErrorProtocol {
|
||||
case notArray
|
||||
case notNSDictionary
|
||||
}
|
||||
|
||||
extension Array where Element: AnyObject {
|
||||
func toJSON() throws -> Data {
|
||||
return try JSONSerialization.data(withJSONObject: self as NSArray, options: JSONSerialization.WritingOptions(rawValue: 0))
|
||||
}
|
||||
}
|
||||
|
||||
extension CharacterSet {
|
||||
static var allowedURLCharacterSet: CharacterSet {
|
||||
return CharacterSet(charactersIn: "!*'();:@&=+$,/?%#[]\" {}").inverted
|
||||
}
|
||||
}
|
||||
|
||||
extension String {
|
||||
func toArray() throws -> [AnyObject] {
|
||||
guard let stringData = data(using: .utf8, allowLossyConversion: false) else { return [] }
|
||||
guard let array = try JSONSerialization.jsonObject(with: stringData, options: .mutableContainers) as? [AnyObject] else {
|
||||
throw JSONError.notArray
|
||||
}
|
||||
|
||||
return array
|
||||
}
|
||||
|
||||
func toNSDictionary() throws -> NSDictionary {
|
||||
guard let binData = data(using: .utf8, allowLossyConversion: false) else { return [:] }
|
||||
guard let json = try JSONSerialization.jsonObject(with: binData, options: .allowFragments) as? NSDictionary else {
|
||||
throw JSONError.notNSDictionary
|
||||
}
|
||||
|
||||
return json
|
||||
}
|
||||
|
||||
func urlEncode() -> String? {
|
||||
return addingPercentEncoding(withAllowedCharacters: .allowedURLCharacterSet)
|
||||
}
|
||||
}
|
||||
@ -94,11 +94,8 @@ struct SocketPacket {
|
||||
}
|
||||
|
||||
do {
|
||||
let jsonSend = try JSONSerialization.data(withJSONObject: data as AnyObject,
|
||||
options: JSONSerialization.WritingOptions(rawValue: 0))
|
||||
guard let jsonString = String(data: jsonSend, encoding: String.Encoding.utf8) else {
|
||||
return message + "[]"
|
||||
}
|
||||
let jsonSend = try data.toJSON()
|
||||
guard let jsonString = String(data: jsonSend, encoding: .utf8) else { return message + "[]" }
|
||||
|
||||
restOfMessage = jsonString
|
||||
} catch {
|
||||
|
||||
@ -126,14 +126,8 @@ extension SocketParsable {
|
||||
|
||||
// Parses data for events
|
||||
private func parseData(_ data: String) -> Either<String, [AnyObject]> {
|
||||
let stringData = data.data(using: String.Encoding.utf8, allowLossyConversion: false)
|
||||
do {
|
||||
if let arr = try JSONSerialization.jsonObject(with: stringData!,
|
||||
options: JSONSerialization.ReadingOptions.mutableContainers) as? [AnyObject] {
|
||||
return .right(arr)
|
||||
} else {
|
||||
return .left("Expected data array")
|
||||
}
|
||||
return .right(try data.toArray())
|
||||
} catch {
|
||||
return .left("Error parsing data for packet")
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ public class SSLSecurity : NSObject {
|
||||
- returns: a representation security object to be used with
|
||||
*/
|
||||
public convenience init(usePublicKeys: Bool = false) {
|
||||
let paths = Bundle.main().pathsForResources(ofType: "cer", inDirectory: ".")
|
||||
let paths = Bundle.main.pathsForResources(ofType: "cer", inDirectory: ".")
|
||||
|
||||
let certs = paths.reduce([SSLCert]()) { (certs: [SSLCert], path: String) -> [SSLCert] in
|
||||
var certs = certs
|
||||
@ -141,9 +141,9 @@ public class SSLSecurity : NSObject {
|
||||
}
|
||||
var policy: SecPolicy
|
||||
if self.validatedDN {
|
||||
policy = SecPolicyCreateSSL(true, domain)!
|
||||
policy = SecPolicyCreateSSL(true, domain)
|
||||
} else {
|
||||
policy = SecPolicyCreateBasicX509()!
|
||||
policy = SecPolicyCreateBasicX509()
|
||||
}
|
||||
SecTrustSetPolicies(trust,policy)
|
||||
if self.usePublicKeys {
|
||||
@ -195,7 +195,7 @@ public class SSLSecurity : NSObject {
|
||||
func extractPublicKey(_ data: Data) -> SecKey? {
|
||||
guard let cert = SecCertificateCreateWithData(nil, data) else { return nil }
|
||||
|
||||
return extractPublicKeyFromCert(cert, policy: SecPolicyCreateBasicX509()!)
|
||||
return extractPublicKeyFromCert(cert, policy: SecPolicyCreateBasicX509())
|
||||
}
|
||||
|
||||
/**
|
||||
@ -246,7 +246,7 @@ public class SSLSecurity : NSObject {
|
||||
let keys = (0..<SecTrustGetCertificateCount(trust)).reduce([SecKey]()) { (keys: [SecKey], index: Int) -> [SecKey] in
|
||||
var keys = keys
|
||||
let cert = SecTrustGetCertificateAtIndex(trust, index)
|
||||
if let key = extractPublicKeyFromCert(cert!, policy: policy!) {
|
||||
if let key = extractPublicKeyFromCert(cert!, policy: policy) {
|
||||
keys.append(key)
|
||||
}
|
||||
|
||||
|
||||
@ -137,7 +137,7 @@ public class WebSocket : NSObject, StreamDelegate {
|
||||
private var didDisconnect = false
|
||||
private var readyToWrite = false
|
||||
private let mutex = Lock()
|
||||
private let notificationCenter = NotificationCenter.default()
|
||||
private let notificationCenter = NotificationCenter.default
|
||||
private var canDispatch: Bool {
|
||||
mutex.lock()
|
||||
let canWork = readyToWrite
|
||||
@ -270,7 +270,7 @@ public class WebSocket : NSObject, StreamDelegate {
|
||||
key += "\(Character(uni))"
|
||||
}
|
||||
let data = key.data(using: String.Encoding.utf8)
|
||||
let baseKey = data?.base64EncodedString(Data.Base64EncodingOptions(rawValue: 0))
|
||||
let baseKey = data?.base64EncodedString(options: Data.Base64EncodingOptions(rawValue: 0))
|
||||
return baseKey!
|
||||
}
|
||||
|
||||
@ -289,19 +289,19 @@ public class WebSocket : NSObject, StreamDelegate {
|
||||
inStream.delegate = self
|
||||
outStream.delegate = self
|
||||
if ["wss", "https"].contains(url.scheme!) {
|
||||
inStream.setProperty(StreamSocketSecurityLevel.negotiatedSSL as NSString, forKey: Stream.PropertyKey.socketSecurityLevelKey.rawValue)
|
||||
outStream.setProperty(StreamSocketSecurityLevel.negotiatedSSL as NSString, forKey: Stream.PropertyKey.socketSecurityLevelKey.rawValue)
|
||||
inStream.setProperty(StreamSocketSecurityLevel.negotiatedSSL as NSString, forKey: Stream.PropertyKey(rawValue: Stream.PropertyKey.socketSecurityLevelKey.rawValue))
|
||||
outStream.setProperty(StreamSocketSecurityLevel.negotiatedSSL as NSString, forKey: Stream.PropertyKey(rawValue: Stream.PropertyKey.socketSecurityLevelKey.rawValue))
|
||||
} else {
|
||||
certValidated = true //not a https session, so no need to check SSL pinning
|
||||
}
|
||||
if voipEnabled {
|
||||
inStream.setProperty(StreamNetworkServiceTypeValue.voip as NSString, forKey: Stream.PropertyKey.networkServiceType.rawValue)
|
||||
outStream.setProperty(StreamNetworkServiceTypeValue.voip as NSString, forKey: Stream.PropertyKey.networkServiceType.rawValue)
|
||||
inStream.setProperty(StreamNetworkServiceTypeValue.voIP as NSString, forKey: Stream.PropertyKey(rawValue: Stream.PropertyKey.networkServiceType.rawValue))
|
||||
outStream.setProperty(StreamNetworkServiceTypeValue.voIP as NSString, forKey: Stream.PropertyKey(rawValue: Stream.PropertyKey.networkServiceType.rawValue))
|
||||
}
|
||||
if selfSignedSSL {
|
||||
let settings: [NSObject: NSObject] = [kCFStreamSSLValidatesCertificateChain: NSNumber(value: false), kCFStreamSSLPeerName: kCFNull]
|
||||
inStream.setProperty(settings as AnyObject?, forKey: kCFStreamPropertySSLSettings as String)
|
||||
outStream.setProperty(settings as AnyObject?, forKey: kCFStreamPropertySSLSettings as String)
|
||||
inStream.setProperty(settings as AnyObject?, forKey: kCFStreamPropertySSLSettings as Stream.PropertyKey)
|
||||
outStream.setProperty(settings as AnyObject?, forKey: kCFStreamPropertySSLSettings as Stream.PropertyKey)
|
||||
}
|
||||
if let cipherSuites = self.enabledSSLCipherSuites {
|
||||
if let sslContextIn = CFReadStreamCopyProperty(inputStream, CFStreamPropertyKey(rawValue: kCFStreamPropertySSLContext)) as! SSLContext?,
|
||||
@ -350,9 +350,9 @@ public class WebSocket : NSObject, StreamDelegate {
|
||||
//delegate for the stream methods. Processes incoming bytes
|
||||
public func stream(_ aStream: Stream, handle eventCode: Stream.Event) {
|
||||
if let sec = security where !certValidated && [.hasBytesAvailable, .hasSpaceAvailable].contains(eventCode) {
|
||||
let possibleTrust: AnyObject? = aStream.property(forKey: kCFStreamPropertySSLPeerTrust as String)
|
||||
let possibleTrust: AnyObject? = aStream.property(forKey: kCFStreamPropertySSLPeerTrust as Stream.PropertyKey)
|
||||
if let trust: AnyObject = possibleTrust {
|
||||
let domain: AnyObject? = aStream.property(forKey: kCFStreamSSLPeerName as String)
|
||||
let domain: AnyObject? = aStream.property(forKey: kCFStreamSSLPeerName as Stream.PropertyKey)
|
||||
if sec.isValid(trust as! SecTrust, domain: domain as! String?) {
|
||||
certValidated = true
|
||||
} else {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user