Description
For a domain that requires pinning, kTSKEnforcePinning: false allows a connection to pass the pin check even when its pin does not match. Report-only mode can help during rollout. Enable enforcement once the pins are verified, and keep normal TLS certificate validation in both modes.
On macOS, kTSKIgnorePinningForUserDefinedTrustAnchors defaults to true. TrustKit skips the pin check for a certificate chain ending in a user-defined trust anchor. Check whether your organization permits that exception.
Potential impact
- Bypass of certificate pinning.
- Server impersonation using a certificate that pinning was intended to block.
- Exposure of sensitive network traffic when an attacker controls the communication path and has the necessary certificate.
Remediation
- Verify the pins and their deployment for each domain that requires pinning. Then set
kTSKEnforcePinning: truefor that domain. - If network delegate swizzling is off, call TrustKit’s
TSKPinningValidatorin the authentication challenge handler. - On macOS, set
kTSKIgnorePinningForUserDefinedTrustAnchors: falseif user-defined trust anchors must also pass pinning. Check that this policy works with any organizational proxies you intend to trust.
Examples
The excerpts show only pin enforcement. A working setup also needs the pin list, TrustKit initialization, and integration with the network authentication challenge handler.
Before
let config = [
kTSKPinnedDomains: [
"api.example.com": [kTSKEnforcePinning: false]
]
]
After
import TrustKit
private enum BuildEmbeddedPins {
// For deployment, replace these values with the server's SHA-256 SPKI pins generated at build time.
static let primary = "HXXQgxueCIU5TTLHob/bPbwcKOKw6DkfsTWYHbxbqTY="
static let backup = "0SDf3cRToyZJaMsoS17oF72VMavLxj/N7WBNasNuiR8="
}
func makeTrustKitConfiguration() -> [String: Any] {
return [
kTSKPinnedDomains: [
"api.example.com": [
kTSKEnforcePinning: true,
kTSKPublicKeyHashes: [
BuildEmbeddedPins.primary,
BuildEmbeddedPins.backup
]
] as [String: Any]
]
]
}
With enforcement on, TrustKit blocks mismatched pins on the connections it checks for this domain. The example leaves the macOS trust-anchor exception at its default. Replace the sample SPKI pins with your current key’s pin and a separately provisioned backup for rotation. Embed both in the signed app and keep remote or user input out of the pin configuration.