#1306 - Adding api_mapbox_com.der (public key) and nsurlconnection checking infrastructure
This commit is contained in:
BIN
common/api_mapbox_com.der
Normal file
BIN
common/api_mapbox_com.der
Normal file
Binary file not shown.
@@ -4,7 +4,7 @@
|
||||
'type': 'none',
|
||||
'hard_dependency': 1,
|
||||
'copies': [{
|
||||
'files': [ '../common/ca-bundle.crt' ],
|
||||
'files': [ '../common/api_mapbox_com.der', '../common/ca-bundle.crt' ],
|
||||
'destination': '<(PRODUCT_DIR)'
|
||||
}],
|
||||
},
|
||||
|
||||
@@ -25,7 +25,7 @@ extern NSString *const MGLEventGesturePanStart;
|
||||
extern NSString *const MGLEventGesturePinchStart;
|
||||
extern NSString *const MGLEventGestureRotateStart;
|
||||
|
||||
@interface MGLMapboxEvents : NSObject
|
||||
@interface MGLMapboxEvents : NSObject <NSURLConnectionDelegate>
|
||||
|
||||
// You must call these methods from the main thread.
|
||||
//
|
||||
|
||||
@@ -395,9 +395,12 @@ NSString *const MGLEventGestureRotateStart = @"Rotation";
|
||||
[request setHTTPBody:jsonData];
|
||||
|
||||
// Send non blocking HTTP Request to server
|
||||
[NSURLConnection sendAsynchronousRequest:request
|
||||
queue:nil
|
||||
completionHandler:nil];
|
||||
NSURLConnection *conn = [NSURLConnection connectionWithRequest:request delegate:weakSelf];
|
||||
[conn start];
|
||||
|
||||
// [NSURLConnection sendAsynchronousRequest:request
|
||||
// queue:nil
|
||||
// completionHandler:nil];
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -638,4 +641,51 @@ NSString *const MGLEventGestureRotateStart = @"Rotation";
|
||||
return result;
|
||||
}
|
||||
|
||||
#pragma mark NSURLConnectionDelegate
|
||||
- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
|
||||
|
||||
// Load Local Copy of Server's Public Key
|
||||
// NSString *cerPath = [[NSBundle mainBundle] pathForResource:@"b.ssl.fastly.net" ofType:@"der"];
|
||||
NSString *cerPath = [[NSBundle mainBundle] pathForResource:@"api_mapbox_com" ofType:@"der"];
|
||||
NSData *localCertData = [NSData dataWithContentsOfFile:cerPath];
|
||||
|
||||
// Get Server's Public Key
|
||||
SecTrustRef serverTrust = challenge.protectionSpace.serverTrust;
|
||||
|
||||
SecTrustResultType trustResult;
|
||||
SecTrustEvaluate(serverTrust, &trustResult);
|
||||
switch (trustResult) {
|
||||
case kSecTrustResultProceed:
|
||||
break;
|
||||
case kSecTrustResultConfirm:
|
||||
break;
|
||||
case kSecTrustResultUnspecified:
|
||||
break;
|
||||
default:
|
||||
[[challenge sender] cancelAuthenticationChallenge:challenge];
|
||||
return;
|
||||
}
|
||||
|
||||
long numKeys = SecTrustGetCertificateCount(serverTrust);
|
||||
NSLog(@"Number of certificaties presented: %ld", numKeys);
|
||||
|
||||
BOOL found = false;
|
||||
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:localCertData]) {
|
||||
NSURLCredential *credential = [NSURLCredential credentialForTrust:serverTrust];
|
||||
[[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
[[challenge sender] cancelAuthenticationChallenge:challenge];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user