Dar*_*ren 14 ssl https self-signed afnetworking ios8
我的应用程序只是连接到家庭设备上的Web服务器并读取一些HTML.它在使用http时工作正常,但现在在iOS 8上使用https时它不起作用.
我使用AFNetworkingv1并使用这些覆盖方法覆盖SSL检查(是的,我知道在正常情况下这不应该完成并且是不安全的等等..但这是另一个主题).
[self setAuthenticationChallengeBlock:^(NSURLConnection *connection, NSURLAuthenticationChallenge *challenge) {
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
}
}];
[self setAuthenticationAgainstProtectionSpaceBlock:^BOOL(NSURLConnection *connection, NSURLProtectionSpace *protectionSpace) {
if([[protectionSpace authenticationMethod] isEqualToString:NSURLAuthenticationMethodServerTrust]) {
return YES; // Self-signed cert will be accepted
}
// If no other authentication is required, return NO for everything else
// Otherwise maybe YES for NSURLAuthenticationMethodDefault and etc.
return NO;
}];
Run Code Online (Sandbox Code Playgroud)
现在使用iOS 8,我收到如下错误:
CFNetwork SSLHandshake失败(-9806)
CFNetwork SSLHandshake失败(-9806)
CFNetwork SSLHandshake失败(-9806)
NSURLConnection/CFURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9806)
连接期间出错:Error Domain = NSURLErrorDomain Code = -1200"发生SSL错误,无法建立与服务器的安全连接." UserInfo = 0x7b66c110 {NSLocalizedDescription =发生了SSL错误,无法与服务器建立安全连接.,NSLocalizedRecoverySuggestion =您是否要连接到服务器?,_kCFStreamErrorCodeKey = -9806,NSErrorFailingURLStringKey = https://xxx.xxx .xxx.xxx:443/live.htm,_kCFStreamErrorDomainKey = 3,NSUnderlyingError = 0x7c0d8a20"发生了SSL错误,无法与服务器建立安全连接.",NSErrorFailingURLKey = https://xxx.xxx.xxx.xxx :443/Info.live.htm }
我已经尝试过切换到FSNetworking,它sometimes在设置时有效:
- (void)connection:(NSURLConnection *)connection
willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
if([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])
{
NSLog(@"Ignoring SSL");
SecTrustRef trust = challenge.protectionSpace.serverTrust;
NSURLCredential *cred;
cred = [NSURLCredential credentialForTrust:trust];
[challenge.sender useCredential:cred forAuthenticationChallenge:challenge];
return;
}
}
Run Code Online (Sandbox Code Playgroud)
但是,如果同时执行2个请求,则只有1个会成功,其中一个会因上述类似错误而失败.只有1个请求似乎达到SSL覆盖点.
任何人都可以对此有所了解,在iOS 8中有什么变化来打破这个,以及我怎么可能修复它?
谢谢
我遇到了与iOS 8相同的问题.
场景:
UIWebViewNSURLConnection失败SSLHandshakeuseCredential:forAuthenticationChallenge 在我们之后立即调用SecTrust*方法时,导致此错误(但仅在打开在同一服务器上的https中打开页面之后).
此代码触发了错误:
[challenge.sender useCredential:urlCredential forAuthenticationChallenge:challenge];
SecTrustRef trustRef = [[challenge protectionSpace] serverTrust];
CFIndex count = SecTrustGetCertificateCount(trustRef);
Run Code Online (Sandbox Code Playgroud)
但这个没有:
SecTrustRef trustRef = [[challenge protectionSpace] serverTrust];
CFIndex count = SecTrustGetCertificateCount(trustRef);
[challenge.sender useCredential:urlCredential forAuthenticationChallenge:challenge];
Run Code Online (Sandbox Code Playgroud)
我不清楚为什么这会导致SSLHandshakeiOS 8而不是iOS 7失败.也许AFNetworking会做出一些事情useCredential:forAuthenticationChallenge导致同样的问题.
您看到的错误可以在 中找到SecureTransport.h。这是一个传输级错误:连接失败,因为它被中止。
在客户端和服务器上,有很多原因可能是造成这种情况的原因。如果服务器向客户端请求证书而客户端没有提供证书,则更有可能发生这种情况,此时服务器决定放弃。如果服务器向客户端请求证书,您的委托方法应该会看到除了服务器信任之外还尝试使用客户端证书进行身份验证。
| 归档时间: |
|
| 查看次数: |
33910 次 |
| 最近记录: |