Created
April 3, 2013 14:10
-
-
Save nerdsRob/5301542 to your computer and use it in GitHub Desktop.
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
| // | |
| // See full source code : | |
| // https://github.com/FLCLjp/VerifyFingerPrint | |
| // | |
| - (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge | |
| { | |
| if ([[challenge protectionSpace] authenticationMethod] == NSURLAuthenticationMethodServerTrust) { | |
| SecTrustRef trustRef = [[challenge protectionSpace] serverTrust]; | |
| CFIndex count = SecTrustGetCertificateCount(trustRef); | |
| for (CFIndex i = 0; i < count; i++) { | |
| SecCertificateRef certRef = SecTrustGetCertificateAtIndex(trustRef, i); | |
| CFDataRef certData = SecCertificateCopyData(certRef); | |
| NSData *sha1 = ((__bridge NSData *)certData).sha1; | |
| CFRelease(certData); | |
| // compare by sha1 strings. | |
| NSString *TWITTER_COM_CER_SHA1 = @"<593f874d e35c49a1 a4f78a14 3c79e58f 032cf992>"; | |
| if ([[sha1 description] isEqualToString:TWITTER_COM_CER_SHA1]) { | |
| [[challenge sender] useCredential:[NSURLCredential credentialForTrust:trustRef] forAuthenticationChallenge:challenge]; | |
| return; | |
| } | |
| } | |
| } | |
| [[challenge sender] cancelAuthenticationChallenge: challenge]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment