【问题标题】:Continuously getting kSecTrustResultRecoverableTrustFailure while trust evaluation - iphone在信任评估时不断获取 kSecTrustResultRecoverableTrustFailure - iphone
【发布时间】:2011-03-17 15:07:24
【问题描述】:

我想安全地与我的服务器通信,这就是我正在做的事情......

NSURLProtectionSpace *protectionSpace = [challenge protectionSpace];
SecTrustRef trust = [protectionSpace serverTrust];
NSURLCredential *credential = [NSURLCredential credentialForTrust:trust];

    SecPolicyRef myPolicy = SecPolicyCreateBasicX509();

NSArray * certs = [[NSArray alloc] initWithObjects:(id)certificate,nil]; //certificate is my server's cert.
credential = [NSURLCredential credentialForTrust:trust];

    SecTrustSetAnchorCertificates(trust,
                                  (CFArrayRef) [NSArray arrayWithObject:(id) certificate ]);    

OSStatus status = SecTrustCreateWithCertificates(certs, myPolicy, &trust);

SecTrustResultType trustResult = 0;

if (status == noErr) {
    status = SecTrustEvaluate(trust, &trustResult);
}

    NSLog(@"Trust I get: %d", trustResult);
[certs release];

if (trustResult == kSecTrustResultRecoverableTrustFailure) {
    NSLog(@"Recoverable Failure");
    CFAbsoluteTime trustTime,currentTime,timeIncrement,newTime;
    CFDateRef newDate;

    trustTime = SecTrustGetVerifyTime(trust);             
    timeIncrement = 31536000;                               
    currentTime = CFAbsoluteTimeGetCurrent();              
    newTime = currentTime - timeIncrement;                  
    if (trustTime - newTime){                               
        newDate = CFDateCreate(NULL, newTime);              
        SecTrustSetVerifyDate(trust, newDate);            
        status = SecTrustEvaluate(trust, &trustResult);   
    }
    NSLog(@"Trust again:%d", trustResult);// AGAIN kSecTrustResultRecoverableTrustFailure(5) over here

}

任何人都知道它为什么会发生...... 似乎这与证书的到期无关(实际上也不是),但可能是原因。

谢谢

al

【问题讨论】:

  • 任何 1 关心回复 :p ?
  • 我也有同样的问题。

标签: ios4 ssl certificate security-framework


【解决方案1】:

SecTrustResultRecoverableTrustFailure 如果发生

  • 证书是 md5 散列 (IOS5)
  • 服务器不提供根证书和中间证书
  • SecTrustSetAnchorCertificatesOnly(trust,YES) 已设置,并且锚点证书仅在内置锚点证书中
  • 证书已过期
  • ?

我通过将网络服务器配置为发送整个证书链而不是仅发送服务器证书解决了我的问题。

通过配置我的 apache mod_ssl: https://httpd.apache.org/docs/2.2/mod/mod_ssl.html#sslcertificatechainfile

【讨论】:

  • 如何配置apache服务器发送整个证书链?
  • 谁能回答新人的问题?我和他在同一条船上......谢谢
  • 取决于您使用的网络服务器。 httpd.apache.org/docs/2.2/mod/… 可能会帮助您处理 apache。
猜你喜欢
  • 2012-05-07
  • 2018-10-04
  • 1970-01-01
  • 1970-01-01
  • 2018-07-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多