ios - 在 iOS 上查找证书

标签 ios certificate keychain

请注意,这个问题是在 2001 年提出的。情况已经发生变化。

我有一台 iOS 设备需要访问 Junos VPN。来自 Junos 管理员的不透明说明说我必须检索已使用 Apple IPCU 提供给设备的证书。我知道证书在设备上(我可以在“设置”中看到它)并且我可以通过 Mail、Safari 和 Junos App 访问 VPN。

Apple 文档指出每个应用程序都有自己的钥匙串(keychain),但所有这三个应用程序都可以看到证书。 Jusos 可以访问 IPCU 提供的证书这一事实意味着任何应用程序都可以访问该证书。但是,当我尝试找到它时:

    CFTypeRef   certificateRef = NULL;                                                  // will hold a ref to the cert we're trying to retrieve
const char *certLabelString = "myCertificateName";                                      // c string of the certificate we're searching for.
CFStringRef certLabel = CFStringCreateWithCString( NULL, certLabelString, kCFStringEncodingUTF8); // the search we need - a string match for a UTF8 String.

const void *keys[] =   { kSecClass, kSecAttrLabel, kSecReturnRef };
const void *values[] = { kSecClassCertificate, certLabel, kCFBooleanTrue };
CFDictionaryRef dict = CFDictionaryCreate(NULL, keys, values, 3, NULL, NULL);       // set up a search to retrieve this certificate.
OSStatus status = SecItemCopyMatching(dict, &certificateRef);                               // Search the keychain, returning in dict

if(status != errSecSuccess)
    NSLog(@"keychain find returned %ld", status);

if(dict)
    CFRelease(dict);

它失败了。我的问题:

  • 这段代码是否正确?其实我知道 不是因为 SecItemCopyMatching 返回 errSecItemNotFound

  • 我应该使用什么值 certLabelString - 我假设 人类可读的名称显示在 设置。

在“设置”中,证书看起来像这样(可悲的是被混淆了)我指定的搜索文本正是设置中显示的文本。

alt text

交叉发布到 Apple developer forums

最佳答案

所以答案(在 Apple forums 上)是 mail.app 和 Safari.app 共享 Apple 钥匙串(keychain)标识符,这是唯一可以使用 Apple MDM 工具将证书推送到的钥匙串(keychain)。任何其他反对这个的人都应该 file a defect以鼓励 Apple 做正确的事。

关于ios - 在 iOS 上查找证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4378892/

相关文章:

ios - 如何使用自动布局约束在表格单元格中安装 2 个可变大小的标签,该表格单元格的高度是使用估计的 HeightForRowAtIndexPath 估计的

ios - 在导航栏中按下后退按钮时刷新 RootViewController 的内容

ios - UICollectionView 单元格选择和单元格重用

ssl - 密码学中有哪些不同的证书类型和格式

android - HttpsUrlconnection 连接时接受任何证书

ios - 如何通过 iCloud 同步钥匙串(keychain)

objective-c - 在执行需要在主线程上执行的大量操作时,避免阻塞 UI

visual-studio - 如何通过 Visual Studio 2019、2017 和 2015 为 Windows 10 UWP 应用程序创建有效的可信和/或自签名证书

ios - 尝试将 NSData 写入钥匙串(keychain)时出错

ios - 将其他变量添加到钥匙串(keychain)中