ios - SecItemCopyMatching 与 kSecMatchItemList 失败

标签 ios

我无法让此调用适用于 IOS。我尝试了多种方法,但似乎没有任何效果:我总是获得 errSecParam 状态。谁能告诉我我做错了什么?

我开始使用它来获取我从字节中提取的证书的属性列表。那没有用,所以我将其简化为这个并收到相同的错误。我在模拟器和 iPhone6 上进行了测试,得到了相同的结果。

首先,我获得一组证书,然后将该数组传递回 SecItemCopyMatching。我试过这个,我只查询属性并得到相同的错误。

我是 IOS 的新手,所以我不怀疑这是我错过的东西。

谢谢。

// Call SecItemCopyMatching twice: the first time fetch an array of certificates
// and the second time use the array with kSecMatchItemList.
- (void) SecItemCopyMatchingTest2 {

    // Now read them from the keychain.
    NSMutableDictionary *query = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                  (__bridge id)kSecClassCertificate,(__bridge id)kSecClass,
                                  (__bridge id)kCFBooleanTrue, (__bridge id)kSecReturnRef,
                                  (__bridge id)kSecMatchLimitAll, (__bridge id)kSecMatchLimit,
                                  nil];
    CFTypeRef result;
    OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)query, &result);
    NSArray *rgRefs = CFBridgingRelease(result);
    if (status == noErr){
        // this works
    }

   // Use the array we received from our previous call
    [query setObject:rgRefs forKey:(__bridge id)kSecMatchItemList];

    CFTypeRef result2;
    // Results in status = errSecParam
    status = SecItemCopyMatching((__bridge CFDictionaryRef)query, &result2);
    if (status == errSecParam){
        // the cal fails.
    }
}

最佳答案

引自头文件文档:

@constant kSecMatchItemList OS X only. Specifies a dictionary key whose value is a CFArray of SecKeychainItemRef items. If provided, returned items will be limited to the subset which are contained in this list.

我知道 __OSX_AVAILABLE_STARTING 声称它存在于 iOS,但这是一个谎言,在邮件列表中,一位 Apple 开发人员声称它从未为 iOS 实现。

尝试使用 kSecUseItemList 设置相同的数组。根据邮件列表,这在当时也没有为 iOS 实现,但如果 Apple 打算为 iOS 实现其中一个(或已经这样做),那么它就是 kSecUseItemList

macOS 和 iOS 之间存在许多奇怪的钥匙串(keychain) API 差异,其中一些差异仅存在于文档或头文件中。这是 SecItemDelete() 删除文档中的另一个示例:

To delete an item identified by a transient reference, on iOS, specify kSecValueRef with a item reference. On OS X, give a kSecMatchItemList containing an item reference.

尝试在 iOS 上使用 kSecMatchItemList 会失败,就像在 macOS 上使用 kSecValueRef 似乎会失败一样。这些 API 差异对我来说没有任何意义,但要么你可以使用 kSecUseItemList 来完成,要么你运气不好,这在​​ iOS 上根本不可能。

关于ios - SecItemCopyMatching 与 kSecMatchItemList 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30448481/

相关文章:

ios - 应用商店评论

ios - 在已经在其他地方分配/初始化之后,如何从 XIB 重新加载 View ?

iphone - ShareKit API 变更

iOS 核心数据 executeFetchRequest 返回空对象

ios - 如何在 SplitView Controller 中隐藏和取消隐藏主视图 Controller

ios - 如果我的分发证书过期会怎样?

ios - 如何同时显示聊天 UI 的文本和按钮

ios - 我可以使用 3D Touch 在 iOS 上为手势添加反馈(凹口)吗?

ios - 使用 AVAssetExportSession 合成和导出后视频持续时间发生变化

ios - 如何删除 Firebase 存储文件?