6

Amazon S3 バケットに保存されている画像を表示しようとしています。URL はhttps://s3.amazon.com/..../test.jpgのようなものです。iPhoneシミュレーターでこれを行うと、画像が正しく表示されます。ただし、実際のデバイス自体でテストすると、次のようになります。

エラー Domain=NSURLErrorDomain Code=-1202 「このサーバーの証明書は無効です。「s3.amazonaws.com」になりすましたサーバーに接続している可能性があり、機密情報が危険にさらされる可能性があります。」UserInfo=0x20007030 {NSErrorFailingURLStringKey= https://s3.amazonaws.com/.../test.jpeg、NSLocalizedRecoverySuggestion=サーバーに接続しますか?、NSErrorFailingURLKey= https://s3.amazonaws.com/. ../test.jpeg、NSLocalizedDescription=このサーバーの証明書は無効です。「s3.amazonaws.com」になりすましたサーバーに接続している可能性があり、機密情報が危険にさらされる可能性があります。, NSUnderlyingError=0x20014d40 「このサーバーの証明書は無効です。 「s3.amazonaws.com」になりすまして機密情報を危険にさらす可能性があります。", NSURLErrorFailingURLPeerTrustErrorKey=}

何か案は?!

ありがとう!

4

2 に答える 2

12

S3 から同じ証明書エラーが発生していましたが、これを NSURLConnectionDelegate に追加すると問題が解決することがわかりました。

-(void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
   if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust] &&
       [challenge.protectionSpace.host hasSuffix:@"example.com"])
   {
       // accept the certificate anyway
       [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
   }
   else
   {
       [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
   }
}

注: 「example.com」を信頼できるドメインに変更するか、「hasSuffix」よりも洗練されたメカニズムを使用する必要があります。

FYI Apple Technote TN2232「HTTPS Server Trust Evaluation」では、証明書が拒否された理由とその処理方法について詳しく説明しています: https://developer.apple.com/library/ios/technotes/tn2232/_index.html

https://stackoverflow.com/a/2033823/235229でこれに答えてくれた Gordon Henriksen に感謝しますが、古い API を使用しています。

于 2013-08-21T20:02:00.880 に答える