如何在iOS应用程序中使用客户端证书身份验证
您的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类参考:
我刚才说didreceiveAuthenticationChallenge现在已被弃用吗? http://developer.apple.com/library/ios/#documentation/Foundation/Reference/NSURLConnectionDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intf/NSURLConnectionDelegate任何人都可以点我一个更完整的例子,使用客户端证书来验证请求? – Rory 2013-02-16 22:59:31
在您的应用程序使用客户端证书(如已经回答了前杰克),你必须在你的应用程序中实现你的应用程序钥匙链导入证书。 (请注意,您需要使用PKCS#12证书格式,但您需要在您的应用程序中注册它(搜索导出的UTI和文档类型),并使用不同的扩展名,而不是已由iOS注册的“.p12”。已在我的应用中使用.x-p12)
或者您需要将证书包含在您的应用包中。
在这里看到:iOS Client Certificates and Mobile Device Management
这里:https://developer.apple.com/library/ios/qa/qa1745/_index.html
的可能重复[iPhone:HTTPS客户端证书认证(http://stackoverflow.com/questions/1460626/iphone-https-client-cert -authentication) – 2011-05-20 10:56:53