Skip to content

Commit

Permalink
Using asynchronous validation for authenticity of certificates
Browse files Browse the repository at this point in the history
  • Loading branch information
Dalmo Cirne committed Nov 9, 2015
1 parent 5ee1c42 commit c7331b6
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 24 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# mParticle CHANGELOG

## 5.1.2

* Using asynchronous validation for authenticity of certificates

## 5.1.1

* Each commerce event action is dealt with in an action-by-action basis for Kahuna
Expand Down
4 changes: 2 additions & 2 deletions Pod/Classes/Event/EventTypeName.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

namespace mParticle {
const vector<string> EventTypeName::names = {"Unknown", "Navigation", "Location", "Search", "Transaction", "UserContent", "UserPreference", "Social", "Other", "Media", // 0-9
"AddToCart", "RemoveFromCart", "Checkout", "CheckoutOption", "Click", "ViewDetail", "Purchase", "Refund", "PromotionView", "PromotionClick", // 10-19
"AddToWishlist", "RemoveFromWishlist", "Impression"}; // 20-22
"ProductAddToCart", "ProductRemoveFromCart", "ProductCheckout", "ProductCheckoutOption", "ProductClick", "ProductViewDetail", "ProductPurchase", "ProductRefund", // 10-17
"PromotionView", "PromotionClick", "ProductAddToWishlist", "ProductRemoveFromWishlist", "ProductImpression"}; // 18-22

const size_t EventTypeName::count = EventTypeName::names.size();

Expand Down
2 changes: 1 addition & 1 deletion Pod/Classes/MPConstants.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
NSUInteger kMPNumberOfMessageTypes = 17;

// mParticle SDK Version
NSString *const kMParticleSDKVersion = @"5.1.0";
NSString *const kMParticleSDKVersion = @"5.1.2";

// Session Upload Settings
NSString *const kMPSessionHistoryValue = @"sh";
Expand Down
39 changes: 19 additions & 20 deletions Pod/Classes/Network/MPConnector.m
Original file line number Diff line number Diff line change
Expand Up @@ -112,23 +112,20 @@ - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didRece
NSString *protocol = [protectionSpace protocol];
__block SecTrustRef serverTrust = [protectionSpace serverTrust];

BOOL trustChallenge = NO;

if ([autheticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust] &&
[host rangeOfString:@"mparticle.com"].location != NSNotFound &&
[protocol isEqualToString:kMPURLScheme] &&
[protectionSpace receivesCredentialSecurely] &&
serverTrust)
{
SecTrustResultType trustResult;
OSStatus status = SecTrustEvaluate(serverTrust, &trustResult);

if (status == errSecSuccess) {
SecTrustCallback evaluateResult = ^(SecTrustRef _Nonnull trustRef, SecTrustResultType trustResult) {
BOOL trustChallenge = NO;

if (trustResult == kSecTrustResultUnspecified || trustResult == kSecTrustResultProceed) {
CFIndex certificateCount = SecTrustGetCertificateCount(serverTrust);
CFIndex certificateCount = SecTrustGetCertificateCount(trustRef);

for (CFIndex certIdx = 1; certIdx < certificateCount; ++certIdx) {
SecCertificateRef certificate = SecTrustGetCertificateAtIndex(serverTrust, certIdx);
SecCertificateRef certificate = SecTrustGetCertificateAtIndex(trustRef, certIdx);
CFDataRef certificateDataRef = SecCertificateCopyData(certificate);

if (certificateDataRef != NULL) {
Expand All @@ -147,19 +144,21 @@ - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didRece
}
}
}
}
}

if (trustChallenge) {
NSURLCredential *urlCredential = [NSURLCredential credentialForTrust:serverTrust];
completionHandler(NSURLSessionAuthChallengeUseCredential, urlCredential);
} else {
if (_active) {
_active = NO;
[self cleariVars];
}

if (trustChallenge) {
NSURLCredential *urlCredential = [NSURLCredential credentialForTrust:trustRef];
completionHandler(NSURLSessionAuthChallengeUseCredential, urlCredential);
} else {
if (_active) {
_active = NO;
[self cleariVars];
}

completionHandler(NSURLSessionAuthChallengeCancelAuthenticationChallenge, nil);
}
};

completionHandler(NSURLSessionAuthChallengeCancelAuthenticationChallenge, nil);
SecTrustEvaluateAsync(serverTrust, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), evaluateResult);
}
}

Expand Down
2 changes: 1 addition & 1 deletion mParticle-iOS-SDK.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "mParticle-iOS-SDK"
s.version = "5.1.1"
s.version = "5.1.2"
s.summary = "mParticle iOS SDK."

s.description = <<-DESC
Expand Down

0 comments on commit c7331b6

Please sign in to comment.