评估服务器证书

发布于 2024-09-27 09:27:19 字数 1074 浏览 0 评论 0原文

如何检测自签名证书和已撤销或过期的证书?

我正在使用 NSURLConnection 并实现 connection:didReceiveAuthenticationChallenge: on delegate:

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge{
    if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]){
        NSURLProtectionSpace *tmpSpace=[challenge protectionSpace];
        SecTrustRef currentServerTrust=[tmpSpace serverTrust];
        SecTrustResultType trustResult;
        OSStatus err = SecTrustEvaluate(currentServerTrust, &trustResult);
        BOOL trusted = (err == noErr) && ((trustResult == kSecTrustResultProceed) ||                                          (trustResult == kSecTrustResultUnspecified));
        if (trusted){
            // Do something
        }
    }
}

目前“if (trusted){}”块仅适用于 iOS 信任的证书,我希望它也适用于其他人,但前提是证书不是“ t 被撤销或过期。

该文档使用 SecTrustSettingsSetTrustSettings 来更改设置并重新评估信任。但我找不到适用于 iOS 的此方法(或 SecTrustSetting),仅适用于 Mac。

谢谢

How can I detect a self signed certificate from a revoked or expired ones?

I'm using NSURLConnection and implementing connection:didReceiveAuthenticationChallenge: on delegate:

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge{
    if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]){
        NSURLProtectionSpace *tmpSpace=[challenge protectionSpace];
        SecTrustRef currentServerTrust=[tmpSpace serverTrust];
        SecTrustResultType trustResult;
        OSStatus err = SecTrustEvaluate(currentServerTrust, &trustResult);
        BOOL trusted = (err == noErr) && ((trustResult == kSecTrustResultProceed) ||                                          (trustResult == kSecTrustResultUnspecified));
        if (trusted){
            // Do something
        }
    }
}

Currently the "if (trusted){}" block only work for certificates trusted by iOS, I want it to work for others as well, but only if the certificate isn't revoked or expired.

The documentation is using SecTrustSettingsSetTrustSettings for changing the settings and reevaluate the trust. but I couldn't find this method (or the SecTrustSetting) for iOS, only for Mac.

Thanks

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

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

发布评论

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

评论(2

层林尽染 2024-10-04 09:27:20

为了成功进行信任评估,

  1. 您需要在设备上安装锚点(根 CA 证书)。
  2. 或者,您可以使用 SecTrustSetAnchorCertificates() 在运行时指定锚点。

无论哪种情况,您都需要有权访问锚点证书。

For the trust evaluation to succeed,

  1. you need to have the anchor (root CA cert) intalled on the device.
  2. or, you specify an anchor at runtime using SecTrustSetAnchorCertificates().

In either case, you need to have access to the anchor certificate.

烟沫凡尘 2024-10-04 09:27:20

请阅读我关于此问题的帖子:

有关 iOS 上 SSL/TLS 证书吊销机制的详细信息

iOS/Security.Framework 的 CRL 和 OCSP 行为?

基本上:

  • OCSP 用于 EV 证书
  • ,“尽力而为”
  • 是一种阻止操作。

read my post here on this issue:

Details on SSL/TLS certificate revocation mechanisms on iOS

CRL and OCSP behavior of iOS / Security.Framework?

Basically:

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