如何在iOS中检索ssl服务器证书?

发布于 2024-10-19 09:53:09 字数 288 浏览 0 评论 0原文

我希望能够获得 ssl 证书(如果可能的话+链),以便能够显示可分辨名称并确定它是否是 EV 证书。 (通过证书策略检测 EV 证书(wikipedia

据我所知,您只能得到如果证书是自签名的,

是否可以使用 CFNetwork 等较低层来检索证书?

I'd like to be able to get the ssl certificate (+chain if possible) to be able to display the distinguished name and to determine if it is an EV certificate. (detecting EV certs via certificate policies (wikipedia)

From what I've seen you only get presented with some certificate details if the certificate is self-signed.

Is it possible using lower layers like CFNetwork to retrieve the certificate(s)?

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

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

发布评论

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

评论(1

深海不蓝 2024-10-26 09:53:09

通过 macnetworkprog.lists.apple.com 邮件列表
http://web.archiveorange.com/archive/v/x0fiWEI9emJFc36DY0UP 并提到了开发者论坛中的一些地方

好吧,默认的 TLS 安全策略应该足够了,但是如果
你想参与这个过程你可以这样做(在 iPhone OS 上)
3.0 及更高版本,以及 Mac OS X 10.6),通过实现
-connection:canAuthenticateAgainstProtectionSpace:
-connection:didReceiveAuthenticationChallenge: 委托回调,
寻找 NSURLAuthenticationMethodServerTrust 身份验证
方法。

为此,请执行以下操作:

  1. 实现 -connection:canAuthenticateAgainstProtectionSpace: 委托回调。

  2. 在您的实现中,如果
    保护空间是NSURLAuthenticationMethodServerTrust,你有
    两个选择:

    2a。返回NO,并让默认的 TLS 算法生效。

    2b。返回 YES,在这种情况下,您的 -connection:didReceiveAuthenticationChallenge: 委托回调将被调用。

如果您想在制作之前查看证书
决定时,您可以在保护空间对象上调用-serverTrust
获取信任对象,然后使用 SecTrust API 获取
证书链。

  1. 如果您采用路径 2b,您的 -connection:didReceiveAuthenticationChallenge: 委托回调将被调用。您有两个选择:

    3a。通过对质询的发送者调用 -cancelAuthenticationChallenge: 来禁止连接。

    3b。通过对质询的发送者调用 -useCredential:forAuthenticationChallenge: 来允许连接。要获取凭据,请调用 -[NSURLCredential initWithTrust:]。实际上,您在这里传递什么信任对象并不重要;保护空间中的即可。

您不必同步执行此操作。你可以只锁住
挑战并从您的委托回调中返回,然后解决
在未来的某个时刻挑战。

via the macnetworkprog.lists.apple.com mailing list
http://web.archiveorange.com/archive/v/x0fiWEI9emJFc36DY0UP and mentioned a few places in the Developer Forums

Well, the default TLS security policy should be sufficient, but if
you want to get involved in this process you can do so (on iPhone OS
3.0 and later, and Mac OS X 10.6) by implementing the
-connection:canAuthenticateAgainstProtectionSpace: and
-connection:didReceiveAuthenticationChallenge: delegate callbacks,
looking for an NSURLAuthenticationMethodServerTrust authentication
method.

To do this:

  1. Implement the -connection:canAuthenticateAgainstProtectionSpace: delegate callback.

  2. In your implementation, if the authentication method of the
    protection space is NSURLAuthenticationMethodServerTrust, you have
    two choices:

    2a. Return NO, and let the default TLS algorithm kick in.

    2b. Return YES, in which case your -connection:didReceiveAuthenticationChallenge: delegate callback will be called.

If you want to look at the certificates before you make that
decision, you can call -serverTrust on the protection space object to
get a trust object, and then use the SecTrust API to get the
certificate chain.

  1. If you take path 2b, your -connection:didReceiveAuthenticationChallenge: delegate callback will be called. You have two choices:

    3a. Disallow the connection by calling -cancelAuthenticationChallenge: on the challenge's sender.

    3b. Allow the connection by calling -useCredential:forAuthenticationChallenge: on the challenge's sender. To get a credential, call -[NSURLCredential initWithTrust:]. It doesn't actually matter what trust object you pass in here; the one from the protection space will do.

You don't have to do this synchronously. You can just latch the
challenge and return from your delegate callback and then resolve the
challenge at some point in the future.

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