Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // for some reason we crash below on the Simulator but not on the actual device...
- NSURLCredential *credential = [NSURLCredential credentialWithIdentity:myIdentity
- certificates:(NSArray *)myCerts
- persistence:NSURLCredentialPersistenceForSession];
- Here is the entire method:
- - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
- NSString *certPath = [[NSBundle mainBundle] pathForResource:@"certificate" ofType:@"p12"];
- NSData *PKCS12Data = [NSData dataWithContentsOfFile:certPath];
- CFDataRef inPKCS12Data = (CFDataRef)PKCS12Data;
- SecCertificateRef myCert = SecCertificateCreateWithData(NULL, inPKCS12Data);
- SecIdentityRef myIdentity;
- SecTrustRef myTrust;
- OSStatus status = noErr;
- status = extractIdentityAndTrust(inPKCS12Data,
- &myIdentity,
- &myTrust);
- SecCertificateRef certArray[1] = { myCert };
- CFArrayRef myCerts = CFArrayCreate(NULL, (void *)certArray, 1, NULL);
- // for some reason we crash below on the Simulator but not on the actual device...
- NSURLCredential *credential = [NSURLCredential credentialWithIdentity:myIdentity
- certificates:(NSArray *)myCerts
- persistence:NSURLCredentialPersistenceForSession];
- CFRelease(myCerts);
- [challenge.sender useCredential:credential forAuthenticationChallenge:challenge];
- }
Add Comment
Please, Sign In to add comment