Hi Eskimo,
so I think I have the same issue like fripp85_reply. Because fripp85_reply hasn’t answered your question yet and before I start a new thread, it maybe makes sense that I answer your question with my experience . I hope this ok!
I made a small sample App on XCode 8.1 with Base SDK 10.1. We are using NSURLSessions to do some local communication with some older hardware with self signed certifcates on it.
- - (void)startRequest{
- NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"<<HTTPS_WITH_LOCAL_IP_ADDRESS>>"]];
- NSURLSessionDataTask *dataTask = [_session dataTaskWithRequest:request
- completionHandler:^(NSData *data,
- NSURLResponse *response,
- NSError *error) {
- if (error) {
- _NSLog(@"FAIL");
- } else {
- _NSLog(@"SUCCESS");
- }
- }];
- [dataTask resume];
- }
- - (void)URLSession:(NSURLSession *)session
- task:(NSURLSessionTask *)task
- didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge
- completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition,
- NSURLCredential *credential))completionHandler{
- … here we are some certificate checking stuff…
- completionHandler(NSURLSessionAuthChallengeUseCredential,[NSURLCredential credentialForTrust: challenge.protectionSpace.serverTrust]);
- }
When we are setting the NSAllowsArbitaryLoads to YES then all is working fine.
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
The app is checking the certifcates for the NSURLAuthenticationMethodServerTrust authentication challenge and accept the Challenge by using the completionhandler.
When we now add the NSAllowsLocalNetworking with YES
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSAllowsLocalNetworking</key>
<true/>
</dict>
We are getting the followoing error :
NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9824)
The problem is that the URLSession:task:didReceiveChallenge:completionHandler: will never get called when NSAllowsLocalNetworking is activated so we won’t have the chance to do accept it. Hope you have an idea how to solve this issue, and thank you in advance.
To give you maybe some more information here is the result from the ATS Diagnostic on the local URL:
/usr/bin/nscurl --ats-diagnostics --verbose
Starting ATS Diagnostics
Configuring ATS Info.plist keys and displaying the result of HTTPS loads to
A test will "PASS" if URLSession:task:didCompleteWithError: returns a nil error.
================================================================================
Default ATS Secure Connection
---
ATS Default Connection
ATS Dictionary:
{
}
2016-11-28 14:12:17.328 nscurl[9140:297067] CFNetwork SSLHandshake failed (-9824)
2016-11-28 14:12:17.328 nscurl[9140:297067] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9824)
Result : FAIL
Error : Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the server cannot be made." UserInfo={_kCFStreamErrorCodeKey=-9824, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, NSUnderlyingError=0x7ffc587246a0 {Error Domain=kCFErrorDomainCFNetwork Code=-1200 "(null)" UserInfo={_kCFStreamPropertySSLClientCertificateState=0, _kCFNetworkCFStreamSSLErrorOriginalValue=-9824, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9824}}, NSLocalizedDescription=An SSL error has occurred and a secure connection to the server cannot be made., NSErrorFailingURLKey=, NSErrorFailingURLStringKey= _kCFStreamErrorDomainKey=3}