Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

siakus

macrumors newbie
Original poster
May 2, 2006
12
0
Hi guys, i am using objective C class NSURLConnection to download files from an https website. And i receive an exception: Bad certificate.
Is there any way to tell the WebKit to accept this certificate or to accept all certificates?

Thanks.
 
By the way, I am using cocoa xcode framework for Mac OS 10.4
 
How to accept bad HTTPS certificates

There is a supported API for ignoring bad certificates during NSURLConnection loads. To do so, simply add something like this to your NSURLConnection delegate:

Code:
- (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 ([trustedHosts containsObject:challenge.protectionSpace.host])
      [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
  
  [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}

Note that connection:didReceiveAuthenticationChallenge: can send its message to challenge.sender (much) later, say from a delegate method for an SFCertificateTrustPanel.

--
Gordon Henriksen
Server Software Engineer
Carbonite Inc.
 
NSURLConnection does not like self-signed certificates, try getting one from a SSL certifier. Thats how you officially get around it without telling it to ignore the issues.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.