8000 [v8] Fix deprecation in GULNetworkURLSession.m by ncooke3 · Pull Request #193 · google/GoogleUtilities · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[v8] Fix deprecation in GULNetworkURLSession.m #193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 21, 2024
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
26 changes: 9 additions & 17 deletions GoogleUtilities/Network/GULNetworkURLSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -387,28 +387,20 @@ - (void)URLSession:(NSURLSession *)session
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

dispatch_async(evaluateBackgroundQueue, ^{
SecTrustResultType trustEval = kSecTrustResultInvalid;
BOOL shouldAllow;
OSStatus trustError;
CFErrorRef errorRef = NULL;

@synchronized([GULNetworkURLSession class]) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
trustError = SecTrustEvaluate(serverTrust, &trustEval);
#pragma clang diagnostic pop
shouldAllow = SecTrustEvaluateWithError(serverTrust, &errorRef);
}

if (trustError != errSecSuccess) {
[self->_loggerDelegate GULNetwork_logWithLevel:kGULNetworkLogLevelError
messageCode:kGULNetworkMessageCodeURLSession008
message:@"Cannot evaluate server trust. Error, host"
contexts:@[ @(trustError), self->_request.URL ]];
shouldAllow = NO;
} else {
// Having a trust level "unspecified" by the user is the usual result, described at
// https://developer.apple.com/library/mac/qa/qa1360
shouldAllow =
(trustEval == kSecTrustResultUnspecified || trustEval == kSecTrustResultProceed);
Comment on lines -410 to -411
Copy link
Member Author
@ncooke3 ncooke3 Jun 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From Apple docs: The SecTrustEvaluateWithError(::) method returns a pass or fail indicator and an error describing the reason for any failure. So, I think it's reasonable to rely on the shouldAllow result.

Furthermore, GTMSessionFetcher relies on the API's return bool value:

https://github.com/google/gtm-session-fetcher/blob/4990f8956605007c2546824d57432f04dc37fe70/Sources/Core/GTMSessionFetcher.m#L2615-L2628

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM! Nice cleanup.

if (errorRef) {
[self->_loggerDelegate
GULNetwork_logWithLevel:kGULNetworkLogLevelError
messageCode:kGULNetworkMessageCodeURLSession008
message:@"Cannot evaluate server trust. Error, host"
contexts:@[ @((int)CFErrorGetCode(errorRef)), self->_request.URL ]];
CFRelease(errorRef);
}

// Call the call back with the permission.
Expand Down
Loading
0