有谁知道任何支持这种功能的库?
任何信息将不胜感激!!
编辑:
所以我目前正在使用红蜘蛛来试试这个.我有证书设置.这是我到目前为止尝试的代码
public struct IDentityAndTrust { public var IDentityRef:SecIDentity public var trust:SecTrust public var certData : Data} var socket = WebSocket(url: URL(string: "\(ConstantKeys.ipAddress)")!,protocols: []) var IDentityTest : IDentityAndTrust? func createTrust(){ do { let urlPath = Bundle.main.path(forResource: "clIEnt",ofType: "p12") let url = NSURL.fileURL(withPath: urlPath!) let certificateData = try Data(contentsOf: url) IDentityTest = extractTrustAndIDentity(certData: certificateData,certPassword: ConstantKeys.password) } catch { print(error) }}func extractTrustAndIDentity(certData:Data,certPassword:String) -> IDentityAndTrust{ var IDentityAndTrust:IDentityAndTrust! var securityError:Osstatus = errSecSuccess var items: CFArray? let certoptions: Dictionary = [ kSecimportExportPassphrase as String : certPassword ]; // import certificate to read its entrIEs securityError = SecPKCS12import(certData as CFData,certoptions as CFDictionary,&items); if securityError == errSecSuccess { let certItems:CFArray = items as CFArray!; let certItemsArray:Array = certItems as Array let dict:AnyObject? = certItemsArray.first; if let certEntry:Dictionary = dict as? Dictionary<String,AnyObject> { // grab the IDentity let IDentityPointer:AnyObject? = certEntry["IDentity"]; let secIDentityRef:SecIDentity = IDentityPointer as! SecIDentity!; // grab the trust let trustPointer:AnyObject? = certEntry["trust"]; let trustRef:SecTrust = trustPointer as! SecTrust; // grab the certificate chain var certRef: SecCertificate? SecIDentitycopyCertificate(secIDentityRef,&certRef); let certArray:NSMutableArray = NSMutableArray(); certArray.add(certRef as SecCertificate!); IDentityAndTrust = IDentityAndTrust(IDentityRef: secIDentityRef,trust: trustRef,certData : certData); } } return IDentityAndTrust}
然后我像这样连接socket
let key = SecTrustcopyPublicKey(IDentityTest!.trust)!; let ssl = SSLCert(key: key) socket.security = SSLSecurity(certs: [ssl],usePublicKeys: false) socket.enabledSSLCipherSuites = [TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384] socket.delegate = self socket.connect()
但是我收到以下错误消息
CFNetwork SSLHandshake Failed (-9807)
TCP Conn 0x604000173980 SSLHandshake Failed (-9807) websocket is
disconnected: The operation Couldn’t be completed. (Osstatus error
-9807.)
我知道证书是有效的,因为我使用它来发出https请求,它工作正常.那么有谁知道它为什么不起作用?或者有没有人知道另一个可以帮助解决这个问题的套接字库?
解决方法 您可以通过简单地使用NSURLSession(URLSession)而不使用任何第三方库来执行SSL固定,但如果您仍想使用它,则SocketRocket,AFNetworking支持它.以下链接可以帮助您:
http://www.yeradis.com/swift-authentication-challenge
http://www.indelible.org/ink/trusted-ssl-certificates/
https://jetforme.org/2013/05/validating-a-self-signed-ssl-certificate-in-ios-and-os-x-against-a-changing-host-name/enter link description here
您选择的任何方法(第三方或URLSession),我建议您阅读此安全问题:
https://github.com/facebook/SocketRocket/pull/534
https://www.synopsys.com/blogs/software-security/ineffective-certificate-pinning-implementations/enter link description here
总结以上是内存溢出为你收集整理的Swift websockets不接受客户端证书全部内容,希望文章能够帮你解决Swift websockets不接受客户端证书所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)