130-v2-conn-protocol.txt 7.3 KB

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