2017-10-19 6 views
4

私はWebSocketでクライアント証明書をサポートするプロジェクトを進めています。私は現在Starscreamを使用していますが、残念なことにドキュメンテーションを読むことから、これに関するサポートに関する情報はないようです。私は他のいくつかの素早いWebソケットライブラリを見てきましたが、どれもこれをサポートしているとは言いません。クライアント証明書を受け付けていないスウィフトWebソケット

このような機能をサポートするライブラリを知っている人はいますか?

情報があれば幸いです。

編集:

私は現在、これを試すためにスタークリームを使用しています。証明書の設定があります。ここで私は、私はそのように

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() 

のようにソケットを接続して、これまで

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 
} 

をしようとしているコードがあるしかし、私は

CFNetworkはSSLHandshakeが失敗し、次のエラーメッセージ(-9807)

を得ました

TCP Conn 0x604000173980 SSLハンドシェイクが失敗しました(-9807)websocketが disconnected: uldnは完了されません。 (OSStatusエラー -9807)

私はhttps要求を行うために使用するので、証明書が有効であり、正常に動作することがわかります。だから誰もそれが動作していない理由を知っていますか?あるいは、誰かがこの問題に役立つ別のソケットライブラリを知っていますか?

答えて

0

サードパーティのライブラリを使わずに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)を選択した任意の方法で、私はあなたがこのセキュリティを読んで行うことを示唆しています号:

私の問題は、SSLをピン留めし、Webリクエストではない

https://www.synopsys.com/blogs/software-security/ineffective-certificate-pinning-implementations/enter link description here

+0

は、私がalamofireを使用して、私は何の問題SSLの問題を処理することはできません。私の問題は純粋にウェブソケットです。私が見たソケットライブラリは、これらの認証の問題を処理する方法を提供していません.SocketRocketは可能性のようですが、これは古いライブラリであり、Objective-cで書かれています。私はSwiftソリューションを望んでいた – AdamM

関連する問題