【问题标题】:ios/SecItemDelete not accepting a SecIdentityRef/kSecMatchItemListios/SecItemDelete 不接受 SecIdentityRef/kSecMatchItemList
【发布时间】:2012-05-17 23:31:52
【问题描述】:

通过 CN 删除证书的简单方法(之前已由 SecItemAdd 从 PKCS12 导入中将证书放在那里);我收到错误消息:

属性列表格式无效:200(属性列表不能包含“SecIdentity”类型的对象)

在哪里基于https://developer.apple.com/documentation/security/1395547-secitemdelete 我想我正在按照说明进行操作:

要删除由临时引用标识的项目,请指定 kSecMatchItemList 搜索键和使用返回的引用 kSecReturnRef 返回类型键在上一次调用 SecItemCopyMatching 或 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)

我做错了什么?

【问题讨论】:

    标签: iphone ios x509 pki


    【解决方案1】:

    引用头文件SecItem.h 中的文档,它是安全框架的一部分:

    默认情况下,此函数会删除与指定查询匹配的所有项目。 您可以通过指定以下键之一来更改此行为:

    • 要删除由临时引用标识的项目,在 iOS 上, 使用项目引用指定 kSecValueRef在 OS X 上,给一个 kSecMatchItemList 包含项目引用。

    • 要删除由持久引用标识的项目,在 iOS 上, 使用返回的持久引用指定 kSecValuePersistentRef 使用 kSecReturnPersistentRef 键到 SecItemCopyMatching 或 SecItemAdd。 在 OSX 上,使用带有持久引用的 kSecMatchItemList 通过使用 kSecReturnPersistentRef 键返回 SecItemCopyMatching 或 SecItemAdd。

    【讨论】:

      【解决方案2】:

      这已在最新的 GM 掉落中得到修复。现实现在与文档同步。

      【讨论】:

      • 我在 iOS 6.1.3 和 iOS 7.1 下遇到了同样的故障。 SecItemDelete 是否仍然适用于您的匹配项列表?
      猜你喜欢
      • 2020-11-18
      • 1970-01-01
      • 2012-12-29
      • 1970-01-01
      • 1970-01-01
      • 2014-02-11
      • 2012-09-25
      • 2013-11-22
      • 2011-12-13
      相关资源
      最近更新 更多