Tag: TLS

  • 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, including ones it has never served. 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>

    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. Pinning is also 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.

  • Why TLS 1.3 Handshakes Are Faster (And What Changed Under the Hood)

    Why TLS 1.3 Handshakes Are Faster (And What Changed Under the Hood)

    The 1-RTT handshake and what changed

    TLS 1.2 vs TLS 1.3 handshake sequence comparison

    TLS 1.3 (RFC 8446, finalized August 2018) isn’t a tuning pass on TLS 1.2. It’s a different protocol with the same name. The headline feature is a 1-RTT handshake instead of 2-RTT, but what I find more interesting is why that became possible: the designers deleted static RSA key exchange, deleted renegotiation, and made forward secrecy mandatory. This post walks through what changed on the wire.

    TLS 1.2’s 2-RTT problem

    A full TLS 1.2 handshake looks like this:

    Client                                               Server
      ClientHello  (cipher suites, supported groups, random) -->
                                                  <-- ServerHello (chosen cipher)
                                                  <-- Certificate
                                                  <-- ServerKeyExchange (if DHE/ECDHE)
                                                  <-- ServerHelloDone
      ClientKeyExchange -->
      [ChangeCipherSpec] -->
      Finished -->
                                                  <-- [ChangeCipherSpec]
                                                  <-- Finished
      Application Data <-->

    The client sends a hello, the server replies with everything needed to pin down the cipher and key exchange, and only then can the client respond with its key material and a Finished message. Application data doesn’t move until after that second round trip. On a connection with 80ms RTT to a distant CDN edge, that’s 160ms spent on negotiation before any application data moves.

    The root cause is ordering: the client has no idea which key exchange group or cipher the server will pick until ServerHello shows up, so it can’t send a key share in the first flight. So it has to wait.

    TLS 1.3’s fix: guess the group instead of negotiating it

    TLS 1.3 collapses the handshake by having the client guess which (EC)DHE group the server prefers and send a key share speculatively, right in the ClientHello:

    Client                                               Server
      ClientHello
        + key_share (e.g. x25519 public value)
        + supported_versions, signature_algorithms -->
                                                  <-- ServerHello
                                                        + key_share
                                                  <-- {EncryptedExtensions}
                                                  <-- {Certificate}
                                                  <-- {CertificateVerify}
                                                  <-- {Finished}
      {Finished} -->
      Application Data <-->                       <-- Application Data

    Everything in {} is encrypted. The server derives handshake traffic keys from its own ephemeral share plus the client’s key_share immediately after ClientHello arrives, so even the certificate exchange is now confidential. That closes a leak 1.2 had for years: certificates went over the wire in cleartext, so a passive eavesdropper could see which server you were talking to. Because the client already sent a key share up front, the server can finish the key agreement and start pushing encrypted application data in its very first response. Once the client has ServerHello and Finished, it can start sending data too, with no extra round trip to acknowledge anything. That’s the 1-RTT.

    If the client guesses wrong (rare these days since x25519 is close to universal), the server sends a HelloRetryRequest and you’re back to something like 2-RTT. That’s the exception, though, not what happens on a normal connection.

    You can watch this happen directly:

    $ curl -v --tlsv1.3 https://example.com 2>&1 | grep -i 'TLS\|SSL connection'
    * TLSv1.3 (OUT), TLS handshake, Client hello (1):
    * TLSv1.3 (IN), TLS handshake, Server hello (2):
    * TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
    * TLSv1.3 (IN), TLS handshake, Certificate (11):
    * TLSv1.3 (IN), TLS handshake, CV (15):
    * TLSv1.3 (IN), TLS handshake, Finished (20):
    * TLSv1.3 (OUT), TLS handshake, Finished (20):
    * SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384

    Notice there’s no ServerKeyExchange or ClientKeyExchange message type anymore. Key exchange data rides inside the Hello messages as an extension (key_share) instead of being its own standalone handshake message.

    Static RSA key exchange is gone

    TLS 1.2 allowed TLS_RSA_WITH_* cipher suites, where the client just encrypts a premaster secret directly with the server’s RSA public key. There’s no Diffie-Hellman anywhere. It was fast (one asymmetric operation, no DHE math) but bad for confidentiality: if the server’s private key is ever compromised, subpoenaed, or pulled out via something like Heartbleed, every past session a passive adversary ever recorded becomes decryptable after the fact. There’s no forward secrecy, because one static key protects every session’s secret.

    RFC 8446 removes static RSA key exchange entirely. TLS 1.3 only supports (EC)DHE-based exchange, plus PSK for resumption, which I’ll get to below. Every handshake negotiates a fresh ephemeral key pair, so compromising the server’s long-term signing key lets an attacker impersonate the server from that point forward, but it buys them nothing against traffic captured earlier. You can no longer misconfigure forward secrecy away with a cipher-suite setting, because the protocol always provides it.

    Renegotiation is gone too. TLS 1.2’s renegotiation, re-running the handshake mid-connection to rotate keys or ask for a client cert, was the root cause of CVE-2009-3555, a plaintext-injection bug that needed the RFC 5746 patch as a partial band-aid. TLS 1.3 replaces that general-purpose “redo the whole handshake” mechanism with two narrower ones: post-handshake authentication (a CertificateRequest sent after the handshake, for mTLS-style client cert checks) and a dedicated KeyUpdate message for rotating keys.

    0-RTT resumption trades replay protection for speed

    For repeat connections, TLS 1.3 offers 0-RTT via PSK resumption. The client reuses a session ticket from an earlier connection and sends encrypted application data in the very first flight, before the server has said a word back:

    Client                                               Server
      ClientHello + early_data + psk extension
      (encrypted with early_data_key)
      Application Data (0-RTT) -->
                                                  <-- ServerHello, ... Finished
      Application Data <-->

    That’s zero round trips of latency before data moves, which helps a mobile client reconnecting to a server it already knows. The catch is that 0-RTT data has no replay protection. The client sends it before the handshake finishes, specifically before the server’s Finished message, which is the thing that actually proves liveness and ties the exchange together. A network-positioned attacker can just capture that first flight and replay it verbatim. At that layer the server can’t tell a replay from a legitimate retransmission.

    RFC 8446 Section 8 doesn’t try to fix this cryptographically. It leaves the problem to the application: only use 0-RTT for idempotent requests (safe GETs, not POST /transfer-funds), and let servers implement their own anti-replay measures, such as single-use tickets or bounded replay caches. Those measures give back some of the latency win in exchange for safety. I’ve seen teams enable 0-RTT, forget the tradeoff, and get surprised when a retry storm double-charges something. Most production setups (NGINX, HAProxy, Cloudflare) either disable 0-RTT outside of static content or require the application to opt in per request.

    Checking your own setup

    If you’re terminating TLS yourself, not sitting behind a CDN, confirm your stack is actually negotiating 1.3 and not quietly falling back to 1.2 for compatibility reasons that stopped mattering years ago. Run openssl s_client -connect host:443 -tls1_3 and check for Protocol: TLSv1.3 in the output.

    Drop any RSA key-exchange cipher suites still sitting in your 1.2 fallback config. Those are the forward secrecy hole TLS 1.3 was designed to close.

    If you turn on 0-RTT, go audit which endpoints can actually receive early data. Most servers let you scope this. Default to none until you’ve confirmed an endpoint is idempotent rather than assuming it.

    TLS 1.3 is more than TLS 1.2 with a speed boost. Static RSA key exchange is gone, renegotiation is replaced by narrower mechanisms, and 0-RTT gives up replay protection for latency. Know which guarantees you’re giving up before you turn it on.