I\'m fighting with a client certificate authentication. When a server needs a credential (a certificate in this case), this method is invoked from NSURLConnection d
I use these steps:
and the rest (a credential initialization) is the same as in my question... I can put here more code if you want. Note that there is a bug (http://openradar.appspot.com/7090030) in the iphone simulator, so it is not possible to work with a lot of certifcates in the simulator.
Of course the problem was with the iPhone simulator in xcode :) After updating to version 3.1 it started to work...
You can also search for identity in keychain if you store this information there:
+ (SecIdentityRef)dumpSecIdentityRef
{
OSStatus err;
CFArrayRef result;
CFIndex resultCount;
CFIndex resultIndex;
result = NULL;
err = SecItemCopyMatching((__bridge CFDictionaryRef) [NSDictionary dictionaryWithObjectsAndKeys:
(__bridge id)kSecClassIdentity,
kSecClass, kSecMatchLimitAll,
kSecMatchLimit, kCFBooleanTrue,
kSecReturnRef, kCFBooleanTrue,
kSecReturnAttributes, nil],
(CFTypeRef *) &result);
if ((result != NULL) && (err == noErr)) {
NSMutableArray *identitiesArray = [NSMutableArray new];
resultCount = CFArrayGetCount(result);
for (resultIndex = 0; resultIndex < resultCount; resultIndex++) {
NSDictionary * thisResult;
thisResult = (__bridge NSDictionary *) CFArrayGetValueAtIndex(result, resultIndex);
NSLog(@"%@", (__bridge id)(result));
[identitiesArray addObject:thisResult];
}
CFRelease(result);
//TO DO - choose correct identity object from array.
SecIdentityRef myIdentity = (__bridge SecIdentityRef)([[identitiesArray objectAtIndex:0] valueForKey:@"v_Ref"]);
return myIdentity;
}
return nil;
}