【问题标题】:SSL certificate for iPhone -> which CA?iPhone 的 SSL 证书 -> 哪个 CA?
【发布时间】:2011-02-15 11:24:35
【问题描述】:
我发现 NSUrlConnection 的所有这些变通方法都使用封闭的 API 来访问不受信任的 SSL 证书。其他选项是首先使用 Safari/Mail 应用程序安装证书。
我想知道安装了哪些根证书,所以我可以从受信任的 CA 获得一个,按照您应该这样做的方式..
有人知道我需要什么 CA 吗?
【问题讨论】:
标签:
iphone
ssl
https
nsurlconnection
certificate-authority
【解决方案1】:
您实际上可以使用公共 API 接受自签名 SSL 证书:
- (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]) {
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
}
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}