【发布时间】:2011-04-14 13:08:16
【问题描述】:
我没有太多关于客户端证书身份验证的经验。谁能告诉我如何在 iOS 应用程序中使用它?谢谢:)
【问题讨论】:
标签: authentication client ios certificate
我没有太多关于客户端证书身份验证的经验。谁能告诉我如何在 iOS 应用程序中使用它?谢谢:)
【问题讨论】:
标签: authentication client ios certificate
您的 NSURLConnection 委托应该响应 connection:didReceiveAuthenticationChallenge: 委托方法(参见下面的链接)。
它应该通过询问其“发送者”的质询并为其提供适当的凭据来响应。
类似:
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
id sender = [challenge sender];
// create a credential from a certificate
// see doco for details of the parameters
NSURLCredential *creds = [NSURLCredential credentialWithIdentity:ident certificates:certs persistence:persistence];
[sender useCredential:creds forAuthenticationChallenge:challenge];
}
请参阅 NSURLCredential 类参考,了解如何根据证书创建凭据:
【讨论】:
在您的应用程序中使用客户端证书之前(正如 Jake 已回答的那样),您必须在您的应用程序中将证书导入到您的应用程序钥匙串。 (注意您需要使用 PKCS#12 证书格式,但您需要在您的应用程序中注册它(搜索导出的 UTI 和文档类型),扩展名不同,而不是“.p12”,它已经被 iOS 注册了。我在我的应用中使用过 .x-p12)
或者您需要将证书包含在您的应用程序包中。
请看这里:iOS Client Certificates and Mobile Device Management
这里:https://developer.apple.com/library/ios/qa/qa1745/_index.html
【讨论】: