Created
February 1, 2013 21:46
-
-
Save pk/4694383 to your computer and use it in GitHub Desktop.
Trusting certain hosts using NSURLConnection delegate to bypass SSL certificate validation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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