请注意,这个问题是在 2001 年提出的。情况发生了变化。
我有一台需要访问 Junos VPN 的 iOS 设备。Junos 管理员的不透明说明说我必须检索已使用 Apple IPCU 配置到设备的证书。我知道证书在设备上(我可以在“设置”中看到),我可以通过 Mail、Safari 和 Junos App 访问 VPN。
Apple 文档声明每个应用程序都有自己的钥匙串,但所有这三个应用程序都可以看到证书。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
- 我假设设置中显示的人类可读名称。
在设置中,证书看起来像这样(可悲的是被混淆了)我指定的搜索文本正是设置中显示的文本。
Cross 发布到Apple 开发者论坛