Workspace

TLS: certificates, trust and the 1-RTT handshake

3 day streakD

TLS: certificates, trust and the 1-RTT handshake

How two strangers agree on a secret over a hostile network, and how the client knows it is talking to the right server. Then what TLS 1.3 removed and why it is faster.

BasicsLesson 2 of 622 min

TLS gives a connection three properties. Confidentiality: nobody on the path can read it. Integrity: nobody can change it undetected. Authentication: the client knows which server it is talking to. The first two come from symmetric encryption with a shared key. The hard parts are agreeing on that key in public, and proving identity.

Key exchange in one idea

In Diffie-Hellman key exchange, each side picks a private number, sends a public value derived from it, and combines its own private number with the other side's public value. Both arrive at the same secret, while an observer who saw only the public values cannot compute it. TLS 1.3 uses elliptic-curve versions such as X25519, and in 2026 increasingly a hybrid that adds a post-quantum algorithm.

Certificates and the chain of trust

A key exchange alone could be with an attacker in the middle. The server therefore proves its identity with a certificate: a document binding its public key to its domain name, signed by a certificate authority. That CA's certificate is signed by a root CA whose certificate ships in your operating system or browser trust store. The client checks each signature up the chain, checks the name matches, and checks nothing has expired.

Figure 2.1

The TLS 1.3 handshake, message by message

ClientServer
    ReadyBefore the handshake

    The TCP handshake is done. Now TLS must agree on keys and prove the server's identity.

    Step 01 / 9
    Step through the handshake. The client guesses the key exchange and sends its key share in the first message, so the server can derive keys immediately and encrypt everything after ServerHello, including its certificate. Application data can follow after one round trip.

    SNI and ALPN

    One IP address often serves thousands of domains. The client names the one it wants in the Server Name Indication extension of its ClientHello, so the server can pick the right certificate. ALPN lets the client list protocols it speaks, such as h2 and http/1.1, and the server picks one during the handshake, saving a round trip of negotiation.

    Forward secrecy and resumption

    TLS 1.3 only allows ephemeral key exchanges: a fresh key pair per connection, thrown away afterwards. If the server's long-term private key leaks next year, recorded traffic from today stays safe. This is forward secrecy. TLS 1.2 also allowed RSA key transport, where a leaked key decrypts everything ever recorded.

    A returning client can resume with a pre-shared key from a previous session ticket, skipping certificate checks. It can even send 0-RTT early data in its first flight. Early data can be replayed by an attacker who captured it, so servers should accept it only for idempotent requests.

    Worked exampleRound trips before the first response byte
    TLS 1.2 full handshake
    TCP 1 RTT + TLS 2 RTT + request 1 RTT = 4 RTT
    TLS 1.3 full handshake
    TCP 1 RTT + TLS 1 RTT + request 1 RTT = 3 RTT
    TLS 1.3 with 0-RTT resumption
    TCP 1 RTT + request sent with the handshake = 2 RTT
    At 150 ms per RTT
    600 ms, 450 ms and 300 ms respectively

    The next lesson adds DNS and QUIC to this table.

    Go deeperThe TLS 1.3 key schedule, briefly

    TLS 1.3 never uses the Diffie-Hellman secret directly. It feeds it through HKDF, a key-derivation function, together with a hash of every handshake message so far, the transcript. Out come separate keys for each direction and each phase: handshake traffic, application traffic, resumption.

    Binding keys to the transcript means any tampering with an earlier message, such as removing a stronger cipher suite from the ClientHello to force a weaker one, produces different keys, and the Finished messages fail to verify. Downgrade attacks that plagued older versions stop working.

    inspect-tls.shShell
    # Handshake details: protocol, cipher, key exchange group, certificate chain
    openssl s_client -connect api.example.com:443 -servername api.example.com -brief </dev/null
    
    # Full chain with issuers
    openssl s_client -connect api.example.com:443 -showcerts </dev/null | grep -E 's:|i:'
    
    # Let Wireshark decrypt your own traffic for study
    SSLKEYLOGFILE=$PWD/keys.log curl -s https://example.com > /dev/null

    Point Wireshark's TLS settings at keys.log and the encrypted records in your capture become readable.

    Where you will meet it

    Certificate expiry outages

    Expired certificates still cause major outages. Automated issuance with ACME, as Let's Encrypt popularised, renews them every few weeks.

    Corporate proxies

    TLS-inspecting proxies install their own root CA on company machines. Tools with pinned or bundled trust stores then fail with certificate errors.

    mTLS

    Service meshes give every service a certificate and require one from the client too, so both sides authenticate.

    Words to know

    Certificate authority
    An organisation trusted to sign certificates binding keys to names.
    SNI
    Server Name Indication: the domain the client wants, sent in the ClientHello.
    ALPN
    Application-Layer Protocol Negotiation: agreeing on h2 or http/1.1 inside the handshake.
    Forward secrecy
    Past sessions stay safe even if long-term keys leak later.

    Check yourself

    Answer out loud before you open each one.

    What does a certificate prove, and who vouches for it?

    That a public key belongs to a domain name. A certificate authority signs it, and the client trusts that CA's root.

    What is forward secrecy?

    Compromising a long-term key later does not decrypt past sessions, because each session used a fresh ephemeral key exchange.

    Why is 0-RTT data dangerous?

    It can be replayed. A request that charges money must not be accepted as 0-RTT data.

    Try it

    Run the openssl s_client -brief command against three sites. Note the TLS version, the key exchange group (look for X25519MLKEM768) and the issuer.

    A good place to start

    Explore a pattern

    A little guidance

    Start with a pattern, read through a problem, and mark it solved when the idea clicks. Save anything you want to revisit.

    New tutorials are added one at a time. Your bookmarks and solved checkmarks stay in this browser.

    Explore the roadmap