2010-10-11 122 views
2

我如何可以檢測從撤銷或已過期自簽名證書評估服務器證書

我使用NSURLConnection的貫徹連接:didReceiveAuthenticationChallenge:對委託:

- (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 
     } 
    } 
} 

目前,「如果(信任){}」塊僅通過iOS的信任證書的工作,我希望它的工作其他人也是如此,但前提是證書未被撤銷或過期。

的文檔使用SecTrustSettingsSetTrustSettings更改設置並重新評估信任。但我找不到iOS的此方法(或SecTrustSetting),僅適用於Mac。

感謝

回答

0

的信任評價獲得成功,

  1. 你需要有龍頭安裝在設備上的錨(根CA證書)。
  2. 或者,您在運行時使用SecTrustSetAnchorCertificates指定錨點()。

在這兩種情況下,你需要訪問到錨證書。