在iOS上查找证书

注意这个问题在2001年被问到。事情已经改变了。

我有一个需要访问Junos VPN的iOS设备。 来自Junospipe理员的不透明指令表示,我必须检索已使用Apple IPCU提供给设备的证书。 我知道证书是在设备上(我可以在设置中看到它),我可以通过Mail,Safari和Junos App访问VPN。

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

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 – 我假设设置中显示的人类可读的名称。

在“设置”中,证书看起来像这样(可悲地被混淆到死亡),我指定的search文本恰好是设置中显示的文本。

替代文字

Cross发布到苹果开发者论坛

所以答案(在苹果论坛上 )是mail.app和Safari.app共享Apple Keychain标识符,这是唯一可以将证书推送到Apple MDM工具的钥匙串。 任何其他反对此事的人都应该提出缺陷 ,以鼓励苹果公司做正确的事情。

自2015年中以来,现在有了Safari Services framework (在WKWebViewUIWebView旁边,我们现在有一个SFSafariViewController )。 SFSafariViewController有能力访问苹果钥匙串,因此可以使用所有的身份:)非常好。

https://developer.apple.com/videos/play/wwdc2015/504/

https://developer.apple.com/library/ios/documentation/SafariServices/Reference/SafariServicesFramework_Ref/index.html#//apple_ref/doc/uid/TP40016218