130-v2-conn-protocol.txt 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. Filename: 130-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: Finished
  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. In summary, The Tor connection protocol has been in need of a redesign
  17. for a while. This proposal describes how we can add to the Tor
  18. protocol:
  19. - A new TLS handshake (to achieve blocking resistance without
  20. breaking backward compatibility)
  21. - Version negotiation (so that future connection protocol changes
  22. can happen without breaking compatibility)
  23. - The actual changes in the v2 Tor connection protocol.
  24. Motivation:
  25. For motivation, see proposal 124.
  26. Proposal:
  27. 0. Terminology
  28. The version of the Tor connection protocol implemented up to now is
  29. "version 1". This proposal describes "version 2".
  30. "Old" or "Older" versions of Tor are ones not aware that version 2
  31. of this protocol exists;
  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 and respond as in the v1
  64. protocol, sending back a two-certificate chain.
  65. After the Client gets a response from the server, it checks for the
  66. number of certificates it received. If there are two certificates,
  67. the client assumes a V1 connection and proceeds as in tor-spec.txt.
  68. But if there is only one certificate, the client assumes a V2 or later
  69. protocol and 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. (The certificate sent by the
  78. server in the renegotiated connection need not be the same that
  79. as sentin the original connection.)
  80. The server MUST NOT write any data until the client has renegotiated.
  81. Once the renegotiation is finished, the server and client check one
  82. another's certificates as in V1. Now they are mutually authenticated.
  83. 1.1. Revised TLS handshake: implementation notes.
  84. It isn't so easy to adjust server behavior based on the client's
  85. ciphersuite list. Here's how we can do it using OpenSSL. This is a
  86. bit of an abuse of the OpenSSL APIs, but it's the best we can do, and
  87. we won't have to do it forever.
  88. We can use OpenSSL's SSL_set_info_callback() to register a function to
  89. be called when the state changes. The type/state tuple of
  90. SSL_CB_ACCEPT_LOOP/SSL3_ST_SW_SRVR_HELLO_A
  91. happens when we have completely parsed the client hello, and are about
  92. to send a response. From this callback, we can check the cipherlist
  93. and act accordingly:
  94. * If the ciphersuite list indicates a v1 protocol, we set the
  95. verify mode to SSL_VERIFY_NONE with a callback (so we get
  96. certificates).
  97. * If the ciphersuite list indicates a v2 protocol, we set the
  98. verify mode to SSL_VERIFY_NONE with no callback (so we get
  99. no certificates) and set the SSL_MODE_NO_AUTO_CHAIN flag (so that
  100. we send only 1 certificate in the response.
  101. Once the handshake is done, the server clears the
  102. SSL_MODE_NO_AUTO_CHAIN flag and sets the callback as for the V1
  103. protocol. It then starts reading.
  104. The other problem to take care of is missing ciphers and OpenSSL's
  105. cipher sorting algorithms. The two main issues are a) OpenSSL doesn't
  106. support some of the default ciphers that Firefox advertises, and b)
  107. OpenSSL sorts the list of ciphers it offers in a different way than
  108. Firefox sorts them, so unless we fix that Tor will still look different
  109. than Firefox.
  110. [XXXX more on this.]
  111. 1.2. Compatibility for clients using libraries less hackable than OpenSSL.
  112. As discussed in proposal 105, servers advertise which protocol
  113. versions they support in their router descriptors. Clients can simply
  114. behave as v1 clients when connecting to servers that do not support
  115. link version 2 or higher, and as v2 clients when connecting to servers
  116. that do support link version 2 or higher.
  117. (Servers can't use this strategy because we do not assume that servers
  118. know one another's capabilities when connecting.)
  119. 2. Version negotiation.
  120. Version negotiation proceeds as described in proposal 105, except as
  121. follows:
  122. * Version negotiation only happens if the TLS handshake as described
  123. above completes.
  124. * The TLS renegotiation must be finished before the client sends a
  125. VERSIONS cell; the server sends its VERSIONS cell in response.
  126. * The VERSIONS cell uses the following variable-width format:
  127. Circuit [2 octets; set to 0]
  128. Command [1 octet; set to 7 for VERSIONS]
  129. Length [2 octets; big-endian]
  130. Data [Length bytes]
  131. The Data in the cell is a series of big-endian two-byte integers.
  132. * It is not allowed to negotiate V1 conections once the v2 protocol
  133. has been used. If this happens, Tor instances should close the
  134. connection.
  135. 3. The rest of the "v2" protocol
  136. Once a v2 protocol has been negotiated, NETINFO cells are exchanged
  137. as in proposal 105, and communications begin as per tor-spec.txt.
  138. Until NETINFO cells have been exchanged, the connection is not open.