@@ -64,7 +64,7 @@ void OnExitBackground() override {
6464
6565} // namespace
6666
67- @interface OLPHttpClient ()<NSURLSessionDataDelegate >
67+ @interface OLPHttpClient () <NSURLSessionDataDelegate >
6868
6969@property (nonatomic ) NSMutableDictionary * tasks;
7070
@@ -92,8 +92,9 @@ - (instancetype)init {
9292 _delegateQueue = [[NSOperationQueue alloc ] init ];
9393 _delegateQueue.name = @" com.here.olp.network.HttpClientSessionQueue" ;
9494
95- _sharedUrlSession =
96- [self urlSessionWithProxy: nil andHeaders: nil andBackgroundId: nil ];
95+ _sharedUrlSession = [self urlSessionWithProxy: nil
96+ andHeaders: nil
97+ andBackgroundId: nil ];
9798
9899 _sharedUrlBackgroundSession =
99100 [self urlSessionWithProxy: nil
@@ -452,34 +453,14 @@ - (void)URLSession:(NSURLSession*)session
452453 " didReceiveChallenge failed - invalid session, "
453454 " task_id=%u" ,
454455 (unsigned int )dataTask.taskIdentifier );
456+ // Don't hang in non-happy path
457+ completionHandler (NSURLSessionAuthChallengeCancelAuthenticationChallenge ,
458+ nil );
455459 return ;
456460 }
457461
458- @autoreleasepool {
459- if ([challenge.protectionSpace.authenticationMethod
460- isEqualToString: NSURLAuthenticationMethodServerTrust ]) {
461- if (dataTask) {
462- OLPHttpTask* httpTask =
463- [self taskWithTaskDescription: dataTask.taskDescription];
464- if (![httpTask isValid ]) {
465- return ;
466- }
467- // TODO: Don't verify certificate is not implemented
468- if (![self shouldTrustProtectionSpace: challenge.protectionSpace]) {
469- completionHandler (
470- NSURLSessionAuthChallengeCancelAuthenticationChallenge , nil );
471- return ;
472- }
473- }
474-
475- NSURLCredential * credential = [NSURLCredential
476- credentialForTrust: challenge.protectionSpace.serverTrust];
477- completionHandler (NSURLSessionAuthChallengeUseCredential , credential);
478- return ;
479- }
480-
481- completionHandler (NSURLSessionAuthChallengePerformDefaultHandling , nil );
482- }
462+ // Use iOS default certificate validation for all authentication challenges
463+ completionHandler (NSURLSessionAuthChallengePerformDefaultHandling , nil );
483464}
484465
485466- (void )URLSession : (NSURLSession *)session
@@ -533,31 +514,6 @@ - (void)URLSession:(NSURLSession*)session
533514 completionHandler (newRequest);
534515}
535516
536- // http://goo.gl/jmZ4Uv
537- - (BOOL )shouldTrustProtectionSpace : (NSURLProtectionSpace *)protectionSpace {
538- if (!protectionSpace) {
539- return NO ;
540- }
541-
542- SecTrustRef serverTrust = protectionSpace.serverTrust ;
543- if (!serverTrust) {
544- return NO ;
545- }
546-
547- // TODO - certificate paths are not supported!
548-
549- // evaluate server trust against certificate
550- SecTrustResultType trustResult = kSecTrustResultInvalid ;
551- OSStatus status = SecTrustEvaluate (serverTrust, &trustResult);
552-
553- if (errSecSuccess != status) {
554- return NO ;
555- }
556-
557- return (trustResult == kSecTrustResultUnspecified ||
558- trustResult == kSecTrustResultProceed );
559- }
560-
561517- (void )URLSession : (NSURLSession *)session
562518 downloadTask : (NSURLSessionTask *)dataTask
563519 didWriteData : (int64_t )bytesWritten
0 commit comments