Skip to content

Commit a94f27b

Browse files
authored
Merge pull request #345 from PLatDT/uikit-fix
Remove UiKit import and use selectors to make sure we can compile for multiple platforms
2 parents cd54e29 + 0cd8152 commit a94f27b

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

TrustKit.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "TrustKit"
3-
s.version = "3.0.6"
3+
s.version = "3.0.7"
44
s.summary = 'TrustKit is an open source framework that makes it easy to deploy SSL pinning in any iOS, macOS, tvOS or watchOS App.'
55
s.homepage = "https://datatheorem.github.io/TrustKit"
66
s.documentation_url = 'https://datatheorem.github.io/TrustKit/documentation/'

TrustKit/Pinning/TSKSPKIHashCache.m

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
See AUTHORS file for the list of project authors.
99
1010
*/
11-
12-
#import <UIKit/UIKit.h>
11+
#import <objc/runtime.h>
12+
#import <objc/message.h>
1313
#import "TSKSPKIHashCache.h"
1414
#import "../TSKLog.h"
1515
#import <CommonCrypto/CommonDigest.h>
@@ -148,6 +148,21 @@ - (SPKICacheDictionnary *)loadSPKICacheFromFileSystem;
148148

149149
@implementation TSKSPKIHashCache
150150

151+
static BOOL isProtectedDataAvailable(void)
152+
{
153+
Class uiApplicationClass = objc_getClass("UIApplication");
154+
if (uiApplicationClass) {
155+
SEL sharedApplicationSelector = sel_registerName("sharedApplication");
156+
SEL isProtectedDataAvailableSelector = sel_registerName("isProtectedDataAvailable");
157+
id sharedApp = ((id (*)(id, SEL))objc_msgSend)(uiApplicationClass, sharedApplicationSelector);
158+
if (sharedApp && [sharedApp respondsToSelector:isProtectedDataAvailableSelector]) {
159+
return (((BOOL (*)(id, SEL))objc_msgSend)(sharedApp, isProtectedDataAvailableSelector));
160+
}
161+
}
162+
163+
return YES;
164+
}
165+
151166
- (instancetype)initWithIdentifier:(NSString *)uniqueIdentifier
152167
{
153168
self = [super init];
@@ -249,7 +264,8 @@ - (NSData *)hashSubjectPublicKeyInfoFromCertificate:(SecCertificateRef)certifica
249264

250265
__weak typeof(self) weakSelf = self;
251266
void (^updateCacheBlock)(void) = ^{
252-
if ([[UIApplication sharedApplication] isProtectedDataAvailable]) {
267+
268+
if (isProtectedDataAvailable()) {
253269
NSData *serializedSpkiCache = [NSKeyedArchiver archivedDataWithRootObject:weakSelf.spkiCache requiringSecureCoding:YES error:nil];
254270
if ([serializedSpkiCache writeToURL:[weakSelf SPKICachePath] atomically:YES] == NO) {
255271
NSAssert(false, @"Failed to write cache");

TrustKitTests/TSKEndToEndSwizzlingTests.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ - (void)test
167167
// Valid pinning configuration
168168
@"www.datatheorem.com" : @{
169169
kTSKEnforcePinning : @YES,
170-
kTSKPublicKeyHashes : @[@"a4FoHyEnsFhauIx0w/gB7ywslD6tWGk83J2F6Pv1phA=", // CA key
170+
kTSKPublicKeyHashes : @[@"F6jTih9VkkYZS8yuYqeU/4DUGehJ+niBGkkQ1yg8H3U=", // CA key
171171
@"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" // Fake key
172172
]},
173173
// Invalid pinning configuration

0 commit comments

Comments
 (0)