2012-05-09 2 views
4

ASIHTTPRequest v1.8.1을 사용하여 HTTPS 요청을하고 있습니다. 문제는 iOS 5.0 & 5.0.1에서는 작동하지 않지만 5.1 & 5.1.1에서는 제대로 작동한다는 것입니다. 코드는 매우 간단하다 : 나는 이것에 대해 무엇을 할 수iOS 5.0/5.0.1에서 SSL을 사용한 ASIHTTP 요청이 실패했습니다.

error = Error Domain=ASIHTTPRequestErrorDomain Code=1 "A connection failure occurred: SSL problem (Possible causes may include a bad/expired/self-signed certificate, clock set to wrong date)" UserInfo=0x18460b0 {NSUnderlyingError=0x1853ab0 "The operation couldn’t be completed. (OSStatus error -9800.)", NSLocalizedDescription=A connection failure occurred: SSL problem (Possible causes may include a bad/expired/self-signed certificate, clock set to wrong date)} 

:

__block ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:RemoteNotiURL]]; 
[request setPostValue:@"i" forKey:@"plat"]; 
[request setPostValue:token forKey:@"token"]; 
[request setValidatesSecureCertificate:NO]; 

[request setCompletionBlock:^{ 
    NSLog(@"done"); 
}]; 

[request setFailedBlock:^{ 
    NSLog(@"error = %@", [request error]); 

}]; 

[request startAsynchronous]; 

RemoteNotiURLhttps://xxx.example.com

오류와 같은 URL은 무엇입니까?

+0

관련이있을 수 있습니다 : http://stackoverflow.com/questions/7792949/ios-5-https-asihttprequest-stop-working – JosephH

답변

13

@JosephH는 sslProperties 사전의 kCFStreamSSLLevel 등록 정보를 변경하기 위해 ASIHTTPRequest.m을 수정해야한다고 설명했습니다. 이 댓글에서 댓글 // Tell CFNetwork not to validate SSL certificates

이 파일의 모습에 절

if (![self validatesSecureCertificate]) { 
     // see: http://iphonedevelopment.blogspot.com/2010/05/nsstream-tcp-and-ssl.html 

     NSDictionary *sslProperties = [[NSDictionary alloc] initWithObjectsAndKeys: 
             [NSNumber numberWithBool:YES], kCFStreamSSLAllowsExpiredCertificates, 
             [NSNumber numberWithBool:YES], kCFStreamSSLAllowsAnyRoot, 
             [NSNumber numberWithBool:NO], kCFStreamSSLValidatesCertificateChain, 
             kCFNull,kCFStreamSSLPeerName, 
             nil]; 

     CFReadStreamSetProperty((CFReadStreamRef)[self readStream], 
           kCFStreamPropertySSLSettings, 
           (CFTypeRef)sslProperties); 
     [sslProperties release]; 
    } 

이해야한다 그래서

if (![self validatesSecureCertificate]) { 
     // see: http://iphonedevelopment.blogspot.com/2010/05/nsstream-tcp-and-ssl.html 

     NSDictionary *sslProperties = [[NSDictionary alloc] initWithObjectsAndKeys: 
             [NSNumber numberWithBool:YES], kCFStreamSSLAllowsExpiredCertificates, 
             [NSNumber numberWithBool:YES], kCFStreamSSLAllowsAnyRoot, 
             [NSNumber numberWithBool:NO], kCFStreamSSLValidatesCertificateChain, 
             kCFNull,kCFStreamSSLPeerName, 
             @"kCFStreamSocketSecurityLevelTLSv1_0SSLv3", kCFStreamSSLLevel, 
             nil]; 

     CFReadStreamSetProperty((CFReadStreamRef)[self readStream], 
           kCFStreamPropertySSLSettings, 
           (CFTypeRef)sslProperties); 
     [sslProperties release]; 
    }else { 
     NSDictionary *sslProperties = [[NSDictionary alloc] initWithObjectsAndKeys: 
             [NSNumber numberWithBool:NO], kCFStreamSSLAllowsExpiredCertificates, 
             [NSNumber numberWithBool:NO], kCFStreamSSLAllowsAnyRoot, 
             [NSNumber numberWithBool:YES], kCFStreamSSLValidatesCertificateChain, 
             @"kCFStreamSocketSecurityLevelTLSv1_0SSLv3", kCFStreamSSLLevel, 
             nil]; 

     CFReadStreamSetProperty((CFReadStreamRef)[self readStream], 
           kCFStreamPropertySSLSettings, 
           (CFTypeRef)sslProperties); 
     [sslProperties release]; 
    } 

이 같은 경우 절을 수정 경우 요청이 다시 작동있다. SSL 인증서의 유효성을 검사하는 요청과 유효성을 검사하지 않는 요청.

IOS 5.0.1 및 5.1.1에서 테스트되었습니다.

희망이 도움이됩니다.

+2

이 작품은 나를 위해! 감사! 나를 위해 –

+0

너무, 위대한! 이것에 대해 – tomsoft

+0

감사합니다. 알아내는 데 시간이 좀 걸렸을거야. – ilyashev

관련 문제