Im trying to implement a simple C# application that is based on Tor protocol, without identity changes every few minutes etc. just to create a circuit and make a request. I created the onion hidden service, and I want to try make a HTTP request to it and receive an answer first. I have read all the specs, and i looked up the Tor source code, but its really hard, because it is using very low-level C. So far what I understood from the technical point of view is this, if i want to fetch the main page of my onion hidden service I have to:
- Choose a random directory server that is serving onion routers microdescriptors (there are 10 hardcoded, but 1 is serving only the bridges)
- Connect to dir server, fetch a consensus document
/tor/status-vote/current/consensus/using HTTP protocol, close the
- Parse the list of onion routers, construct the circuit from 3 nodes.
- Parse the entry node with the attributes
Fast Guard HSDir Running Stable Valid.
- Parse the exit node with the attributes
Fast Exit HSDir Running Stable Valid.
- Parse the random middle node? Is it just a OR in the list
Guardattributes? Or any OR with attributes
Guardcan also be used as a middle node?
- Create a TCP socket and connect to the parsed entry node with
the given IP port. Then create a cell packet with the command
CREATEwith the payload of Diffie-Hellman handshake. Receive a command
CREATEDwit the encryption key.
- Form a relay cell packet with command
RELAY_EXTENDcontaining the IP port of the middle node, and encrypted half handshake for the middle relay, with the key we parsed from previous action, send it to the connected entry node, receive an answer as
RELAY_EXTENDEDpacket, parse new encryption key from it. And use it later to encrypt last diffie hellman handshake payload.
- Do the previous action, send
RELAY_EXTEND, to the guard node, but with the address of the exit node, and encrypted diffie hellman handshake with the key we received from middle node.
- I guess that is it? The circuit is ready? Now i can use a relay
cell packets,sending them to my guard node socket connection, encrypted with the key i received from exit node with
RELAY_BEGINto connect to hosts,
RELAY_DATAto send data to them?