How Tor Finds an Onion Service
If someone sends you a .onion address, the Tor client can find a way to contact the service without learning the server’s Internet Protocol (IP) address. How can the same name work tomorrow if the relays that hold the contact information change?
The 56 characters before the .onion suffix in a version 3 address encode the service’s Ed25519 public identity key, a checksum and a version byte. The client decodes the address and uses the key to verify the service’s identity through the protocol. The address itself contains no network location. Encoding onion addresses
What the service publishes
Before a client arrives, the service builds circuits to several introduction points. The service keeps these circuits open so the relays can forward introduction requests. Each sees the neighboring relay on that circuit. The service publishes an onion descriptor. For each introduction point, the descriptor includes the relay to contact and the public key the client needs to encrypt its invitation to the service. Onion service protocol overview
Other relays, called hidden service directories (HSDirs), store copies of that descriptor. The service uploads it through Tor circuits. A directory relay can hand you the descriptor. An introduction point can forward your message. The two roles are used at different stages. Onion service protocol overview
What changes while the address stays the same
The service and client can independently derive the same blinded public key for a time period from the public identity in the address and the protocol’s period parameters. The service certifies a descriptor signing key using the corresponding blinded private key. The certified key signs the descriptor. The client verifies the certificate with the blinded public key it derived. It uses the certified signing key to verify the descriptor’s signature. Deriving blinded keys , Descriptor outer wrapper
Both endpoints take their list of eligible directories from the consensus, Tor’s signed network view. They apply the same rules to that list and to the service’s blinded key. Picture a ring of numbers. The numbers represent positions in a hash space, independent of where the machines are physically located.
| Position on the ring | What determines it |
|---|---|
| A descriptor replica’s starting point | The blinded public key, the time period and the replica number |
| A directory relay’s position | The relay identity, the time period and a shared random value from the consensus |
Starting at each replica’s index, the service publishes to a specified number of eligible directory relays in ring order. The client considers a specified number for fetching and chooses among them at random. Starting from the same index and relay order gives the service and client compatible lookups even though they can use different numbers of directories. Where descriptors are published
Compare two periods in this example with four directory relays. Follow the ring clockwise from the diamond. Relay B comes first in period 1. In period 2, both the starting index and the relay positions have moved. Relay D now comes first.
The drawing shows the first eligible directory for one replica in each period. Through the transition, the service keeps descriptors for both periods available, so clients using either period can still find introduction points. Overlapping descriptors
What the client learns
The client repeats the lookup, fetches the descriptor over Tor and verifies it. A directory that only has the stored bytes needs the onion identity to open the first encryption layer. Someone who already knows the address can derive that layer’s key material. With optional client authorization enabled, an inner layer also requires an authorized client’s credential. Descriptor encryption
The saved address worked again. After the lookup, the client has an introduction point and the keys it needs to send an introduction. It can now pick a rendezvous relay for the actual connection.