rend-spec.txt 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. $Id$
  2. [XXX We need to make nicknames in intro* cells padded to 20
  3. bytes, and maybe have a fixed length for nicknames in the
  4. descriptor too -RD]
  5. Tor Rendezvous Spec
  6. 0. Overview and preliminaries
  7. Rendezvous points provide location-hidden services (server
  8. anonymity) for the onion routing network. With rendezvous points,
  9. Bob can offer a TCP service (say, a webserver) via the onion
  10. routing network, without revealing the IP of that service.
  11. Bob does this by anonymously advertising a public key for his
  12. service, along with a list of onion routers to act as "Introduction
  13. Points" for his service. He creates forward OR circuits to those
  14. introduction points, and tells them about his public key. To
  15. connect to Bob, Alice first builds an OR circuit to an OR to act as
  16. her "Rendezvous Point", then connects to one of Bob's chosen
  17. introduction points, and asks it to tell him about her Rendezvous
  18. Point (RP). If Bob chooses to answer, he builds an OR circuit to her
  19. RP, and tells it to connect him to Alice. The RP joints their
  20. circuits together, and begins relaying cells. Alice's 'BEGIN'
  21. cells are received directly by Bob's OP, which responds by
  22. communication with the local server implementing Bob's service.
  23. Below, we describe a network-level specification of this service,
  24. along with interfaces to make this process transparent to Alice
  25. (so long as she is using an OP).
  26. 0.1. Notation, conventions and prerequisites
  27. In the specifications below, we use the same notation as in
  28. "tor-spec.txt". The service specified here also requires the existence of
  29. an onion routing network as specified in "tor-spec.txt".
  30. H(x) is a SHA1 digest of x.
  31. PKSign(SK,x) is a PKCS.1-padded RSA signature of x with SK.
  32. PKEncrypt(SK,x) is a PKCS.1-padded RSA encryption of x with SK.
  33. Public keys are all RSA, and encoded in ASN.1.
  34. All integers are stored in network (big-endian) order.
  35. All symmetric encryption uses AES in counter mode, except where
  36. otherwise noted.
  37. In all discussions, "Alice" will refer to a user connecting to a
  38. location-hidden service, and "Bob" will refer to a user running a
  39. location-hidden service.
  40. 0.2. Protocol outline
  41. 1. Bob->Bob's OP: "Offer IP:Port as public-key-name:Port". [configuration]
  42. (We do not specify this step; it is left to the implementor of
  43. Bob's OP.)
  44. 2. Bob's OP generates keypair and rendezvous service descriptor:
  45. "Meet public-key X at introduction point A, B, or C." (signed)
  46. 3. Bob's OP->Introduction point via Tor: [introduction setup]
  47. "This pk is me."
  48. 4. Bob's OP->directory service via Tor: publishes Bob's service descriptor
  49. [advertisement]
  50. 5. Out of band, Alice receives a y.onion:port address. She opens a
  51. SOCKS connection to her OP, and requests y.onion:port.
  52. 6. Alice's OP retrieves Bob's descriptor via Tor: [descriptor lookup.]
  53. 7. Alice's OP chooses a rendezvous point, opens a circuit to that
  54. rendezvous point, and establishes a rendezvous circuit. [rendezvous
  55. setup.]
  56. 8. Alice connects to the Introduction point via Tor, and tells it about
  57. her rendezvous point. (Encrypted to Bob.) [Introduction 1]
  58. 9. The Introduction point passes this on to Bob's OP via Tor, along the
  59. introduction circuit. [Introduction 2]
  60. 10. Bob's OP decides whether to connect to Alice, and if so, creates a
  61. circuit to Alice's RP via Tor. Establishes a shared circuit.
  62. [Rendezvous.]
  63. 11. Alice's OP sends begin cells to Bob's OP. [Connection]
  64. 0.3. Constants and new cell types
  65. Relay cell types
  66. 32 -- RELAY_ESTABLISH_INTRO
  67. 33 -- RELAY_ESTABLISH_RENDEZVOUS
  68. 34 -- RELAY_INTRODUCE1
  69. 35 -- RELAY_INTRODUCE2
  70. 36 -- RELAY_RENDEZVOUS1
  71. 37 -- RELAY_RENDEZVOUS2
  72. 1. The Protocol
  73. 1.1. Bob configures his local OP.
  74. We do not specify a format for the OP configuration file. However,
  75. OPs SHOULD allow Bob to provide more than one advertised service
  76. per OP, and MUST allow Bob to specify one or more virtual ports per
  77. service. Bob provides a mapping from each of these virtual ports
  78. to a local IP:Port pair.
  79. 1.2. Bob's OP generates service descriptors.
  80. The first time the OP provides an advertised service, it generates
  81. a public/private keypair (stored locally). Periodically, the OP
  82. generates service descriptor, containing:
  83. KL Key length [2 octets]
  84. PK Bob's public key [KL octets]
  85. TS A timestamp [4 octets]
  86. NI Number of introduction points [2 octets]
  87. Ipt A list of NUL-terminated OR nicknames [variable]
  88. SIG Signature of above fields [variable]
  89. KL is the length of PK, in octets. (Currently, KL must be 128.)
  90. TS is the number of seconds elapsed since Jan 1, 1970.
  91. [It's ok for Bob to advertise 0 introduction points. He might want
  92. to do that if he previously advertised some introduction points,
  93. and now he doesn't have any. -RD]
  94. [Shouldn't the nicknames be hostname:port's instead? That way, Alice's
  95. directory servers don't need to know Bob's chosen introduction points.
  96. Not important now, but essential if we ever have a non-total-knowledge
  97. design. -NM]
  98. 1.3. Bob's OP establishes his introduction points.
  99. The OP establishes a new introduction circuit to each introduction
  100. point. These circuits MUST NOT be used for anything but rendezvous
  101. introduction. To establish the introduction, Bob sends a
  102. RELAY_ESTABLISH_INTRO cell, containing:
  103. KL Key length [2 octets]
  104. PK Bob's public key [KL octets]
  105. HS Hash of session info [20 octets]
  106. SIG Signature of above information [variable]
  107. To prevent replay attacks, the HS field contains a SHA-1 hash based on the
  108. shared secret KH between Bob's OP and the introduction point, as
  109. follows:
  110. HS = H(KH | "INTRODUCE")
  111. That is:
  112. HS = H(KH | [49 4E 54 52 4F 44 55 43 45])
  113. (KH, as specified in tor-spec.txt, is H(g^xy | [00]) .)
  114. Upon receiving such a cell, the OR first checks that the signature is
  115. correct with the included public key. If so, it checks whether HS is
  116. correct given the shared state between Bob's OP and the OR. If either
  117. check fails, the OP discards the cell; otherwise, it associates the
  118. circuit with Bob's public key, and dissociates any other circuits
  119. currently associated with PK.
  120. 1.4. Bob's OP advertises his server descriptor
  121. Bob's OP opens a stream to each directory server's directory port via Tor.
  122. (He may re-use old circuits for this.)
  123. Over this stream, Bob's OP makes an HTTP 'POST' request, to the URL
  124. '/rendezvous/publish' (relative to the directory server's root),
  125. containing as its body Bob's service descriptor. Upon receiving a
  126. descriptor, the directory server checks the signature, and discards the
  127. descriptor if the signature does not match the enclosed public key. Next,
  128. the directory server checks the timestamp. If the timestamp is more than
  129. 24 hours in the past or more than 1 hour in the future, or the directory
  130. server already has a newer descriptor with the same public key, the server
  131. discards the descriptor. Otherwise, the server discards any older
  132. descriptors with the same public key, and associates the new descriptor
  133. with the public key. The directory server remembers this descriptor for
  134. at least 24 hours after its timestamp. At least every 24 hours, Bob's OP
  135. uploads a fresh descriptor.
  136. 1.5. Alice receives a y.onion address
  137. When Alice receives a pointer to a location-hidden service, it is as a
  138. hostname of the form "y.onion", where y is a base-32 encoding of a
  139. 10-octet hash of Bob's service's public key, computed as follows:
  140. 1. Let H = H(PK).
  141. 2. Let H' = the first 80 bits of H, considering each octet from
  142. most significant bit to least significant bit.
  143. 2. Generate a 16-character encoding of H', taking H' 5 bits at
  144. a time, and mapping each 5-bit value to a character as follows:
  145. 0..25 map to the characters 'a'...'z', respectively.
  146. 26..31 map to the characters '0'...'5', respectively.
  147. (We only use 80 bits instead of the 160 bits from SHA1 because we don't
  148. need to worry about man-in-the-middle attacks, and because it will make
  149. handling the url's more convenient.)
  150. [Yes, numbers are allowed at the beginning. See RFC1123. -NM]
  151. 1.6. Alice's OP retrieves a service descriptor
  152. Alice opens a stream to a directory server via Tor, and makes an HTTP GET
  153. request for the document '/rendezvous/<y>', where '<y> is replaced with the
  154. encoding of Bob's public key as described above. (She may re-use old
  155. circuits for this.) The directory replies with a 404 HTTP response if
  156. it does not recognize <y>, and otherwise returns Bob's most recently
  157. uploaded service descriptor.
  158. If Alice's OP receives a 404 response, it tries the other directory
  159. servers, and only fails the lookup if none recognizes the public key hash.
  160. Upon receiving a service descriptor, Alice verifies with the same process
  161. as the directory server uses, described above in section 1.4.
  162. The directory server gives a 400 response if it cannot understand Alice's
  163. request.
  164. Alice should cache the descriptor locally, but should not use
  165. descriptors that are more than 24 hours older than their timestamp.
  166. [Caching may make her partitionable, but she fetched it anonymously,
  167. and we can't very well *not* cache it. -RD]
  168. 1.7. Alice's OP establishes a rendezvous point.
  169. When Alice requests a connection to a given location-hidden service,
  170. and Alice's OP does not have an established circuit to that service,
  171. the OP builds a rendezvous circuit. It does this by establishing
  172. a circuit to a randomly chosen OR, and sending a
  173. RELAY_ESTABLISH_RENDEZVOUS cell to that OR. The body of that cell
  174. contains:
  175. RC Rendezvous cookie [20 octets]
  176. The rendezvous cookie is an arbitrary 20-byte value, chosen randomly by
  177. Alice's OP.
  178. Upon receiving a RELAY_ESTABLISH_RENDEZVOUS cell, the OR associates the
  179. RC with the circuit that sent it.
  180. Alice's OP MUST NOT use the circuit which sent the cell for any purpose
  181. other than rendezvous with the given location-hidden service.
  182. 1.8. Introduction: from Alice's OP to Introduction Point
  183. Alice builds a separate circuit to one of Bob's chosen introduction
  184. points, and sends it a RELAY_INTRODUCE1 cell containing:
  185. Cleartext
  186. PK_ID Identifier for Bob's PK [20 octets]
  187. Encrypted to Bob's PK:
  188. RP Rendezvous point's nickname [20 octets]
  189. RC Rendezvous cookie [20 octets]
  190. g^x Diffie-Hellman data, part 1 [128 octetes]
  191. PK_ID is the hash of Bob's public key. RP is NUL-padded.
  192. The data is encrypted to Bob's PK as follows: Suppose Bob's PK is L octets
  193. long. If the data to be encrypted is shorter than L-42, then it is
  194. encrypted directly (with OAEP padding). If the data is at least as long
  195. as L-42, then a randomly generated 16-byte symmetric key is prepended to
  196. the data, after which the first L-16-42 bytes of the data are encrypted with
  197. Bob's PK; and the rest of the data is encrypted with the symmetric key.
  198. 1.9. Introduction: From the Introduction Point to Bob's OP
  199. If the Introduction Point recognizes PK_ID as a public key which has
  200. established a circuit for introductions as in 1.3 above, it sends the body
  201. of the cell in a new RELAY_INTRODUCE2 cell down the corresponding circuit.
  202. (If the PK_ID is unrecognized, the RELAY_INTRODUCE1 cell is discarded.)
  203. When Bob's OP receives the RELAY_INTRODUCE2 cell, it decrypts it with
  204. the private key for the corresponding hidden service, and extracts the
  205. rendezvous point's nickname, the rendezvous cookie, and the value of g^x
  206. chosen by Alice.
  207. 1.10. Rendezvous
  208. Bob's OP build a new Tor circuit ending at Alice's chosen rendezvous
  209. point, and sends a RELAY_RENDEZVOUS1 cell along this circuit, containing:
  210. RC Rendezvous cookie [20 octets]
  211. g^y Diffie-Hellman [128 octets]
  212. KH Handshake digest [20 octets]
  213. (Bob's OP MUST NOT use this circuit for any other purpose.)
  214. If the RP recognizes RC, it relays the rest of the cell down the
  215. corresponding circuit in a RELAY_RENDEZVOUS2 cell, containing:
  216. g^y Diffie-Hellman [128 octets]
  217. KH Handshake digest [20 octets]
  218. (If the RP does not recognize the RC, it discards the cell and
  219. tears down the circuit.)
  220. When Alice's OP receives a RELAY_RENDEZVOUS2 cell on a circuit which
  221. has sent a RELAY_ESTABLISH_RENDEZVOUS cell but which has not yet received
  222. a reply, it uses g^y and H(g^xy) to complete the handshake as in the Tor
  223. circuit extend process: they establish a 60-octet string as
  224. K = SHA1(g^xy | [00]) | SHA1(g^xy | [01]) | SHA1(g^xy | [02])
  225. and generate
  226. KH = K[0..15]
  227. Kf = K[16..31]
  228. Kb = K[32..47]
  229. Subsequently, the rendezvous point passes relay cells, unchanged, from
  230. each of the two circuits to the other. When Alice's OP sends
  231. RELAY cells along the circuit, it first encrypts them with the
  232. Kf, then with all of the keys for the ORs in Alice's side of the circuit;
  233. and when Alice's OP receives RELAY cells from the circuit, it decrypts
  234. them with the keys for the ORs in Alice's side of the circuit, then
  235. decrypts them with Kb. Bob's OP does the same, with Kf and Kb
  236. interchanged.
  237. 1.11. Creating streams
  238. To open TCP connections to Bob's location-hidden service, Alice's OP sends
  239. a RELAY_BEGIN cell along the established circuit, using the special
  240. address "", and a chosen port. Bob's OP chooses a destination IP and
  241. port, based on the configuration of the service connected to the circuit,
  242. and opens a TCP stream. From then on, Bob's OP treats the stream as an
  243. ordinary exit connection.
  244. [ Except he doesn't include addr in the connected cell or the end
  245. cell. -RD]
  246. Alice MAY send multiple RELAY_BEGIN cells along the circuit, to open
  247. multiple streams to Bob. Alice SHOULD NOT send RELAY_BEGIN cells for any
  248. other address along her circuit to Bob; if she does, Bob MUST reject them.