Is it possible to update a Keychain item's kSecAttrAccessible value? Is it possible to update a Keychain item's kSecAttrAccessible value? ios ios

Is it possible to update a Keychain item's kSecAttrAccessible value?


After opening a support incident at Apple Developer Technical Support (ADTS), I received a reply that answers this question. SecItemUpdate() requires the Keychain item's data via the attribute kSecValueData to perform the update of the attribute kSecAttrAccessible. According to ADTS, this constraint is currently not documented in the reference documentation.

NSData *encodedIdentifier = [@"BUNDLE_IDENTIFIER"                              dataUsingEncoding:NSUTF8StringEncoding];NSDictionary *query = [NSDictionary dictionaryWithObjectsAndKeys:                       kSecClassGenericPassword, kSecClass,                       encodedIdentifier, kSecAttrGeneric,                       encodedIdentifier, kSecAttrService,                       nil];// Obtain the Keychain item's data via SecItemCopyMatching()NSData *itemData = ...;NSDictionary *updatedAttributes =     [NSDictionary dictionaryWithObjectsAndKeys:        kSecAttrAccessibleAfterFirstUnlock, kSecAttrAccessible,        (CFDataRef)itemData, kSecValueData,        nil];OSStatus updateItemStatus = SecItemUpdate((CFDictionaryRef)query,                                           (CFDictionaryRef)updatedAttributes);// updateItemStatus should have the value errSecSuccess


I was unable to get the other answer to work. I ended up testing kSecAttrAccessibile and if it wasn't what I wanted I recorded the value and attributes in the keychain in local variables, reset the keychain, set kSecAttrAccessible as desired and then set the value and attributes in the keychain to their original settings.