Every key pair in this simulator is a real ECDSA P-256 key generated by the browser's own crypto.subtle.generateKey. Each connection attempt exports the presented public key as real SPKI bytes (exportKey('spki', β¦)) and hashes them with real crypto.subtle.digest('SHA-256', β¦) β the same construction as an actual mobile app's SPKI-hash pin:
pins = { SHA-256(SPKI_expected), SHA-256(SPKI_backup) }
step 1: CA-chain check β this sim's "CA" trusts any cert it is shown
(models a compromised/malicious CA, or a corporate MITM proxy
with its root installed on the device β a real-world case
where CA validation alone is not enough)
step 2: pin check β connect β SHA-256(SPKI_presented) β pins
final: connect β step 1 passes AND (pinning off OR step 2 passes)
Without pinning, step 1 alone decides the connection β and because the simulated CA accepts any certificate (mirroring how any of hundreds of trusted root CAs, or one attacker-installed root, is enough in real TLS), the attacker's genuinely different key pair is accepted every time. With pinning enabled, step 2 runs a real byte-for-byte comparison of the freshly computed SHA-256 hash against the pinned hash, and the attacker's real hash β being the digest of a real but different SPKI β never equals the pinned one, so the connection is torn down before any data is exchanged.
The catch is pinning's failure mode is self-inflicted outage, not just security: rotate the real server key pair without a staged backup pin, and the legitimate server's new hash also fails the same real comparison. This is why real deployments always ship at least one backup pin alongside the primary β try Rotate Server Certificate with and without Backup Pin Staged to see both outcomes.
- Certificate Pinning β toggles whether step 2 (the real hash comparison) runs at all.
- MITM Attacker β inserts a proxy that generates its own real ECDSA key pair and presents it in place of the server's.
- Backup Pin Staged β pre-registers the server's next real SPKI hash so a legitimate rotation doesn't lock users out.
- Rotate Server Certificate β the server calls
generateKey again for a genuinely fresh key pair, simulating a real cert renewal event.