Skip to content

Commit fa456c9

Browse files
committed
Add null checks to DomainPinningPolicy
1 parent ced60e3 commit fa456c9

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

trustkit/src/main/java/com/datatheorem/android/trustkit/config/DomainPinningPolicy.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,22 @@ public final class DomainPinningPolicy {
5353
if (publicKeyHashStrList == null)
5454
publicKeyHashStrList = new HashSet<>();
5555

56+
// Parse boolean settings and handle default values
57+
if (shouldEnforcePinning == null) {
58+
this.shouldEnforcePinning = false;
59+
} else {
60+
this.shouldEnforcePinning = shouldEnforcePinning;
61+
}
62+
if (shouldIncludeSubdomains == null) {
63+
this.shouldIncludeSubdomains = false;
64+
} else {
65+
this.shouldIncludeSubdomains = shouldIncludeSubdomains;
66+
}
67+
5668

5769
// Check if the configuration has a empty pin-set and still would enforce pinning
5870
// TrustKit should not work if the configuration contains both (opposite behaviors)
59-
if (publicKeyHashStrList.isEmpty() && shouldEnforcePinning) {
71+
if (publicKeyHashStrList.isEmpty() && this.shouldEnforcePinning) {
6072
throw new ConfigurationException("An empty pin-set was supplied "+
6173
"for domain " + this.hostname + " with the enforcePinning set to true. " +
6274
"An empty pin-set disables pinning and can't be use with enforcePinning set to true.");
@@ -65,7 +77,7 @@ public final class DomainPinningPolicy {
6577
// Check if the configuration has at least two pins (including a backup pin)
6678
// TrustKit should not work if the configuration contains only one pin
6779
// more info (https://tools.ietf.org/html/rfc7469#page-21)
68-
if (publicKeyHashStrList.size() < 2 && shouldEnforcePinning) {
80+
if (publicKeyHashStrList.size() < 2 && this.shouldEnforcePinning) {
6981
throw new ConfigurationException("Less than two pins were supplied "+
7082
"for domain " + this.hostname + ". This might " +
7183
"brick your App; please review the Getting Started guide in " +
@@ -91,18 +103,6 @@ public final class DomainPinningPolicy {
91103
reportUris.add(DEFAULT_REPORTING_URL);
92104
}
93105

94-
// Parse boolean settings and handle default values
95-
if (shouldEnforcePinning == null) {
96-
this.shouldEnforcePinning = false;
97-
} else {
98-
this.shouldEnforcePinning = shouldEnforcePinning;
99-
}
100-
if (shouldIncludeSubdomains == null) {
101-
this.shouldIncludeSubdomains = false;
102-
} else {
103-
this.shouldIncludeSubdomains = shouldIncludeSubdomains;
104-
}
105-
106106
this.expirationDate = expirationDate;
107107
}
108108

0 commit comments

Comments
 (0)