如何在iOS App中使用客户端证书身份验证

时间:2010-09-20 07:33:38

标签: authentication client ios certificate

我对客户端证书身份验证没有太多经验。任何人都可以告诉我如何在iOS应用程序中使用它?谢谢:))

2 个答案:

答案 0 :(得分:18)

您的 NSURLConnection 委托应该响应connection:didReceiveAuthenticationChallenge:委托方法(请参阅下面的链接)。

http://developer.apple.com/library/ios/documentation/cocoa/reference/foundation/Classes/NSURLConnection_Class/Reference/Reference.html#//apple_ref/occ/instm/NSObject/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 类参考:

答案 1 :(得分:3)

在您的应用中使用客户端证书之前(已经由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