learning-it by example

#280 How it works, by example 6.9 min

How HTTPS Works: Watch a TLS 1.3 Handshake in Python

In a TLS 1.3 handshake, every handshake message after the two hellos is encrypted, but the site name is not.

1. In a TLS 1.3 handshake, which two handshake messages can still be read on the wire before everything is encrypted?
2. What readable detail did the client hello show in the handshake run, even though HTTPS was in use?
3. A client trusts only the certificate that the test made. It connects asking for the name example.com instead of localhost. What result did the video show for this case?
4. Why did the system trust store reject the throwaway certificate in the video?
5. How does the video run a TLS handshake between a client and a server without any network?

Practice only: nothing is saved and no score counts towards anything. Each answer comes with the reason.

  1. Predict the three trust results

    Copy the code folder first. This needs the cryptography package that the video already requires, so these are prediction tasks. Read part 2 of run.py and predict, for each of the three clients, whether it will be accepted or rejected and the reason. Then run python run.py and compare your predictions with the output.

    A hint

    Check which certificates each client context was built to trust, and which host name it asks for.

  2. Predict a different wrong name

    In run.py, change the host in the third client from example.com to example.org. Predict what the line for that client will say, and whether the server's certificate or the name is the problem. Then run it and compare. The video says a valid certificate for another name is still the wrong server.

    A hint

    The certificate names localhost only.

  3. Read the five-byte record header

    Open watch.py and read the records function. Using the comment about the record, work out which byte tells the type. Then predict the name it gives for a record of type 22 whose sixth byte is 2, for type 20, and for type 23. Check your answers against the TYPES and HANDSHAKE dictionaries.

    A hint

    The names are in the TYPES and HANDSHAKE dictionaries.

  4. Find where the name hides

    In watch.py, the server_name function walks past fixed fields and then looks through the extensions for number 0. Write down in order the fields it skips (headers, version, random bytes, session id, cipher suites, compression methods). Then explain, in one sentence, why the video says HTTPS does not always hide the site name.

    A hint

    Only Encrypted Client Hello, where both sides support it, hides it.

These tasks are for you to try on your own machine. Nothing is checked or saved.

What this does not show

One handshake in memory on one machine, with a throwaway self-signed certificate; it names record types only and does not show certificate chains, session resumption or Encrypted Client Hello.

Up next in How it works, by example

More in How it works, by example

All How it works, by example videos

Related videos