Skip to content

Instantly share code, notes, and snippets.

@pk
Created February 1, 2013 21:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pk/4694383 to your computer and use it in GitHub Desktop.
Save pk/4694383 to your computer and use it in GitHub Desktop.
Trusting certain hosts using NSURLConnection delegate to bypass SSL certificate validation.
- (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 ([[[GJEnvironment sharedEnvironment] trustedHosts] containsObject:challenge.protectionSpace.host])
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment