176-revising-handshake.txt 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. Filename: 176-revising-handshake.txt
  2. Title: Proposed version-3 link handshake for Tor
  3. Author: Nick Mathewson
  4. Created: 31-Jan-2011
  5. Status: Draft
  6. Target: 0.2.3
  7. Supersedes: 169
  8. 1. Overview
  9. I propose a (mostly) backward-compatible change to the Tor
  10. connection establishment protocol to avoid the use of TLS
  11. renegotiation, to avoid certain protocol fingerprinting attacks,
  12. and to make it easier to write Tor clients and servers.
  13. Rather than doing a TLS renegotiation to exchange certificates
  14. and authenticate the original handshake, this proposal takes an
  15. approach similar to Steven Murdoch's proposal 124 and my old
  16. proposal 169, and uses Tor cells to finish authenticating the
  17. parties' identities once the initial TLS handshake is finished.
  18. I discuss some alternative design choices and why I didn't make
  19. them in section 7; please have a quick look there before
  20. telling me that something is pointless or makes no sense.
  21. Terminological note: I use "client" below to mean the Tor
  22. instance (a client or a bridge or a relay) that initiates a TLS
  23. connection, and "server" to mean the Tor instance (a bridge or a
  24. relay) that accepts it.
  25. 2. History and Motivation
  26. The _goals_ of the Tor link handshake have remained basically uniform
  27. since our earliest versions. They are:
  28. * Provide data confidentiality, data integrity
  29. * Provide forward secrecy
  30. * Allow responder authentication or bidirectional authentication.
  31. * Try to look like some popular too-important-to-block-at-whim
  32. encryption protocol, to avoid fingerprinting and censorship.
  33. * Try to be implementatble -- on the client side at least! --
  34. by as many TLS implementations as possible.
  35. When we added the v2 handshake, we added another goal:
  36. * Remain compatible with older versions of the handshake
  37. protocol.
  38. In the original Tor TLS connection handshake protocol ("V1", or
  39. "two-cert"), parties that wanted to authenticate provided a
  40. two-cert chain of X.509 certificates during the handshake setup
  41. phase. Every party that wanted to authenticate sent these
  42. certificates. The security properties of this protocol are just
  43. fine; the problem was that our behavior of sending
  44. two-certificate chains made Tor easy to identify.
  45. In the current Tor TLS connection handshake protocol ("V2", or
  46. "renegotiating"), the parties begin with a single certificate
  47. sent from the server (responder) to the client (initiator), and
  48. then renegotiate to a two-certs-from-each-authenticating party.
  49. We made this change to make Tor's handshake look like a browser
  50. speaking SSL to a webserver. (See proposal 130, and
  51. tor-spec.txt.) So from an observer's point of view, two parties
  52. performing the V2 handshake begin by making a regular TLS
  53. handshake with a single certificate, then renegotiate
  54. immediately.
  55. To tell whether to use the V1 or V2 handshake, the servers look
  56. at the list of ciphers sent by the client. (This is ugly, but
  57. there's not much else in the ClientHello that they can look at.)
  58. If the list contains any cipher not used by the V1 protocol, the
  59. server sends back a single cert and expects a renegotiation. If
  60. the client gets back a single cert, then it withholds its own
  61. certificates until the TLS renegotiation phase.
  62. In other words, V2-supporting initiator behavior currently looks
  63. like this:
  64. - Begin TLS negotiation with V2 cipher list; wait for
  65. certificate(s).
  66. - If we get a certificate chain:
  67. - Then we are using the V1 handshake. Send our own
  68. certificate chain as part of this initial TLS handshake
  69. if we want to authenticate; otherwise, send no
  70. certificates. When the handshake completes, check
  71. certificates. We are now mutually authenticated.
  72. Otherwise, if we get just a single certificate:
  73. - Then we are using the V2 handshake. Do not send any
  74. certificates during this handshake.
  75. - When the handshake is done, immediately start a TLS
  76. renegotiation. During the renegotiation, expect
  77. a certificate chain from the server; send a certificate
  78. chain of our own if we want to authenticate ourselves.
  79. - After the renegotiation, check the certificates. Then
  80. send (and expect) a VERSIONS cell from the other side to
  81. establish the link protocol version.
  82. And V2-supporting responder behavior now looks like this:
  83. - When we get a TLS ClientHello request, look at the cipher
  84. list.
  85. - If the cipher list contains only the V1 ciphersuites:
  86. - Then we're doing a V1 handshake. Send a certificate
  87. chain. Expect a possible client certificate chain in
  88. response.
  89. Otherwise, if we get other ciphersuites:
  90. - We're using the V2 handshake. Send back a single
  91. certificate and let the handshake complete.
  92. - Do not accept any data until the client has renegotiated.
  93. - When the client is renegotiating, send a certificate
  94. chain, and expect (possibly multiple) certificates in
  95. reply.
  96. - Check the certificates when the renegotiation is done.
  97. Then exchange VERSIONS cells.
  98. Late in 2009, researchers found a flaw in most applications' use
  99. of TLS renegotiation: Although TLS renegotiation does not
  100. reauthenticate any information exchanged before the renegotiation
  101. takes place, many applications were treating it as though it did,
  102. and assuming that data sent _before_ the renegotiation was
  103. authenticated with the credentials negotiated _during_ the
  104. renegotiation. This problem was exacerbated by the fact that
  105. most TLS libraries don't actually give you an obvious good way to
  106. tell where the renegotiation occurred relative to the datastream.
  107. Tor wasn't directly affected by this vulnerability, but the
  108. aftermath hurts us in a few ways:
  109. 1) OpenSSL has disabled renegotiation by default, and created
  110. a "yes we know what we're doing" option we need to set to
  111. turn it back on. (Two options, actually: one for openssl
  112. 0.9.8l and one for 0.9.8m and later.)
  113. 2) Some vendors have removed all renegotiation support from
  114. their versions of OpenSSL entirely, forcing us to tell
  115. users to either replace their versions of OpenSSL or to
  116. link Tor against a hand-built one.
  117. 3) Because of 1 and 2, I'd expect TLS renegotiation to become
  118. rarer and rarer in the wild, making our own use stand out
  119. more.
  120. Furthermore, there are other issues related to TLS and
  121. fingerprinting that we want to fix in any revised handshake:
  122. 1) We should make it easier to use self-signed certs, or maybe
  123. even existing HTTPS certificates, for the server side
  124. handshake, since most non-Tor SSL handshakes use either
  125. self-signed certificates or
  126. 2) We should make it harder to probe for a Tor server. Right
  127. now, you can just do a handshake with a server,
  128. renegotiate, then see if it gives you a VERSIONS cell.
  129. That's no good.
  130. 3) We should allow other changes in our use of TLS and in our
  131. certificates so as to resist fingerprinting based on how
  132. our certificates look.
  133. 3. Design
  134. 3.1. The view in the large
  135. Taking a cue from Steven Murdoch's proposal 124 and my old
  136. proposal 169, I propose that we move the work currently done by
  137. the TLS renegotiation step (that is, authenticating the parties
  138. to one another) and do it with Tor cells instead of with TLS
  139. alone.
  140. This section outlines the protocol; we go into more detail below.
  141. To tell the client that it can use the new cell-based
  142. authentication system, the server sends a "V3 certificate" during
  143. the initial TLS handshake. (More on what makes a certificate
  144. "v3" below.) If the client recognizes the format of the
  145. certificate and decides to pursue the V3 handshake, then instead
  146. of renegotiating immediately on completion of the initial TLS
  147. handshake, the client instead sends a VERSIONS cell (and the
  148. negotiation begins).
  149. So the flowchart on the server side is:
  150. Wait for a ClientHello.
  151. IF the client sends a ClientHello that indicates V1:
  152. - Send a certificate chain.
  153. - When the TLS handshake is done, if the client sent us a
  154. certificate chain, then check it.
  155. If the client sends a ClientHello that indicates V2 or V3:
  156. - Send a self-signed certificate or a CA-signed certificate
  157. - When the TLS handshake is done, wait for renegotiation or data.
  158. - If renegotiation occurs, the client is V2: send a
  159. certificate chain and maybe receive one. Check the
  160. certificate chain as in V1.
  161. - If the client sends data without renegotiating, it is
  162. starting the V3 handshake. Proceed with the V3
  163. handshake as below.
  164. And the client-side flowchart is:
  165. - Send a ClientHello with a set of ciphers that indicates V2/V3.
  166. - After the handshake is done:
  167. - If the server sent us a certificate chain, check it: we
  168. are using the V1 handshake.
  169. - If the server sent us a single "V2 certificate", we are
  170. using the v2 handshake: the client begins to renegotiate
  171. and proceeds as before.
  172. - Finally, if the server sent us a "v3 certificate", we are
  173. doing the V3 handshake below.
  174. And the cell-based part of the V3 handshake, in summary, is:
  175. C<->S: TLS handshake where S sends a "v3 certificate"
  176. In TLS:
  177. C->S: VERSIONS cell
  178. S->C: VERSIONS cell, CERT cell, AUTH_CHALLENGE cell, NETINFO cell
  179. C->S: Optionally: CERT cell, AUTHENTICATE cell
  180. A "CERTS" cell contains a set of certificates; an "AUTHENTICATE"
  181. cell authenticates the client to the server. More on these
  182. later.
  183. 3.2. Distinguishing V2 and V3 certificates
  184. In the protocol outline above, we require that the client can
  185. distinguish between v2 certificates (that is, those sent by
  186. current servers) and a v3 certificates. We further require that
  187. existing clients will accept v3 certificates as they currently
  188. accept v2 certificates.
  189. Fortunately, current certificates have a few characteristics that
  190. make them fairly mannered as it is. We say that a certificate
  191. indicates a V2-only server if ALL of the following hold:
  192. * The certificate is not self-signed.
  193. * There is no DN field set in the certificate's issuer or
  194. subject other than "commonName".
  195. * The commonNames of the issuer and subject both end with
  196. ".net"
  197. * The public modulus is at most 1024 bits long.
  198. Otherwise, the client should assume that the server supports the
  199. V3 handshake.
  200. To the best of my knowledge, current clients will behave properly
  201. on receiving non-v2 certs during the initial TLS handshake so
  202. long as they eventually get the correct V2 cert chain during the
  203. renegotiation.
  204. The v3 requirements are easy to meet: any certificate designed to
  205. resist fingerprinting will likely be self-signed, or if it's
  206. signed by a CA, then the issuer will surely have more DN fields
  207. set. Certificates that aren't trying to resist fingerprinting
  208. can trivially become v3 by using a CN that doesn't end with .net,
  209. or using a 1024-bit key.
  210. 3.3. Authenticating via Tor cells: server authentication
  211. Once the TLS handshake is finished, if the client renegotiates,
  212. then the server should go on as it does currently.
  213. If the client implements this proposal, however, and the server
  214. has shown it can understand the V3+ handshake protocol, the
  215. client immediately sends a VERSIONS cell to the server
  216. and waits to receive a VERSIONS cell in return. We negotiate
  217. the Tor link protocol version _before_ we proceed with the
  218. negotiation, in case we need to change the authentication
  219. protocol in the future.
  220. Once either party has seen the VERSIONS cell from the other, it
  221. knows which version they will pick (that is, the highest version
  222. shared by both parties' VERSIONS cells). All Tor instances using
  223. the handshake protocol described in 3.2 MUST support at least
  224. link protocol version 3 as described here. If a version lower
  225. than 3 is negotiated with the V3 handshake in place, a Tor
  226. instance MUST close the connection.
  227. On learning the link protocol, the server then sends the client a
  228. CERT cell and a NETINFO cell. If the client wants to
  229. authenticate to the server, it sends a CERT cell, an AUTHENTICATE
  230. cell, and a NETINFO cell, or it may simply send a NETINFO cell if
  231. it does not want to authenticate.
  232. The CERT cell describes the keys that a Tor instance is claiming
  233. to have. It is a variable-length cell. Its payload format is:
  234. N: Number of certs in cell [1 octet]
  235. N times:
  236. CertType [1 octet]
  237. CLEN [2 octets]
  238. Certificate [CLEN octets]
  239. Any extra octets at the end of a CERT cell MUST be ignored.
  240. CertType values are:
  241. 1: Link key certificate from RSA1024 identity
  242. 2: RSA1024 Identity certificate
  243. 3: RSA1024 AUTHENTICATE cell link certificate
  244. The certificate format is X509.
  245. To authenticate the server, the client MUST check the following:
  246. * The CERTS cell contains exactly one CertType 1 "Link" certificate.
  247. * The CERTS cell contains exactly one CertType 2 "ID"
  248. certificate.
  249. * Both certificates have validAfter and validUntil dates that
  250. are not expired.
  251. * The certified key in the Link certificate matches the
  252. link key that was used to negotiate the TLS connection.
  253. * The certified key in the ID certificate is a 1024-bit RSA key.
  254. * The certified key in the ID certificate was used to sign both
  255. certificates.
  256. * The link certificate is correctly signed with the key in the
  257. ID certificate
  258. * The ID certificate is correctly self-signed.
  259. If all of these conditions hold, then the client knows that it is
  260. connected to the server whose identity key is certified in the ID
  261. certificate. If any condition does not hold, the client closes
  262. the connection. If the client wanted to connect to a server with
  263. a different identity key, the client closes the connection.
  264. An AUTH_CHALLENGE cell is a variable-length cell with the following
  265. fields:
  266. Challenge [32 octets]
  267. It is sent from the server to the client. Clients MUST ignore
  268. unexpected bytes at the end of the cell. Servers MUST generate
  269. every challenge using a strong RNG or PRNG.
  270. 3.4. Authenticating via Tor cells: Client authentication
  271. A client does not need to authenticate to the server. If it
  272. does not wish to, it responds to the server's valid CERT cell by
  273. sending NETINFO cell: once it has gotten a valid NETINFO cell
  274. back, the client should consider the connection open, and the
  275. server should consider the connection as opened by an
  276. unauthenticated client.
  277. If a client wants to authenticate, it responds to the
  278. AUTH_CHALLENGE cell with a CERT cell and an AUTHENTICATE cell.
  279. The CERT cell is as a server would send, except that instead of
  280. sending a CertType 1 cert for an arbitrary link certificate, the
  281. client sends a CertType 3 cert for an RSA AUTHENTICATE key.
  282. (This difference is because we allow any link key type on a TLS
  283. link, but the protocol described here will only work for 1024-bit
  284. RSA keys. A later protocol version should extend the protocol
  285. here to work with non-1024-bit, non-RSA keys.)
  286. AuthType [2 octets]
  287. AuthLen [2 octets]
  288. Authentication [AuthLen octets]
  289. Servers MUST ignore extra bytes at the end of an AUTHENTICATE
  290. cell. If AuthType is 1 (meaning "RSA-SHA256-TLSSecret"), then the
  291. Authentication contains the following:
  292. Type: The characters "AUTH0001" [8 octets]
  293. CID: A SHA256 hash of the client's RSA1024 identity key [32 octets]
  294. SID: A SHA256 hash of the server's RSA1024 identity key [32 octets]
  295. SLOG: A SHA256 hash of all bytes sent from the server to the client
  296. as part of the negotiation up to and including the
  297. AUTH_CHALLENGE cell; that is, the VERSIONS cell,
  298. the CERT cell, and the AUTH_CHALLENGE cell. [32 octets]
  299. CLOG: A SHA256 hash of all bytes sent from the client to the
  300. server as part of the negotiation so far; that is, the
  301. VERSIONS cell and the CERT cell. [32 octets]
  302. SCERT: A SHA256 hash of the server's TLS link
  303. certificate. [32 octets]
  304. TLSSECRETS: Either 32 zero octets, or a SHA256 HMAC, using
  305. the TLS master secret as the secret key, of the following:
  306. - client_random, as sent in the TLS Client Hello
  307. - server_random, as sent in the TLS Server Hello
  308. - the NUL terminated ASCII string:
  309. "Tor V3 handshake TLS cross-certification"
  310. [32 octets]
  311. TIME: The time of day in seconds since the POSIX epoch. [8 octets]
  312. NONCE: A 16 byte value, randomly chosen by the client [16 octets]
  313. SIG: A signature of a SHA256 hash of all the previous fields
  314. using the client's "Authenticate" key as presented. (As
  315. always in Tor, we use OAEP-MGF1 padding; see tor-spec.txt
  316. section 0.3.)
  317. [variable length]
  318. To check the AUTHENTICATE cell, a server checks that all fields
  319. containing a hash contain the correct value, then verifies the
  320. signature. The server MUST ignore any extra bytes after
  321. the SHA256 hash.
  322. When possible (that is, when implemented using C TLS API),
  323. implementations SHOULD include and verify the TLSSECRETS field.
  324. 3.5. Responding to extra cells, and other security checks.
  325. If the handshake is a V3+ TLS handshake, both parties MUST reject
  326. any negotiated link version less than 3. Both parties MUST check
  327. this and close the connection if it is violated.
  328. If the handshake is not a V3+ TLS handshake, both parties MUST
  329. still advertise all link protocols they support in their versions
  330. cell. Both parties MUST close the link if it turns out they both
  331. would have supported version 3 or higher, but they somehow wound
  332. up using a v2 or v1 handshake. (More on this in section 6.4.)
  333. A server SHOULD NOT send any sequence of cells when starting a v3
  334. negotiation other than "VERSIONS, CERT, AUTH_CHALLENGE,
  335. NETINFO". A client SHOULD drop a CERT, AUTH_CHALLENGE, or
  336. NETINFO cell that appears at any other time or out of sequence.
  337. A client should not begin a v3 negotiation with any sequence
  338. other than "VERSIONS, NETINFO" or "VERSIONS, CERT, AUTHENTICATE,
  339. NETINFO". A server SHOULD drop a CERT, AUTH_CHALLENGE, or
  340. NETINFO cell that appears at any other time or out of sequence.
  341. 4. Numbers to assign
  342. We need a version number for this link protocol. I've been
  343. calling it "3".
  344. We need to reserve command numbers for CERT, AUTH_CHALLENGE, and
  345. AUTHENTICATE. I suggest that in link protocol 3 and higher, we
  346. reserve a separate range of commands for variable-length cells.
  347. 5. Efficiency
  348. This protocol adds a round-trip step when the client sends a
  349. VERSIONS cell to the server, and waits for the {VERSIONS, CERT,
  350. NETINFO} response in turn. (The server then waits for the
  351. client's {NETINFO} or {CERT, AUTHENTICATE, NETINFO} reply,
  352. but it would have already been waiting for the client's NETINFO,
  353. so that's not an additional wait.)
  354. This is actually fewer round-trip steps than required before for
  355. TLS renegotiation, so that's a win over v2.
  356. 6. Security argument
  357. These aren't crypto proofs, since I don't write those. They are
  358. meant be reasonably convincing.
  359. 6.1. The server is authenticated
  360. TLS guarantees that if the TLS handshake completes successfully,
  361. the client knows that it is speaking to somebody who knows the
  362. private key corresponding to the public link key that was used in
  363. the TLS handshake.
  364. Because this public link key is signed by the server's identity
  365. key in the CERT cell, the client knows that somebody who holds
  366. the server's private identity key says that the server's public
  367. link key corresponds to the server's public identity key.
  368. Therefore, if the crypto works, and if TLS works, and if the keys
  369. aren't compromised, then the client is talking to somebody who
  370. holds the server's private identity key.
  371. 6.2. The client is authenticated
  372. Once the server has checked the client's certificates, the server
  373. knows that somebody who knows the client's private identity key
  374. says that he is the one holding the private key corresponding to
  375. the client's presented link-authentication public key.
  376. Once the server has checked the signature in the AUTHENTICATE
  377. cell, the server knows that somebody holding the client's
  378. link-authentication private key signed the data in question. By
  379. the standard certification argument above, the server knows that
  380. somebody holding the client's private identity key signed the
  381. data in question.
  382. So the server's remaining question is: am I really talking to
  383. somebody holding the client's identity key, or am I getting a
  384. replayed or MITM'd AUTHENTICATE cell that was previously sent by
  385. the client?
  386. If the client included a non-zero TLSSECRET component, and the
  387. server is able to verify it, then the answer is easy: the server
  388. knows for certain that it is talking to the party with whom it
  389. did the TLS handshake, since if somebody else generated a correct
  390. TLSSECRET, they would have to know the master secret of the TLS
  391. connection, which would require them to have broken TLS.
  392. If the client was not able to include a non-zero TLSSECRET
  393. component, or the server can't check it, the answer is a little
  394. trickier. The server knows that it is not getting a replayed
  395. AUTHENTICATE cell, since the cell authenticates (among other
  396. stuff) the server's AUTH_CHALLENGE cell, which it has never used
  397. before. The server knows that it is not getting a MITM'd
  398. AUTHENTICATE cell, since the cell includes a hash of the server's
  399. link certificate, which nobody else should have been able to use
  400. in a successful TLS negotiation.
  401. 6.3. MITM attacks won't work any better than they do against TLS
  402. TLS guarantees that a man-in-the-middle attacker can't read the
  403. content of a successfully negotiated encrypted connection, nor
  404. alter the content in any way other than truncating it, unless he
  405. compromises the session keys or one of the key-exchange secret
  406. keys used to establish that connection. Let's make sure we do at
  407. least that well.
  408. Suppose that a client Alice connects to an MITM attacker Mallory,
  409. thinking that he is connecting to some server Bob. Let's assume
  410. that the TLS handshake between Alice and Mallory finishes
  411. successfully and the v3 protocol is chosen. [If the v1 or v2
  412. protocol is chosen, those already resist MITM. If the TLS
  413. handshake doesn't complete, then Alice isn't connected to anybody.]
  414. During the v3 handshake, Mallory can't convince Alice that she is
  415. talking to Bob, since she should not be able to produce a CERT
  416. cell containing a certificate chain signed by Bob's identity key
  417. and used to authenticate the link key that Mallory used during
  418. TLS. (If Mallory used her own link key for the TLS handshake, it
  419. won't match anything Bob signed unless Bob is compromised.
  420. Mallory can't use any key that Bob _did_ produce a certificate
  421. for, since she doesn't know the private key.)
  422. Even if Alice fails to check the certificates from Bob, Mallory
  423. still can't convince Bob that she is really Alice. Assuming that
  424. Alice's keys aren't compromised, Mallory can't sent a CERT cell
  425. with a cert chain from Alice's identity key to a key that Mallory
  426. controls, so if Mallory wants to impersonate Alice's identity
  427. key, she can only do so by sending an AUTHENTICATE cell really
  428. generated by Alice. Because Bob will check that the random bytes
  429. in the AUTH_CHALLENGE cell will influence the SLOG hash, Mallory
  430. needs to send Bob's challenge to Alice, and can't use any other
  431. AUTHENTICATE cell that Alice generated before. But because the
  432. AUTHENTICATE cell Alice will generate will include in the SCERT
  433. field a hash of the link certificate used by Mallory, Bob will
  434. reject it as not being valid to connect to him.
  435. 6.4. Protocol downgrade attacks won't work.
  436. Assuming that Alice checks the certificates from Bob, she knows
  437. that Bob really sent her the VERSION cell that she received.
  438. Because the AUTHENTICATE cell from Alice includes signed hashes
  439. of the VERSIONS cells from Alice and Bob, Bob knows that Alice
  440. got the VERSIONS cell he sent and sent the VERSIONS cell that he
  441. received.
  442. But what about attempts to downgrade the protocol earlier in the
  443. handshake? Here TLS comes to the rescue: because the TLS
  444. Finished handshake message includes an authenticated digest of
  445. everything previously said during the handshake, an attacker
  446. can't replace the client's ciphersuite list (to trigger a
  447. downgrade to the v1 protocol) or the server's certificate [chain]
  448. (to trigger a downgrade to the v1 or v2 protocol).
  449. 7. Design considerations
  450. I previously considered adding our own certificate format in
  451. order to avoid the pain associated with X509, but decided instead
  452. to simply use X509 since a correct Tor implementation will
  453. already need to have X509 code to handle the other handshake
  454. versions and to use TLS.
  455. The trickiest part of the design here is deciding what to stick
  456. in the AUTHENTICATE cell. Some of it is strictly necessary, and
  457. some of it is left there for security margin in case my other
  458. security arguments fail. Because of the CID and SID elements
  459. you can't use an AUTHENTICATE cell for anything other than
  460. authenticating a client ID to a server with an appropriate
  461. server ID. The SLOG and CLOG elements are there mostly to
  462. authenticate the VERSIONS cells and resist downgrade attacks
  463. once there are two versions of this. The presence of the
  464. AUTH_CHALLENGE field in the stuff authenticated in SLOG
  465. prevents replays and ensures that the AUTHENTICATE cell was
  466. really generated by somebody who is reading what the server is
  467. sending over the TLS connection. The SCERT element is meant to
  468. prevent MITM attacks. When the TLSSECRET field is
  469. used, it should prevent the use of the AUTHENTICATE cell for
  470. anything other than the TLS connection the client had in mind.
  471. A signature of the TLSSECRET element on its own should be
  472. sufficient to prevent the attacks we care about, but because we
  473. don't necessarily have access to the TLS master secret when using
  474. a non-C TLS library, we can't depend on it. I added it anyway
  475. so that, if there is some problem with the rest of the protocol,
  476. clients and servers that _are_ written in C (that is, the official
  477. Tor implementation) can still be secure.
  478. If the client checks the server's certificates and matches them
  479. to the TLS connection link key before proceding with the
  480. handshake, then signing the contents of the AUTH_CHALLENGE cell
  481. would be sufficient to authenticate the client. But implementers
  482. of allegedly compatible Tor clients have in the past skipped
  483. certificate verification steps, and I didn't want a client's
  484. failure to verify certificates to mean that a server couldn't
  485. trust that he was really talking to the client. To prevent this,
  486. I added the TLS link certificate to the authenticated data: even
  487. if the Tor client code doesn't check any certificates, the TLS
  488. library code will still check that the certificate used in the
  489. handshake contains a link key that matches the one used in the
  490. handshake.
  491. 8. Open questions:
  492. - May we cache which certificates we've already verified? It
  493. might leak in timing whether we've connected with a given server
  494. before, and how recently.
  495. - With which TLS libraries is it feasible to yoink client_random,
  496. server_random, and the master secret? If the answer is "All
  497. free C TLS libraries", great. If the answer is "OpenSSL only",
  498. not so great.
  499. - Should we do anything to check the timestamp in the AUTHENTICATE
  500. cell?
  501. - Can we give some way for clients to signal "I want to use the
  502. V3 protocol if possible, but I can't renegotiate, so don't give
  503. me the V2"? Clients currently have a fair idea of server
  504. versions, so they could potentially do the V3+ handshake with
  505. servers that support it, and fall back to V1 otherwise.
  506. - What should servers that don't have TLS renegotiation do? For
  507. now, I think they should just stick with V1. Eventually we can
  508. deprecate the V2 handshake as we did with the V1 handshake.
  509. When that happens, servers can be V3-only.