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.

FBFenwei BianAuthorNov 24, 2026
  • 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 setServer uses AServer switches to B
A onlyPin matchesPin fails
A and BPin matchesPin matches
B onlyPin failsPin 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.

Sources and further reading

About the author(s)

Software Developer & Writer • Namefi
FBAuthor

Fenwei Bian is a software developer in her thirties who spends her working hours in pull requests and her weekends with her hands in soil or sawdust. Years of open source on GitHub taught her that names are interfaces: a good one is clear, honest about what it does, and kind to whoever has to use it next.

She gardens because it rewards patience and punishes wishful thinking, and she does woodwork because a joint either fits or it doesn't. Both habits show up in how she writes about naming — measure twice, check the source, and don't sand over a rough spot and hope no one notices.

For Namefi she writes about how domain markets actually move, the practical trade-offs of tokenizing and flipping names, and picking a domain you'll still be glad you own in twenty years.

Related guides

Discuss this post

View the discussion on Namefi Discuss