2014-04-09 73 views
1

我只想信任一個特定的證書+所有的根證書。例如:帶AFNetworking的證書/ SSL固定 - 如果孩子可信,如何信任所有父母證書?

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 

怎麼可能接受根證書嗎?

回答

1

AFNetworking 2.1.0添加了certificate chain validation,默認爲YES(驗證鏈)。您可以禁用它:

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

你的證書是由谷歌的互聯網機構G2 CA頒發,和根CA是全球GeoTrust的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,因此它將證書鏈中的每個證書數據與捆綁中的證書文件進行比較。通常它用於驗證自簽名證書。你應該禁用它。