【问题标题】:SecTrustEvaluate returns kSecTrustResultRecoverableTrustFailure on iOS 5SecTrustEvaluate 在 iOS 5 上返回 kSecTrustResultRecoverableTrustFailure
【发布时间】:2011-11-14 17:59:50
【问题描述】:

在报告无法使用测试版后,我必须将应用程序更新到 iOS5。问题的根源在于我们的自定义 SSL 证书验证不再有效。

在 didReceiveAuthenticationChallenge 部分,我们获取根证书并调用 SecTrustEvaluate。这在 iOS4 上运行良好。

protectionSpace = [challenge protectionSpace];
    trust = [protectionSpace serverTrust];

    err = SecTrustEvaluate(trust, &trustResult);

    trusted = (err == noErr) && ((trustResult == kSecTrustResultProceed) || (trustResult == kSecTrustResultUnspecified));

    if (!trusted) { 
        err = SecTrustSetAnchorCertificates(trust, (CFArrayRef)[EagleAccessAppDelegate getDelegate].rootCertificates);

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

        trusted = (err == noErr) && ((trustResult == kSecTrustResultProceed) || (trustResult == kSecTrustResultUnspecified));
    }

    if (trusted) { 
        NSURLCredential *cred = [NSURLCredential credentialForTrust:trust];
        [[challenge sender] useCredential:cred forAuthenticationChallenge:challenge];
    } else { 
        [[challenge sender] cancelAuthenticationChallenge:challenge];
    }

证书以 DER 格式存储为应用程序中包含的资源。

// Load Certificates. 
NSString *devFilePath = [[NSBundle mainBundle] pathForResource:@"ipms-dev-ca.der" ofType:@"crt"];  
NSData *devRootCertificate = [[[NSData alloc] initWithContentsOfFile:devFilePath] autorelease];
SecCertificateRef devRoot = SecCertificateCreateWithData(NULL, (CFDataRef) devRootCertificate);

NSString *prodFilePath = [[NSBundle mainBundle] pathForResource:@"ipms-prod-ca.der" ofType:@"crt"];  
NSData *prodRootCertificate = [[[NSData alloc] initWithContentsOfFile:prodFilePath] autorelease];
SecCertificateRef prodRoot = SecCertificateCreateWithData(NULL, (CFDataRef) prodRootCertificate);

self.rootCertificates = [[NSArray alloc] initWithObjects:(id)devRoot, (id)prodRoot, nil];

我们基本上有自己的 CA 证书,我们用它来为我们的应用连接到的服务器颁发证书。

我可以使用 AdvancedURLConnections 示例应用程序重新创建它。

【问题讨论】:

    标签: ios pki


    【解决方案1】:

    问题是证书是 MD5 签名。 iOS5 不再支持这些签名。

    【讨论】:

    • 感谢您的提示。只需要使用 openssl req -new -x509 -sha512 创建我的根证书 ...
    • 我正在尝试做几乎完全相同的事情。但是,在我的情况下,锚证书 服务器拥有的证书(它是它自己的根证书)。另外,我不在乎验证服务器地址(它是动态分配的)。我的证书是 SHA-1 RSA 签名的。我错过了什么吗?我仍然得到错误。
    猜你喜欢
    • 2017-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-06
    • 2015-10-06
    • 2015-01-27
    相关资源
    最近更新 更多