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

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

你的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]; } 

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

在您的应用程序中使用客户端证书之前(正如Jake已经回答的那样),您必须在您的应用程序中将证书导入到您的应用程序钥匙串中。 (注意,您需要使用PKCS#12证书格式,但是您需要在您的应用程序(search导出的UTI和文档types)中注册不同的扩展名,而不是已经由iOS注册的“.p12”。已经在我的应用程序中使用了.x-p12)

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

请参阅此处: iOS客户端证书和移动设备pipe理

并在这里: https : //developer.apple.com/library/ios/qa/qa1745/_index.html