【问题标题】:Evaluating server certificate评估服务器证书
【发布时间】:2011-04-23 16:51:46
【问题描述】:

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

我正在使用 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 信任的证书,我希望它也适用于其他人,但前提是证书没有被撤销或过期。

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

谢谢

【问题讨论】:

    标签: iphone security certificate


    【解决方案1】:

    为了使信任评估成功,

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

    在任何一种情况下,您都需要访问锚证书。

    【讨论】:

      【解决方案2】:

      阅读我关于这个问题的帖子:

      Details on SSL/TLS certificate revocation mechanisms on iOS

      CRL and OCSP behavior of iOS / Security.Framework?

      基本上:

      • OCSP 用于 EV 证书
      • “尽力而为”
      • 是一个阻塞操作。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-09
        • 2021-10-03
        • 2013-10-18
        • 1970-01-01
        • 1970-01-01
        • 2014-09-05
        相关资源
        最近更新 更多