xxx-v2-conn-protocol.txt 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. Filename: xxx-v2-conn-protocol.txt
  2. Title: Version 2 Tor connection protocol
  3. Version: $Revision$
  4. Last-Modified: $Date$
  5. Author: Nick Mathewson
  6. Created: 2007-10-25
  7. Status: Draft
  8. Overview:
  9. This proposal describes the significant changes to be made in the v2
  10. Tor connection protocol.
  11. This proposal relates to other proposals as follows:
  12. It refers to and supersedes:
  13. Proposal 124: Blocking resistant TLS certificate usage
  14. It refers to aspects of:
  15. Proposal 105: Version negotiation for the Tor protocol
  16. Proposal 110: Avoid infinite length circuits
  17. In summary, The Tor connection protocol has been in need of a redesign
  18. for a while. This proposal describes how we can add to the Tor
  19. protocol:
  20. - A new TLS handshake (to achieve blocking resistance without
  21. breaking backward compatibility)
  22. - Version negotiation (so that future connection protocol changes
  23. can happen without breaking compatibility)
  24. - The actual changes in the v2 Tor connection protocol.
  25. Motivation:
  26. For motivation, see proposal 124.
  27. Proposal:
  28. 0. Terminology
  29. The version of the Tor connection protocol implemented up to now is
  30. "version 1". This proposal describes "version 2".
  31. "Old" or "Older" versions of Tor are ones not aware of this protocol;
  32. "New" or "Newer" versions are ones that are.
  33. The connection initiator is referred to below as the Client; the
  34. connection responder is referred to below as the Server.
  35. 1. The revised TLS handshake.
  36. For motivation, see proposal 124. This is a simplified version of the
  37. handshake that uses TLS's renegotiation capability in order to avoid
  38. some of the extraneous steps in proposal 124.
  39. The Client connects to the Server and, as in ordinary TLS, sends a
  40. list of ciphers. Older versions of Tor will send only ciphers from
  41. the list:
  42. TLS_DHE_RSA_WITH_AES_256_CBC_SHA
  43. TLS_DHE_RSA_WITH_AES_128_CBC_SHA
  44. SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA
  45. SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA
  46. Clients that support the revised handshake will send the recommended
  47. list of ciphers from proposal 124, in order to emulate the behavior of
  48. a web browser.
  49. If the server notices that the list of ciphers contains only ciphers
  50. from this list, it proceeds with Tor's version 1 TLS handshake as
  51. documented in tor-spec.txt.
  52. (The server may also notice cipher lists used by other implementations
  53. of the Tor protocol (in particular, the BouncyCastle default cipher
  54. list as used by some Java-based implementations), and whitelist them.)
  55. On the other hand, if the server sees a list of ciphers that could not
  56. have been sent from an older implementation (because it includes other
  57. ciphers, and does not match any known-old list), the server sends a
  58. reply containing a single connection certificate, constructed as for
  59. the link certificate in the v1 Tor protocol. The subject names in
  60. this certificate SHOULD NOT have any strings to identify them as
  61. coming from a Tor server. The server does not ask the client for
  62. certificates.
  63. Old Servers will (mostly) ignore the cipher list respond as in the v1
  64. protocol, and send back a two-certificate chain.
  65. After the Client gets a response from the server, it checks for the
  66. number of certificates. If there are two certificates, the client
  67. assumes a V1 connection and proceeds as in tor-spec.txt. But if there
  68. is only one certificate, the client assumes a V2 or later protocol and
  69. continues.
  70. At this point, the client has established a TLS connection with the
  71. server, but the parties have not been authenticated: the server hasn't
  72. sent its identity certificate, and the client hasn't sent any
  73. certificates at all. To fix this, the client begins a TLS session
  74. renegotiation. This time, the server continues with two certificates
  75. as usual, and asks for certificates so that the client will send
  76. certificates of its own. Because the TLS connection has been
  77. established, all of this is encrypted.
  78. The server MUST NOT write any data until the client has renegotiated.
  79. Once the renegotiation is finished, the server and client check one
  80. another's certificates as in V1. Now they are mutually authenticated.
  81. 1.1. Revised TLS handshake: implementation notes.
  82. It isn't so easy to adjust server behavior based on the client's
  83. ciphersuite list. Here's how we can do it using OpenSSL. This is a
  84. bit of an abuse of the OpenSSL APIs, but it's the best we can do, and
  85. we won't have to do it forever.
  86. We can use OpenSSL's SSL_set_info_callback() to register a function to
  87. be called when the state changes. The type/state tuple of
  88. SSL_CB_ACCEPT_LOOP/SSL3_ST_SW_SRVR_HELLO_A
  89. happens when we have completely parsed the client hello, and are about
  90. to send a response. From this callback, we can check the cipherlist
  91. and act accordingly:
  92. * If the ciphersuite list indicates a v1 protocol, we set the
  93. verify mode to SSL_VERIFY_NONE with a callback (so we get
  94. certificates).
  95. * If the ciphersuite list indicates a v2 protocol, we set the
  96. verify mode to SSL_VERIFY_NONE with no callback (so we get
  97. no certificates) and set the SSL_MODE_NO_AUTO_CHAIN flag (so that
  98. we send only 1 certificate in the response.
  99. Once the handshake is done, the server clears the
  100. SSL_MODE_NO_AUTO_CHAIN flag and sets the callback as for the V1
  101. protocol. It then starts reading.
  102. The other problem to take care of is missing ciphers and OpenSSL's
  103. cipher sorting algorithms. [XXXX more on this.]
  104. 1.2. Compatibility for clients using libraries less hackable than OpenSSL.
  105. As discussed in proposal 105, servers advertise which protocol
  106. versions they support in their router descriptors. Clients can simply
  107. behave as v1 clients when connecting to servers that do not support
  108. link version 2 or higher, and as v2 clients when connecting to servers
  109. that do support link version 2 or higher.
  110. (Servers can't use this strategy because we do not assume that servers
  111. know one another's capabilities when connecting.)
  112. 2. Version negotiation.
  113. Version negotiation proceeds as described in proposal 105, except as
  114. follows:
  115. * Version negotiation only happens if the TLS handshake as described
  116. above completes.
  117. * The TLS renegotiation must be finished before the client sends a
  118. VERSIONS cell; the server sends its VERSIONS cell in response.
  119. * The VERSIONS cell uses the following variable-width format:
  120. Circuit [2 octets; set to 0]
  121. Command [1 octet; set to 7 for VERSIONS]
  122. Length [2 octets; big-endian]
  123. Data [Length bytes]
  124. The Data in the cell is a series of big-endian two-byte integers.
  125. 3. The rest of the "v2" protocol
  126. Once a v2 protocol has been negotiated, NETINFO cells are exchanged
  127. as in proposal 105, and communications begin as per tor-spec.txt.
  128. RELAY_EARLY cells are accepted as in proposal 110, and treated as
  129. RELAY cells except that they are relayed as RELAY_EARLY if the next
  130. host in the circuit has negotiated v2 or later; otherwise, not.
  131. Command value 9 is used for RELAY_EARLY.