[英]HTTPS with NSURLConnection - NSURLErrorServerCertificateUntrusted
我有一个通过http连接的应用程序。 尝试https时,我收到的错误表明根证书不受信任。 我找到了我的站点证书,其CA证书和CA的根证书的URL,并通过Safari将它们添加到手机中。 现在,当我转到首选项 - >常规 - >配置文件时,我可以看到所有证书一直在链上。 每个证书上都有一个红色的未签名标签。 当我连接时,我得到NSURLErrorServerCertificateUntrusted错误。 我想弄清楚接下来要去哪里。
任何帮助都会很棒。 唯一可能影响这一点的是我连接到一个奇数端口。 所以我的网址是www.domain.com:port。 端口号是否创建证书 - 域名不匹配?
现在我使用iPhone配置实用程序将配置配置文件添加到手机。 它有我的根证书,ca证书和站点证书。 手机上的个人资料显示已经过验证。 在细节中,我可以看到我的三个证书。 但是当我尝试连接时,仍然会收到不受信任的证书错误。 有什么建议么?
试着看看是否还有其他人可以帮忙解决这个问题?
在NSURLConnection加载期间,有一个支持的API用于忽略错误的证书。 为此,只需将这样的内容添加到NSURLConnection委托:
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])
if (... user allows connection despite bad certificate ...)
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}
请注意,connection:didReceiveAuthenticationChallenge:如果需要,在向用户显示对话框之后,可以稍后将其消息发送到challenge.sender(等等)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.