Skip to content

Commit 3a43c16

Browse files
authored
Merge pull request #14 from BranchMetrics/staging
Release certificate fix
2 parents e71223a + bf72353 commit 3a43c16

File tree

17 files changed

+25
-176
lines changed

17 files changed

+25
-176
lines changed

Branch.xcodeproj/project.pbxproj

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,7 @@
11841184
CODE_SIGN_IDENTITY = "Mac Developer";
11851185
CODE_SIGN_STYLE = Automatic;
11861186
DEVELOPMENT_TEAM = "";
1187-
MARKETING_VERSION = 1.2.3;
1187+
MARKETING_VERSION = 1.2.4;
11881188
PRODUCT_BUNDLE_IDENTIFIER = io.branch.sdk.mac;
11891189
PROVISIONING_PROFILE_SPECIFIER = "";
11901190
};
@@ -1196,7 +1196,7 @@
11961196
CODE_SIGN_IDENTITY = "";
11971197
CODE_SIGN_STYLE = Automatic;
11981198
DEVELOPMENT_TEAM = "";
1199-
MARKETING_VERSION = 1.2.3;
1199+
MARKETING_VERSION = 1.2.4;
12001200
PRODUCT_BUNDLE_IDENTIFIER = io.branch.sdk.mac;
12011201
PROVISIONING_PROFILE_SPECIFIER = "";
12021202
};
@@ -1205,6 +1205,7 @@
12051205
4D67477120C74E81001639C5 /* Debug */ = {
12061206
isa = XCBuildConfiguration;
12071207
buildSettings = {
1208+
MARKETING_VERSION = 1.2.4;
12081209
PRODUCT_BUNDLE_IDENTIFIER = io.branch.sdk.mac;
12091210
SDKROOT = appletvos;
12101211
};
@@ -1213,6 +1214,7 @@
12131214
4D67477320C74E81001639C5 /* Release */ = {
12141215
isa = XCBuildConfiguration;
12151216
buildSettings = {
1217+
MARKETING_VERSION = 1.2.4;
12161218
PRODUCT_BUNDLE_IDENTIFIER = io.branch.sdk.mac;
12171219
SDKROOT = appletvos;
12181220
};
@@ -1300,7 +1302,7 @@
13001302
CODE_SIGN_IDENTITY = "";
13011303
CODE_SIGN_STYLE = Automatic;
13021304
DEVELOPMENT_TEAM = "";
1303-
MARKETING_VERSION = 1.2.3;
1305+
MARKETING_VERSION = 1.2.4;
13041306
PRODUCT_BUNDLE_IDENTIFIER = io.branch.sdk.mac;
13051307
PROVISIONING_PROFILE_SPECIFIER = "";
13061308
};
@@ -1328,6 +1330,7 @@
13281330
4DFB135720CCD96400AF3E47 /* UnitTests */ = {
13291331
isa = XCBuildConfiguration;
13301332
buildSettings = {
1333+
MARKETING_VERSION = 1.2.4;
13311334
PRODUCT_BUNDLE_IDENTIFIER = io.branch.sdk.mac;
13321335
SDKROOT = appletvos;
13331336
};

Branch/BNCNetworkAPIService.m

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,6 @@ - (instancetype) initWithConfiguration:(BranchConfiguration *)configuration {
7171
self.settings = self.configuration.settings;
7272
self.networkService = [configuration.networkServiceClass new];
7373
self.persistence = [[BNCPersistence alloc] initWithAppGroup:BNCApplication.currentApplication.bundleID];
74-
if (self.configuration.useCertificatePinning) {
75-
NSError*error = [self.networkService pinSessionToPublicSecKeyRefs:self.class.publicSecKeyRefs];
76-
if (error) {
77-
BNCLogError(@"Can't pin network certificates: %@.", error);
78-
error = [NSError branchErrorWithCode:BNCInvalidNetworkPublicKeyError];
79-
BNCLogError(@"Can't pin network certificates: %@.", error);
80-
}
81-
}
8274
self.operationQueue = [[NSOperationQueue alloc] init];
8375
self.operationQueue.qualityOfService = NSQualityOfServiceUserInitiated;
8476
self.operationQueue.name = @"io.branch.sdk.BNCNetworkAPIService";

Branch/BNCNetworkService.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,10 @@ NS_ASSUME_NONNULL_BEGIN
3333
- (id<BNCNetworkOperationProtocol>) networkOperationWithURLRequest:(NSMutableURLRequest*)request
3434
completion:(void (^)(id<BNCNetworkOperationProtocol>operation))completion;
3535

36-
- (NSError*_Nullable) pinSessionToPublicSecKeyRefs:(NSArray/**<SecKeyRef>*/*_Nullable)publicKeys;
37-
38-
/// An array of host domains that we will allow with a self-signed SSL cert.
39-
@property (atomic, strong, null_resettable) NSMutableSet<NSString*>* anySSLCertHosts;
4036
@property (atomic, assign) NSInteger maxConcurrentOperationCount;
37+
4138
- (void) cancelAllOperations;
39+
4240
@end
4341

4442
NS_ASSUME_NONNULL_END

Branch/BNCNetworkService.m

Lines changed: 0 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ @interface BNCNetworkOperation ()
2727
#pragma mark - BNCNetworkService
2828

2929
@interface BNCNetworkService () <NSURLSessionDelegate> {
30-
NSMutableArray*_pinnedPublicKeys;
31-
NSMutableSet<NSString*>*_anySSLCertHosts;
3230
NSOperationQueue*_serviceQueue;
3331
NSURLSession*_session;
3432
}
@@ -117,19 +115,6 @@ - (NSInteger) maxConcurrentOperationCount {
117115
return self.serviceQueue.maxConcurrentOperationCount;
118116
}
119117

120-
- (NSMutableSet<NSString*>*) anySSLCertHosts {
121-
@synchronized(self) {
122-
if (!_anySSLCertHosts) _anySSLCertHosts = [NSMutableSet new];
123-
return _anySSLCertHosts;
124-
}
125-
}
126-
127-
- (void) setAnySSLCertHosts:(NSMutableSet<NSString*>*)anySSLCertHosts_ {
128-
@synchronized(self) {
129-
_anySSLCertHosts = [anySSLCertHosts_ copy];
130-
}
131-
}
132-
133118
- (id<BNCNetworkOperationProtocol>) networkOperationWithURLRequest:(NSMutableURLRequest*)request
134119
completion:(void (^)(id<BNCNetworkOperationProtocol>operation))completion {
135120
BNCNetworkOperation *operation = [BNCNetworkOperation new];
@@ -187,104 +172,6 @@ - (void) startOperation:(BNCNetworkOperation*)operation {
187172
[operation.sessionTask resume];
188173
}
189174

190-
#pragma mark - Transport Security
191-
192-
- (NSError*_Nullable) pinSessionToPublicSecKeyRefs:(NSArray/**<SecKeyRef>*/*)publicKeys {
193-
@synchronized (self) {
194-
NSError*error = nil;
195-
_pinnedPublicKeys = [NSMutableArray array];
196-
for (id secKey in publicKeys) {
197-
if (CFGetTypeID((SecKeyRef)secKey) == SecKeyGetTypeID())
198-
[_pinnedPublicKeys addObject:secKey];
199-
else {
200-
error = [NSError errorWithDomain:NSNetServicesErrorDomain
201-
code:NSNetServicesBadArgumentError userInfo:nil];
202-
}
203-
}
204-
return error;
205-
}
206-
}
207-
208-
- (NSArray*) pinnedPublicKeys {
209-
@synchronized (self) {
210-
return _pinnedPublicKeys;
211-
}
212-
}
213-
214-
- (void) URLSession:(NSURLSession *)session
215-
task:(NSURLSessionTask *)task
216-
didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge
217-
completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition,
218-
NSURLCredential *credential))completionHandler {
219-
220-
BOOL trusted = NO;
221-
SecTrustResultType trustResult = 0;
222-
OSStatus err = 0;
223-
224-
// Keep a local copy in case they mutate.
225-
NSArray *localPinnedKeys = [self.pinnedPublicKeys copy];
226-
NSSet<NSString*>*localAllowedHosts = [self.anySSLCertHosts copy];
227-
228-
// Release these:
229-
SecKeyRef key = nil;
230-
SecPolicyRef hostPolicy = nil;
231-
232-
// Get remote certificate
233-
SecTrustRef serverTrust = challenge.protectionSpace.serverTrust;
234-
@synchronized ((__bridge id<NSObject, OS_dispatch_semaphore>)serverTrust) {
235-
236-
// Set SSL policies for domain name check
237-
hostPolicy = SecPolicyCreateSSL(true, (__bridge CFStringRef)challenge.protectionSpace.host);
238-
if (!hostPolicy) goto exit;
239-
SecTrustSetPolicies(serverTrust, (__bridge CFTypeRef _Nonnull)(@[ (__bridge id)hostPolicy ]));
240-
241-
// Evaluate server certificate
242-
SecTrustEvaluate(serverTrust, &trustResult);
243-
switch (trustResult) {
244-
case kSecTrustResultRecoverableTrustFailure:
245-
if ([localAllowedHosts containsObject:challenge.protectionSpace.host])
246-
break;
247-
else
248-
goto exit;
249-
case kSecTrustResultUnspecified:
250-
case kSecTrustResultProceed:
251-
break;
252-
default:
253-
goto exit;
254-
}
255-
256-
if (localPinnedKeys == nil) {
257-
trusted = YES;
258-
goto exit;
259-
}
260-
261-
key = SecTrustCopyPublicKey(serverTrust);
262-
if (!key) goto exit;
263-
}
264-
265-
for (id<NSObject> pinnedKey in localPinnedKeys) {
266-
if ([pinnedKey isEqual:(__bridge id<NSObject>)key]) {
267-
trusted = YES;
268-
goto exit;
269-
}
270-
}
271-
272-
exit:
273-
if (err) {
274-
NSError *error = [NSError errorWithDomain:NSOSStatusErrorDomain code:err userInfo:nil];
275-
BNCLogError(@"Error while validating cert: %@.", error);
276-
}
277-
if (key) CFRelease(key);
278-
if (hostPolicy) CFRelease(hostPolicy);
279-
280-
if (trusted) {
281-
NSURLCredential *credential = [NSURLCredential credentialForTrust:serverTrust];
282-
completionHandler(NSURLSessionAuthChallengeUseCredential, credential);
283-
} else {
284-
completionHandler(NSURLSessionAuthChallengeCancelAuthenticationChallenge, NULL);
285-
}
286-
}
287-
288175
- (void) cancelAllOperations {
289176
@synchronized(self) {
290177
[self.session invalidateAndCancel];

Branch/BranchMainClass.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,10 @@ NS_ASSUME_NONNULL_BEGIN
3131
- (instancetype) initWithKey:(NSString*)key NS_DESIGNATED_INITIALIZER;
3232

3333
/** Your Branch key. */
34-
@property (atomic, strong) NSString*key;
35-
36-
/** Use certificate pinning for extra security. The default is to use certificate pinning. */
37-
@property (atomic, assign) BOOL useCertificatePinning;
34+
@property (atomic, strong) NSString *key;
3835

3936
/** The URL to the Branch API servers. */
40-
@property (atomic, copy) NSString*branchAPIServiceURL;
37+
@property (atomic, copy) NSString *branchAPIServiceURL;
4138

4239
/**
4340
This is `Class` for the network service. If you want to use your own underlying network service,

Branch/BranchMainClass.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ - (instancetype) init {
4646
- (instancetype) initWithKey:(NSString *)key {
4747
self = [super init];
4848
self.key = [key copy];
49-
self.useCertificatePinning = YES;
49+
5050
self.branchAPIServiceURL = @"https://api.branch.io";
5151
self.networkServiceClass = [BNCNetworkService class];
5252
self.blackListURLRegex = [NSArray new];
@@ -55,7 +55,6 @@ - (instancetype) initWithKey:(NSString *)key {
5555

5656
- (instancetype) copyWithZone:(NSZone*)zone {
5757
BranchConfiguration* configuration = [[BranchConfiguration alloc] initWithKey:self.key];
58-
configuration.useCertificatePinning = self.useCertificatePinning;
5958
configuration.branchAPIServiceURL = [self.branchAPIServiceURL copy];
6059
configuration.networkServiceClass = self.networkServiceClass;
6160
configuration.blackListURLRegex = [self.blackListURLRegex copy];

Branch/BranchNetworkServiceProtocol.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@ NS_ASSUME_NONNULL_BEGIN
9191
- (id<BNCNetworkOperationProtocol>) networkOperationWithURLRequest:(NSMutableURLRequest*)request
9292
completion:(void (^)(id<BNCNetworkOperationProtocol>operation))completion;
9393

94-
/// Pins the session to the array of public keys.
95-
@optional
96-
- (NSError*_Nullable) pinSessionToPublicSecKeyRefs:(NSArray/* <SecKeyRef> */*_Nullable)publicKeys;
97-
9894
@end
9995

10096
NS_ASSUME_NONNULL_END

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
Branch Mac SDK Change Log
22

3+
## v1.2.4 - June 17, 2020
4+
* Remove certificate pinning
5+
36
## v1.2.3 - May 13, 2020
47
* Fix control param location in request payload
58

Examples/TestBed-macOS/TestBed-macOS/APPAppDelegate.m

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,10 @@ - (void)applicationWillFinishLaunching:(NSNotification *)aNotification {
5353
name:BranchDidOpenURLWithSessionNotification
5454
object:nil];
5555

56-
BranchConfiguration*configuration =
57-
[[BranchConfiguration alloc] initWithKey:@"key_live_ait5BYsDbZKRajyPlkzzTancDAp41guC"];
58-
59-
#if 0
60-
configuration.useCertificatePinning = NO;
61-
configuration.branchAPIServiceURL = @"http://esmith.api.beta.branch.io";
62-
configuration.key = @"key_live_ait5BYsDbZKRajyPlkzzTancDAp41guC";
63-
#elif 0
64-
configuration.useCertificatePinning = NO;
65-
configuration.branchAPIServiceURL = @"http://cjones.api.beta.branch.io";
66-
configuration.key = @"key_live_ocyWSee4dsA1EUPxxMvFchefuqdjuxyW";
67-
#else
68-
configuration.useCertificatePinning = YES;
56+
BranchConfiguration *configuration = [[BranchConfiguration alloc] initWithKey:@"key_live_ait5BYsDbZKRajyPlkzzTancDAp41guC"];
57+
6958
configuration.branchAPIServiceURL = @"https://api.branch.io";
7059
configuration.key = @"key_live_glvYEcNtDkb7wNgLWwni2jofEwpCeQ3N";
71-
#endif
7260

7361
[[Branch sharedInstance] startWithConfiguration:configuration];
7462
}
-6.42 KB
Binary file not shown.

0 commit comments

Comments
 (0)