I need to update the kSecAttrAccessible of a keychain entry. I don't need to update the actual data, just the accessibility attribute.
First I try to find the item to make sure that my query dictionary is good:
sanityCheck = SecItemCopyMatching((__bridge CFDictionaryRef)(queryPrivateKey), (void *)&privateKeyRef);
This line successfully finds me the item I am looking for (return code is 0).
I then update the kSecAttrAccessible attribute using the same query:
if (sanityCheck == noErr && privateKeyRef != nil) {
// found it, update accessibility
NSMutableDictionary *updatedAttributes = [[NSMutableDictionary alloc] init];
updatedAttributes[(__bridge id)kSecAttrAccessible] = (__bridge id)kSecAttrAccessibleAlways;
OSStatus updateItemStatus = SecItemUpdate((__bridge CFDictionaryRef)queryPrivateKey, (__bridge CFDictionaryRef)updatedAttributes);
}
At this point, updateItemStatus is -50 (paramErr).
I have looked at this thread: Is it possible to update a Keychain item's kSecAttrAccessible value?
However my issue is different. It returns -50 even if I add kSecValueData to my updatedAttributes
. Besides, the documentation also states that we need to add kSecValueData only for iOS 4 and earlier. I am supporting iOS 7 and above, so this shouldn't be my issue.
Could anyone point out what I am missing here? Thanks a lot.