The following code block used to get all identities from login and system keychains.
I prefer working with objective-c types like NSArray for the output list of identities. However, method SecItemCopyMatching accepts only CoreFoundation types (CFArrayRef) do I had to cast the NSArray to CFArrayRef when calling it.
CFMutableArrayRef arrayContent = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
for (const std::string& keychainName :
{"/Library/Keychains/System.keychain", "login.keychain"}) {
status = SecKeychainOpen(keychainName.c_str(), &keychain);
if (status != errSecSuccess) {
NSLog(@"Err");
}
CFArrayAppendValue(arrayContent, (const void *) keychain);
}
NSArray *allIdentities = NULL;
NSDictionary *query = @{(id)kSecMatchSearchList:(id)CFBridgingRelease(arrayContent),
(id)kSecClass:(id)kSecClassIdentity,
(id)kSecReturnRef:(id)kCFBooleanTrue,
(id)kSecMatchLimit:(id)kSecMatchLimitAll};
status = SecItemCopyMatching((CFDictionaryRef)query, (CFTypeRef *)&allIdentities);
Unfortunately, in the last line, it fails on the following error :
Cast of an indirect pointer to an Objective-C pointer to 'CFTypeRef *' (aka 'const void **') is disallowed with ARC
I can, of course, disable ARC for the file contain this method... but I wonder if there's a better approach to make it compile with minimal usage of CoreFoundation objects.
Thanks !