Assert only in the cert untrusted error path

This commit is contained in:
Cameron Gutman
2018-12-28 00:45:32 -08:00
parent 3717228e28
commit 90e582a263
+7 -4
View File
@@ -114,7 +114,12 @@ static const NSString* HTTPS_PORT = @"47984";
[self executeRequestSynchronously:request]; [self executeRequestSynchronously:request];
} }
} }
else if (_error && [_error code] == NSURLErrorServerCertificateUntrusted && request.fallbackRequest) { else if (_error && [_error code] == NSURLErrorServerCertificateUntrusted) {
// We must have a pinned cert for HTTPS. If we fail, it must be due to
// a non-matching cert, not because we had no cert at all.
assert(_serverCert != nil);
if (request.fallbackRequest) {
// This will fall back to HTTP on serverinfo queries to allow us to pair again // This will fall back to HTTP on serverinfo queries to allow us to pair again
// and get the server cert updated. // and get the server cert updated.
Log(LOG_D, @"Attempting fallback request after certificate trust failure"); Log(LOG_D, @"Attempting fallback request after certificate trust failure");
@@ -124,11 +129,9 @@ static const NSString* HTTPS_PORT = @"47984";
[self executeRequestSynchronously:request]; [self executeRequestSynchronously:request];
} }
} }
}
- (NSURLRequest*) createRequestFromString:(NSString*) urlString timeout:(int)timeout { - (NSURLRequest*) createRequestFromString:(NSString*) urlString timeout:(int)timeout {
// Assert that we only issue HTTPS requests with a pinned cert
assert([urlString hasPrefix:@"http://"] || _serverCert != nil);
NSURL* url = [[NSURL alloc] initWithString:urlString]; NSURL* url = [[NSURL alloc] initWithString:urlString];
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url]; NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url];
[request setTimeoutInterval:timeout]; [request setTimeoutInterval:timeout];