Let's say I have a login keychain with ACL that contains trusted application list.
Now I want to add a new SecTrustedApplicationRef to this existing list, and hence update the ACL of this object.
Here's the steps I took, but doesn't seem to be working
- retrieve keychain item reference of kSecClassGenericPassword object
OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)queryDictionary,(CFTypeRef *)&attributeDictionary);
- Then get existing access ref
SecKeychainItemRef itemRef = (SecKeychainItemRef) CFBridgingRetain([bridgedDict objectForKey:(__bridge id)kSecValueRef]);
SecAccessRef accessRef = NULL;
status = SecKeychainItemCopyAccess(itemRef,&accessRef);
- Update this existing Access Ref by appending a new ACL that contains new trusted apps info
status = SecACLCreateWithSimpleContents(accessRef, (__bridge CFArrayRef)microsoftTrustedApps, (__bridge CFStringRef)tenantIdentifier, kSecKeychainPromptRequirePassphase, &newAcl);
- Finally, update access ref using SecItemUpdate
NSMutableDictionary *origQuery = [NSMutableDictionary new];
[origQuery setObject:tenantIdentifier forKey:(__bridge id)kSecAttrService];
[origQuery setObject:(__bridge id)kSecClassGenericPassword forKey:(__bridge id)kSecClass];
NSMutableDictionary *updateQuery = [NSMutableDictionary new];
[updateQuery setObject:(__bridge id)accessRef forKey:(__bridge id)kSecAttrAccess];
status = SecItemUpdate((CFDictionaryRef)origQuery, (CFDictionaryRef)updateQuery);
It does return errSecSuccess, and I get prompted for passphrase during SecItemUpdate, but the resultant login keychain object in keychain access still doesn't show the new app under "always allow access by these applications" under "Access Control" tab.
Any help would be appreciated. Thanks!