← Project 2 overview

Project 2B: Message Flows

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.

1 · The programs

Click a program for what it can see, what it can't, and what it has to do.

2 · Frames

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.

3 · Step through a circuit

4 · Who holds which key

KeyMade byHeld byUsed for
Ingress public key
keys/ingress.pub
keygen, onceAnyone. The relay client loads it from --ingress-key.seal() the outer setup message
Ingress private key
keys/ingress.key
keygen, onceThe ingress onlyunseal() the outer setup message
Egress public key
keys/egress.pub
keygen, onceAnyone. The relay client loads it from --egress-key.seal() the inner setup message
Egress private key
keys/egress.key
keygen, onceThe egress onlyunseal() the inner setup message
k_inThe relay client, with new_key(), fresh for every circuitThe relay client, and the ingress once it unseals the outer messageThe ingress's layer on the status and on every data frame
k_egThe relay client, with new_key(), fresh for every circuitThe relay client, and the egress once it unseals the inner messageThe 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.