tor-spec.txt 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. $Id$
  2. TOR (The Onion Router) Spec
  3. Note: This is an attempt to specify TOR as it exists as implemented in
  4. early March, 2003. It is not recommended that others implement this
  5. design as it stands; future versions of TOR will implement improved
  6. protocols.
  7. 0. Notation:
  8. PK -- a public key.
  9. SK -- a private key
  10. K -- a key for a symmetric cypher
  11. All numeric values are encoded in network (big-endian) order.
  12. Unless otherwise specified, all symmetric ciphers are DES in OFB
  13. mode, with an IV of all 0 bytes. All asymmetric ciphers are RSA
  14. with 1024-bit keys, and exponents of 65537.
  15. [Comments: DES? This should be AES. Why are
  16. 1. System overview
  17. ????
  18. 2. Connections
  19. 2.1. Establishing OR-to-OR connections
  20. When one onion router opens a connection to another, the initiating
  21. OR (called the 'client') and the listening OR (called the 'server')
  22. perform the following handshake.
  23. Before the handshake begins, the client and server use one
  24. another's (1024-bit) public keys, IPV4 addresses, and ports.
  25. 1. Client connects to server:
  26. The client generates a pair of 8-byte symmetric keys (one
  27. [K_f] for the 'forward' stream from client to server, and one
  28. [K_b] for the 'backward' stream from server to client.
  29. The client then generates a 'Client authentication' message [M]
  30. containing:
  31. The client's published IPV4 address [4 bytes]
  32. The client's published port [2 bytes]
  33. The server's published IPV4 address [4 bytes]
  34. The server's published port [2 bytes]
  35. The forward key (K_f) [8 bytes]
  36. The backward key (K_f) [8 bytes]
  37. The maximum bandwidth (units????) [4 bytes]
  38. Arbitrary data (BUG?????) [4 bytes]
  39. [Total: 36 bytes]
  40. The client then RSA-encrypts the message with the server's
  41. public key, and PKCS1 padding to given an encrypted message
  42. [Commentary: 1024 bytes is probably too short, and this protocol can't
  43. support IPv6. -NM]
  44. [Commentary: Is there a bug on line 740 of connection_or.c?
  45. I think that "conn->pkey, buf, 36, cipher, RSA_PKCS1_PADDING"
  46. should be "conn->pkey, buf, 32, cipher, RSA_PKCS1_PASSING"
  47. -NM]
  48. The client then opens a TCP connection to the server, sends
  49. the 128-byte RSA-encrypted data to the server, and waits for a
  50. reply.
  51. 2. Server authenticates to client:
  52. Upon receiving a TCP connection, the server waits to receive
  53. 128 bytes from the client. It decrypts the message with its
  54. private key, and checks the PKCS1 padding. If the padding is
  55. incorrect, or if the message's length is other than 36 bytes,
  56. the server closes the TCP connection and stops handshaking.
  57. The server then checks the list of known ORs for one with the
  58. address and port given in the client's authentication. If no
  59. such OR is known, or if the server is already connected to
  60. that OR, the server closes the current TCP connection and
  61. stops handshaking.
  62. For later use, the server sets its keys for this connection,
  63. setting K_f to the client's K_b, and K_b to the client's K_f.
  64. The server then creates a server authentication message[M2] as
  65. follows:
  66. Modified client authentication [36 bytes]
  67. A random nonce [N] [8 bytes]
  68. [Total: 44 bytes]
  69. The client authentication is generated from M by replacing
  70. the client's preferred bandwidth [B_c] with the server's
  71. preferred bandwidth [B_s], if B_s < B_c.
  72. The server encrypts M2 with the client's public key (found
  73. from the list of known routers), using PKCS1 padding.
  74. The server sends the 128-byte encrypted message to the client,
  75. and waits for a reply.
  76. 3. Client authenticates to server.
  77. Once the client has received 128 bytes, it decrypts them with
  78. its public key, and checks the PKCS1 padding. If the padding
  79. is invalid, or the decrypted message's length is other than 44
  80. bytes, the client closes the TCP connection.
  81. The client checks that the addresses and keys in the reply
  82. message are the same as the ones it originally sent. If not,
  83. it closes the TCP connection.
  84. The client updates the connection's bandwidth to that set by
  85. the server, and generates the following authentication message [M3]:
  86. The client's published IPV4 address [4 bytes]
  87. The client's published port [2 bytes]
  88. The server's published IPV4 address [4 bytes]
  89. The server's published port [2 bytes]
  90. The server-generated nonce [N] [8 bytes]
  91. [Total: 20 bytes]
  92. Once again, the client encrypts this message using the
  93. server's public key and PKCS1 padding, and sends the resulting
  94. 128-byte message to the server.
  95. 4. Server checks client authentication
  96. The server once again waits to receive 128 bytes from the
  97. client, decrypts the message with its private key, and checks
  98. the PKCS1 padding. If the padding is incorrect, or if the
  99. message's length is other than 20 bytes, the server closes the
  100. TCP connection and stops handshaking.
  101. If the addresses in the decrypted message M3 match those in M
  102. and M2, and if the nonce in M3 is the same as in M2, the
  103. handshake is complete, and the client and server begin sending
  104. cells to one another. Otherwise, the server closes the TCP
  105. connection.
  106. 2.2. Establishing OP-to-OR connections
  107. When an OP needs to establish a connection to an OR, the handshake
  108. is simpler because the OR does not need to verify the OR's
  109. identity. The OP and OR establish the following steps:
  110. 1. OP connects to OR:
  111. First, the OP generates a pair of 8-byte symmetric keys (one
  112. [K_f] for the 'forward' stream from OP to OP, and one
  113. [K_b] for the 'backward' stream from OR to OP.
  114. The OP generates a message [M] in the following format:
  115. Maximum bandwidth [4 bytes]
  116. Forward key [K_f] [8 bytes]
  117. Backward key [K_b] [8 bytes]
  118. [Total: 20 bytes]
  119. The OP encrypts M with the OR's public key and PKCS1 padding,
  120. opens a TCP connection to the OR's TCP port, and sends the
  121. resulting 128-byte encrypted message to the OR.
  122. 2. OR receives keys:
  123. When the OR receives a connection from an OP [This is on a
  124. different port, right? How does it know the difference? -NM],
  125. it waits for 128 bytes of data, and decrypts the resulting
  126. data with its private key, checking the PKCS1 padding. If the
  127. padding is invalid, or the message is not 20 bytes long, the
  128. OR closes the connection.
  129. Otherwise, the connection is established, and the O is ready
  130. to receive cells.
  131. The server sets its keys for this connection, setting K_f to
  132. the client's K_b, and K_b to the client's K_f.
  133. 2.3. Sending cells and link encryption
  134. Once the handshake is complete, the ORs or OR and OP send cells
  135. (specified below) to one another. Cells are sent serially,
  136. encrypted with the DES-OFB keystream specified by the handshake
  137. protocol. Over a connection, communicants encrypt outgoing cells
  138. with the connection's K_f, and decrypt incoming cells with the
  139. connection's K_b.
  140. [Commentary: This means that OR/OP->OR connections are malleable; I
  141. can flip bits in cells as they go across the wire, and see flipped
  142. bits coming out the cells as they are decrypted at the next
  143. server. I need to look more at the data format to see whether
  144. this is exploitable, but if there's no integrity checking there
  145. either, I suspect we may have an attack here. -NM]
  146. 3. Cell Packet format
  147. The basic unit of communication between onion routers and onion
  148. proxies is a fixed-width "Cell." Each Cell contains the following
  149. fields:
  150. ACI (anonymous circuit identifier) [2 bytes]
  151. Command [1 byte]
  152. Length [1 byte]
  153. Sequence number (unused) [4 bytes]
  154. Payload (padded with 0 bytes) [120 bytes]
  155. [Total size: 128 bytes]
  156. The 'Command' field holds one of the following values:
  157. 0 -- PADDING (Random padding)
  158. 1 -- CREATE (Create a circuit)
  159. 2 -- DATA (End-to-end data)
  160. 3 -- DESTROY (Stop using a circuit)
  161. 4 -- ACK (unused)
  162. 5 -- NACK (unused)
  163. 6 -- SENDME (For flow control)
  164. The interpretation of 'Length' and 'Payload' depend on....
  165. 4. Onions and circuit management
  166. 5. Topic management
  167. 6. Flow control