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

ase*_*_le 13 authentication client certificate ios

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

小智 19

您的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];
}
Run Code Online (Sandbox Code Playgroud)

有关如何基于证书创建凭据的详细信息,请参阅NSURLCredential类参考: