Skip to content

Why Tor Picks the Exit Before the Guard

A signal operator reaches past two gray levers for the far red one.

Say Tor needs a new circuit for a connection to example.com on port 443. It builds the first hop to the guard. It chooses the exit first.

These are two separate operations. The client first picks a route from its directory information . It then builds that route one hop at a time. A request can also use an existing compatible circuit, including one built in advance. The order here applies when a new three-hop exit circuit is being chosen. Path selection , When Tor builds circuits

What port 443 changes

The exit is the relay that will open a connection to the website. Each exit publishes a policy describing the addresses and ports it will accept. If the client already has the destination’s Internet Protocol (IP) address, it can check both address and port against the policy. With just a hostname, it can choose an exit whose policy might allow the connection on port 443. The exit resolves the name later and can refuse the connection if its policy rejects the resulting address. Choosing an exit

Next, the client chooses a guard. On first use it samples guard candidates from the directory information and saves that state. Across circuits it favors a small set of primary guards. Every new guard would put another operator in a position to see the client’s source address. Reusing guards limits how often that happens. Entry guard selection

With the exit and guard in place, the client chooses a middle relay that meets the path constraints. For ordinary paths, those constraints rule out using the same relay twice within one circuit and ordinarily exclude relays from the same declared family or configured network range. Selection among eligible relays is weighted by bandwidth and the role-specific weights in the consensus. Path selection and constraints

The client can finish choosing all three relays before it sends a circuit-creation message. Read the two columns from the top. The relay chosen first is the one added last.

Choice order is exit, guard, middle. Construction order is guard, middle, exit.

The route grows from the guard

The client opens or reuses a channel to the guard. The connection uses Transport Layer Security (TLS). It sends a CREATE2 cell and finishes an authenticated handshake with the guard. It now has a one-hop circuit and key material it shares with that relay. Tor channels , Creating and extending circuits

To reach the middle, the client sends an EXTEND2 message through the one-hop circuit to the guard. The guard opens or reuses a channel to the middle and forwards the handshake. The reply returns through the guard. The client verifies it and derives a separate set of keys with the middle. Creating circuits

The client asks the guard to extend to the middle. The guard sends CREATE2 and passes back the middle’s reply. The client verifies the handshake.

The next EXTEND2 travels through the two-hop circuit to the middle, which passes the handshake to the exit. The client’s direct network connection to the relay network is still to the guard. If the guard cannot reach the chosen middle during the first extension, the handshake cannot finish and this attempt yields no usable three-hop circuit. The client needs a successfully built circuit before it can open the stream. Creating and extending circuits

Tor also builds circuits that end inside its network. Those circuits use role-specific rules, so an exit policy for port 443 is irrelevant to them. For the circuit we’ve followed, the exit is finally reachable. The next step is to ask it to open a stream to the site . Internal circuits