#1659 - Adding tile stream certificate and ssl pin check for test server.

This commit is contained in:
Brad Leege
2015-05-28 15:51:50 -07:00
parent 6c166b564e
commit d44450ac7b
2 changed files with 23 additions and 0 deletions

View File

@@ -16,6 +16,7 @@
static const NSUInteger version = 1;
static NSString *const MGLMapboxEventsUserAgent = @"MapboxEventsiOS/1.0";
static NSString *MGLMapboxEventsAPIBase = @"https://api.tiles.mapbox.com";
static BOOL usingTestServer = NO;
NSString *const MGLEventTypeAppUserTurnstile = @"appUserTurnstile";
NSString *const MGLEventTypeMapLoad = @"map.load";
@@ -148,6 +149,7 @@ const NSTimeInterval MGLFlushInterval = 60;
@property (atomic) NSURLSession *session;
@property (atomic) NSData *digicertCert;
@property (atomic) NSData *geoTrustCert;
@property (atomic) NSData *testServerCert;
// Main thread only
@property (nonatomic) CLLocationManager *locationManager;
@@ -239,6 +241,7 @@ const NSTimeInterval MGLFlushInterval = 60;
NSString *testURL = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"MGLMetricsTestServerURL"];
if (testURL != nil) {
MGLMapboxEventsAPIBase = testURL;
usingTestServer = YES;
}
_paused = YES;
@@ -256,6 +259,10 @@ const NSTimeInterval MGLFlushInterval = 60;
if (cerPath != nil) {
_digicertCert = [NSData dataWithContentsOfFile:cerPath];
}
cerPath = [resourceBundle pathForResource:@"star_tilestream_net" ofType:@"der"];
if (cerPath != nil) {
_testServerCert = [NSData dataWithContentsOfFile:cerPath];
}
// Events Control
_eventQueue = [[NSMutableArray alloc] init];
@@ -878,6 +885,22 @@ const NSTimeInterval MGLFlushInterval = 60;
}
}
if (!found && usingTestServer) {
// See if this is test server
for (int lc = 0; lc < numKeys; lc++) {
SecCertificateRef certificate = SecTrustGetCertificateAtIndex(serverTrust, lc);
NSData *remoteCertificateData = CFBridgingRelease(SecCertificateCopyData(certificate));
// Compare Remote Key With Local Version
if ([remoteCertificateData isEqualToData:_testServerCert]) {
// Found the certificate; continue connecting
completionHandler(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]);
found = true;
break;
}
}
}
if (!found) {
// The certificate wasn't found in GeoTrust nor Digicert. Cancel the connection.
completionHandler(NSURLSessionAuthChallengeCancelAuthenticationChallenge, [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]);

Binary file not shown.