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

发布于 2024-09-24 10:37:38 字数 52 浏览 0 评论 0原文

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

I don't have a lot experience about Client Certificate Authentication. Anybody can tell me how to use it in iOS app? Thanks :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暮倦 2024-10-01 10:37:38

您的 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 类参考:

Your NSURLConnection delegate should respond to the connection:didReceiveAuthenticationChallenge: delegate method (see link below).

http://developer.apple.com/library/ios/documentation/cocoa/reference/foundation/Classes/NSURLConnection_Class/Reference/Reference.html#//apple_ref/occ/instm/NSObject/connection:didReceiveAuthenticationChallenge:

It should respond by asking the challenge for its 'sender' and providing it with an appropriate credential.

Something like:

- (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];
}

See the NSURLCredential class reference for details of how to create a credential based on a certificate:

痴梦一场 2024-10-01 10:37:38

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

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

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

和此处:< a href="https://developer.apple.com/library/ios/qa/qa1745/_index.html" rel="nofollow noreferrer">https://developer.apple.com/library/ios/qa/qa1745 /_index.html

Before using client certificates in your app (as already answered by Jake) you have to implement import of certificate within your app to your app keychain. (note you need to use PKCS#12 certificate format, but you need to register it in your app (search for exported UTIs and Document types) with different extension, other than ".p12", which is already registered by the iOS. I've used .x-p12 in my app)

Or you need to include the certificate with your app bundle.

See here: iOS Client Certificates and Mobile Device Management

and here: https://developer.apple.com/library/ios/qa/qa1745/_index.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文