在一个简单的方法中通过CN删除Certs(之前由SecItemAdd从PKCS12导入中放置了证书);我收到错误:
属性列表格式无效:200(属性列表不能包含'SecIdentity'类型的对象)
基于https://developer.apple.com/documentation/security/1395547-secitemdelete的地方,我想我遵循的指示:
要删除由瞬态引用标识的项,请在先前对SecItemCopyMatching或SecItemAdd函数的调用中使用kSecReturnRef返回类型键指定kSecMatchItemList搜索键和返回的引用。
致信。代码如下:
NSDictionary * attributes;
NSString * cnString = @"/CN=foo";
attributes = [NSDictionary dictionaryWithObjectsAndKeys:
(__bridge id)(kSecClassIdentity), kSecClass,
cnString, kSecMatchSubjectContains,
kSecMatchLimitAll, kSecMatchLimit,
kCFBooleanTrue, kSecReturnRef,
nil];
CFArrayRef result;
status = SecItemCopyMatching((__bridge CFDictionaryRef)(attributes),
(CFTypeRef *)&result);
if (status == noErr) {
for(int i = 0; i < CFArrayGetCount(result); i++) {
SecIdentityRef item = (SecIdentityRef) CFArrayGetValueAtIndex(result, i);
NSLog(@"Item #%d: %@", i, item);
attributes = [NSDictionary dictionaryWithObjectsAndKeys:
(__bridge id)(kSecClassIdentity), kSecClass,
[NSArray arrayWithObject:(__bridge id)item], kSecMatchItemList,
kSecMatchLimitOne, kSecMatchLimit,
nil];
status = SecItemDelete((__bridge CFDictionaryRef)(attributes));
if (status != noErr || status != errSecItemNotFound)
NSLog(@"Delete %d/%@failed: %ld (ignored)", i,item, status);
};
};
控制台上的输出是:
Item #0: <SecIdentityRef: 0xc7359ff0>
在查找之后直接(如果搜索扩大,我们得到这些的数组)。
然后从Security.dylib内部深处:
属性列表格式无效:200(属性列表不能包含'SecIdentity'类型的对象)
最终保释:
Delete 0/<SecIdentityRef: 0xc7359ff0>failed: -50 (ignored)
我究竟做错了什么?
这已在最新的GM下降中得到修复。现在现在与文档同步。
引用头文件SecItem.h
中的文档,它是安全框架的一部分:
默认情况下,此函数删除与指定查询匹配的所有项。您可以通过指定以下其中一个键来更改此行为:
- 要删除由瞬态引用标识的项目,请在iOS上使用项目引用指定kSecValueRef。在OS X上,提供包含项引用的kSecMatchItemList。
- 要删除由持久性引用标识的项,请在iOS上指定kSecValuePersistentRef,其中包含使用kSecReturnPersistentRef键返回到SecItemCopyMatching或SecItemAdd的持久引用。在OSX上,使用kSecMatchItemList和使用带有SecItemCopyMatching或SecItemAdd的kSecReturnPersistentRef键返回的持久引用。