获取“此服务器的证书无效。” 在iPad上从Amazon S3(HTTPS)加载图像时,但是在模拟器上没有错误

阿比森

我正在尝试显示存储在Amazon S3存储桶上的图像。该URL类似于https://s3.amazon.com/..../test.jpg每当我在iPhone模拟器上执行此操作时,图像都会正确显示。但是,如果我在实际设备上对其进行测试,则会不断得到:

错误域= NSURLErrorDomain代码= -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 =}

有任何想法吗?!

谢谢!

戴维姆

我从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”更复杂的机制。

仅供参考,Apple Technote TN2232“ HTTPS服务器信任评估”详细介绍了为何拒绝证书以及如何处理证书:https//developer.apple.com/library/ios/technotes/tn2232/_index.html

感谢Gordon Henriksen在https://stackoverflow.com/a/2033823/235229上回答此问题,但使用了较旧的api。

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

Related 関連記事

ホットタグ

アーカイブ