Skip to content

Commit

Permalink
Merge pull request #336 from EthanArbuckle/SCAN-4624
Browse files Browse the repository at this point in the history
check for isProtectedDataAvailable before writing to pinning cache
  • Loading branch information
EthanArbuckle authored Oct 2, 2024
2 parents e6f9f76 + 750bd66 commit 2adabbf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions TrustKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1521,7 +1521,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
APPLICATION_EXTENSION_API_ONLY = YES;
APPLICATION_EXTENSION_API_ONLY = NO;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
Expand Down Expand Up @@ -1595,7 +1595,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
APPLICATION_EXTENSION_API_ONLY = YES;
APPLICATION_EXTENSION_API_ONLY = NO;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
Expand Down
3 changes: 2 additions & 1 deletion TrustKit/Pinning/TSKSPKIHashCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

#import <UIKit/UIKit.h>
#import "TSKSPKIHashCache.h"
#import "../TSKLog.h"
#import <CommonCrypto/CommonDigest.h>
Expand Down Expand Up @@ -244,7 +245,7 @@ - (NSData *)hashSubjectPublicKeyInfoFromCertificate:(SecCertificateRef)certifica
});

// Update the cache on the filesystem
if (self.spkiCacheFilename.length > 0)
if (self.spkiCacheFilename.length > 0 && [[UIApplication sharedApplication] isProtectedDataAvailable])
{
NSData *serializedSpkiCache = [NSKeyedArchiver archivedDataWithRootObject:_spkiCache requiringSecureCoding:YES error:nil];
if ([serializedSpkiCache writeToURL:[self SPKICachePath] atomically:YES] == NO)
Expand Down
9 changes: 9 additions & 0 deletions TrustKitTests/TSKPinningValidatorTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ - (void)tearDown
// Pin to any of CA, Intermediate CA and Leaf certificates public keys (all valid) and ensure it succeeds
- (void)testVerifyAgainstAnyPublicKey
{
id mockApplication = OCMClassMock([UIApplication class]);
OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);

// Mock isProtectedDataAvailable to return YES
OCMStub([mockApplication isProtectedDataAvailable]).andReturn(YES);

// Create a valid server trust
SecCertificateRef certChainArray[1] = {_leafCertificate};
SecCertificateRef trustStoreArray[1] = {_rootCertificate};
Expand Down Expand Up @@ -165,6 +171,9 @@ - (void)testVerifyAgainstAnyPublicKey
XCTAssertEqual([fsCache count], 1UL, @"SPKI cache for RSA 4096 must be persisted to the file system");

CFRelease(trust);

OCMVerify([mockApplication isProtectedDataAvailable]);
[mockApplication stopMocking];
}


Expand Down

0 comments on commit 2adabbf

Please sign in to comment.