|
8 | 8 | See AUTHORS file for the list of project authors. |
9 | 9 | |
10 | 10 | */ |
11 | | - |
12 | | -#import <UIKit/UIKit.h> |
| 11 | +#import <objc/runtime.h> |
| 12 | +#import <objc/message.h> |
13 | 13 | #import "TSKSPKIHashCache.h" |
14 | 14 | #import "../TSKLog.h" |
15 | 15 | #import <CommonCrypto/CommonDigest.h> |
@@ -148,6 +148,21 @@ - (SPKICacheDictionnary *)loadSPKICacheFromFileSystem; |
148 | 148 |
|
149 | 149 | @implementation TSKSPKIHashCache |
150 | 150 |
|
| 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 | + |
151 | 166 | - (instancetype)initWithIdentifier:(NSString *)uniqueIdentifier |
152 | 167 | { |
153 | 168 | self = [super init]; |
@@ -249,7 +264,8 @@ - (NSData *)hashSubjectPublicKeyInfoFromCertificate:(SecCertificateRef)certifica |
249 | 264 |
|
250 | 265 | __weak typeof(self) weakSelf = self; |
251 | 266 | void (^updateCacheBlock)(void) = ^{ |
252 | | - if ([[UIApplication sharedApplication] isProtectedDataAvailable]) { |
| 267 | + |
| 268 | + if (isProtectedDataAvailable()) { |
253 | 269 | NSData *serializedSpkiCache = [NSKeyedArchiver archivedDataWithRootObject:weakSelf.spkiCache requiringSecureCoding:YES error:nil]; |
254 | 270 | if ([serializedSpkiCache writeToURL:[weakSelf SPKICachePath] atomically:YES] == NO) { |
255 | 271 | NSAssert(false, @"Failed to write cache"); |
|
0 commit comments