Maybe I will be wrong, please correct me and at the same time answer my question. I know the keys are exchanged between client and Tor relays through circuit extension requests (other than first relay), so in short, whatever keys are generated for Tor relays in the circuit, all the keys have to pass through the first relay point and first relays point has access to all shared keys.

If the first relay is compromised then all keys in our circuit will be compromised and anonymity will be gone. So how does onion routing counters this problem ?

  • 2
    Not really. The host will conduct a separate key exchange with each of the nodes in the circuit. Since key exchange algorithms like Diffie-Hellman (+ some authentication algo) allow us to securely establish a shared secret key over an insecure channel, it doesn't matter whether or not the first node is compromised/can be trusted.
    – nobody
    Commented May 28, 2023 at 18:00
  • 1
    an interesting follow-up question would be how these nodes are authenticated (e.g. where do you get their public keys from) :-)
    – ambiso
    Commented May 29, 2023 at 9:28
  • Can you also explain how Tor relays are decided since it does not know the hidden services ip address . How it is which Tor relays to include in circuit making between client and hidden services. Commented May 31, 2023 at 6:25

1 Answer 1


A Tor client obtains the public keys of all Tor nodes just by asking their list to hosts called Tor Directory Authorities (whose public keys are hardcoded in the Tor software). Therefore, unless the Tor software was compromised, the Tor client possesses the correct public keys of all Tor nodes.

The client then decides which nodes to use in its path (circuit). As part of circuit extension request it establishes a secure TLS connection with each of the circuit nodes, one at a time starting from the first, passing through all previous nodes of the circuit. Each node is authenticated with the respective public key.

The first node has only access to the encrypted TLS traffic between the client and the second node. The first node cannot decode the traffic, hence it cannot know the data or what the third and subsequent nodes are. If the first node forwards the traffic to a node different from the one chosen by the client, the client will know because the public key will not match the one it received from the Tor Directory Authorities.

Ref. https://support.torproject.org/about/key-management

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .