2016-07-06 7 views
6

私は、HTTPS用に自己署名入りのSSL証明書を使用するサーバーを持っています。私は自分のアプリにバンドルされた自己署名付きルート証明書を持っています。 NSURLSession-URLSession:didReceiveChallenge:completionHandler:デリゲートメソッドのSecTrustSetAnchorCertificates()を使用して、自己署名付きルート証明書を使用して検証することができます。HTTPSと自己署名入りサーバー証明書でAVPlayerを使用するにはどうすればよいですか?

ただし、AVPlayerで試してみると、SSLエラーが発生し、再生に失敗します。これは私のAVAssetResourceLoaderデリゲートの実装です:

- (BOOL)resourceLoader:(AVAssetResourceLoader *)resourceLoader shouldWaitForResponseToAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge 
{ 
    if ([challenge.protectionSpace.authenticationMethod isEqual:NSURLAuthenticationMethodServerTrust]) { 
     SecTrustRef trust = challenge.protectionSpace.serverTrust; 
     SecTrustSetAnchorCertificates(trust, (__bridge CFArrayRef)self.secTrustCertificates); 

     SecTrustResultType trustResult = kSecTrustResultInvalid; 
     OSStatus status = SecTrustEvaluate(trust, &trustResult); 

     if (status == errSecSuccess && (trustResult == kSecTrustResultUnspecified || trustResult == kSecTrustResultProceed)) { 
      [challenge.sender useCredential:[NSURLCredential credentialForTrust:trust] forAuthenticationChallenge:challenge]; 
      return YES; 
     } else { 
      [challenge.sender cancelAuthenticationChallenge:challenge]; 
      return YES; 
     } 
    } 
    return NO; 
} 

デリゲートが呼び出されると、trustResultは予想通り、(「明示的なユーザーの上書きせずに、信頼された」を意味する)kSecTrustResultUnspecifiedに相当します。しかし、再生は以下のAVPlayerItem.errorと、直後に失敗します。

エラードメイン= NSURLErrorDomainコード= -1200「SSLエラーが発生し、サーバーへの安全な接続ができません。」 UserInfo = {NSLocalizedRecoverySuggestion =サーバーに接続しますか?NSUnderlyingError = 0x16c35720 {エラードメイン= NSOSStatusErrorDomainコード= -1200 "(null)"}、NSLocalizedDescription = SSLエラーが発生しました。 }

AVPlayerにSSLハンドシェイクを受け入れる方法を教えてください。

答えて

2

この実装は、私のために働いています

- (BOOL)resourceLoader:(AVAssetResourceLoader *)resourceLoader 
shouldWaitForResponseToAuthenticationChallenge:(NSURLAuthenticationChallenge *)authenticationChallenge 
{ 
    //server trust 
    NSURLProtectionSpace *protectionSpace = authenticationChallenge.protectionSpace; 
    if ([protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) { 
     [authenticationChallenge.sender useCredential:[NSURLCredential credentialForTrust:authenticationChallenge.protectionSpace.serverTrust] forAuthenticationChallenge:authenticationChallenge]; 
     [authenticationChallenge.sender continueWithoutCredentialForAuthenticationChallenge:authenticationChallenge]; 
    } 
    else { // other type: username password, client trust... 
    } 
    return YES; 
} 

しかし、それは私が識別するためには至っていない理由のiOS 10.0.1のように動作を停止しました。これはあなたに役立つかもしれません。がんばろう!

+0

これは実際にはデバイス上で正常に動作していましたが、少なくともiOS 9.3.xでは、iOSシミュレータで奇妙で予測できない方法で失敗することがありました。私はまだiOS 10でテストしていません。 –

+0

同じ問題が、私の実装がiOS 10で動作するのを止めました。Appleのエンジニアとこの問題を解決しようとするために、「テクニカルサポートインシデント」を開きました。彼らがこの問題を解決することができれば、ここで解決策を投稿します。 – Sylverb

+0

アップルのエンジニアがTSIに応答しました。おそらくバグでしょう。さらなる調査のためにレーダーを埋める必要があります。 – Sylverb

関連する問題