tor-spec.txt 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  1. $Id$
  2. Tor Spec
  3. Roger Dingledine
  4. Nick Mathewson
  5. (who else wrote this?)
  6. Note: This is an attempt to specify Tor as it exists as implemented in
  7. mid-August, 2004. It is not recommended that others implement this
  8. design as it stands; future versions of Tor will implement improved
  9. protocols.
  10. This is not a design document; most design criteria are not examined. For
  11. more information on why Tor acts as it does, see tor-design.pdf.
  12. TODO: (very soon)
  13. - REASON_CONNECTFAILED should include an IP.
  14. - Copy prose from tor-design to make everything more readable.
  15. 0. Notation:
  16. PK -- a public key.
  17. SK -- a private key
  18. K -- a key for a symmetric cypher
  19. a|b -- concatenation of 'a' and 'b'.
  20. [A0 B1 C2] -- a three-byte sequence, containing the bytes with
  21. hexadecimal values A0, B1, and C2, in that order.
  22. All numeric values are encoded in network (big-endian) order.
  23. Unless otherwise specified, all symmetric ciphers are AES in counter
  24. mode, with an IV of all 0 bytes. Asymmetric ciphers are either RSA
  25. with 1024-bit keys and exponents of 65537, or DH with the safe prime
  26. from rfc2409, section 6.2, whose hex representation is:
  27. "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E08"
  28. "8A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B"
  29. "302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9"
  30. "A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE6"
  31. "49286651ECE65381FFFFFFFFFFFFFFFF"
  32. All "hashes" are 20-byte SHA1 cryptographic digests.
  33. When we refer to "the hash of a public key", we mean the SHA1 hash of the
  34. ASN.1 encoding of an RSA public key (as specified in PKCS.1).
  35. 1. System overview
  36. Onion Routing is a distributed overlay network designed to anonymize
  37. low-latency TCP-based applications such as web browsing, secure shell,
  38. and instant messaging. Clients choose a path through the network and
  39. build a ``circuit'', in which each node (or ``onion router'' or ``OR'')
  40. in the path knows its predecessor and successor, but no other nodes in
  41. the circuit. Traffic flowing down the circuit is sent in fixed-size
  42. ``cells'', which are unwrapped by a symmetric key at each node (like
  43. the layers of an onion) and relayed downstream.
  44. 2. Connections
  45. There are two ways to connect to an onion router (OR). The first is
  46. as an onion proxy (OP), which allows the OP to authenticate the OR
  47. without authenticating itself. The second is as another OR, which
  48. allows mutual authentication.
  49. Tor uses TLS for link encryption. All implementations MUST support
  50. the TLS ciphersuite "TLS_EDH_RSA_WITH_DES_192_CBC3_SHA", and SHOULD
  51. support "TLS_DHE_RSA_WITH_AES_128_CBC_SHA" if it is available.
  52. Implementations MAY support other ciphersuites, but MUST NOT
  53. support any suite without ephemeral keys, symmetric keys of at
  54. least 128 bits, and digests of at least 160 bits.
  55. [what kind of cert does an OP send? -RD]
  56. An OR always sends a two-certificate chain, consisting of a self-signed
  57. certificate containing the OR's identity key, and a second certificate
  58. using a short-term connection key. The commonName of the second
  59. certificate is the OR's nickname, and the commonName of the first
  60. certificate is the OR's nickname, followed by a space and the string
  61. "<identity>".
  62. All parties receiving certificates must confirm that the identity key is
  63. as expected. (When initiating a connection, the expected identity key is
  64. the one given in the directory; when creating a connection because of an
  65. EXTEND cell, the expected identity key is the one given in the cell.) If
  66. the key is not as expected, the party must close the connection.
  67. Once a TLS connection is established, the two sides send cells
  68. (specified below) to one another. Cells are sent serially. All
  69. cells are 512 bytes long. Cells may be sent embedded in TLS
  70. records of any size or divided across TLS records, but the framing
  71. of TLS records MUST NOT leak information about the type or contents
  72. of the cells.
  73. OR-to-OR connections are never deliberately closed. When an OR
  74. starts or receives a new directory, it tries to open new
  75. connections to any OR it is not already connected to.
  76. [not true, unused OR conns close after 5 mins too -RD]
  77. OR-to-OP connections are not permanent. An OP should close a
  78. connection to an OR if there are no circuits running over the
  79. connection, and an amount of time (KeepalivePeriod, defaults to 5
  80. minutes) has passed.
  81. 3. Cell Packet format
  82. The basic unit of communication for onion routers and onion
  83. proxies is a fixed-width "cell". Each cell contains the following
  84. fields:
  85. CircID [2 bytes]
  86. Command [1 byte]
  87. Payload (padded with 0 bytes) [509 bytes]
  88. [Total size: 512 bytes]
  89. The CircID field determines which circuit, if any, the cell is
  90. associated with.
  91. The 'Command' field holds one of the following values:
  92. 0 -- PADDING (Padding) (See Sec 6.2)
  93. 1 -- CREATE (Create a circuit) (See Sec 4)
  94. 2 -- CREATED (Acknowledge create) (See Sec 4)
  95. 3 -- RELAY (End-to-end data) (See Sec 5)
  96. 4 -- DESTROY (Stop using a circuit) (See Sec 4)
  97. The interpretation of 'Payload' depends on the type of the cell.
  98. PADDING: Payload is unused.
  99. CREATE: Payload contains the handshake challenge.
  100. CREATED: Payload contains the handshake response.
  101. RELAY: Payload contains the relay header and relay body.
  102. DESTROY: Payload is unused.
  103. Upon receiving any other value for the command field, an OR must
  104. drop the cell.
  105. The payload is padded with 0 bytes.
  106. PADDING cells are currently used to implement connection keepalive.
  107. If there is no other traffic, ORs and OPs send one another a PADDING
  108. cell every few minutes.
  109. CREATE, CREATED, and DESTROY cells are used to manage circuits;
  110. see section 4 below.
  111. RELAY cells are used to send commands and data along a circuit; see
  112. section 5 below.
  113. 4. Circuit management
  114. 4.1. CREATE and CREATED cells
  115. Users set up circuits incrementally, one hop at a time. To create a
  116. new circuit, OPs send a CREATE cell to the first node, with the
  117. first half of the DH handshake; that node responds with a CREATED
  118. cell with the second half of the DH handshake plus the first 20 bytes
  119. of derivative key data (see section 4.2). To extend a circuit past
  120. the first hop, the OP sends an EXTEND relay cell (see section 5)
  121. which instructs the last node in the circuit to send a CREATE cell
  122. to extend the circuit.
  123. The payload for a CREATE cell is an 'onion skin', which consists
  124. of the first step of the DH handshake data (also known as g^x).
  125. The data is encrypted to Bob's PK as follows: Suppose Bob's PK is
  126. L octets long. If the data to be encrypted is shorter than L-42,
  127. then it is encrypted directly (with OAEP padding). If the data is at
  128. least as long as L-42, then a randomly generated 16-byte symmetric
  129. key is prepended to the data, after which the first L-16-42 bytes
  130. of the data are encrypted with Bob's PK; and the rest of the data is
  131. encrypted with the symmetric key.
  132. So in this case, the onion skin on the wire looks like:
  133. RSA-encrypted:
  134. OAEP padding [42 bytes]
  135. Symmetric key [16 bytes]
  136. First part of g^x [70 bytes]
  137. Symmetrically encrypted:
  138. Second part of g^x [58 bytes]
  139. The relay payload for an EXTEND relay cell consists of:
  140. Address [4 bytes]
  141. Port [2 bytes]
  142. Onion skin [186 bytes]
  143. Public key hash [20 bytes]
  144. The port and address field denote the IPV4 address and port of the next
  145. onion router in the circuit; the public key hash is the SHA1 hash of the
  146. PKCS#1 ASN1 encoding of the next onion router's identity (signing) key.
  147. [XXXX Before 0.0.8, EXTEND cells did not include the public key hash.
  148. Servers running 0.0.8 distinguish the old-style cells based on the
  149. length of payloads. (Servers running 0.0.7 blindly pass on the extend
  150. cell regardless of length.) In a future release, old-style EXTEND
  151. cells will not be supported.]
  152. The payload for a CREATED cell, or the relay payload for an
  153. EXTENDED cell, contains:
  154. DH data (g^y) [128 bytes]
  155. Derivative key data (KH) [20 bytes] <see 4.2 below>
  156. The CircID for a CREATE cell is an arbitrarily chosen 2-byte
  157. integer, selected by the node (OP or OR) that sends the CREATE
  158. cell. To prevent CircID collisions, when one OR sends a CREATE
  159. cell to another, it chooses from only one half of the possible
  160. values based on the ORs' nicknames: if the sending OR has a
  161. lexicographically earlier nickname, it chooses a CircID with a high
  162. bit of 0; otherwise, it chooses a CircID with a high bit of 1.
  163. 4.2. Setting circuit keys
  164. Once the handshake between the OP and an OR is completed, both
  165. servers can now calculate g^xy with ordinary DH. From the base key
  166. material g^xy, they compute derivative key material as follows.
  167. First, the server represents g^xy as a big-endian unsigned integer.
  168. Next, the server computes 100 bytes of key data as K = SHA1(g^xy |
  169. [00]) | SHA1(g^xy | [01]) | ... SHA1(g^xy | [04]) where "00" is
  170. a single octet whose value is zero, [01] is a single octet whose
  171. value is one, etc. The first 20 bytes of K form KH, bytes 21-40 form
  172. the forward digest Df, 41-60 form the backward digest Db, 61-76 form
  173. Kf, and 77-92 form Kb.
  174. KH is used in the handshake response to demonstrate knowledge of the
  175. computed shared key. Df is used to seed the integrity-checking hash
  176. for the stream of data going from the OP to the OR, and Db seeds the
  177. integrity-checking hash for the data stream from the OR to the OP. Kf
  178. is used to encrypt the stream of data going from the OP to the OR, and
  179. Kb is used to encrypt the stream of data going from the OR to the OP.
  180. 4.3. Creating circuits
  181. When creating a circuit through the network, the circuit creator
  182. (OP) performs the following steps:
  183. 1. Choose an onion router as an exit node (R_N), such that the onion
  184. router's exit policy does not exclude all pending streams
  185. that need a circuit.
  186. 2. Choose a chain of (N-1) chain of N onion routers
  187. (R_1...R_N-1) to constitute the path, such that no router
  188. appears in the path twice.
  189. 3. If not already connected to the first router in the chain,
  190. open a new connection to that router.
  191. 4. Choose a circID not already in use on the connection with the
  192. first router in the chain; send a CREATE cell along the
  193. connection, to be received by the first onion router.
  194. 5. Wait until a CREATED cell is received; finish the handshake
  195. and extract the forward key Kf_1 and the backward key Kb_1.
  196. 6. For each subsequent onion router R (R_2 through R_N), extend
  197. the circuit to R.
  198. To extend the circuit by a single onion router R_M, the OP performs
  199. these steps:
  200. 1. Create an onion skin, encrypted to R_M's public key.
  201. 2. Send the onion skin in a relay EXTEND cell along
  202. the circuit (see section 5).
  203. 3. When a relay EXTENDED cell is received, verify KH, and
  204. calculate the shared keys. The circuit is now extended.
  205. When an onion router receives an EXTEND relay cell, it sends a CREATE
  206. cell to the next onion router, with the enclosed onion skin as its
  207. payload. The initiating onion router chooses some circID not yet
  208. used on the connection between the two onion routers. (But see
  209. section 4.1. above, concerning choosing circIDs based on
  210. lexicographic order of nicknames.)
  211. As an extension (called router twins), if the desired next onion
  212. router R in the circuit is down, and some other onion router R'
  213. has the same public keys as R, then it's ok to extend to R' rather than R.
  214. When an onion router receives a CREATE cell, if it already has a
  215. circuit on the given connection with the given circID, it drops the
  216. cell. Otherwise, after receiving the CREATE cell, it completes the
  217. DH handshake, and replies with a CREATED cell. Upon receiving a
  218. CREATED cell, an onion router packs it payload into an EXTENDED relay
  219. cell (see section 5), and sends that cell up the circuit. Upon
  220. receiving the EXTENDED relay cell, the OP can retrieve g^y.
  221. (As an optimization, OR implementations may delay processing onions
  222. until a break in traffic allows time to do so without harming
  223. network latency too greatly.)
  224. 4.4. Tearing down circuits
  225. Circuits are torn down when an unrecoverable error occurs along
  226. the circuit, or when all streams on a circuit are closed and the
  227. circuit's intended lifetime is over. Circuits may be torn down
  228. either completely or hop-by-hop.
  229. To tear down a circuit completely, an OR or OP sends a DESTROY
  230. cell to the adjacent nodes on that circuit, using the appropriate
  231. direction's circID.
  232. Upon receiving an outgoing DESTROY cell, an OR frees resources
  233. associated with the corresponding circuit. If it's not the end of
  234. the circuit, it sends a DESTROY cell for that circuit to the next OR
  235. in the circuit. If the node is the end of the circuit, then it tears
  236. down any associated edge connections (see section 5.1).
  237. After a DESTROY cell has been processed, an OR ignores all data or
  238. destroy cells for the corresponding circuit.
  239. (The rest of this section is not currently used; on errors, circuits
  240. are destroyed, not truncated.)
  241. To tear down part of a circuit, the OP may send a RELAY_TRUNCATE cell
  242. signaling a given OR (Stream ID zero). That OR sends a DESTROY
  243. cell to the next node in the circuit, and replies to the OP with a
  244. RELAY_TRUNCATED cell.
  245. When an unrecoverable error occurs along one connection in a
  246. circuit, the nodes on either side of the connection should, if they
  247. are able, act as follows: the node closer to the OP should send a
  248. RELAY_TRUNCATED cell towards the OP; the node farther from the OP
  249. should send a DESTROY cell down the circuit.
  250. 4.5. Routing relay cells
  251. When an OR receives a RELAY cell, it checks the cell's circID and
  252. determines whether it has a corresponding circuit along that
  253. connection. If not, the OR drops the RELAY cell.
  254. Otherwise, if the OR is not at the OP edge of the circuit (that is,
  255. either an 'exit node' or a non-edge node), it de/encrypts the payload
  256. with AES/CTR, as follows:
  257. 'Forward' relay cell (same direction as CREATE):
  258. Use Kf as key; decrypt.
  259. 'Back' relay cell (opposite direction from CREATE):
  260. Use Kb as key; encrypt.
  261. The OR then decides whether it recognizes the relay cell, by
  262. inspecting the payload as described in section 5.1 below. If the OR
  263. recognizes the cell, it processes the contents of the relay cell.
  264. Otherwise, it passes the decrypted relay cell along the circuit if
  265. the circuit continues. If the OR at the end of the circuit
  266. encounters an unrecognized relay cell, an error has occurred: the OR
  267. sends a DESTROY cell to tear down the circuit.
  268. When a relay cell arrives at an OP, the OP decrypts the payload
  269. with AES/CTR as follows:
  270. OP receives data cell:
  271. For I=N...1,
  272. Decrypt with Kb_I. If the payload is recognized (see
  273. section 5.1), then stop and process the payload.
  274. For more information, see section 5 below.
  275. 5. Application connections and stream management
  276. 5.1. Relay cells
  277. Within a circuit, the OP and the exit node use the contents of
  278. RELAY packets to tunnel end-to-end commands and TCP connections
  279. ("Streams") across circuits. End-to-end commands can be initiated
  280. by either edge; streams are initiated by the OP.
  281. The payload of each unencrypted RELAY cell consists of:
  282. Relay command [1 byte]
  283. 'Recognized' [2 bytes]
  284. StreamID [2 bytes]
  285. Digest [4 bytes]
  286. Length [2 bytes]
  287. Data [498 bytes]
  288. The relay commands are:
  289. 1 -- RELAY_BEGIN
  290. 2 -- RELAY_DATA
  291. 3 -- RELAY_END
  292. 4 -- RELAY_CONNECTED
  293. 5 -- RELAY_SENDME
  294. 6 -- RELAY_EXTEND
  295. 7 -- RELAY_EXTENDED
  296. 8 -- RELAY_TRUNCATE
  297. 9 -- RELAY_TRUNCATED
  298. 10 -- RELAY_DROP
  299. 11 -- RELAY_RESOLVE
  300. 12 -- RELAY_RESOLVED
  301. The 'Recognized' field in any unencrypted relay payload is always
  302. set to zero; the 'digest' field is computed as the first four bytes
  303. of the running SHA-1 digest of all the bytes that have travelled
  304. over this circuit, seeded from Df or Db respectively (obtained in
  305. section 4.2 above), and including this RELAY cell's entire payload
  306. (taken with the digest field set to zero).
  307. When the 'recognized' field of a RELAY cell is zero, and the digest
  308. is correct, the cell is considered "recognized" for the purposes of
  309. decryption (see section 4.5 above).
  310. All RELAY cells pertaining to the same tunneled stream have the
  311. same stream ID. StreamIDs are chosen randomly by the OP. RELAY
  312. cells that affect the entire circuit rather than a particular
  313. stream use a StreamID of zero.
  314. The 'Length' field of a relay cell contains the number of bytes in
  315. the relay payload which contain real payload data. The remainder of
  316. the payload is padded with NUL bytes.
  317. 5.2. Opening streams and transferring data
  318. To open a new anonymized TCP connection, the OP chooses an open
  319. circuit to an exit that may be able to connect to the destination
  320. address, selects an arbitrary StreamID not yet used on that circuit,
  321. and constructs a RELAY_BEGIN cell with a payload encoding the address
  322. and port of the destination host. The payload format is:
  323. ADDRESS | ':' | PORT | [00]
  324. where ADDRESS can be a DNS hostname, or an IPv4 address in
  325. dotted-quad format, or an IPv6 address surrounded by square brackets;
  326. and where PORT is encoded in decimal.
  327. [What is the [00] for? -NM]
  328. [It's so the payload is easy to parse out with string funcs -RD]
  329. Upon receiving this cell, the exit node resolves the address as
  330. necessary, and opens a new TCP connection to the target port. If the
  331. address cannot be resolved, or a connection can't be established, the
  332. exit node replies with a RELAY_END cell. (See 5.4 below.)
  333. Otherwise, the exit node replies with a RELAY_CONNECTED cell, whose
  334. payload is the 4-byte IPv4 address or the 16-byte IPv6 address to which
  335. the connection was made.
  336. The OP waits for a RELAY_CONNECTED cell before sending any data.
  337. Once a connection has been established, the OP and exit node
  338. package stream data in RELAY_DATA cells, and upon receiving such
  339. cells, echo their contents to the corresponding TCP stream.
  340. RELAY_DATA cells sent to unrecognized streams are dropped.
  341. Relay RELAY_DROP cells are long-range dummies; upon receiving such
  342. a cell, the OR or OP must drop it.
  343. 5.3. Closing streams
  344. When an anonymized TCP connection is closed, or an edge node
  345. encounters error on any stream, it sends a 'RELAY_END' cell along the
  346. circuit (if possible) and closes the TCP connection immediately. If
  347. an edge node receives a 'RELAY_END' cell for any stream, it closes
  348. the TCP connection completely, and sends nothing more along the
  349. circuit for that stream.
  350. The payload of a RELAY_END cell begins with a single 'reason' byte to
  351. describe why the stream is closing, plus optional data (depending on
  352. the reason.) The values are:
  353. 1 -- REASON_MISC (catch-all for unlisted reasons)
  354. 2 -- REASON_RESOLVEFAILED (couldn't look up hostname)
  355. 3 -- REASON_CONNECTFAILED (couldn't connect to host/port)
  356. 4 -- REASON_EXITPOLICY (OR refuses to connect to host or port)
  357. 5 -- REASON_DESTROY (circuit is being destroyed [???-NM])
  358. 6 -- REASON_DONE (anonymized TCP connection was closed)
  359. 7 -- REASON_TIMEOUT (OR timed out while connecting [???-NM])
  360. (With REASON_EXITPOLICY, the 4-byte IPv4 address or 16-byte IPv6 address
  361. forms the optional data; no other reason currently has extra data.)
  362. *** [The rest of this section describes unimplemented functionality.]
  363. Because TCP connections can be half-open, we follow an equivalent
  364. to TCP's FIN/FIN-ACK/ACK protocol to close streams.
  365. An exit connection can have a TCP stream in one of three states:
  366. 'OPEN', 'DONE_PACKAGING', and 'DONE_DELIVERING'. For the purposes
  367. of modeling transitions, we treat 'CLOSED' as a fourth state,
  368. although connections in this state are not, in fact, tracked by the
  369. onion router.
  370. A stream begins in the 'OPEN' state. Upon receiving a 'FIN' from
  371. the corresponding TCP connection, the edge node sends a 'RELAY_FIN'
  372. cell along the circuit and changes its state to 'DONE_PACKAGING'.
  373. Upon receiving a 'RELAY_FIN' cell, an edge node sends a 'FIN' to
  374. the corresponding TCP connection (e.g., by calling
  375. shutdown(SHUT_WR)) and changing its state to 'DONE_DELIVERING'.
  376. When a stream in already in 'DONE_DELIVERING' receives a 'FIN', it
  377. also sends a 'RELAY_FIN' along the circuit, and changes its state
  378. to 'CLOSED'. When a stream already in 'DONE_PACKAGING' receives a
  379. 'RELAY_FIN' cell, it sends a 'FIN' and changes its state to
  380. 'CLOSED'.
  381. If an edge node encounters an error on any stream, it sends a
  382. 'RELAY_END' cell (if possible) and closes the stream immediately.
  383. 5.4. Remote hostname lookup
  384. To find the address associated with a hostname, the OP sends a
  385. RELAY_RESOLVE cell containing the hostname to be resolved. The OR
  386. replies with a RELAY_RESOLVED cell containing a status byte, and any
  387. number of answers. Each answer is of the form:
  388. Type (1 octet)
  389. Length (1 octet)
  390. Value (variable-width)
  391. "Length" is the length of the Value field.
  392. "Type" is one of:
  393. 0x04 -- IPv4 address
  394. 0x06 -- IPv6 address
  395. 0xF0 -- Error, transient
  396. 0xF1 -- Error, nontransient
  397. If any answer has a type of 'Error', then no other answer may be given.
  398. The RELAY_RESOLVE cell must use a nonzero, distinct streamID; the
  399. corresponding RELAY_RESOLVED cell must use the same streamID. No stream
  400. is actually created by the OR when resolving the name.
  401. 6. Flow control
  402. 6.1. Link throttling
  403. Each node should do appropriate bandwidth throttling to keep its
  404. user happy.
  405. Communicants rely on TCP's default flow control to push back when they
  406. stop reading.
  407. 6.2. Link padding
  408. Currently nodes are not required to do any sort of link padding or
  409. dummy traffic. Because strong attacks exist even with link padding,
  410. and because link padding greatly increases the bandwidth requirements
  411. for running a node, we plan to leave out link padding until this
  412. tradeoff is better understood.
  413. 6.3. Circuit-level flow control
  414. To control a circuit's bandwidth usage, each OR keeps track of
  415. two 'windows', consisting of how many RELAY_DATA cells it is
  416. allowed to package for transmission, and how many RELAY_DATA cells
  417. it is willing to deliver to streams outside the network.
  418. Each 'window' value is initially set to 1000 data cells
  419. in each direction (cells that are not data cells do not affect
  420. the window). When an OR is willing to deliver more cells, it sends a
  421. RELAY_SENDME cell towards the OP, with Stream ID zero. When an OR
  422. receives a RELAY_SENDME cell with stream ID zero, it increments its
  423. packaging window.
  424. Each of these cells increments the corresponding window by 100.
  425. The OP behaves identically, except that it must track a packaging
  426. window and a delivery window for every OR in the circuit.
  427. An OR or OP sends cells to increment its delivery window when the
  428. corresponding window value falls under some threshold (900).
  429. If a packaging window reaches 0, the OR or OP stops reading from
  430. TCP connections for all streams on the corresponding circuit, and
  431. sends no more RELAY_DATA cells until receiving a RELAY_SENDME cell.
  432. [this stuff is badly worded; copy in the tor-design section -RD]
  433. 6.4. Stream-level flow control
  434. Edge nodes use RELAY_SENDME cells to implement end-to-end flow
  435. control for individual connections across circuits. Similarly to
  436. circuit-level flow control, edge nodes begin with a window of cells
  437. (500) per stream, and increment the window by a fixed value (50)
  438. upon receiving a RELAY_SENDME cell. Edge nodes initiate RELAY_SENDME
  439. cells when both a) the window is <= 450, and b) there are less than
  440. ten cell payloads remaining to be flushed at that edge.
  441. 7. Directories and routers
  442. 7.1. Extensible information format
  443. Router descriptors and directories both obey the following lightweight
  444. extensible information format.
  445. The highest level object is a Document, which consists of one or more Items.
  446. Every Item begins with a KeywordLine, followed by one or more Objects. A
  447. KeywordLine begins with a Keyword, optionally followed by a space and more
  448. non-newline characters, and ends with a newline. A Keyword is a sequence of
  449. one or more characters in the set [A-Za-z0-9-]. An Object is a block of
  450. encoded data in pseudo-Open-PGP-style armor. (cf. RFC 2440)
  451. More formally:
  452. Document ::= (Item | NL)+
  453. Item ::= KeywordLine Object*
  454. KeywordLine ::= Keyword NL | Keyword SP ArgumentsChar+ NL
  455. Keyword = KeywordChar+
  456. KeywordChar ::= 'A' ... 'Z' | 'a' ... 'z' | '0' ... '9' | '-'
  457. ArgumentChar ::= any printing ASCII character except NL.
  458. Object ::= BeginLine Base-64-encoded-data EndLine
  459. BeginLine ::= "-----BEGIN " Keyword "-----" NL
  460. EndLine ::= "-----END " Keyword "-----" NL
  461. The BeginLine and EndLine of an Object must use the same keyword.
  462. When interpreting a Document, software MUST reject any document containing a
  463. KeywordLine that starts with a keyword it doesn't recognize.
  464. The "opt" keyword is reserved for non-critical future extensions. All
  465. implementations MUST ignore any item of the form "opt keyword ....." when
  466. they would not recognize "keyword ....."; and MUST treat "opt keyword ....."
  467. as synonymous with "keyword ......" when keyword is recognized.
  468. 7.1. Router descriptor format.
  469. Every router descriptor MUST start with a "router" Item; MUST end with a
  470. "router-signature" Item and an extra NL; and MUST contain exactly one
  471. instance of each of the following Items: "published" "onion-key" "link-key"
  472. "signing-key" "bandwidth". Additionally, a router descriptor MAY contain any
  473. number of "accept", "reject", "fingerprint", "uptime", and "opt" Items.
  474. Other than "router" and "router-signature", the items may appear in any
  475. order.
  476. The items' formats are as follows:
  477. "router" nickname address (ORPort SocksPort DirPort)?
  478. Indicates the beginning of a router descriptor. "address" must be an
  479. IPv4 address in dotted-quad format. The Port values will soon be
  480. deprecated; using them here is equivalent to using them in a "ports"
  481. item.
  482. "ports" ORPort SocksPort DirPort
  483. Indicates the TCP ports at which this OR exposes functionality.
  484. ORPort is a port at which this OR accepts TLS connections for the main
  485. OR protocol; SocksPort is the port at which this OR accepts SOCKS
  486. connections; and DirPort is the port at which this OR accepts
  487. directory-related HTTP connections. If any port is not supported, the
  488. value 0 is given instead of a port number.
  489. "bandwidth" bandwidth-avg bandwidth-burst bandwidth-observed
  490. Estimated bandwidth for this router, in bytes per second. The
  491. "average" bandwidth is the volume per second that the OR is willing
  492. to sustain over long periods; the "burst" bandwidth is the volume
  493. that the OR is willing to sustain in very short intervals. The
  494. "observed" value is an estimate of the capacity this server can
  495. handle. The server remembers the max bandwidth sustained output
  496. over any ten second period in the past day, and another sustained
  497. input. The "observed" value is the lesser of these two numbers.
  498. [bandwidth-observed was not present before 0.0.8.]
  499. "platform" string
  500. A human-readable string describing the system on which this OR is
  501. running. This MAY include the operating system, and SHOULD include
  502. the name and version of the software implementing the Tor protocol.
  503. "published" YYYY-MM-DD HH:MM:SS
  504. The time, in GMT, when this descriptor was generated.
  505. "fingerprint"
  506. A fingerprint (20 byte SHA1 hash of asn1 encoded public key, encoded
  507. in hex, with spaces after every 4 characters) for this router's
  508. identity key.
  509. "uptime"
  510. The number of seconds that this OR has been running.
  511. "onion-key" NL a public key in PEM format
  512. This key is used to encrypt EXTEND cells for this OR. The key MUST
  513. be accepted for at least XXXX hours after any new key is published in
  514. a subsequent descriptor.
  515. "signing-key" NL a public key in PEM format
  516. The OR's long-term identity key.
  517. "accept" exitpattern
  518. "reject" exitpattern
  519. These lines, in order, describe the rules that an OR follows when
  520. deciding whether to allow a new stream to a given address. The
  521. 'exitpattern' syntax is described below.
  522. "router-signature" NL Signature NL
  523. The "SIGNATURE" object contains a signature of the PKCS1-padded SHA1
  524. hash of the entire router descriptor, taken from the beginning of the
  525. "router" line, through the newline after the "router-signature" line.
  526. The router descriptor is invalid unless the signature is performed
  527. with the router's identity key.
  528. nickname ::= between 1 and 19 alphanumeric characters, case-insensitive.
  529. exitpattern ::= addrspec ":" portspec
  530. portspec ::= "*" | port | port "-" port
  531. port ::= an integer between 1 and 65535, inclusive.
  532. addrspec ::= "*" | ip4spec | ip6spec
  533. ipv4spec ::= ip4 | ip4 "/" num_ip4_bits | ip4 "/" ip4mask
  534. ip4 ::= an IPv4 address in dotted-quad format
  535. ip4mask ::= an IPv4 mask in dotted-quad format
  536. num_ip4_bits ::= an integer between 0 and 32
  537. ip6spec ::= ip6 | ip6 "/" num_ip6_bits
  538. ip6 ::= an IPv6 address, surrounded by square brackets.
  539. num_ip6_bits ::= an integer between 0 and 128
  540. Ports are required; if they are not included in the router
  541. line, they must appear in the "ports" lines.
  542. 7.2. Directory format
  543. A Directory begins with a "signed-directory" item, followed by one each of
  544. the following, in any order: "recommended-software", "published",
  545. "router-status". It may include any number of "opt" items. After these
  546. items, a directory includes any number of router descriptors, and a single
  547. "directory-signature" item.
  548. "signed-directory"
  549. Indicates the start of a
  550. "published" YYYY-MM-DD HH:MM:SS
  551. The time at which this directory was generated and signed, in GMT.
  552. "recommended-software" comma-separated-version-list
  553. A list of which versions of which implementations are currently
  554. believed to be secure and compatible with the network.
  555. "running-routers" space-separated-list
  556. A description of which routers are currently believed to be up or
  557. down. Every entry consists of an optional "!", followed by either an
  558. OR's nickname, or "$" followed by a hexadecimal encoding of the hash
  559. of an OR's identity key. If the "!" is included, the router is
  560. believed to be running; otherwise, it is believed not to be running.
  561. If a router's nickname is given, exactly one router of that nickname
  562. will appear in the directory, and that router is "approved" by the
  563. directory server. If a hashed identity key is given, that OR is not
  564. "approved". [XXXX The 'running-routers' line is only provided for
  565. backward compatibility. New code should parse 'router-status'
  566. instead.]
  567. "router-status" space-separated-list
  568. A description of which routers are currently believed to be up or
  569. down, and which are verified or unverified. Contains one entry for
  570. every router that the directory server knows. Each entry is of the
  571. format:
  572. !name=$digest [Verified router, currently not live.]
  573. name=$digest [Verified router, currently live.]
  574. !$digest [Unverified router, currently not live.]
  575. or $digest [Unverified router, currently live.]
  576. (where 'name' is the router's nickname and 'digest' is a hexadecimal
  577. encoding of the hash of the routers' identity key).
  578. When parsing this line, clients should only mark a router as
  579. 'verified' if its nickname AND digest match the one provided.
  580. [XXXX 'router-status' was added in 0.0.9pre5; older directory code
  581. uses 'running-routers' instead.]
  582. "directory-signature" nickname-of-dirserver NL Signature
  583. Note: The router descriptor for the directory server MUST appear first.
  584. The signature is computed by computing the SHA-1 hash of the
  585. directory, from the characters "signed-directory", through the newline
  586. after "directory-signature". This digest is then padded with PKCS.1,
  587. and signed with the directory server's signing key.
  588. If software encounters an unrecognized keyword in a single router descriptor,
  589. it should reject only that router descriptor, and continue using the
  590. others. If it encounters an unrecognized keyword in the directory header,
  591. it should reject the entire directory.
  592. 7.3. Network-status descriptor
  593. A "network-status" (a.k.a "running-routers") document is a truncated
  594. directory that contains only the current status of a list of nodes, not
  595. their actual descriptors. It contains exactly one of each of the following
  596. entries.
  597. "network-status"
  598. Must appear first.
  599. "published" YYYY-MM-DD HH:MM:SS
  600. (see 7.2 above)
  601. "router-status" list
  602. (see 7.2 above)
  603. "directory-signature" NL signature
  604. (see 7.2 above)
  605. 7.4. Behavior of a directory server
  606. lists nodes that are connected currently
  607. speaks http on a socket, spits out directory on request
  608. A.1. Differences between spec and implementation
  609. - The current specification requires all ORs to have IPv4 addresses, but
  610. allows servers to exit and resolve to IPv6 addresses, and to declare IPv6
  611. addresses in their exit policies. The current codebase has no IPv6
  612. support at all.
  613. -----------
  614. (for emacs)
  615. Local Variables:
  616. mode:text
  617. indent-tabs-mode:nil
  618. fill-column:77
  619. End: