Created
March 31, 2014 19:25
-
-
Save xdumaine/9900201 to your computer and use it in GitHub Desktop.
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 didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { | |
// gets a certificate from local resources | |
NSString *thePath = [[NSBundle mainBundle] pathForResource:@"MyCertificate" ofType:@"pfx"]; | |
NSData *PKCS12Data = [[NSData alloc] initWithContentsOfFile:thePath]; | |
CFDataRef inPKCS12Data = (CFDataRef)PKCS12Data; | |
SecIdentityRef identity; | |
// extract the ideneity from the certificate | |
[self extractIdentity :inPKCS12Data :&identity]; | |
SecCertificateRef certificate = NULL; | |
SecIdentityCopyCertificate (identity, &certificate); | |
const void *certs[] = {certificate}; | |
CFArrayRef certArray = CFArrayCreate(kCFAllocatorDefault, certs, 1, NULL); | |
// create a credential from the certificate and ideneity, then reply to the challenge with the credential | |
NSURLCredential *credential = [NSURLCredential credentialWithIdentity:identity certificates:(NSArray*)certArray persistence:NSURLCredentialPersistencePermanent]; | |
[challenge.sender useCredential:credential forAuthenticationChallenge:challenge]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment