Every message in Project 2B, Private HTTP over TCP, drawn from SPEC.md. Start with the programs involved: click one for what it can see and what it has to do. Then pick a scenario and step through it to see each message byte by byte, which layers of encryption it carries, and who can open them.
You write three programs: the relay client, the ingress and the egress. The application (curl or a browser) asks the relay client for a TCP connection to a destination using HTTP CONNECT. Each application connection gets its own circuit: a TCP connection from the relay client to the ingress, one from the ingress to the egress, and one from the egress to the destination, plus two fresh keys. The ingress knows who you are but not where you're going. The egress knows where you're going but not who you are.
Click a program for what it can see, what it can't, and what it has to do.
TCP delivers a stream of bytes, not messages. It keeps the bytes in order but forgets where one sendall() ended and the next began, so the receiver's recv() calls can split the stream anywhere. Each encrypted message has to be decrypted whole, so on the two links marked TCP · frames in the diagrams, every message is sent as a frame: a 4-byte length, then exactly that many bytes. SPEC §1.1
recv_frame() in netutil.py does this reading for you: it reads 4 bytes, then exactly that many more, however many recv() calls that takes, and returns one whole message. Use send_frame() and recv_frame() for every message on those two links, and never call recv() on them directly. The application and destination links carry plain bytes, with no frames.
| Key | Made by | Held by | Used for |
|---|---|---|---|
Ingress public keykeys/ingress.pub | keygen, once | Anyone. The relay client loads it from --ingress-key. | seal() the outer setup message |
Ingress private keykeys/ingress.key | keygen, once | The ingress only | unseal() the outer setup message |
Egress public keykeys/egress.pub | keygen, once | Anyone. The relay client loads it from --egress-key. | seal() the inner setup message |
Egress private keykeys/egress.key | keygen, once | The egress only | unseal() the inner setup message |
k_in | The relay client, with new_key(), fresh for every circuit | The relay client, and the ingress once it unseals the outer message | The ingress's layer on the status and on every data frame |
k_eg | The relay client, with new_key(), fresh for every circuit | The relay client, and the egress once it unseals the inner message | The egress's layer on the status and on every data frame |
Every message on this page follows SPEC.md in the Project 2B starter repository. If this page and SPEC.md ever disagree, SPEC.md is right. The encrypted bytes shown are made up; real ones look just as random.