使用AFNetworking进行证书/ SSL固定 - 如果孩子信任,如何信任所有父母证书?

时间:2014-04-09 23:35:24

标签: ios ssl ssl-certificate afnetworking afnetworking-2

我只想信任特定证书+所有根证书。例如:

GeoTrust Global CA               <= Automatically trusted
    Google Internet Authority G2 <= Automatically trusted
        *.google.com             <= Trusted because in a .cer in the app bundle

但AFNetworking 2.2.1现在发生的是:

GeoTrust Global CA               <= Not trusted because not in the bundle
    Google Internet Authority G2 <= Not trusted because not in the bundle
        *.google.com             <= Trusted because in a .cer in the app bundle

如何接受根证书呢?

2 个答案:

答案 0 :(得分:2)

您的证书由Google Internet Authority G2 CA颁发,而根CA是GeoTrust Global CA,因此iOS应该信任该证书。确实如此。

您可以在此处查看“List of available trusted root certificates”。

https://developer.apple.com/library/ios/documentation/Security/Reference/certifkeytrustservices/#//apple_ref/c/func/SecTrustEvaluate

  

SecTrustEvaluate函数根据信任管理对象中包含的策略,通过验证证书的签名以及证书链中证书的签名(最多为锚证书)来验证证书。

     

如果信任管理对象中缺少验证叶证书所需的某些证书​​,则SecTrustEvaluate会在以下位置搜索证书:

     
      
  • 当前在来电者钥匙串搜索列表中的任何钥匙串中(请参阅SecTrustSetKeychains)。
  •   
  • 以前通过调用SecTrustSetAnchorCertificates提供的任何证书。
  •   
  • 在为此目的提供的系统提供的一组钥匙链中。
  •   
  • 如果用于构建链的证书中存在某些扩展名,则通过网络。
  •   

因此,如果SecTrustEvaluate返回errSecSuccess并且结果是kSecTrustResultUnspecified / kSecTrustResultProceed,那么它已经信任证书链。

在您的情况下,validatesCertificateChain为YES,因此它将证书链中的每个证书数据与捆绑包中的证书文件进行比较。通常它用于验证自签名证书。你应该禁用它。

答案 1 :(得分:1)

AFNetworking 2.1.0添加了certificate chain validation,默认为YES(验证链)。你可以禁用它:

// policy used by AFHTTPRequestOperation / AFHTTPRequestOperationManager
AFSecurityPolicy *securityPolicy = somePolicy; 
securityPolicy.validatesCertificateChain = NO;