A banking app pins its API keys and two-year-old builds are still installed; how do you rotate the server key without locking those builds out?
answer
- the pin set changes only by update
- a backup key held offline
- an end date that fails open
- ship the key long before using it
- the server is the side you can roll back
basics
~20 sNever deploy a key that installed builds do not pin. Each build ships the live key, an offline backup and an expiry on the pin set; a new key goes live only after shipping for one expiry window, so every build pins it or has expired.
solid answer
~50 sA pin set is compiled into the binary, so it changes only when a user installs an update, and a server key outside it locks that build out. Each release therefore carries at least two keys: the live one and a backup whose private key the bank keeps offline and has never deployed. The pin set also carries an expiry, after which the build stops enforcing pins and falls back to normal certificate checks: it fails open instead of bricking, at the price of losing pinning on stale builds. A planned rotation moves to a key that has already shipped in the pin set for longer than that expiry window, so every installed build either pins the new key or no longer enforces pins. The next release adds a fresh offline backup. Pin failures and expiries are reported per app version, and a build that does fail shows an update screen rather than a generic error.
code
pseudocode · 17 linespin_set = { host: "api.bank.example",
keys: [live_key_hash, backup_key_hash],
expires: build_release_date + pin_lifetime }
on tls_connect(host, chain):
if not system_checks_pass(chain):
fail("untrusted certificate")
if host != pin_set.host:
allow()
if today() > pin_set.expires:
report("pins_expired", app_version)
allow()
if any key in chain_keys(chain) is in pin_set.keys:
allow()
queue_report("pin_failure", host, app_version, chain_key_hashes(chain))
fail("pin mismatch")
show_screen("secure_connection_blocked", offer_store_update = true)go deeper
Recall that pins are built into the app, so a server key the build does not list locks that build out until the user updates.
Explain why every build carries a live key and an offline backup, and what an expiry on the pin set does when a build is never updated.
Plan the rotation across installed versions: ship the key at least one pin lifetime ahead, report failures per version, and roll the server back if you erred.
Choose the pin lifetime from the adoption curve and the bank's tolerance for stale builds running unpinned, and decide when a minimum-version gate must close the gap.
## Why a pin is a promise the binary cannot take back A **pin set** is the list of server public keys an app will accept on top of ordinary certificate checks. On a phone it is compiled into the release build, and one platform's documentation says it outright: without a backup key, a forced key change means pushing out an app update to restore connectivity. If the server starts presenting a key outside the set, that build refuses to connect, and nothing the bank does on the network can change the build's mind. In this scenario, builds up to two years old are still installed, so a careless key change locks out every customer who has not updated, at once, on a banking app. ## The pin set every build carries - **The live key**: the one the API serves today. - **A backup key**: a key pair generated in advance whose private half the bank keeps **offline** and has never deployed. One platform's guidance says to always include a backup key; the other's says to pin more than one key. The historical web standard for pinning required a backup pin and warned that whoever steals the undeployed backup key can intercept undetected, which is why it stays offline. - **An expiry**: a date after which the build stops enforcing pins and uses normal certificate checks only. One platform supports this directly and notes both sides: it prevents connectivity failures in builds that were never updated, and it can let an attacker past the pins once the date has gone. ## The rotation sequence 1. **Generate the next key early** and ship it in the pin set as the backup in the coming releases. 2. **Wait** until no build that lacks it still enforces pins (see the sizing below). 3. **Deploy the new key** on the API. Every build either pins it or has expired. 4. **Add a fresh offline backup** to the next release, and start the clock for the following rotation. 5. **Watch pin-failure reports by app version** during and after the switch; a spike in one version means a build was missed. ## Sizing the lead time Inputs, all assumptions of this scenario: a release every four weeks; each build's pin set expires 15 months after its release; builds up to 24 months old are installed. | Build age at rotation | Carries the new key? | Enforces pins? | Outcome | |---|---|---|---| | 0 to 15 months, released after the key shipped | yes | yes | connects, pinned | | Older than 15 months | no | no, expired | connects on normal certificate checks | | Any build that lacks the key but is younger than 15 months | no | yes | **locked out** | The last row is empty only if the new key shipped **at least 15 months** before it goes live. So the rule is: **lead time at least the pin set's lifetime**. A shorter expiry shortens the lead time but leaves more stale builds unpinned; a longer one protects old builds for longer but makes every rotation slower. If the bank cannot accept stale builds running unpinned, the answer is a minimum-version gate on the server, which is a separate decision. ``` plan: ship key B as backup ......... month 0 key B pinned in every build .. months 0 to 15+ switch API to key B .......... month 15 or later ship key C as backup ......... next release ``` ## When the live key is compromised There is no time for a 15-month plan. The bank switches the API to the **offline backup**, which every supported build already pins, then ships a new backup. This is the scenario the backup exists for. A team that pinned only the live key has no move left except an emergency update and a lockout. ## What a locked-out build sees A build that fails the pin cannot hear from the pinned API, so it cannot be told to update by that API. The app must decide locally what to show: - a specific screen ("secure connection could not be verified") with a route to the store listing; - no "continue anyway" button, since a pin failure might be a real attack; - a failure report to a host outside the pin set, queued if necessary. And if the lockout was the bank's own mistake, the fastest fix is on the server, the one side that *can* roll back: put the previous, still-pinned key back. ## Trade-offs to state | Pin set expiry | Old builds after a mistake | Old builds against an attacker | |---|---|---| | None | locked out until updated | protected indefinitely | | Long | locked out for longer | protected for longer | | Short | recover sooner | unprotected sooner | No figure in any platform's guidance gives the right expiry; it is chosen from the adoption curve and the bank's tolerance for stale builds running unpinned.
- Why does the backup key's private half stay offline rather than on the API servers beside the live key?Because whoever holds it can impersonate the API to every build that pins it, and nothing would look wrong. Kept offline and never deployed, it is out of reach of an attacker who breaches the servers, so it remains a clean way out if the live key is stolen.
- Can the bank shorten the wait by pushing the new key to old builds through remote configuration?Only if the build already had code to accept pins from configuration, and then the configuration channel itself becomes the thing to protect: whoever can forge it can install their own key. Builds without that code cannot learn a new pin except by updating.
- How does the bank check, before the switch, that no pinning build lacks the new key?Compare the API's request logs by app version against the pin set each version shipped, counting builds that lack the key and have not expired; by construction that should be zero. Then serve the new key from a small slice of API servers first and watch pin-failure reports by version before moving everything.
Re-keying an office building where tenants hold keys for years: you hand every tenant the new key months before you change the lock, keep a spare master key in a safe, and only change the lock once nobody still carries just the old key.
- A single pinned key is enough if the certificate is renewed on time.
- Old builds will pick up the new pin from the server at their next connection.
- Rotate the server key first, then add its pin in the next app release.
- A locked-out build can be told to update by the API it can no longer reach.
- The offline backup key can live on the API servers beside the live key.