What Is Certificate Pinning, and What Happens When a Key Rotates?
See how public-key pinning adds a client-side trust condition and plan certificate rotation for mobile app versions that are still in use.
- tls
- certificates
- mobile-apps
- guide
Certificate pinning adds a client-side identity condition to ordinary TLS validation. With public-key pinning, the client checks whether a key in the verified certificate chain matches one of the keys it expects. A valid replacement certificate can still fail for a pinned client if its chain no longer contains an expected key. That matters when the app updates more slowly than the server. Android documents its public-key pin behavior.
Keep the ordinary certificate checks in view
For HTTPS, the client first needs a certificate that can verify the intended service identity under its trust rules. A pin imposes an additional check. Android’s Network Security Configuration describes pins based on a hash of the certificate’s Subject Public Key Info. The configured chain must contain an allowed key. This differs from pinning a hash of an entire certificate, where renewing the certificate may change the pinned value even if the key stays the same. RFC 9525 explains service identity verification.
Android’s platform guidance discourages pinning for ordinary apps. A server or certificate authority change can make older app versions unable to connect until the users update. Use the platform’s normal TLS validation unless the team has an explicit requirement and owns the client update, backup key and rotation process. Read Android’s warning about server changes.
Test a rotation against installed app versions
Suppose the active server presents a certificate using key A and the app pins leaf keys. The planned replacement will use key B. During the transition, the following clients could behave differently even with a valid certificate on each server version.
| Installed pin set | Server uses A | Server switches to B |
|---|---|---|
| A only | Pin matches | Pin fails |
| A and B | Pin matches | Pin matches |
| B only | Pin fails | Pin matches |
Test the actual release builds with both the present and planned chains. Include older app versions that remain in use and verify which chain the CDN or load balancer presents. A staging endpoint with the wrong chain cannot establish that production rotation will work. When a backup pin exists, make sure the corresponding private key stays protected and an accepted certificate can be obtained for it.
Keep the rotation plan close to the certificate inventory
Document which app versions contain which pin set, who can use the backup key and how the team will know that the overlap is sufficient. For an elective rotation, ship and verify the new pin before the server switches. For a key compromise, follow the incident response plan. Restoring a compromised key just to make old clients connect would create a separate risk.
When one mobile client fails but a browser succeeds, inspect the served chain with the normal certificate checks, then compare it with the installed app’s pin set. Preserve certificate validation while fixing the trust configuration. Pinning succeeds as an operational policy only when the people who renew the certificate can coordinate with the people who ship and support the client.
