Created
July 19, 2013 18:50
-
-
Save pt-arvind/6041458 to your computer and use it in GitHub Desktop.
public key pinning
This file contains 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
- (void)connection:(NSURLConnection *)connection | |
willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge | |
{ | |
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) { | |
SecTrustRef serverTrust = challenge.protectionSpace.serverTrust; | |
BOOL shouldPerformConnectionSecurityMeasures = [[MINetworkSecurityManager sharedManager] shouldPerformConnectionSecurityMeasuresForURLConnection:connection]; | |
BOOL trusted = shouldPerformConnectionSecurityMeasures ? [[MINetworkSecurityManager sharedManager] evaluateServerTrust:serverTrust] : [[MINetworkSecurityManager sharedManager] evaluateTrust:serverTrust forSecurityModel:MINetworkSecurityModelStandard error:nil]; | |
if (trusted) { | |
NSURLCredential *credential = [NSURLCredential credentialForTrust:serverTrust]; | |
[[challenge sender] useCredential:credential forAuthenticationChallenge:challenge]; | |
} else { | |
self.networkSecurityErrorDetected = YES; | |
[[challenge sender] cancelAuthenticationChallenge:challenge]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment