Tor (Onion Routing)

The Tor network provides pseudonymous communication through layered encryption across distributed relays.

Period1995 - Present

What is Tor?

Tor (The Onion Router) is a distributed anonymity network that routes traffic through multiple relays to obscure the origin and destination of communications. Developed in the mid-1990s by Paul Syverson, Michael Reed, and David Goldschlag at the US Naval Research Lab, Tor was designed to protect intelligence communications. The Tor Project was founded in 2006 as a non-profit, transforming research into deployed public infrastructure. Today the network consists of approximately 7,000 relays operated by volunteers worldwide.

Onion Routing Mechanics

Tor builds circuits of three relays (entry guard, middle, exit) using incremental circuit construction. Each relay in the circuit knows only its predecessor and successor—no single relay knows the complete path. This design ensures that observing any single relay reveals neither the original source nor the final destination.

Circuit creation uses a telescoping approach: the client negotiates a session key with the first relay, then uses that to extend to the second, and so on. Each layer of encryption is peeled back at each relay:

  • Client creates layered encryption: E1(E2(E3(data)))
  • Exit relay decrypts outermost layer E3 and sees only E2(E3(data))
  • Middle relay decrypts E2 and sees only E1(data)
  • Entry guard decrypts E1 and sees only data, but does not know the destination

The exit relay sees the destination IP but not the client IP. The entry guard sees the client IP but not the destination. Neither sees both.

Cell Protocol

Tor uses fixed-size cells (512 bytes) for all circuit traffic. This uniformity prevents traffic analysis based on packet size. There are two types:

  • Control cells: Carry IRC/CMDS commands for circuit management, authentication, and routing operations
  • Relay cells: Carry encrypted stream data. Each relay cell contains a relay command, stream ID, digest for integrity checking, and the encrypted payload

The relay payload is encrypted with the session key of the relay for which the cell is destined. Each relay along the circuit peels off one layer of encryption, revealing the next relay's identity and the encrypted payload for the next hop.

Onion Services (Hidden Services)

Tor onion services (formerly called hidden services) provide anonymity for servers, not just clients. The service generates a public/private key pair and advertises a descriptor to the Tor network through a distributed hash table. The descriptor contains:

  • Onion address (v3): A 56-character base32 address derived from the public key using SHA-256 and base32 encoding
  • Introduction points: Pre-selected nodes that receive connection attempts from clients
  • Encrypted descriptor: Only retrievable by clients who possess the onion address
  • Authenticating key: Used to sign the descriptor

Clients discover onion addresses through out-of-band channels or directory services, then establish a circuit to an introduction point. The service builds a separate circuit to a rendezvous point, and the client connects through both. Neither party ever reveals its IP address. The complete connection involves 6 relays total.

Onion Service Protocol Flow

  1. Service builds circuits to 3+ introduction points and uploads signed descriptor to DHT
  2. Client fetches descriptor using onion address, verifies signature
  3. Client creates circuit to a rendezvous point, sends introduce message to introduction point
  4. Service receives introduce message, builds circuit to rendezvous point
  5. Rendezvous point connects the two circuits bidirectionally
  6. Client and service communicate end-to-end through the rendezvous point

Pluggable Transports

To evade censorship, Tor uses Pluggable Transports (PT) that disguise traffic signatures to bypass deep packet inspection (DPI). These are critical in countries that block Tor directly:

  • obfs4: Looks like random bytes with a TLS handshake wrapper. Requires a bridge certificate. Most widely used transport.
  • meek: Domain-fronted connections through cloud providers (Azure, Google, AWS). Traffic appears to be to a major cloud service.
  • Snowflake: Ephemeral WebRTC connections. Proxies are temporary and numerous, making blocking difficult.
  • Shadowsocks: Traffic disguised as Shadowsocks protocol using AEAD ciphers.
  • Format-transforming encryption (FTE): Transforms Tor traffic to match specified formats (HTTP, JPEG, etc.).

Bridges are unlisted relays that help users in censored regions connect to the Tor network. Bridge addresses are distributed through email requests and the Tor website.

Entry Guards

To prevent traffic analysis attacks on the entry node, Tor uses entry guards—trusted relays that are the only entry points for a user's circuits. Clients select a small set of guards (typically 1-3) and only use those for new circuits. This limits exposure to guard-enumeration attacks because an adversary observing a user would need to control that specific guard. The entry guard concept was formalized in a 2008 paper by Wright et al. demonstrating that without guards, an attacker with modest resources could de-anonymize users through repeated circuit selection.

Limitations and Attacks

Tor provides strong anonymity but is not perfect:

  • End-to-end correlation: An adversary controlling both entry and exit can potentially correlate traffic timing across both points
  • Website fingerprinting: Passive observers can sometimes identify which page a user is visiting based on traffic patterns
  • Exit node tampering: Exit relays can inspect or modify unencrypted traffic
  • Sybil attacks: An adversary deploying many relays can increase probability of controlling path nodes
  • Guard selection bias: Long-lived guards create a trade-off between anonymity and performance

Comparison to Other Anonymity Networks

PropertyTorI2PGNUnet
Design focusClearnet exit, bidirectionalInternal services, peer-to-peerDecentralized, censorship-resistant
RoutingOnion (bidirectional circuits)Garlic (bundled messages)PLT (peer-to-peer)
Exit nodesYesNo (internal only)No
LatencyModerateHighHigh
EcosystemLarge, matureSmaller, activeSmall, research-focused

Timeline

1995Onion routing conceived — US Naval Research Lab develops concept for protecting intelligence communications
1996First onion routing paper published by Syverson, Reed, Goldschlag
2002Tor (The Onion Router) v1 developed — simplified design enables wider deployment
2004Tor becomes open-source —代码由Freehaven转交自由软件基金会
2006The Tor Project founded as non-profit organization
2015Onion services v3 (扩充版) deployed — stronger cryptography, better anonymity
2021Onion services become default — Tor Browser 10.5 disables v2
2024Onion service v2 deprecated and removed