Authentication 如何在iOS应用程序中使用客户端证书身份验证

Authentication 如何在iOS应用程序中使用客户端证书身份验证,authentication,client,ios,certificate,Authentication,Client,Ios,Certificate,我对客户端证书身份验证没有太多经验。谁能告诉我如何在iOS应用程序中使用它?谢谢:)您的NSURLConnection委托应响应连接:didReceiveAuthenticationChallenge:委托方法(请参阅下面的链接) : 它应该通过询问其“发送者”的质询并向其提供适当的凭证来响应 比如: - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthentic

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

您的NSURLConnection委托应响应
连接: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)

或者,您需要将证书包含在应用程序包中

请看这里:


这里:

我说的didReceiveAuthenticationChallenge现在不推荐了,对吗?有人能给我举一个更完整的使用客户端证书对请求进行身份验证的例子吗?