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