Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 5 additions & 50 deletions olp-cpp-sdk-core/src/http/ios/OLPHttpClient.mm
Original file line number Diff line number Diff line change
Expand Up @@ -452,34 +452,14 @@ - (void)URLSession:(NSURLSession*)session
"didReceiveChallenge failed - invalid session, "
"task_id=%u",
(unsigned int)dataTask.taskIdentifier);
// Don't hang in non-happy path
completionHandler(NSURLSessionAuthChallengeCancelAuthenticationChallenge,
nil);
return;
}

@autoreleasepool {
if ([challenge.protectionSpace.authenticationMethod
isEqualToString:NSURLAuthenticationMethodServerTrust]) {
if (dataTask) {
OLPHttpTask* httpTask =
[self taskWithTaskDescription:dataTask.taskDescription];
if (![httpTask isValid]) {
return;
}
// TODO: Don't verify certificate is not implemented
if (![self shouldTrustProtectionSpace:challenge.protectionSpace]) {
completionHandler(
NSURLSessionAuthChallengeCancelAuthenticationChallenge, nil);
return;
}
}

NSURLCredential* credential = [NSURLCredential
credentialForTrust:challenge.protectionSpace.serverTrust];
completionHandler(NSURLSessionAuthChallengeUseCredential, credential);
return;
}

completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil);
}
// Use iOS default certificate validation for all authentication challenges
completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil);
}

- (void)URLSession:(NSURLSession*)session
Expand Down Expand Up @@ -533,31 +513,6 @@ - (void)URLSession:(NSURLSession*)session
completionHandler(newRequest);
}

// http://goo.gl/jmZ4Uv
- (BOOL)shouldTrustProtectionSpace:(NSURLProtectionSpace*)protectionSpace {
if (!protectionSpace) {
return NO;
}

SecTrustRef serverTrust = protectionSpace.serverTrust;
if (!serverTrust) {
return NO;
}

// TODO - certificate paths are not supported!

// evaluate server trust against certificate
SecTrustResultType trustResult = kSecTrustResultInvalid;
OSStatus status = SecTrustEvaluate(serverTrust, &trustResult);

if (errSecSuccess != status) {
return NO;
}

return (trustResult == kSecTrustResultUnspecified ||
trustResult == kSecTrustResultProceed);
}

- (void)URLSession:(NSURLSession*)session
downloadTask:(NSURLSessionTask*)dataTask
didWriteData:(int64_t)bytesWritten
Expand Down
Loading