1
如果主機位於可信列表中,我希望允許使用NSURLConnection的自簽名證書。使用NSURLConnection處理自簽名證書
我看到很多人做着這樣的:
- (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
而且continueWithoutCredentialForAuthenticationChallenge
之後。
這不可行 - 它是由我連接的主機發送的。 –
@將會下載並安裝。你不需要私鑰。只需證書就足夠了。 –
是否會有任何代碼更改來識別此自定義證書?這看起來更簡單,更安全。 –