是否可以更新钥匙串物品的kSecAttrAccessible值?
|
是否可以更新钥匙串中现有项目的属性“ 0”的值?在将商品添加到钥匙串后,似乎无法更改。以下步骤支持我的假设。
向钥匙串添加新项目:
NSData *encodedIdentifier = [@\"BUNDLE_IDENTIFIER\"
dataUsingEncoding:NSUTF8StringEncoding];
NSData *encodedPassword = [@\"PASSWORD\"
dataUsingEncoding:NSUTF8StringEncoding];
// Construct a Keychain item
NSDictionary *keychainItem =
[NSDictionary dictionaryWithObjectsAndKeys:
kSecClassGenericPassword, kSecClass,
encodedIdentifier, kSecAttrGeneric,
encodedIdentifier, kSecAttrService,
@\"USERNAME\", kSecAttrAccount,
kSecAttrAccessibleWhenUnlocked, kSecAttrAccessible,
encodedPassword, kSecValueData
nil];
// Add item to Keychain
OSStatus addItemStatus = SecItemAdd((CFDictionaryRef)keychainItem, NULL);
稍后,将属性“ 0”从“ 3”更改为“ 4”:
NSData *encodedIdentifier = [@\"BUNDLE_IDENTIFIER\"
dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *query = [NSDictionary dictionaryWithObjectsAndKeys:
kSecClassGenericPassword, kSecClass,
encodedIdentifier, kSecAttrGeneric,
encodedIdentifier, kSecAttrService,
nil];
NSDictionary *updatedAttributes =
[NSDictionary dictionaryWithObject:kSecAttrAccessibleAfterFirstUnlock
forKey:kSecAttrAccessible];
OSStatus updateItemStatus = SecItemUpdate((CFDictionaryRef)query,
(CFDictionaryRef)updatedAttributes);
这种方法的问题在于,“ 6”总是导致状态“ 7”。
我认为应该可以更新ѭ0的值,因为应用程序的要求会发生变化。如果应用程序过去在没有将保护等级指定为“ 0”的情况下向钥匙串添加了十个项目,该怎么办。如果开发人员未明确设置保护等级,则钥匙串将为新项目隐式分配值“ 3”。以后,开发人员需要将保护级别更改为“ 4”,因为应用程序必须在后台访问它(多任务)。开发人员如何才能做到这一点?
苹果开发者论坛中已经有一个主题,但尚未给出答案:https://devforums.apple.com/thread/87646?tstart=0
没有找到相关结果
已邀请:
2 个回复
艰管垮淮
通过属性
要求钥匙串项目的数据来执行属性
的更新。根据ADTS,此约束当前未在参考文档中记录。
布埃郝卞簿