Objective c 使用NSURLConnection处理自签名证书
我希望允许使用NSURLConnection的自签名证书,前提是主机位于受信任列表中 我看到很多人都在做这样的事情:Objective c 使用NSURLConnection处理自签名证书,objective-c,ssl,nsurlconnection,Objective C,Ssl,Nsurlconnection,我希望允许使用NSURLConnection的自签名证书,前提是主机位于受信任列表中 我看到很多人都在做这样的事情: - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace { if ([protectionSpace.authenticationMethod isEqualToString:
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
if ([protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
if (allowSelfSignedCertForThisHost) {
NSLog(@"Allowing self signed!");
return YES;
}
}
return NO;
}
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
if ([trustedHosts containsObject:challenge.protectionSpace.host]) {
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
}
}
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}
但是,,我想知道为什么您会调用
useCredential:forAuthenticationChallenge
,但之后也会调用继续使用outCredentialforAuthenticationChallenge
。只需在带有iPhone配置实用程序
或Apple Configurator的设备上添加该证书,这是不可行的-它是由我正在连接到@Will,请下载并安装。你不需要它的私钥。只要证书就足够了。是否有任何代码更改来识别此自定义证书?这似乎更简单、更安全。一旦安装了自定义证书,是否需要通过编程执行任何操作来识别此证书?@Will,无需任何操作。如果您在Safari中打开您的链接,它还将显示证书是可信的。