在通过CN删除证书的简单方法中(证书以前由SecItemAdd从PKCS12导入中放置在那里(;我收到错误:
属性列表的格式无效:200(属性列表不能包含类型为"SecIdentity"的对象(
根据 https://developer.apple.com/documentation/security/1395547-secitemdelete 我认为我正在遵循说明:
要删除由瞬态引用标识的项,请指定 kSecMatchItemList 搜索键,其中包含通过使用 kSecReturnRef 返回类型键在上一次调用 SecItemCopyMatch 或 SecItemAdd 函数。
到信。代码如下:
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)
我做错了什么?
头文件中找到的文档 SecItem.h
,安全框架的一部分:
默认情况下,此函数删除与指定查询匹配的所有项目。 您可以通过指定以下键之一来更改此行为:
若要删除由瞬态引用标识的项目,请在 iOS 上, 使用项引用指定 kSecValueRef。在 OS X 上,给出 kSecMatchItemList 包含一个项目引用。
若要删除由持久引用标识的项目,请在 iOS 上, 使用 返回的持久引用指定 kSecValuePersistentRef 使用 kSecReturnPersistentRef 键到 SecItemCopyMatch 或 SecItemAdd.在 OSX 上,将 kSecMatchItemList 与持久引用一起使用 通过使用 kSecReturnPersistentRef 键返回 SecItemCopyMatch 或 SecItemAdd.
这已在最新的 GM 下降中修复。现实现在与文档同步。