Skip to content

Commit

Permalink
Remove deprecated symbols & Podspec, provide more details on trust fa…
Browse files Browse the repository at this point in the history
…ilure. (#21)
  • Loading branch information
russellhancox authored Dec 19, 2022
1 parent fcd5ac9 commit 38b5ee4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 48 deletions.
15 changes: 0 additions & 15 deletions MOLAuthenticatingURLSession.podspec

This file was deleted.

5 changes: 0 additions & 5 deletions Podfile

This file was deleted.

12 changes: 0 additions & 12 deletions Podfile.lock

This file was deleted.

26 changes: 10 additions & 16 deletions Source/MOLAuthenticatingURLSession/MOLAuthenticatingURLSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ - (instancetype)initWithSessionConfiguration:(NSURLSessionConfiguration *)config

- (instancetype)init {
NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
[config setTLSMinimumSupportedProtocol:kTLSProtocol12];
[config setHTTPShouldUsePipelining:YES];
config.TLSMinimumSupportedProtocolVersion = tls_protocol_version_TLSv12;
config.HTTPShouldUsePipelining = YES;
return [self initWithSessionConfiguration:config];
}

Expand Down Expand Up @@ -308,17 +308,12 @@ - (NSURLCredential *)serverCredentialForProtectionSpace:(NSURLProtectionSpace *)
}

// Evaluate the server's cert chain.
SecTrustResultType result = kSecTrustResultInvalid;
err = SecTrustEvaluate(protectionSpace.serverTrust, &result);
if (err != errSecSuccess) {
[self log:@"Server Trust: Unable to evaluate certificate chain for server: %d", err];
return nil;
}

// Having a trust level "unspecified" by the user is the usual result, described at
// https://developer.apple.com/library/mac/qa/qa1360
if (result != kSecTrustResultProceed && result != kSecTrustResultUnspecified) {
[self log:@"Server Trust: Server isn't trusted. SecTrustResultType: %d", result];
CFErrorRef cfErrRef;
if (!SecTrustEvaluateWithError(protectionSpace.serverTrust, &cfErrRef)) {
NSError *errRef = CFBridgingRelease(cfErrRef);
NSError *underlyingError = errRef.userInfo[NSUnderlyingErrorKey];
NSString *errMsg = CFBridgingRelease(SecCopyErrorMessageString((OSStatus)underlyingError.code, NULL));
[self log:@"Server Trust: Unable to evaluate certificate chain for server: %@ (%d)", errMsg, underlyingError.code];
return nil;
}

Expand Down Expand Up @@ -449,9 +444,8 @@ - (NSArray *)locateIntermediatesForCertificate:(MOLCertificate *)leafCert
// use the result of the evaluation. The certificates seem to be available
// without calling this but the documentation is clear that
// SecTrustGetCertificateAtIndex shouldn't be called without calling
// SecTrustEvaluate first.
SecTrustResultType _; // unused
SecTrustEvaluate(t, &_);
// SecTrustEvaluateWithError first.
(void)SecTrustEvaluateWithError(t, NULL);

NSMutableArray *intermediates = [NSMutableArray array];
CFIndex certCount = SecTrustGetCertificateCount(t);
Expand Down

0 comments on commit 38b5ee4

Please sign in to comment.