Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 1 bug, and several static analysis warnings #187

Merged
merged 1 commit into from
Dec 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ const char* GetHostnamePart(size_t offset) {
}

int HasLeafChildren(const struct TrieNode* node) {
if (node == NULL) { return 0; }
if (node->first_child_offset < g_leaf_node_table_offset) return 0;
return 1;
}
Expand Down
6 changes: 3 additions & 3 deletions TrustKit/parse_configuration.m
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@

// Always start with the optional excludeSubDomain setting; if it set, no other TSKDomainConfigurationKey can be set for this domain
NSNumber *shouldExcludeSubdomain = domainPinningPolicy[kTSKExcludeSubdomainFromParentPolicy];
if (shouldExcludeSubdomain)
if (shouldExcludeSubdomain != nil && [shouldExcludeSubdomain boolValue])
{
// Confirm that no other TSKDomainConfigurationKeys were set for this domain
if ([[domainPinningPolicy allKeys] count] > 1)
Expand Down Expand Up @@ -143,7 +143,7 @@

// Extract the optional enforcePinning setting
NSNumber *shouldEnforcePinning = domainPinningPolicy[kTSKEnforcePinning];
if (shouldEnforcePinning)
if (shouldEnforcePinning != nil)
{
domainFinalConfiguration[kTSKEnforcePinning] = shouldEnforcePinning;
}
Expand All @@ -156,7 +156,7 @@

// Extract the optional disableDefaultReportUri setting
NSNumber *shouldDisableDefaultReportUri = domainPinningPolicy[kTSKDisableDefaultReportUri];
if (shouldDisableDefaultReportUri)
if (shouldDisableDefaultReportUri != nil)
{
domainFinalConfiguration[kTSKDisableDefaultReportUri] = shouldDisableDefaultReportUri;
}
Expand Down
23 changes: 22 additions & 1 deletion TrustKitTests/TSKPinConfigurationTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,28 @@ - (void)testDisablePinningForSubdomainAndNoPublicKey
XCTAssertEqualObjects(serverConfigKey, @"unsecured.good.com", @"Did not receive a configuration for pinned subdomain");
}

- (void)testExplicitNotDisablePinningForSubdomainAdditionalDomainKeys
{
NSDictionary *trustKitConfig;
trustKitConfig = parseTrustKitConfiguration(@{kTSKPinnedDomains : @{
@"good.com" : @{
kTSKPublicKeyHashes : @[@"TQEtdMbmwFgYUifM4LDF+xgEtd0z69mPGmkp014d6ZY=",
@"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=",
],
kTSKIncludeSubdomains: @YES},
@"unsecured.good.com": @{
// When using this option, TrustKit should allow/require a policy for the subdomain
kTSKExcludeSubdomainFromParentPolicy: @NO,
kTSKPublicKeyHashes : @[@"TQEtdMbmwFgYUifM4LDF+xgEtd0z69mPGmkp014d6ZY=",
@"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=",
],
}
}
});

NSString *serverConfigKey = getPinningConfigurationKeyForDomain(@"unsecured.good.com", trustKitConfig[kTSKPinnedDomains]);
XCTAssertEqualObjects(serverConfigKey, @"unsecured.good.com", @"Did not receive a configuration for pinned subdomain");
}

- (void)testDisablePinningForSubdomainWithoutParentAndNoPublicKey
{
Expand Down Expand Up @@ -105,7 +127,6 @@ - (void)testDisablePinningForSubdomainAdditionalDomainKeys
@"Configuration with kTSKExcludeSubdomainFromParentPolicy must reject additional domain keys");
}


- (void)testNokTSKSwizzleNetworkDelegates
{
XCTAssertThrows(parseTrustKitConfiguration(@{kTSKPinnedDomains : @{
Expand Down