Tag: certificates

  • Certificate pinning, Certificate Transparency and what to do when a CA misissues

    Certificate pinning, Certificate Transparency and what to do when a CA misissues

    The flaw everyone knows about

    Any CA in your browser's or operating system's trust store can issue a valid certificate for any domain. Not just the domains it has customers for. All of them. The web PKI is only as strong as the weakest of a few hundred organizations, and some of them have been breached.

    The 2011 DigiNotar compromise is the textbook case. Attackers got fraudulent certificates issued, including one for *.google.com, and used them against users in Iran. The reports I've read put the number of rogue certificates at roughly 500. Chrome flagged it because Google had pinned its own properties in the browser, and a user hit the warning and posted about it. Detection came from a hardcoded list, not from anything in the protocol.

    Two mechanisms came out of that era to deal with it: pinning, which limits which keys a client will accept, and Certificate Transparency, which makes every issuance publicly visible. They solve different halves of the problem, and the web ended up keeping one and mostly abandoning the other.

    Pinning: sharp, and aimed at your own foot

    HTTP Public Key Pinning (RFC 7469, 2015) let a site send a header telling browsers which public keys to trust for it. The failure modes were ugly. Pin the wrong key, or lose the one you pinned, and your site is unreachable for every returning visitor until max-age runs out. An attacker who briefly controlled your server could pin a key of their own and hold you hostage. Chrome removed HPKP support in version 67 in 2018 and nobody missed it.

    Pinning still makes sense in one place: clients you ship yourself, talking to servers you run. A mobile app or an internal service-to-service client. Pin the hash of the SubjectPublicKeyInfo, not the leaf certificate, so renewals that keep the key don't break you. Always include a backup pin for a key you haven't deployed yet.

    openssl s_client -connect example.com:443 -servername example.com </dev/null 2>/dev/null \
      | openssl x509 -pubkey -noout \
      | openssl pkey -pubin -outform der \
      | openssl dgst -sha256 -binary | base64

    On Android, Network Security Config takes that value directly, and the expiration attribute is the part people skip and then regret:

    <network-security-config>
      <domain-config>
        <domain includeSubdomains="true">api.example.com</domain>
        <pin-set expiration="2027-06-01">
          <pin digest="SHA-256">PRIMARY_KEY_HASH_BASE64=</pin>
          <pin digest="SHA-256">BACKUP_KEY_HASH_BASE64=</pin>
        </pin-set>
      </domain-config>
    </network-security-config>

    My honest opinion: if you can't force an app update quickly, don't pin a public CA's key. A bad pin on phones is an outage you can't roll back, because the fix has to go through app review and then through users actually updating. If you do pin, pin to a private CA you control, or to an intermediate with a backup, and treat the pin-set as something with an owner and a calendar entry. Also keep in mind that pinning is a speed bump on a device the user controls. Anyone with a rooted phone and Frida will get past it in minutes. It stops network attackers, not the person holding the handset.

    Certificate Transparency: detection, not prevention

    CT (RFC 6962, 2013) takes the opposite approach. CAs submit every certificate to public, append-only logs built on Merkle trees, and get back a signed certificate timestamp (SCT) that gets embedded in the certificate. Chrome began requiring SCTs for newly issued publicly trusted certificates in April 2018, and Apple followed later that year. A certificate with no SCT doesn't validate in those browsers.

    CT does not stop a CA from issuing a bad certificate. The rogue certificate still validates. What changed is that it can no longer be issued quietly, because a log entry has to exist for it to work. That only helps if somebody is reading the logs. For your own domains, that somebody is you.

    The quick version uses crt.sh:

    curl -s 'https://crt.sh/?q=example.com&output=json' \
      | jq -r '.[] | select(.issuer_name | test("Let.s Encrypt") | not)
               | [.id, .not_before, .issuer_name, .name_value] | @tsv'

    That prints every logged certificate for the name that wasn't issued by the CA you expect. It's fine for a spot check. crt.sh is a free service that times out regularly, so for a real alert use a monitor that tails the logs, such as Cert Spotter or certstream, and send hits somewhere a human reads.

    One cost to know about: precertificates put every hostname in the public logs. If your internal service names are sensitive, issuing publicly trusted certificates for them tells the world they exist. Use a wildcard or run a private CA for the internal names. Staging hostnames with project codenames in them are a common thing to find in a log search.

    Make the expected issuer a written fact

    Monitoring only works if "unexpected" is defined. Keep a short list of which CAs are allowed to issue for each domain, and publish it as DNS CAA records (RFC 8659). CAs must check CAA before issuing. RFC 8657 adds an accounturi parameter that restricts issuance to your specific ACME account, which is much tighter than naming the CA.

    example.com. IN CAA 0 issue "letsencrypt.org; accounturi=https://acme-v02.api.letsencrypt.org/acme/acct/1234567"
    example.com. IN CAA 0 iodef "mailto:[email protected]"

    CAA is a control on honest CAs. A compromised or malicious CA ignores it. So CAA reduces mistakes, and CT monitoring catches whatever gets past it. You want both.

    When a certificate shows up that you didn't request

    I'd run it in this order.

    First, rule out yourself. Check your ACME account history, your cloud load balancer certificates and your CDN, because the most common unexpected certificate is one that a colleague or a vendor requested. Most alerts end here.

    If it's really not yours, report it to the issuing CA with the log entry ID and ask for revocation. The CA/Browser Forum Baseline Requirements set revocation deadlines of 24 hours or five days depending on the reason, and a certificate issued without the domain holder's authorization is a clear case. Meanwhile, treat the domain as under attack: check DNS records and registrar access, since the usual route to a bad certificate is a hijacked validation path and not a rogue CA.

    Revocation itself is weak. Browsers don't reliably check OCSP or CRLs on every connection. Chrome relies on its CRLSets and Firefox on CRLite, and both cover only part of the picture. A revoked certificate can stay usable against some clients for a while, so don't assume revocation ends the exposure.

    For a CA that misissues repeatedly, the real enforcement is the root programs. File an incident report with Mozilla's CA program or send the details to Chrome's root program. That path has teeth: Chrome distrusted Symantec's PKI in stages across 2018, and distrusted new Entrust certificates issued after November 11, 2024.

    Shorter lifetimes help more than any of this

    The cleanest mitigation is a smaller window. The CA/Browser Forum's ballot SC-081v3, approved in 2025, steps maximum certificate lifetime down to 200 days from March 2026, 100 days from March 2027 and 47 days from March 2029. A misissued certificate that expires in 47 days is a smaller problem than one that lasts a year, and automation that renews that often will also notice when something changes.

    If I had one afternoon for this, I wouldn't spend it on pinning. I'd write the CAA records with account URIs, set up a CT monitor that pages on any issuer I didn't list, and write down who to call at each CA. Pinning can come later, and only for clients I can update.