A trusted certificate authority can still become a weak link: if it signs a certificate for your domain with an attacker-controlled key, a man-in-the-middle attack may impersonate your server. Public key pinning gives a client a fixed expectation instead of trusting any otherwise valid certificate. section 9.3
The client-side check works in a short sequence:
- Hardcode a specific server certificate, usually its hash, or the server’s expected long-term public key. section 9.3
- Connect through TLS and inspect the certificate presented during the handshake’s authentication phase. section 9.3 section 9.6
- Continue only when the certificate or contained public key matches the pinned value; otherwise abort the connection. section 9.3
Pinning is especially practical for mobile applications, which know their expected server in advance. It is harder for browsers serving arbitrary sites, and it can make certificate or key changes difficult. Certificate revocation and certificate monitoring provide other defenses against compromised certificates or certificate authorities. section 9.3 section 9.6
