105-handshake-revision.txt 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. Filename: 105-handshake-revision.txt
  2. Title: Version negotiation for the Tor protocol.
  3. Version: $Revision$
  4. Last-Modified: $Date$
  5. Author: Nick Mathewson, Roger Dingledine
  6. Created:
  7. Status: Finished
  8. Overview:
  9. This document was extracted from a modified version of tor-spec.txt that we
  10. had written before the proposal system went into place. It adds two new
  11. cells types to the Tor link connection setup handshake: one used for
  12. version negotiation, and another to prevent MITM attacks.
  13. This proposal is partially implemented, and partially proceded by
  14. proposal 130.
  15. Motivation: Tor versions
  16. Our *current* approach to versioning the Tor protocol(s) has been as
  17. follows:
  18. - All changes must be backward compatible.
  19. - It's okay to add new cell types, if they would be ignored by previous
  20. versions of Tor.
  21. - It's okay to add new data elements to cells, if they would be
  22. ignored by previous versions of Tor.
  23. - For forward compatibility, Tor must ignore cell types it doesn't
  24. recognize, and ignore data in those cells it doesn't expect.
  25. - Clients can inspect the version of Tor declared in the platform line
  26. of a router's descriptor, and use that to learn whether a server
  27. supports a given feature. Servers, however, aren't assumed to all
  28. know about each other, and so don't know the version of who they're
  29. talking to.
  30. This system has these problems:
  31. - It's very hard to change fundamental aspects of the protocol, like the
  32. cell format, the link protocol, any of the various encryption schemes,
  33. and so on.
  34. - The router-to-router link protocol has remained more-or-less frozen
  35. for a long time, since we can't easily have an OR use new features
  36. unless it knows the other OR will understand them.
  37. We need to resolve these problems because:
  38. - Our cipher suite is showing its age: SHA1/AES128/RSA1024/DH1024 will
  39. not seem like the best idea for all time.
  40. - There are many ideas circulating for multiple cell sizes; while it's
  41. not obvious whether these are safe, we can't do them at all without a
  42. mechanism to permit them.
  43. - There are many ideas circulating for alternative circuit building and
  44. cell relay rules: they don't work unless they can coexist in the
  45. current network.
  46. - If our protocol changes a lot, it's hard to describe any coherent
  47. version of it: we need to say "the version that Tor versions W through
  48. X use when talking to versions Y through Z". This makes analysis
  49. harder.
  50. Motivation: Preventing MITM attacks
  51. TLS prevents a man-in-the-middle attacker from reading or changing the
  52. contents of a communication. It does not, however, prevent such an
  53. attacker from observing timing information. Since timing attacks are some
  54. of the most effective against low-latency anonymity nets like Tor, we
  55. should take more care to make sure that we're not only talking to who
  56. we think we're talking to, but that we're using the network path we
  57. believe we're using.
  58. Motivation: Signed clock information
  59. It's very useful for Tor instances to know how skewed they are relative
  60. to one another. The only way to find out currently has been to download
  61. directory information, and check the Date header--but this is not
  62. authenticated, and hence subject to modification on the wire. Using
  63. BEGIN_DIR to create an authenticated directory stream through an existing
  64. circuit is better, but that's an extra step and it might be nicer to
  65. learn the information in the course of the regular protocol.
  66. Proposal:
  67. 1.0. Version numbers
  68. The node-to-node TLS-based "OR connection" protocol and the multi-hop
  69. "circuit" protocol are versioned quasi-independently.
  70. Of course, some dependencies will continue to exist: Certain versions
  71. of the circuit protocol may require a minimum version of the connection
  72. protocol to be used. The connection protocol affects:
  73. - Initial connection setup, link encryption, transport guarantees,
  74. etc.
  75. - The allowable set of cell commands
  76. - Allowable formats for cells.
  77. The circuit protocol determines:
  78. - How circuits are established and maintained
  79. - How cells are decrypted and relayed
  80. - How streams are established and maintained.
  81. Version numbers are incremented for backward-incompatible protocol changes
  82. only. Backward-compatible changes are generally implemented by adding
  83. additional fields to existing structures; implementations MUST ignore
  84. fields they do not expect. Unused portions of cells MUST be set to zero.
  85. Though versioning the protocol will make it easier to maintain backward
  86. compatibility with older versions of Tor, we will nevertheless continue to
  87. periodically drop support for older protocols,
  88. - to keep the implementation from growing without bound,
  89. - to limit the maintenance burden of patching bugs in obsolete Tors,
  90. - to limit the testing burden of verifying that many old protocol
  91. versions continue to be implemented properly, and
  92. - to limit the exposure of the network to protocol versions that are
  93. expensive to support.
  94. The Tor protocol as implemented through the 0.1.2.x Tor series will be
  95. called "version 1" in its link protocol and "version 1" in its relay
  96. protocol. Versions of the Tor protocol so old as to be incompatible with
  97. Tor 0.1.2.x can be considered to be version 0 of each, and are not
  98. supported.
  99. 2.1. VERSIONS cells
  100. When a Tor connection is established, both parties normally send a
  101. VERSIONS cell before sending any other cells. (But see below.)
  102. VersionsLen [2 byte]
  103. Versions [VersionsLen bytes]
  104. "Versions" is a sequence of VersionsLen bytes. Each value between 1 and
  105. 127 inclusive represents a single version; current implementations MUST
  106. ignore other bytes. Parties should list all of the versions which they
  107. are able and willing to support. Parties can only communicate if they
  108. have some connection protocol version in common.
  109. Version 0.2.0.x-alpha and earlier don't understand VERSIONS cells,
  110. and therefore don't support version negotiation. Thus, waiting until
  111. the other side has sent a VERSIONS cell won't work for these servers:
  112. if the other side sends no cells back, it is impossible to tell
  113. whether they
  114. have sent a VERSIONS cell that has been stalled, or whether they have
  115. dropped our own VERSIONS cell as unrecognized. Therefore, we'll
  116. change the TLS negotiation parameters so that old parties can still
  117. negotiate, but new parties can recognize each other. Immediately
  118. after a TLS connection has been established, the parties check
  119. whether the other side negotiated the connection in an "old" way or a
  120. "new" way. If either party negotiated in the "old" way, we assume a
  121. v1 connection. Otherwise, both parties send VERSIONS cells listing
  122. all their supported versions. Upon receiving the other party's
  123. VERSIONS cell, the implementation begins using the highest-valued
  124. version common to both cells. If the first cell from the other party
  125. has a recognized command, and is _not_ a VERSIONS cell, we assume a
  126. v1 protocol.
  127. (For more detail on the TLS protocol change, see forthcoming draft
  128. proposals from Steven Murdoch.)
  129. Implementations MUST discard VERSIONS cells that are not the first
  130. recognized cells sent on a connection.
  131. The VERSIONS cell must be sent as a v1 cell (2 bytes of circuitID, 1
  132. byte of command, 509 bytes of payload).
  133. [NOTE: The VERSIONS cell is assigned the command number 7.]
  134. 2.2. MITM-prevention and time checking
  135. If we negotiate a v2 connection or higher, the second cell we send SHOULD
  136. be a NETINFO cell. Implementations SHOULD NOT send NETINFO cells at other
  137. times.
  138. A NETINFO cell contains:
  139. Timestamp [4 bytes]
  140. Other OR's address [variable]
  141. Number of addresses [1 byte]
  142. This OR's addresses [variable]
  143. Timestamp is the OR's current Unix time, in seconds since the epoch. If
  144. an implementation receives time values from many ORs that
  145. indicate that its clock is skewed, it SHOULD try to warn the
  146. administrator. (We leave the definition of 'many' intentionally vague
  147. for now.)
  148. Before believing the timestamp in a NETINFO cell, implementations
  149. SHOULD compare the time at which they received the cell to the time
  150. when they sent their VERSIONS cell. If the difference is very large,
  151. it is likely that the cell was delayed long enough that its
  152. contents are out of date.
  153. Each address contains Type/Length/Value as used in Section 6.4 of
  154. tor-spec.txt. The first address is the one that the party sending
  155. the NETINFO cell believes the other has -- it can be used to learn
  156. what your IP address is if you have no other hints.
  157. The rest of the addresses are the advertised addresses of the party
  158. sending the NETINFO cell -- we include them
  159. to block a man-in-the-middle attack on TLS that lets an attacker bounce
  160. traffic through his own computers to enable timing and packet-counting
  161. attacks.
  162. A Tor instance should use the other Tor's reported address
  163. information as part of logic to decide whether to treat a given
  164. connection as suitable for extending circuits to a given address/ID
  165. combination. When we get an extend request, we use an
  166. existing OR connection if the ID matches, and ANY of the following
  167. conditions hold:
  168. - The IP matches the requested IP.
  169. - We know that the IP we're using is canonical because it was
  170. listed in the NETINFO cell.
  171. - We know that the IP we're using is canonical because it was
  172. listed in the server descriptor.
  173. [NOTE: The NETINFO cell is assigned the command number 8.]
  174. Discussion: Versions versus feature lists
  175. Many protocols negotiate lists of available features instead of (or in
  176. addition to) protocol versions. While it's possible that some amount of
  177. feature negotiation could be supported in a later Tor, we should prefer to
  178. use protocol versions whenever possible, for reasons discussed in
  179. the "Anonymity Loves Company" paper.
  180. Discussion: Bytes per version, versions per cell
  181. This document provides for a one-byte count of how many versions a Tor
  182. supports, and allows one byte per version. Thus, it can only support only
  183. 254 more versions of the protocol beyond the unallocated v0 and the
  184. current v1. If we ever need to split the protocol into 255 incompatible
  185. versions, we've probably screwed up badly somewhere.
  186. Nevertheless, here are two ways we could support more versions:
  187. - Change the version count to a two-byte field that counts the number of
  188. _bytes_ used, and use a UTF8-style encoding: versions 0 through 127
  189. take one byte to encode, versions 128 through 2047 take two bytes to
  190. encode, and so on. We wouldn't need to parse any version higher than
  191. 127 right now, since all bytes used to encode higher versions would
  192. have their high bit set.
  193. We'd still have a limit of 380 simultaneously versions that could be
  194. declared in any version. This is probably okay.
  195. - Decide that if we need to support more versions, we can add a
  196. MOREVERSIONS cell that gets sent before the VERSIONS cell. The spec
  197. above requires Tors to ignore unrecognized cell types that they get
  198. before the first VERSIONS cell, and still allows version negotiation
  199. to
  200. succeed.
  201. [Resolution: Reserve the high bit and the v0 value for later use. If
  202. we ever have more live versions than we can fit in a cell, we've made a
  203. bad design decision somewhere along the line.]
  204. Discussion: Reducing round-trips
  205. It might be appealing to see if we can cram more information in the
  206. initial VERSIONS cell. For example, the contents of NETINFO will pretty
  207. soon be sent by everybody before any more information is exchanged, but
  208. decoupling them from the version exchange increases round-trips.
  209. Instead, we could speculatively include handshaking information at
  210. the end of a VERSIONS cell, wrapped in a marker to indicate, "if we wind
  211. up speaking VERSION 2, here's the NETINFO I'll send. Otherwise, ignore
  212. this." This could be extended to opportunistically reduce round trips
  213. when possible for future versions when we guess the versions right.
  214. Of course, we'd need to be careful about using a feature like this:
  215. - We don't want to include things that are expensive to compute,
  216. like PK signatures or proof-of-work.
  217. - We don't want to speculate as a mobile client: it may leak our
  218. experience with the server in question.
  219. Discussion: Advertising versions in routerdescs and networkstatuses.
  220. In network-statuses:
  221. The networkstatus "v" line now has the format:
  222. "v" IMPLEMENTATION IMPL-VERSION "Link" LINK-VERSION-LIST
  223. "Circuit" CIRCUIT-VERSION-LIST NL
  224. LINK-VERSION-LIST and CIRCUIT-VERSION-LIST are comma-separated lists of
  225. supported version numbers. IMPLEMENTATION is the name of the
  226. implementation of the Tor protocol (e.g., "Tor"), and IMPL-VERSION is the
  227. version of the implementation.
  228. Examples:
  229. v Tor 0.2.5.1-alpha Link 1,2,3 Circuit 2,5
  230. v OtherOR 2000+ Link 3 Circuit 5
  231. Implementations that release independently of the Tor codebase SHOULD NOT
  232. use "Tor" as the value of their IMPLEMENTATION.
  233. Additional fields on the "v" line MUST be ignored.
  234. In router descriptors:
  235. The router descriptor should contain a line of the form,
  236. "protocols" "Link" LINK-VERSION-LIST "Circuit" CIRCUIT_VERSION_LIST
  237. Additional fields on the "protocols" line MUST be ignored.
  238. [Versions of Tor before 0.1.2.5-alpha rejected router descriptors with
  239. unrecognized items; the protocols line should be preceded with an "opt"
  240. until these Tors are obsolete.]
  241. Security issues:
  242. Client partitioning is the big danger when we introduce new versions; if a
  243. client supports some very unusual set of protocol versions, it will stand
  244. out from others no matter where it goes. If a server supports an unusual
  245. version, it will get a disproportionate amount of traffic from clients who
  246. prefer that version. We can mitigate this somewhat as follows:
  247. - Do not have clients prefer any protocol version by default until that
  248. version is widespread. (First introduce the new version to servers,
  249. and have clients admit to using it only when configured to do so for
  250. testing. Then, once many servers are running the new protocol
  251. version, enable its use by default.)
  252. - Do not multiply protocol versions needlessly.
  253. - Encourage protocol implementors to implement the same protocol version
  254. sets as some popular version of Tor.
  255. - Disrecommend very old/unpopular versions of Tor via the directory
  256. authorities' RecommmendedVersions mechanism, even if it is still
  257. technically possible to use them.