What is certificate pinning and what are its trade-offs?

Understanding TLS trust chain attacks beyond HTTPS.
Pinning hardcodes a server key to block rogue CA MITM; trade-offs are breakage on cert rotation and forced updates.
What's really being asked
This question probes whether you understand the gap between default TLS and real-world trust chain vulnerabilities on mobile. Interviewers want to see that you know the device trust store is only as strong as its weakest CA, and that you have shipped enough network code to respect operational realities like certificate rotation and emergency patches.
The full answer
A good answer hits four things in order. First, a crisp definition: certificate pinning means the app bundles or hardcodes an expected server certificate or public key hash and refuses to connect if the presented chain does not match, regardless of whether the system trust store accepts it. Second, the specific attack: man-in-the-middle via a fraudulently issued or compromised CA certificate, which would otherwise pass default validation. Third, the trade-offs: you gain protection against rogue CAs but lose flexibility, so legitimate certificate rotation will break older app versions and may force an emergency release or kill switch. Fourth, maintenance challenges: pinning requires a rotation strategy such as backup pins, a way to deliver updates out-of-band, and careful coordination with your server team to avoid bricking users on long-lived installs.
The mistakes people make
Common wrong answers include claiming pinning prevents all MITM attacks without mentioning that it does nothing if the attacker controls the device or the pinned material itself. Another red flag is describing it as pure benefit with no cost; senior engineers should immediately mention certificate expiry, rotation, and the risk of locking users out. Confusing pinning with hostname verification or saying it replaces TLS entirely are also signs of shallow knowledge.
What usually comes next
Interviewers often follow up by asking how you would rotate a pinned certificate without breaking existing users, how to implement backup pins, or how Network Security Config on Android differs from OkHttp certificate pinning. They may also ask what you would do if a private key matching a pinned certificate were compromised.
A concrete example
Suppose your Android app pins the SHA-256 hash of your API server's leaf public key in OkHttp. Your CA is compromised and an attacker issues a valid cert for your domain; standard devices trust it, but your app rejects it because the public key hash does not match the pinned value. Six months later your server team rotates the key for routine hygiene. Users on the old app version now see SSL handshake failures and cannot refresh content. To mitigate this you should have shipped a backup pin in the original binary and used a staged rollout for the new pin before the old cert expired.
Interview question
An app pins its API server's leaf public key. Six months later, old app versions cannot connect after a server update. Why?
- a.The pinned certificate expired, causing the app to reject all subsequent TLS handshakes.
- b.The device trust store no longer includes the CA that signed the new certificate.
- c.The server rotated its certificate, so the pinned public key hash no longer matches.Correct
- d.A rogue CA issued a fraudulent certificate that triggered the pin mismatch.
Why? this is the answer
The card explains that legitimate certificate rotation breaks older app versions because the hardcoded public key hash no longer matches the new certificate. Option A tempts those who conflate expiry with rotation, but the scenario describes a routine key rotation, and pinning validates the expected hash rather than simply blocking expired certificates.
Just read this? Test yourself on what you have been reading.
Read the original → developer.android.com
- #android
- #security
- #tls
- #certificate-pinning
- #networking
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on android — each one lists the topics its interview covers.
See open roles