【发布时间】: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