From d44450ac7beba2ec517ffec7c6dd191de7cc0df5 Mon Sep 17 00:00:00 2001 From: Brad Leege Date: Thu, 28 May 2015 15:51:50 -0700 Subject: [PATCH] #1659 - Adding tile stream certificate and ssl pin check for test server. --- platform/ios/MGLMapboxEvents.m | 23 ++++++++++++++++++ .../ios/resources/star_tilestream_net.der | Bin 0 -> 1338 bytes 2 files changed, 23 insertions(+) create mode 100644 platform/ios/resources/star_tilestream_net.der diff --git a/platform/ios/MGLMapboxEvents.m b/platform/ios/MGLMapboxEvents.m index e7f400c5d..3211a6039 100644 --- a/platform/ios/MGLMapboxEvents.m +++ b/platform/ios/MGLMapboxEvents.m @@ -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]); diff --git a/platform/ios/resources/star_tilestream_net.der b/platform/ios/resources/star_tilestream_net.der new file mode 100644 index 0000000000000000000000000000000000000000..e302cd76867208934f6260647db191fc77ec434e GIT binary patch literal 1338 zcmXqLVl^{pVv$?G%*4pV#4K{3-GG;kQ>)FR?K>|cBP%O|fsG-z0Vf-CC<~h~Q)sZE zxPd5$!zIk;o|+$0R9al3qu`mBtY;`xPE$=8Ja1!RMEB-tw2nIj3zgcV5n1;mF*gFz?k*H!H!^ zYsuyptE1O9$L;9)Z)CBo^laCAHxn0Cm0RHlkH$P+sTn+_OF>|Ffx9>v))%bN zO!(c$o7VH_TK(m)btk^@@IL?lcPmTn%)W$sH9qrX_>Mfe#YcQ$tjQ{&4LuIrNHo@>5I6 zJS%pq4_bngay%^AC#7*}GchwVFfMLl+zkwo?FRC|V3bv6kuVTz5XsK8&605Py4%l` zYWdexrLAJ3n1KNwNC7`1<9`+wW+v7J2C^W&DvOwb2pfks8!$z(Gc&?jOa|H@X+ahh z1EnU6sA=Luiz;W3VtE!D11kfI1!fCO+Ke(vN(!v>^0iH3Z^g3A(ELnA)sOEYzXWTpi(m7lFzS!1 zd#V5YWVxKmstOyS8dBjxwn%7!EqiXl`pp9$ek|fRuo?U3+sM?txel9w4#jBfY zORwH~nVah8yW`N=(wY7DJ-;wsJk4cAmSp4p^uA675eYp(mak3qMP5;^p0EEK zYQ|qzKdt+_eD31C&37D1Wv@#ytjL{e$#z6n-#^3S$7#Q-qSIf;9C1AEdHHeBvW|F{ zZCAH$WZktO)JI)n&6??_A5ODZRXHJ|X6?;dl~tuzsl&m=Z+cZ`i}^E!UEDbUCUndK literal 0 HcmV?d00001