My server requires a client certificate, after some time searching and reading examples in AFNetworking documents, I tried to set setAuthenticationChallengeBlock and provide a client certificate.
The browser provided by certifacete works fine.
[requestOperation setAuthenticationChallengeBlock:^(NSURLConnection *connection, NSURLAuthenticationChallenge *challenge) { NSLog(@"AuthenticationChallenge"); NSString *thePath = [[NSBundle mainBundle] pathForResource:@"client" ofType:@"pfx"]; NSData *PKCS12Data = [[NSData alloc] initWithContentsOfFile:thePath]; CFDataRef inPKCS12Data = (__bridge CFDataRef)PKCS12Data; SecIdentityRef identity; [self extractIdentity:inPKCS12Data :&identity]; SecCertificateRef certificate = NULL; SecIdentityCopyCertificate (identity, &certificate); const void *certs[] = {certificate}; CFArrayRef certArray = CFArrayCreate(kCFAllocatorDefault, certs, 1, NULL); NSURLCredential *credential = [NSURLCredential credentialWithIdentity:identity certificates:(__bridge NSArray*)certArray persistence:NSURLCredentialPersistencePermanent]; [challenge.sender useCredential:credential forAuthenticationChallenge:challenge]; }]; [requestOperation start];
but the code inside the block is never called, and the server returns a 403 error as expected.
Code in other blocks, such as setUploadBlock, etc., works fine.
Any idea where my mistake is?
source share