Skip to content

Commit

Permalink
TSKSPKIHashCache must be passed a non-nil identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
codyd51 committed Nov 27, 2017
1 parent 42c673a commit 754cefd
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 13 deletions.
5 changes: 2 additions & 3 deletions TrustKit/Pinning/TSKSPKIHashCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ typedef NSMutableDictionary<NSData *, NSData *> SPKICacheDictionnary;

/**
Create a new cache of SPKI hashes. The identifier is required to ensure that multiple cache
instances do not attempt to use the same file on disk for persistence. If nil, persistence
will be disabled (not recommended).
instances do not attempt to use the same file on disk for persistence.
@param uniqueIdentifier A unique identifier that is stable across app launches/instance creation
@return An initialized hash cache.
*/
- (instancetype _Nullable)initWithIdentifier:(NSString * _Nullable)uniqueIdentifier NS_DESIGNATED_INITIALIZER;
- (instancetype _Nullable)initWithIdentifier:(NSString*)uniqueIdentifier NS_DESIGNATED_INITIALIZER;

/**
Get a pin cache for the provided certificate and public key algorithm. The pins
Expand Down
8 changes: 3 additions & 5 deletions TrustKit/Pinning/TSKSPKIHashCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ - (instancetype)initWithIdentifier:(NSString *)uniqueIdentifier
// Initialize our locks
_lockQueue = dispatch_queue_create("TSKSPKIHashLock", DISPATCH_QUEUE_CONCURRENT);

_spkiCacheFilename = uniqueIdentifier; // if this value is nil, persistence will always fail.
// Ensure a non-nil identifier was provided
NSAssert(uniqueIdentifier, @"TSKSPKIHashCache initializer must be passed a unique identifier");
_spkiCacheFilename = uniqueIdentifier;

// First try to load a cached version from the filesystem
_subjectPublicKeyInfoHashesCache = [self loadSPKICacheFromFileSystem];
Expand Down Expand Up @@ -278,10 +280,6 @@ - (NSData *)getPublicKeyDataFromCertificate:(SecCertificateRef)certificate

- (NSURL *)SPKICachePath
{
if (!self.spkiCacheFilename)
{
return nil;
}
NSURL *cachesDirUrl = [NSFileManager.defaultManager URLsForDirectory:NSCachesDirectory
inDomains:NSUserDomainMask].firstObject;
return [cachesDirUrl URLByAppendingPathComponent:self.spkiCacheFilename];
Expand Down
5 changes: 0 additions & 5 deletions TrustKitTests/TSKPublicKeyAlgorithmTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,19 @@ @interface TSKPublicKeyAlgorithmTests : XCTestCase
@implementation TSKPublicKeyAlgorithmTests
{
TSKSPKIHashCache *spkiCache;
TSKSPKIHashCache *nonPersistentSpkiCache;
}

- (void)setUp
{
[super setUp];
[spkiCache resetSubjectPublicKeyInfoDiskCache];
[nonPersistentSpkiCache resetSubjectPublicKeyInfoDiskCache];
spkiCache = [[TSKSPKIHashCache alloc] initWithIdentifier:@"test"];
nonPersistentSpkiCache = [[TSKSPKIHashCache alloc] initWithIdentifier:nil];
}

- (void)tearDown
{
[spkiCache resetSubjectPublicKeyInfoDiskCache];
[nonPersistentSpkiCache resetSubjectPublicKeyInfoDiskCache];
spkiCache = nil;
nonPersistentSpkiCache = nil;
[super tearDown];
}

Expand Down

0 comments on commit 754cefd

Please sign in to comment.