Guest User

Untitled

a guest
Feb 20th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. // for some reason we crash below on the Simulator but not on the actual device...
  2. NSURLCredential *credential = [NSURLCredential credentialWithIdentity:myIdentity
  3. certificates:(NSArray *)myCerts
  4. persistence:NSURLCredentialPersistenceForSession];
  5.  
  6. Here is the entire method:
  7.  
  8. - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
  9. NSString *certPath = [[NSBundle mainBundle] pathForResource:@"certificate" ofType:@"p12"];
  10. NSData *PKCS12Data = [NSData dataWithContentsOfFile:certPath];
  11. CFDataRef inPKCS12Data = (CFDataRef)PKCS12Data;
  12. SecCertificateRef myCert = SecCertificateCreateWithData(NULL, inPKCS12Data);
  13. SecIdentityRef myIdentity;
  14. SecTrustRef myTrust;
  15. OSStatus status = noErr;
  16. status = extractIdentityAndTrust(inPKCS12Data,
  17. &myIdentity,
  18. &myTrust);
  19. SecCertificateRef certArray[1] = { myCert };
  20. CFArrayRef myCerts = CFArrayCreate(NULL, (void *)certArray, 1, NULL);
  21. // for some reason we crash below on the Simulator but not on the actual device...
  22. NSURLCredential *credential = [NSURLCredential credentialWithIdentity:myIdentity
  23. certificates:(NSArray *)myCerts
  24. persistence:NSURLCredentialPersistenceForSession];
  25. CFRelease(myCerts);
  26. [challenge.sender useCredential:credential forAuthenticationChallenge:challenge];
  27. }
Add Comment
Please, Sign In to add comment