SSL, TLS and What HTTPS Actually Does

Application Layer and Security · 30 min

Core CS · Computer Networks

Three guarantees, and only one of them is encryption

TLS is not a secret code bolted onto HTTP. It is a thin layer under it that proves who the server is, agrees a key that neither side ever sends, and only then starts encrypting. Take away the proof and the encryption protects nothing at all.

Step a handshake message by message and watch the wire go dark
Public-key cryptography is used for exactly two jobs: proving the server is who it claims, and agreeing on a shared secret. Every byte of your actual data is then carried by fast symmetric encryption under a key that was computed on both machines and transmitted on neither.

01 The idea

A private conversation needs three things, not one

Every packet you send crosses machines you do not own. The café router, your college’s NAT box, three or four ISP routers, and whatever sits in front of the server. Any one of them can read your bytes, change your bytes, or answer in the server’s place. So a connection over an untrusted network has to solve three separate problems, and it is worth being able to name all three, because candidates who name only the first one get caught by the follow-up.

The first is confidentiality: nobody in the middle can read what you sent. The mechanism is symmetric encryption of every record with a shared session key. The second is integrity: nobody in the middle can change what you sent without being caught. Encryption alone does not give you this, which surprises people. A ciphertext you cannot read is still a ciphertext you can flip bits in, and the receiver would decrypt it to something different and never know. The mechanism is a message authentication code, a short tag computed from the data and the key; change one bit of the record and the tag no longer matches, so the receiver throws the record away.

The third is authentication, and it is the one this lesson keeps coming back to: you are talking to the machine you meant to talk to and not to an impostor. The mechanism is a certificate, signed by an authority your machine already trusts. Say plainly what happens without it. If you encrypt to whoever answers, an attacker who intercepts the connection completes the handshake with you himself, opens a second connection to the real server, and forwards everything between the two. Both halves are properly encrypted. Both halves have valid integrity tags. He reads and edits every byte. Encryption without authentication is not weak security, it is close to no security, because it protects a conversation with the attacker.

Now the placement in the stack, which is the other half of the idea. TLS is not an application protocol. It is a layer that sits between the transport layer and the application: TCP hands it a byte stream, it hands the application a byte stream that happens to be private, and the application protocol above it does not change by one character. That is why HTTPS is exactly HTTP, with the same methods, the same status codes and the same headers, carried inside TLS on port 443 instead of in the clear on port 80. It is also why SMTP, IMAP, POP3, FTP, LDAP and DNS all have TLS variants without anybody redesigning their grammar. You wrap the pipe; you do not rewrite what flows through it.

TLS gives three guarantees, each from a different mechanism: nobody can read it (symmetric encryption), nobody can change it undetected (an authentication tag), and you know who you are talking to (a certificate). Drop the third and the first two are still perfectly intact, protecting your conversation with the attacker.
Symmetric encryption and the session keyOne key, used by both ends to encrypt and to decrypt. It is fast: AES-128-GCM with hardware support runs at roughly a gigabyte per second per core, so it can carry a video stream without being noticed. Its one problem is the obvious one, which is getting that single key into two machines that have never met.
Public-key cryptographyA key pair. What one key locks, only the other opens, and holding the public one tells you nothing about the private one. It solves the meeting problem, but it is slow: a single RSA-2048 private-key operation costs on the order of a millisecond, so it is hopeless for bulk data. TLS uses it only during setup.
CertificateA file that binds a hostname to a public key, signed by a certificate authority. It carries the public key, never the private one. It is the only thing standing between an encrypted connection to your bank and an equally encrypted connection to somebody pretending to be your bank.

02 Worked example

One browser, one server, one handshake

A browser opens https://www.example.com/. TCP has already finished its own three-way handshake to port 443, so a byte stream exists and nothing on it is private yet. What follows is a TLS 1.2 handshake compressed to five moves, and it is the same connection for the rest of the lesson: the message table in section 03 expands it row by row, the console in section 04 lets you step it, and every claim in the cheat sheet is checked against it. Read left to right, and watch which moves are readable by anyone on the path.

1 · Two hellos, two randomsThe client says which TLS versions and cipher suites it supports and sends a 32-byte random value. The server picks one version and one suite and sends its own 32-byte random. All in the clear, because nothing has been agreed yet.
2 · The certificateThe server sends its certificate and the intermediates above it. Inside are the hostnames it is valid for, its public key, the validity dates and the CA’s signature. The private key stays on the server and is never sent anywhere, ever.
3 · Key agreementEach side sends a fresh Diffie-Hellman public value and keeps the matching private value. Each then combines its own private value with the other’s public value and gets the same secret. The server signs its value with the certificate’s private key, which is what ties the key to the identity.
4 · Switch, and prove itBoth sides announce that everything after this point is encrypted, then each sends a Finished message. Finished is the first encrypted message and it carries a hash of every handshake message so far, so any tampering earlier is caught here.
5 · The request, at lastOnly now does GET / HTTP/1.1 go out, byte for byte the request that would have gone over port 80, wrapped in an encrypted record with a 16-byte authentication tag on the end.

Two things in that sequence do most of the work, and node 3 is both of them. Take the key first. The word agreement is doing something specific and it is the point students most often get wrong. Nobody generates a session key and sends it. Each side picks a private value, publishes a value derived from it, and then does one calculation that turns its own private value plus the other side’s public value into a shared secret. Both calculations land on the same number. An observer who recorded every single byte of the handshake holds two public values and cannot get from them to that number. The session key is computed twice and transmitted zero times, which is why recording the traffic does not help you.

The second thing is the signature in node 3, and it is what stops the whole scheme from being a polite conversation with an attacker. Notice that a certificate on its own proves nothing. It is a public document; anyone can connect to www.example.com, take a copy of its certificate, and present that copy to you. What an impostor cannot do is produce a signature that verifies against the public key inside it, because that needs the private key. So the server signs its Diffie-Hellman public value, together with both random values from node 1, using the private key that matches the certificate. The client verifies that signature with the public key it just received. Only then does it believe anything.

Both random values are in that signature for a reason worth stating, because it is the difference between an answer and a memorised one. If the server signed only its own key share, an attacker could record a signed message from a real connection today and replay it in a fake connection tomorrow. Including the client’s fresh random makes the signature specific to this connection, so a recorded one is useless. That is the same reason the client random exists at all.

Finally, look at where the encryption starts. Moves 1, 2 and 3 are entirely in the clear. Anybody on the path can read which site you are contacting, which cipher suites your browser offers, and the full certificate the server sent back. The connection only goes dark at move 4. That is the ordering to remember for TLS 1.2, and it is precisely the part TLS 1.3 rearranges.

03 Mechanics

Every message, every guarantee, and every version that is now dead

Five tables, in the order the questions come. First the handshake in full, because "walk me through the TLS handshake" is asked directly and the follow-up is always which of those was readable. The last column is the one to study. Read down it and find the row where it flips.

#MessageDirectionWhat it carriesOn the wire
1ClientHelloclient to serverHighest version supported, a 32-byte client_random, the list of cipher suites it will accept, and extensions including SNI, the hostname being requested.cleartext
2ServerHelloserver to clientThe one version and the one cipher suite the server chose from those lists, plus a 32-byte server_random.cleartext
3Certificateserver to clientThe server’s certificate and the intermediate certificates above it. Public key inside. No private key, here or anywhere else on the wire.cleartext
4ServerKeyExchangeserver to clientThe server’s ephemeral Diffie-Hellman public value, signed with the certificate’s private key over both randoms and that value. This message is what authenticates the server.cleartext, but signed
5ServerHelloDoneserver to clientNo fields. It marks the end of the server’s flight, which completes round trip one.cleartext
6ClientKeyExchangeclient to serverThe client’s ephemeral Diffie-Hellman public value. Both sides derive the shared secret at this point, and the secret is in no field of any message.cleartext
7ChangeCipherSpecclient to serverA single byte meaning "everything you get from me after this is under the new keys". The last thing the client sends in the clear.cleartext
8Finishedclient to serverA value computed from a hash of every handshake message so far, keyed with the master secret. The first encrypted message of the connection.ENCRYPTED
9ChangeCipherSpecserver to clientThe same one-byte switch in the other direction.cleartext
10Finishedserver to clientThe server’s transcript check. This completes round trip two, and the handshake is over.ENCRYPTED
Two round trips, ten messages, and not one byte of your request has moved yet. On top of the TCP handshake’s own round trip, that is three round trips before the server sees GET /. This is the entire reason TLS 1.3 exists and the entire reason real systems reuse connections instead of opening a fresh one per request.
11Application dataclient to serverGET / HTTP/1.1 and its headers, unchanged, inside an AES-GCM record with a 16-byte tag.ENCRYPTED
12Application dataserver to clientThe HTTP response, under a different key from the request: the two directions get separate write keys from the same master secret.ENCRYPTED

Why the switch happens at message 8 and not earlier. The keys do not exist before message 6, so nothing before message 6 could have been encrypted. But that leaves an obvious hole: messages 1 to 7 were readable, so they were also editable. An attacker on the path could have deleted the strong cipher suites from the ClientHello and left only a weak one, and both machines would have negotiated the weak suite believing it was the best on offer. Finished closes that hole. Each side hashes the complete transcript of every handshake message it sent and received, and puts the result, keyed with the master secret, into its Finished. If the two transcripts differ by a single byte the check fails and the connection is torn down before any data moves. The handshake is in the clear, but it is not unprotected.

And why the slow cryptography is confined to the setup. The numbers make the design obvious. AES-128-GCM with the AES instructions present on every modern CPU processes on the order of a gigabyte per second per core. One RSA-2048 private-key operation takes on the order of a millisecond. Encrypting a 2 MB page with public-key operations is not slightly slower, it is not something you would attempt. So TLS spends its asymmetric budget on two things and stops: one signature to authenticate the server, and one key agreement. From message 8 onwards everything is symmetric, and the connection runs at line rate. When somebody asks why TLS uses both kinds of cryptography, that pair of sentences is the answer.

Now the three guarantees, each pinned to the mechanism that supplies it and the message it is delivered in. The last column is what an attacker does when that one row is missing, and it is the column that turns a memorised list into an answer.

GuaranteeMechanismDelivered atWithout it, the attacker
Confidentialitysymmetric encryption of every record with the session keyEach direction from its own Finished, messages 8 and 10; keys derived at message 6.Reads your password, your session cookie and your bank balance straight off the wire.
Integrityan authentication tag on every record, plus the transcript hash inside FinishedTag on every encrypted record; transcript checked in messages 8 and 10.edits ciphertext in flight and downgrades your cipher list without either side noticing
Authenticationa certificate chain, plus a signature made with the matching private key over this connection’s valuesMessages 3 and 4 together. Neither one alone is enough.completes the handshake as the server and encrypts everything with you instead of with the site
Forward secrecythe Diffie-Hellman private values are ephemeral and are destroyed when the connection endsMessage 6, and it costs nothing extra.Records your traffic today, steals the server’s private key next year, and decrypts the recording.

Forward secrecy, and the one honest exception to "the key is never sent". Older TLS also allowed RSA key transport, where the client generated the pre-master secret itself, encrypted it with the public key from the certificate, and sent it across. That version really did put key material on the wire, protected by a key that lives on the server for years. Record the traffic, obtain that private key at any point in the future, and every past session opens. Ephemeral Diffie-Hellman has no such value: the private halves are thrown away when the connection closes and cannot be recovered from anything. This is why TLS 1.3 removed RSA key transport entirely, and why the honest form of the claim is: in the ephemeral key exchange that both versions use in practice, and the only one TLS 1.3 permits, nothing that crosses the wire is the key.

Reading a cipher suite name. TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 is four decisions written out. ECDHE is the key agreement, elliptic-curve Diffie-Hellman, ephemeral, so this connection has forward secrecy. RSA is the signature algorithm used to authenticate, which tells you what kind of key is in the certificate. AES_128_GCM is the bulk cipher, an AEAD mode that encrypts and produces the integrity tag in one pass. SHA256 is the hash for the key derivation. TLS 1.3 shortens the whole thing to TLS_AES_128_GCM_SHA256, because key agreement and authentication are negotiated separately in extensions and are no longer part of the suite name.

The certificate is the second half of the topic and the half that generates real support tickets. A certificate binds a set of hostnames to a public key, and it is trusted because of a chain: your server’s leaf certificate is signed by an intermediate CA, the intermediate is signed by a root CA, and the root is self-signed and already present in your operating system’s or browser’s trust store because it was shipped with it. The server sends the leaf and the intermediates; it does not send the root, because a root you receive from a stranger proves nothing and a root you already trust does not need sending. Here is what a browser then checks, and what it says when each check fails.

What the browser saysWhat actually failedWhat fixes it
ERR_CERT_DATE_INVALIDToday is outside the notBefore to notAfter window written inside the certificate. Usually expiry; occasionally the client’s own clock is wrong.Reissue and redeploy, then automate the renewal so it cannot happen twice.
ERR_CERT_COMMON_NAME_INVALIDThe hostname the user typed is not in the certificate’s Subject Alternative Name list. Modern browsers ignore the old Common Name field entirely and read only the SAN list.Reissue with every name the site is served under, wildcards included.
ERR_CERT_AUTHORITY_INVALIDThe chain does not reach a root in this client’s trust store. Either the certificate is self-signed, or the server sent the leaf and forgot the intermediates.Serve the full chain. If the CA really is private, install its root on the client deliberately.
ERR_CERT_REVOKEDThe CA has published that this certificate is no longer valid, which almost always means the private key leaked.Reissue with a new key pair. Revoking without changing the key achieves nothing, because the leaked key still matches.
Revocation is the weak one, and interviewers know it. Certificate revocation lists grew large, and browsers query the Online Certificate Status Protocol in a way that fails open, so an attacker who can block the check can also make it pass. The practical answers are OCSP stapling, where the server fetches a signed freshness statement and attaches it to the handshake, and short certificate lifetimes, which shrink the window revocation would have had to cover. Let’s Encrypt issues 90-day certificates for exactly this reason.

Versions next, and this is a table to get exactly right, because a candidate who says "we use SSL" has already told the interviewer something. SSL was the Netscape original; TLS is the IETF standardisation of it, and every version in production use today is TLS.

VersionYearStatusRound trips before the first requestWhy
SSL 2.01995prohibited, RFC 6176The handshake itself was not protected, so it could be downgraded silently.
SSL 3.01996deprecated, RFC 75682Broken by POODLE in 2014, which exploited its CBC padding.
TLS 1.01999deprecated, RFC 89962Still SSL 3.0’s shape underneath. Browsers removed it in 2020.
TLS 1.12006deprecated, RFC 89962Fixed one CBC problem and was overtaken before it was ever widely deployed.
TLS 1.22008widely deployed, still allowed2First version with AEAD suites and SHA-256. Keeps a lot of legacy options that have to be configured off.
TLS 1.32018current, RFC 84461Legacy options deleted rather than discouraged. AEAD only, forward secrecy compulsory, one round trip.

How TLS 1.3 gets to one round trip, and what it deleted to do it. In TLS 1.2 the client cannot send its key share until it has seen which group the server picked, which costs a whole round trip. TLS 1.3 has the client guess: it puts a key share for the group it expects into the ClientHello itself. The server usually accepts that group, replies with its own share in the ServerHello, and at that moment both sides can derive keys. So everything the server sends after the ServerHello is already encrypted, including the certificate, which was in the clear in TLS 1.2. The client then sends its Finished and its HTTP request in the same flight, which is why the count is one round trip and not two. The deletions are the other half of the story: no RSA key transport, no static Diffie-Hellman, no CBC modes, no RC4, no compression and no renegotiation, and the suite list shrank from hundreds to five. There is also 0-RTT resumption, where a returning client sends data in its very first flight using a key remembered from an earlier session, at the cost of no forward secrecy for that early data and no protection against it being replayed.

Finally, the payoff of TLS being a layer rather than a protocol. Every one of these keeps its own commands and its own grammar and runs them unchanged inside TLS. There are two ways to arrange that, and the difference is examinable: implicit TLS starts the handshake on the very first byte on a dedicated port, while explicit TLS begins as an ordinary plaintext session on the normal port and upgrades in place with a command such as STARTTLS.

ProtocolPlaintext portUpgrade in place (explicit)TLS from byte zero (implicit)
HTTP80Not used in practice.443 — this is all HTTPS is.
SMTP submission587STARTTLS on 587.465
SMTP between servers25STARTTLS on 25, opportunistically.
IMAP143STARTTLS on 143.993
POP3110STLS on 110.995
FTP21 control, 20 data in active modeAUTH TLS on 21.990
LDAP389The Start TLS extended operation on 389.636
DNS53853 for DNS over TLS; DNS over HTTPS rides on 443.
SSH on port 22 is deliberately not in this table. It does the same three jobs, but with its own protocol, its own key format and its own handshake, and it authenticates the server with a host key you trusted the first time you connected rather than with a CA-signed certificate. "SSH uses TLS" is a wrong answer that sounds right.

Explicit upgrades have a weakness that implicit ports do not. On port 587 the first few lines of conversation are plaintext, and the server advertises STARTTLS in that plaintext. An attacker who can rewrite packets can delete that advertisement, the client concludes the server does not support TLS, and the session continues in the clear with neither side alarmed. On port 465 there is no plaintext conversation to edit. This is why the mail standards moved back towards implicit TLS, and why HSTS exists on the web: a 301 redirect from port 80 to port 443 still leaves one plaintext request that an attacker can intercept, and the Strict-Transport-Security header, plus the preload list shipped inside browsers, removes even that one.

Close on the limits, because "TLS protects everything" is the answer that gets picked apart. Here is what a passive observer captures from our connection, straight off the record layer. The first byte of every TLS record is its type, and the two after it are a version, so an observer can classify records without decrypting anything.

-- four of the TLS records of https://www.example.com/ , as captured16 03 01 00 c5   Handshake        ClientHello       readable: versions, random, suites, SNI=www.example.com16 03 03 00 51   Handshake        ServerHello       readable: chosen version and cipher suite16 03 03 0b 8e   Handshake        Certificate       readable: the entire X.509 chain, 2958 bytes of it17 03 03 01 f4   ApplicationData                    opaque: the 500-byte length covers the ciphertext and its 16-byte tag -- 0x16 = handshake, 0x17 = application data, 0x14 = change cipher spec, 0x15 = alert-- the two bytes after the type are a version; the two after that are the record length-- the ClientHello record reads 03 01 to get past old middleboxes; the real version is chosen inside the hellos

What TLS still does not hide. Three things, and you should be able to say all three. First, the server’s IP address, which sits in the IP header outside everything TLS touches; TLS cannot encrypt the address a packet has to be routed to. Second, how much data flowed and when. Record lengths are visible, timing is visible, and traffic analysis on those two alone can identify which video you streamed or which page of a site you loaded. Third, and most often forgotten, the hostname. The Server Name Indication extension exists because one IP address serves many sites and the server must know which certificate to present, so the name is sent in the ClientHello before any key exists, in the clear, in TLS 1.3 as much as in TLS 1.2. TLS 1.3 encrypting the certificate closes one leak and leaves this one wide open. Encrypted Client Hello is the fix for it and is still being rolled out. On top of that, the DNS lookup that found the address was probably plaintext on port 53 unless you were using DNS over TLS on 853 or DNS over HTTPS on 443.

Encryption is the guarantee people name and the one that is hardest to get wrong. Authentication is the guarantee people skip, and skipping it does not weaken the connection, it redirects it. An attacker who is not challenged for a certificate does not need to break any cryptography at all: he runs one handshake with you and another with the server, and both of them are perfect.

05 Cheat sheet

The answers that get asked, and the wrong ones that get given

Every row is something you should be able to state in under ten seconds. The right-hand column is the specific wrong answer that gets written down, not a general caution.

What they askThe answerThe trap
What does TLS give youconfidentiality, integrity, authentication"it encrypts the data" — that is one of the three, and not the interesting one
Which mechanism gives each onesymmetric cipher · authentication tag · certificateNaming the guarantees without the mechanisms. The follow-up is always "how".
Why both kinds of cryptographyasymmetric to authenticate and agree a key, symmetric to carry the data"TLS encrypts your data with RSA" — it never encrypts bulk data with RSA
Is the session key sentno · each side derives it from a Diffie-Hellman exchangeSaying the server sends the key encrypted. That was RSA key transport, deleted in TLS 1.3.
What is in a certificatehostnames, the public key, validity dates, issuer, the CA’s signature"the private key" — it is never in the certificate and never on the wire
Which message authenticates the serverthe signed key exchange, not the certificate on its ownSaying "the certificate". Anyone can copy a certificate; only the key holder can sign.
Where the handshake goes encryptedTLS 1.2 at the first Finished · TLS 1.3 right after the ServerHello"the whole handshake is encrypted" — the hellos never are, in either version
Which version, which round tripsTLS 1.2 needs 2 · TLS 1.3 needs 1swapping them — 1.3 is the newer and the faster one
Is the certificate encryptedcleartext in TLS 1.2 · encrypted in TLS 1.3Assuming it is protected in both. It is one of the biggest visible changes in 1.3.
Which versions are deadSSL 2.0 and 3.0, TLS 1.0 and 1.1 · RFC 8996calling any of it "SSL" in an answer about a live system
What HTTPS isHTTP, unchanged, inside TLS, on port 443Describing it as a different protocol with different methods or status codes.
Forward secrecyephemeral DH keys, destroyed at close, so a future key theft reveals nothing"the certificate expires" — expiry has nothing to do with it
What TLS does not hidethe server IP, the volume and timing, and the SNI hostnameClaiming the hostname is protected in TLS 1.3. Only the certificate is.
Three guarantees, three mechanismsConfidentiality comes from a symmetric cipher, integrity from an authentication tag on every record, authentication from a certificate plus a signature made with its private key. Answering with the list of three is half marks; answering with the three pairs is the answer.
Asymmetric to agree, symmetric to carryPublic-key operations cost about a millisecond each and are spent on exactly two things: one signature and one key agreement. After that the connection runs on AES-GCM at roughly a gigabyte a second. Every design decision in TLS follows from that ratio.
The key is computed, never carriedEach side keeps a private value and publishes a derived one. Both combine and land on the same secret. Someone who recorded every byte holds two public values and nothing else, which is why traffic recorded today does not become readable when a key leaks tomorrow.

06 Where & why

Four systems where this is a command you type

None of this is a diagram from a textbook. Every message in section 03 is something you can print on your own machine in one command, and three of the four systems below differ from the plain description in a way worth naming out loud.

OpenSSL · s_client
The handshake, printed

openssl s_client -connect www.example.com:443 -servername www.example.com runs a real handshake and prints the certificate chain it received, the negotiated protocol and cipher, and a line reading Verify return code: 0 (ok) when the chain validated. The -servername flag is the SNI, and leaving it off on a shared host gets you the wrong certificate, which is itself a good demonstration of what SNI is for. Add -tls1_2 or -tls1_3 to force a version and see the message order change.

Let’s Encrypt · ACME
Certificates that expire in 90 days on purpose

ACME is a protocol for proving you control a hostname, by serving a token at a URL under it or publishing one in its DNS, after which a certificate is issued automatically. Certificates last 90 days, which forces renewal to be a cron job rather than a calendar reminder. Note precisely what the CA verified: control of the name. It did not verify that the operator is honest, which is why a padlock on a phishing site is not a contradiction.

nginx
Two directives that decide everything

ssl_certificate must point at a file containing the leaf certificate followed by the intermediates, in that order, because that is the sequence the server sends. ssl_certificate_key points at the private key, which is the file that never leaves the machine. ssl_protocols TLSv1.2 TLSv1.3; is how you refuse the deprecated versions, and ssl_stapling on; turns on OCSP stapling so the freshness proof rides along with the handshake.

Chrome · root store and HSTS
Who your machine already trusts, and how the first request is protected

Chrome ships its own root store rather than using the operating system’s, so the set of authorities you trust is a list somebody curates and can remove entries from. It also enforces Certificate Transparency: a public certificate must appear in public append-only logs or Chrome rejects it, which makes a quietly misissued certificate detectable. And it ships a HSTS preload list, so for the sites on it the browser goes straight to https:// and never sends the first plaintext request at all.

Every one of those four is doing the same job from a different angle: deciding whose signature you are willing to believe. The cryptography in this lesson is settled and nobody attacks it directly. What gets attacked is the trust decision around it, which is why the interesting failures are expired certificates, missing intermediates, misissued certificates and users clicking through a warning.

07 Interview questions

What they ask, and what they follow up with

This topic is asked in two ways. In a networks round it is "walk me through the handshake". In a systems or security round it is "why is that safe", and the second one is where candidates run out of material after two sentences. Answer with mechanisms rather than adjectives: "a signature over both randoms" is an answer, "it is secure" is not.

What does TLS actually give you?
Three things, and each comes from a different mechanism. Confidentiality, from symmetric encryption of every record with a session key. Integrity, from an authentication tag computed over each record, so a single flipped bit makes the receiver discard it. And authentication, from a certificate signed by an authority your machine already trusts, so you know which server you reached. Most candidates give the first one and stop, and the follow-up is always about the third.
Why does TLS use both symmetric and asymmetric cryptography instead of picking one?
Because they solve different problems and one of them is far too slow to carry data. Symmetric encryption is fast, roughly a gigabyte a second per core with AES-GCM, but it needs both ends to already share a key. Asymmetric solves that, since you can publish one half of the pair, but a single RSA-2048 private-key operation costs about a millisecond, so encrypting a page with it is not practical. TLS therefore spends asymmetric operations on exactly two jobs, authenticating the server and agreeing on a secret, and runs everything after that symmetrically.
Is the session key sent across the network?
No. Each side picks a private value, publishes a value derived from it, and combines its own private value with the peer’s public one. Both calculations land on the same shared secret, so it is computed twice and transmitted zero times, and an observer who captured every byte holds two public values that do not get them there. The one honest exception is the old RSA key transport option, where the client did encrypt a pre-master secret with the server’s public key and send it; that had no forward secrecy and TLS 1.3 removed it entirely.
What is inside a certificate, and what has the CA actually verified?
The hostnames it is valid for, the subject’s public key, a validity window, the issuer, and the CA’s signature over all of that. The private key is not in it and never leaves the server. As for what the CA checked: for an ordinary certificate, only control of the name, proved by serving a token at a URL under that hostname or publishing one in its DNS. It did not check that the operator is honest or that the site is safe, which is exactly why a phishing site can have a valid padlock and why the padlock has never meant "trustworthy".
The data is encrypted either way. Why does authentication matter?
Because encryption tells you nobody else can read the conversation, not who you are having it with. An attacker on the path who is never asked for a valid certificate completes the handshake with you himself, opens a second connection to the real server, and forwards traffic between the two. Both halves are correctly encrypted, both have valid integrity tags, and he reads and edits everything. He does not break any cryptography; he is the party you agreed a key with. That is why a certificate warning is not a formality to click through.
Walk me through the TLS 1.2 handshake, and tell me what an observer can read.
ClientHello with the supported versions, a random, the cipher suite list and the hostname in SNI. ServerHello choosing one version and one suite and returning its own random. Certificate. ServerKeyExchange carrying the server’s ephemeral key share, signed with the certificate’s private key. ServerHelloDone. Then ClientKeyExchange with the client’s key share, at which point both sides derive the secret, then ChangeCipherSpec and Finished from each side. Everything up to and including the ChangeCipherSpec is readable; the first Finished is the first encrypted message. It is two round trips before the request goes out, on top of TCP’s own.
What did TLS 1.3 change, and how many round trips does each version need?
TLS 1.2 needs 2 round trips before the client can send its request; TLS 1.3 needs 1. It gets there by having the client send its key share in the ClientHello rather than waiting to be told which group to use, so both sides can derive keys as soon as the ServerHello arrives. The other half of the change is deletion rather than addition: RSA key transport, static Diffie-Hellman, CBC modes, RC4, compression and renegotiation are all gone, only AEAD ciphers remain, forward secrecy is compulsory, and the suite list dropped from hundreds of options to five.
What is forward secrecy?
It means that compromising the server’s long-term private key later does not decrypt traffic captured earlier. You get it by deriving each session key from ephemeral Diffie-Hellman values that are generated per connection and destroyed when it closes, so there is nothing left anywhere to steal. Key exchanges that reuse a long-lived key, such as RSA key transport, do not have it: record the traffic now, obtain that key at any point in the future, and every past session opens. Look for ECDHE at the front of the cipher suite name.
Is HTTPS a different protocol from HTTP?
No. It is the same HTTP, with the same methods, headers and status codes, carried inside a TLS session on port 443 instead of in the clear on port 80. TLS is a layer between the transport and the application, so the application protocol above it does not change by a character. That is also why it was so easy to apply the same trick to other protocols without redesigning any of them.
What does TLS not protect?
Three things. The server’s IP address, which is in the IP header and has to be readable for the packet to be routed at all. How much data flowed and when, since record lengths and timing are visible, and traffic analysis on those alone can often identify the page or video you fetched. And usually the hostname, because the SNI extension carries it in the ClientHello before any key exists, so it is in the clear even in TLS 1.3; Encrypted Client Hello is the fix and is still being deployed. The DNS lookup that produced the address is a fourth leak unless it went over DNS over TLS or DNS over HTTPS.
An attacker deletes the four strongest cipher suites from a ClientHello in flight. Does the handshake still succeed?
No, it aborts. The hellos are in the clear so the edit itself works, and both machines will negotiate the weaker suite, but each side’s Finished message carries a keyed hash over the complete transcript of every handshake message it sent and received. The client hashed what it sent and the server hashed what it received, and those two transcripts now differ, so the verification fails and the connection is torn down before any application data moves. This is the standard answer to "the handshake is in the clear, so why is it safe".

08 Practice problems

Six to work on paper

Two of these are arithmetic and want a pen. Two are certificate failures, so write out the four checks a client makes before it trusts a server and find the one that fails, because in both of those exactly one thing is wrong and the other three are fine. The last two are about where in a session TLS starts, and what a connection gives up to start it early.

What the extra round trip costs

Easy
A client is 40 ms of one-way propagation delay from a server. It opens a TCP connection, completes a TLS handshake, and sends a 300-byte HTTP request. Counting propagation only and ignoring transmission and processing time, give the number of milliseconds from the first packet leaving the client until the request arrives at the server, once for TLS 1.2 and once for TLS 1.3, and give the difference.
Follow-up
The TCP handshake happens first and costs a round trip that has nothing to do with TLS, so neither answer is a pure multiple of the TLS cost. In one of the two versions the client’s last handshake message and its request travel together, and in the other they cannot.
Show the hint
Draw a timeline in one-way hops of 40 ms rather than in round trips, and stop the clock the moment the request lands at the server rather than when the response comes back.

Four checks, one failure

Easy
A server presents a certificate that is signed by an intermediate whose root is in your trust store, whose validity window ends next month, and whose Subject Alternative Name list reads shop.example.com, www.example.com. A user opens https://api.example.com/. Say whether the browser connects, name the check that decided it, and say what the site owner has to do.
Follow-up
The certificate is not expired, not revoked, not self-signed and its chain is complete, so three of the four things a browser verifies pass cleanly. Only one fails, and it is the one people assume the padlock covers rather than the one it actually does.
Show the hint
Write out the list the browser compares the typed hostname against, then ask whether a name that differs by one label counts as the same name.

The chain that was half deployed

Medium
A team installs a new certificate. The site loads in the lead developer’s browser, but curl on a freshly built server reports a certificate problem and an Android app refuses to connect. The certificate is in date, its SAN list contains the hostname, and the CA is a well known one. Name what is missing from what the server sends, explain why exactly one of the three clients succeeded, and say which file on the server has to change.
Follow-up
Nothing is wrong with the certificate and nothing is wrong with the CA. The failure is in what the server chose to transmit, and the client that worked did so for a reason that makes the bug look intermittent and unreproducible.
Show the hint
The chain has three links and the server is responsible for sending two of them. Ask what a browser might already be holding from some earlier visit to an unrelated site signed by the same authority.

Two people, one number, nothing sent

Medium
Run a Diffie-Hellman agreement by hand with the public parameters p = 23 and g = 5. A side holding the private value x publishes g^x mod p, and turns a received public value Y into the shared secret with Y^x mod p. The client picks 6 and the server picks 15. Compute the public value each side sends, compute the shared secret from the client’s side and again from the server’s side, and then list every number an eavesdropper who captured all the traffic now holds.
Follow-up
The two sides run different calculations on different inputs and must still land on the same value, so getting two different answers means an arithmetic slip rather than a misunderstanding. The eavesdropper’s list is the whole point of the exercise, and the number missing from it is the only one that was never transmitted.
Show the hint
Reduce modulo 23 after every squaring instead of computing the full power first, and build the exponents from squares you have already reduced.

Three ports, and one that cannot be talked out of it

Medium
A mail client connects to the same server on port 587, on port 465 and on port 25. Say which one of the three begins its TLS handshake on the very first byte, name the command the other two depend on instead, and describe what an attacker who can rewrite packets can do on those two that is impossible on the first.
Follow-up
All three can finish on the same TLS version and the same cipher suite, so the strength of the cryptography is identical in every case. What differs is whether TLS starts before or after the protocol has said its first words, and therefore whether ending up with no TLS at all is even on the table.
Show the hint
Look at what the server has to say in plaintext before TLS can begin on those two ports, and ask what is left of the session if that one line never reaches the client.

The order that was placed twice

Hard
A shop enables TLS 1.3 0-RTT so returning customers can send their first request with no round trip of delay. Weeks later an order is recorded twice from a single tap, with two identical requests seconds apart. Explain the mechanism that makes this possible, say why the server cannot tell the second one apart from the first, explain why 0-RTT data also lacks forward secrecy when the rest of the connection has it, and give a rule for which requests may safely be sent as early data.
Follow-up
Nothing was decrypted, nothing was forged and no key leaked. Someone only had to send the same bytes a second time. The property TLS gave up here is not confidentiality and not integrity, and it is the one that has no name in the list of three.
Show the hint
Ask what the server contributes to the key that protects the very first flight, given that the server has not spoken yet, and then ask what would have to be different about that key for a replayed record to fail.