2011-09-11 28 views
4

正在嘗試更新應用程序我必須在iOS5報告其不支持測試版後才能更新應用程序。我們追蹤到的問題是,我們的自定義SSL證書驗證不再有效。SecTrustEvaluate返回iOS 5上的kSecTrustResultRecoverableTrustFailure

在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示例應用程序來重新創建它。

回答

4

問題是證書是MD5簽名。 iOS5不再支持這些簽名。

+0

感謝您的提示。只需要用openssl創建我的根證書req -new -x509 -sha512 ... – Luis

+0

我正在嘗試做幾乎完全相同的事情。但在我的情況中,錨定證書*是服務器所擁有的證書(它是它自己的根證書)。另外,我不在意驗證服務器地址(它是動態分配的)。我的證書是SHA-1 RSA簽名的。我錯過了什麼嗎?我仍然得到錯誤。 – Rick

相關問題