114-distributed-storage.txt 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963
  1. Filename: 114-distributed-storage.txt
  2. Title: Distributed Storage for Tor Hidden Service Descriptors
  3. Version: $Revision$
  4. Last-Modified: $Date$
  5. Author: Karsten Loesing
  6. Created: 13-May-2007
  7. Status: Open
  8. Change history:
  9. 13-May-2007 Initial proposal
  10. 14-May-2007 Added changes suggested by Lasse Øverlier
  11. 30-May-2007 Changed descriptor format, key length discussion, typos
  12. 09-Jul-2007 Incorporated suggestions by Roger, added status of specification
  13. and implementation for upcoming GSoC mid-term evaluation
  14. 11-Aug-2007 Updated implementation statuses, included non-consecutive
  15. replication to descriptor format
  16. Overview:
  17. The basic idea of this proposal is to distribute the tasks of storing and
  18. serving hidden service descriptors from currently three authoritative
  19. directory nodes among a large subset of all onion routers. The three
  20. reasons to do this are better robustness (availability), better
  21. scalability, and improved security properties. Further,
  22. this proposal suggests changes to the hidden service descriptor format to
  23. prevent new security threats coming from decentralization and to gain even
  24. better security properties.
  25. Motivation:
  26. The current design of hidden services exhibits the following performance and
  27. security problems:
  28. First, the three hidden service authoritative directories constitute a
  29. performance bottleneck in the system. The directory nodes are responsible for
  30. storing and serving all hidden service descriptors. At the moment there are
  31. about 1000 descriptors at a time, but this number is assumed to increase in
  32. the future. Further, there is no replication protocol for descriptors between
  33. the three directory nodes, so that hidden services must ensure the
  34. availability of their descriptors by manually publishing them on all
  35. directory nodes. Whenever a fourth or fifth hidden service authoritative
  36. directory is added, hidden services will need to maintain an equally
  37. increasing number of replicas. These scalability issues have an impact on the
  38. current usage of hidden services and put an even higher burden on the
  39. development of new kinds of applications for hidden services that might
  40. require storing even more descriptors.
  41. Second, besides posing a limitation to scalability, storing all hidden
  42. service descriptors on three directory nodes also constitutes a security
  43. risk. The directory node operators could easily analyze the publish and fetch
  44. requests to derive information on service activity and usage and read the
  45. descriptor contents to determine which onion routers work as introduction
  46. points for a given hidden service and need to be attacked or threatened to
  47. shut it down. Furthermore, the contents of a hidden service descriptor offer
  48. only minimal security properties to the hidden service. Whoever gets aware of
  49. the service ID can easily find out whether the service is active at the
  50. moment and which introduction points it has. This applies to (former)
  51. clients, (former) introduction points, and of course to the directory nodes.
  52. It requires only to request the descriptor for the given service ID, which
  53. can be performed by anyone anonymously.
  54. This proposal suggests two major changes to approach the described
  55. performance and security problems:
  56. The first change affects the storage location for hidden service descriptors.
  57. Descriptors are distributed among a large subset of all onion routers instead
  58. of three fixed directory nodes. Each storing node is responsible for a subset
  59. of descriptors for a limited time only. It is not able to choose which
  60. descriptors it stores at a certain time, because this is determined by its
  61. onion ID which is hard to change frequently and in time (only routers which
  62. are stable for a given time are accepted as storing nodes). In order to
  63. resist single node failures and untrustworthy nodes, descriptors are
  64. replicated among a certain number of storing nodes. A first replication
  65. protocol makes sure that descriptors don't get lost when the node population
  66. changes; therefore, a storing node periodically requests the descriptors from
  67. its siblings. A second replication protocol distributes descriptors among
  68. non-consecutive nodes of the ID ring to prevent a group of adversaries from
  69. generating new onion keys until they have consecutive IDs to create a 'black
  70. hole' in the ring and make random services unavailable. Connections to
  71. storing nodes are established by extending existing circuits by one hop to
  72. the storing node. This also ensures that contents are encrypted. The effect
  73. of this first change is that the probability that a single node operator
  74. learns about a certain hidden service is very small and that it is very hard
  75. to track a service over time, even when it collaborates with other node
  76. operators.
  77. The second change concerns the content of hidden service descriptors.
  78. Obviously, security problems cannot be solved only by decentralizing storage;
  79. in fact, they could also get worse if done without caution. At first, a
  80. descriptor ID needs to change periodically in order to be stored on changing
  81. nodes over time. Next, the descriptor ID needs to be computable only for the
  82. service's clients, but should be unpredictable for all other nodes. Further,
  83. the storing node needs to be able to verify that the hidden service is the
  84. true originator of the descriptor with the given ID even though it is not a
  85. client. Finally, a storing node should learn as little information as
  86. necessary by storing a descriptor, because it might not be as trustworthy as
  87. a directory node; for example it does not need to know the list of
  88. introduction points. Therefore, a second key is applied that is only known to
  89. the hidden service provider and its clients and that is not included in the
  90. descriptor. It is used to calculate descriptor IDs and to encrypt the
  91. introduction points. This second key can either be given to all clients
  92. together with the hidden service ID, or to a group or a single client as
  93. an authentication token. In the future this second key could be the result of
  94. some key agreement protocol between the hidden service and one or more
  95. clients. A new text-based format is proposed for descriptors instead of an
  96. extension of the existing binary format for reasons of future extensibility.
  97. Design:
  98. The proposed design is described by the required changes to the current
  99. design. These requirements are grouped by content, rather than by affected
  100. specification documents or code files, and numbered for reference below.
  101. Hidden service clients, servers, and directories:
  102. /1/ Create routing list
  103. All participants can filter the consensus status document received from the
  104. directory authorities to one routing list containing only those servers
  105. that store and serve hidden service descriptors and which are running for
  106. at least 24 hours. A participant only trusts its own routing list and never
  107. learns about routing information from other parties.
  108. - rend-spec.txt, section 1.4: Added description of how to obtain a routing
  109. list of hidden service directories.
  110. - routerparse.c: Changed routerstatus_parse_entry_from_string to parse the
  111. "HSDir" flag in vote and consensus status documents.
  112. - routerlist.c: Changed router_get_routerlist() to initialize routing list.
  113. - or.h: Added hs_dirs member to routerlist_t.
  114. - Changed routerlist_free() to free storage held by routing list.
  115. - Added UPDATE_HS_DIRS_INTERVAL.
  116. - Added update_hs_dir_routing_table().
  117. - Changed run_scheduled_events().
  118. - Added is_hs_dir member to routerstatus_t.
  119. [Aug 11: Specified and running.]
  120. /2/ Determine responsible hidden service directory
  121. All participants can determine the hidden service directory that is
  122. responsible for storing and serving a given ID, as well as the hidden
  123. service directories that replicate its content. Every hidden service
  124. directory is responsible for the descriptor IDs in the interval from
  125. its predecessor, exclusive, to its own ID, inclusive. Further, a hidden
  126. service directory holds replicas for its n predecessors, where n denotes
  127. the number of consecutive replicas. (requires /1/)
  128. - rend-spec.txt, section 1.4: Added description of how to determine the
  129. responsible node(s) for a given descriptor ID.
  130. - routerlist.c: Added get_responsible_hs_dirs() to determine the routers
  131. that are responsible for a given descriptor ID.
  132. - Added is_hs_dir member to routerstatus_t.
  133. - Added have_enough_hs_dirs().
  134. - Added next_hs_dir().
  135. [July 9: Specified and running.]
  136. Hidden service clients and providers:
  137. /3/ Send tunneled HTTP request to hidden service directory in BEGIN_DIR cell
  138. - rend-spec.txt, section 1.4: Added the requirement that requests need to
  139. be sent via Tor.
  140. - rend-spec.txt, section 1.6: Added the requirement that requests need to
  141. be sent via Tor.
  142. [July 9: Pending]
  143. Hidden service directory nodes:
  144. /4/ Process tunneled HTTP request in BEGIN_DIR cell
  145. - rend-spec.txt, section 3.2: Added the requirement that requests need to
  146. be contained within BEGIN_DIR cells.
  147. - rend-spec.txt, section 3.3: Added the requirement that requests need to
  148. be contained within BEGIN_DIR cells.
  149. [July 9: Pending]
  150. /5/ Advertise hidden service directory functionality
  151. Every onion router that has its directory port open can decide whether it
  152. wants to store and serve hidden service descriptors by setting a new config
  153. option "HSDir" 0|1 to 1. An onion router with this config option being set
  154. includes the flag "hidden-service-dir" in its router descriptors that it
  155. sends to directory authorities.
  156. - tor.1.in: Added the config option HSDir.
  157. - dir-spec.txt, section 2.1: Added the flag hidden-service-dir to the
  158. router descriptor format.
  159. - rend-spec.txt, section 3.1: Added process of configuring a hidden service
  160. directory.
  161. - router.c: Changed router_dump_router_to_string() to include the
  162. hidden-service-dir flag in a router descriptor if configured.
  163. - or.h: Added HSDir to or_options_t.
  164. - config.c: Added config option HSDir.
  165. [July 9: Specified and running.]
  166. /6/ Accept v2 publish requests, parse and store v2 descriptors
  167. Hidden service directory nodes accept publish requests for hidden service
  168. descriptors and store them to their local memory. (It is not necessary to
  169. make descriptors persistent, because after disconnecting, the onion router
  170. would not be accepted as storing node anyway, because it has not been
  171. running for at least 24 hours.) All requests and replies are formatted as
  172. HTTP messages. Requests are directed to the router's directory port and are
  173. contained within BEGIN_DIR cells. A hidden service directory node stores a
  174. descriptor only when it thinks that it is responsible for storing that
  175. descriptor based on its own routing table. Every hidden service directory
  176. node is responsible for the descriptor IDs in the interval of its n-th
  177. predecessor in the ID circle up to its own ID (n denotes the number of
  178. consecutive replicas). (requires /1/ and /4/)
  179. - rend-spec.txt, section 1.2: Added the new v2 hidden service descriptor
  180. format.
  181. - rend-spec.txt, section 3.2: Added the acceptance of v2 publish requests.
  182. - routerparse.c: Added rend_parse_v2_service_descriptor() to parse a v2
  183. hidden service descriptor.
  184. - routerparse.c: Added desc_token_table[] to parse v2 hidden service
  185. descriptors.
  186. - routerparse.c: Added 8 keywords to directory_keyword to parse v2 hidden
  187. service descriptors.
  188. - rendcommon.c: Added rend_cache_store_v2_dir() to allow a hidden service
  189. directory to parse a v2 descriptor and store it in the local cache under
  190. its descriptor ID instead of its service ID.
  191. - or.h: Added constant REND_DESC_ID_V2_LEN to reflect that v2 descriptor
  192. IDs are longer than v0/1 onion addresses.
  193. - Changed directory_handle_command_post().
  194. [Aug 11: Specified and running.]
  195. /7/ Accept v2 fetch requests
  196. Same as /6/, but with fetch requests for hidden service descriptors.
  197. (requires /2/ and /4/)
  198. - rend-spec.txt, section 3.3: Added the processing of v2 fetch requests.
  199. - rendcommon.c: Added rend_cache_lookup_v2_dir() to allow a hidden service
  200. directory to look up a v2 descriptor in the local cache under its
  201. descriptor ID instead of its service ID.
  202. - or.h: Added constant REND_DESC_ID_V2_LEN to reflect that v2 descriptor
  203. IDs are longer than v0/1 onion addresses.
  204. - Changed directory_handle_command_get().
  205. [Aug 11: Specified and running.]
  206. /8/ Replicate descriptors with neighbors
  207. A hidden service directory node replicates descriptors from its two
  208. predecessors by downloading them once an hour. Further, it checks its
  209. routing table periodically for changes. Whenever it realizes that a
  210. predecessor has left the network, it establishes a connection to the new
  211. n-th predecessor and requests its stored descriptors in the interval of its
  212. (n+1)-th predecessor and the requested n-th predecessor. Whenever it
  213. realizes that a new onion router has joined with an ID higher than its
  214. former n-th predecessor, it adds it to its predecessors and discards all
  215. descriptors in the interval of its (n+1)-th and its n-th predecessor.
  216. (requires /1/)
  217. - rend-spec.txt, section 3.3: Added the replication of v2 descriptors.
  218. - Added HS_DIR_REPLICATION_INTERVAL.
  219. - Added next_hs_dir and previous_hs_dir.
  220. - Changed directory_handle_command_get().
  221. - Changed run_scheduled_events.
  222. - Added hs_dir_perform_replication().
  223. - Added rend_cache_lookup_v2_replicas.
  224. - Added DIR_PURPOSE_REPLICATE_RENDDESC_V2.
  225. - Changed directory_initiate_command.
  226. - directory_send_command.
  227. - Changed connection_dir_client_reached_eof.
  228. [Aug 11: To some extend specified, running.]
  229. Authoritative directory nodes:
  230. /9/ Confirm a router's hidden service directory functionality
  231. Directory nodes include a new flag "HSDir" for routers that decided to
  232. provide storage for hidden service descriptors and that are running for at
  233. least 24 hours. The last requirement prevents a node from frequently
  234. changing its onion key to become responsible for an identifier it wants to
  235. target.
  236. - dir-spec.txt, section 3.2: Added the status flag "HSDir" to the vote and
  237. consensus status document format.
  238. - dir-spec.txt, section 3.3: Added a rule for how an authority decides
  239. whether a router is assigned the flag "HSDir".
  240. - rend-spec.txt, section 3.1: Added the decision on whether an onion router
  241. is confirmed to act as hidden service directory or not.
  242. - routerparse.c: Changed router_parse_entry_from_string() to parse the
  243. "hidden-service-dir" flag in router descriptors.
  244. - routerparse.c: Added an entry to routerdesc_token_table[] to parse the
  245. "hidden-service-directory" flag in router descriptors.
  246. - routerparse.c: Added 1 keyword to directory_keyword to parse the
  247. "hidden-service-dir" flag in router descriptors.
  248. - or.h: Added is_hs_dir and wants_to_be_hs_dir members to routerinfo_t.
  249. - dirserv.c: Changed routerstatus_format_entry() to include the "HSDir"
  250. flag in vote and consensus status documents.
  251. - dirserv.c: Changed set_routerstatus_from_routerinfo() to set the "HSDir"
  252. flag.
  253. - Added dirserv_thinks_router_is_hs_dir().
  254. - Added MIN_UPTIME_HS_DIR and HS_DIR_REACHABLE_TIMEOUT.
  255. [Aug 11: Specified and running.]
  256. Hidden service provider:
  257. /10/ Configure v2 hidden service
  258. Each hidden service provider that has set the config option
  259. "PublishV2HidServDescriptors" 0|1 to 1 is configured to publish v2
  260. descriptors and conform to the v2 connection establishment protocol. When
  261. configuring a hidden service, a hidden service provider checks if it has
  262. already created a random secret_cookie and a hostname2 file; if not, it
  263. creates both of them. (requires /2/)
  264. - tor.1.in: Added the config option PublishV2HidServDescriptors.
  265. - tor.1.in: Added the files hostname2 and secret_cookie.
  266. - rend-spec.txt, section 1.1: Added requirement to create secret_cookie and
  267. hostname2 file.
  268. - rendservice.c: Added rend_get_hostname2() to assemble a v2 onion address.
  269. - rendservice.c: Changed rend_service_load_keys() to write a secret_cookie
  270. and a hostname2 file.
  271. - rendservice.c: Extended rend_service_t by a member secret_cookie.
  272. - or.h: Added PublishV2HidServDescriptors to or_options_t.
  273. - config.c: Added config option PublishV2HidServDescriptors.
  274. [July 9: Specified and running.]
  275. /11/ Establish introduction points with fresh key
  276. If configured to publish only v2 descriptors and no v0/v1 descriptors any
  277. more, a hidden service provider that is setting up the hidden service at
  278. introduction points does not pass its own public key, but the public key
  279. of a freshly generated key pair. It also includes these fresh public keys
  280. in the hidden service descriptor together with the other introduction point
  281. information. The reason is that the introduction point does not need to and
  282. therefore should not know for which hidden service it works, so as to
  283. prevent it from tracking the hidden service's activity. (If a hidden
  284. service provider supports both, v0/v1 and v2 descriptors, v0/v1 clients
  285. rely on the fact that all introduction points accept the same public key,
  286. so that this new feature cannot be used.)
  287. - rend-spec.txt, section 1.3: Instead of Bob's public key, the hidden
  288. service provider uses a freshly generated public key for every
  289. introduction point.
  290. - TODO: Change in rend_encode_v2_descriptors.
  291. [July 9: Specified, but not yet implemented.]
  292. /12/ Encode v2 descriptors and send v2 publish requests
  293. If configured to publish v2 descriptors, a hidden service provider
  294. publishes a new descriptor whenever its content changes or a new
  295. publication period starts for this descriptor. If the current publication
  296. period would only last for less than 60 minutes (= 2 x 30 minutes to allow
  297. the server to be 30 minutes behind and the client 30 minutes ahead), the
  298. hidden service provider publishes both a current descriptor and one for
  299. the next period. Publication is performed by sending the descriptor to all
  300. hidden service directories that are responsible for keeping replicas for
  301. the descriptor ID. This includes two non-consecutive replicas that are
  302. stored at 3 consecutive nodes each. (requires /1/, /2/, and /3/)
  303. - rend-spec.txt, section 1.2: Added the new v2 hidden service descriptor
  304. format.
  305. - rend-spec.txt, section 1.4: Bob's OP does not only upload v0/v1 service
  306. descriptors to the authoritative directories, but also v2 service
  307. descriptors to the hidden service directories.
  308. - rendservice.c: Changed upload_service_descriptor() to upload v2 hidden
  309. service descriptors, if configured.
  310. - rendservice.c: Changed rend_consider_services_upload() to also initiate
  311. the upload of v2 descriptors, if configured.
  312. - rendservice.c: Extended rend_service_t by a member secret_cookie.
  313. - rendcommon.c: Added rend_encode_v2_descriptor() to encode a v2
  314. descriptor.
  315. - or.h: Added constant DIR_PURPOSE_UPLOAD_RENDDESC_V2.
  316. - directory.c: Added directory_post_to_hs_dir().
  317. - directory.c: Changed directory_initiate_command() to also recognize v2
  318. publish requests.
  319. - directory.c: Changed directory_send_command() to also prepare v2 publish
  320. requests.
  321. - crypto.c: Added implementation for crypto_cipher_encrypt_cbc().
  322. - Changed connection_dir_client_reached_eof().
  323. [Aug 11: Specified and running.]
  324. Hidden service client:
  325. /13/ Send v2 fetch requests
  326. A hidden service client that has set the config option
  327. "FetchV2HidServDescriptors" 0|1 to 1 handles SOCKS requests for v2 onion
  328. addresses by requesting a v2 descriptor from a randomly chosen hidden
  329. service directory that is responsible for keeping replica for the
  330. descriptor ID. In total there are six replicas of which the first and the
  331. last three are stored on consecutive nodes. The probability of picking one
  332. of the three consecutive replicas is 1/6, 2/6, and 3/6 to incorporate the
  333. fact that the availability will be the highest on the node with next higher
  334. ID. A hidden service client relies on the hidden service provider to store
  335. two sets of descriptors to compensate clock skew between service and
  336. client. (requires /1/, /2/, and /3/)
  337. - tor.1.in: Added the config option FetchV2HidServDescriptors.
  338. - rend-spec.txt, section 1.5: Added the new v2 onion address format.
  339. - rend-spec.txt, section 1.6: Alice's OP downloads the service descriptors
  340. similarly as Bob's OP uploaded them in 1.4.
  341. - rendcommon.c: Changed rend_cache_lookup_entry to enable it to also lookup
  342. v2 descriptors.
  343. - rendcommon.c: Added rend_compute_v2_desc_id() to generate v2 descriptor IDs
  344. from v2 onion addresses.
  345. - rendcommon.c: Changed rend_valid_service_id() to also consider v2 onion
  346. addresses as valid and return the version number of the request (0 or 2).
  347. - rendclient.c: Added rend_client_refetch_v2_renddesc() to fetch v2 service
  348. descriptors using the secret cookie.
  349. - rendclient.c: Changed rend_client_remove_intro_point() to copy the secret
  350. cookie if the local descriptor has expired or there are no introduction
  351. points left.
  352. - or.h: Added FetchV2HidServDescriptors to or_options_t.
  353. - or.h: Added constant REND_DESC_ID_V2_LEN to reflect that v2 descriptor
  354. IDs are longer than v0/1 onion addresses.
  355. - or.h: Added constant DIR_PURPOSE_FETCH_RENDDESC_V2.
  356. - directory.c: Added directory_get_from_hs_dir().
  357. - directory.c: Changed directory_initiate_command() to also recognize v2
  358. fetch requests.
  359. - directory.c: Changed directory_send_command() to also prepare v2 fetch
  360. requests.
  361. - connection_edge.c: Changed connection_ap_handshake_rewrite_and_attach()
  362. to fetch v2 service descriptors.
  363. - connection_edge.c: Changed parse_extended_hostname() to accept both,
  364. current and v2 onion addresses.
  365. - config.c: Added config options FetchV2HidServDescriptors.
  366. [Aug 11: Base version specified and running, but no memory of failed
  367. hidden service directories, yet.]
  368. /14/ Process v2 fetch reply and parse v2 descriptors
  369. A hidden service client that has sent a request for a v2 descriptor can
  370. parse it and store it to the local cache of rendezvous service descriptors.
  371. - rend-spec.txt, section 1.2: Added the new v2 hidden service descriptor
  372. format.
  373. - rend-spec.txt, section 1.6: Alice's OP parses the reply received from the
  374. hidden service directory.
  375. - routerparse.c: Added rend_parse_v2_service_descriptor() to parse a v2
  376. hidden service descriptor.
  377. - routerparse.c: Added rend_decrypt_introduction_points() to decrypt and
  378. parse the list of introduction points.
  379. - routerparse.c: Added ipo_token_table[] to parse the decrypted
  380. introduction points of v2 hidden service descriptors.
  381. - routerparse.c: Added desc_token_table[] to parse v2 hidden service
  382. descriptors.
  383. - routerparse.c: Added 8 keywords to directory_keyword to parse v2 hidden
  384. service descriptors, and 5 to parse the decrypted list of introduction
  385. points.
  386. - rendcommon.c: Added rend_cache_store_v2_client() to parse a v2 descriptor
  387. and parse the encrypted list of introduction points.
  388. - or.h: Added rend_version and secret_cookie to edge_connection_t, to
  389. dir_connection_t, and to origin_circuit_t to be able to decrypt
  390. introduction points when receiving a v2 descriptor.
  391. - directory.c: Changed connection_dir_client_reached_eof() to also parse v2
  392. fetch replies.
  393. - crypto.c: Added implementation for crypto_cipher_decrypt_cbc().
  394. [July 9: Specified and running.]
  395. /15/ Establish connection to v2 hidden service
  396. A hidden service client can establish a connection to a hidden service
  397. using a v2 descriptor. This includes using the secret cookie for decrypting
  398. the introduction points contained in the descriptor. When contacting an
  399. introduction point, the client does not use the public key of the hidden
  400. service provider, but the freshly-generated public key that is included in
  401. the hidden service descriptor. Whether or not a fresh key is used instead
  402. of the key of the hidden service depends on the available protocol versions
  403. that are included in the descriptor; by this, connection establishment is
  404. to a certain extend decoupled from fetching the descriptor.
  405. - rend-spec.txt, section 1.8: Alice uses the public key that is included in
  406. the descriptor instead of Bob's permanent service key.
  407. - rendclient.c: Changed rend_client_introduction_acked() to copy the secret
  408. cookie in case the introduction point denied the request.
  409. - rendclient.c: Changed rend_client_remove_intro_point() to copy the secret
  410. cookie if the local descriptor has expired or there are no introduction
  411. points left.
  412. - or.h: Added secret_cookie to edge_connection_t, to dir_connection_t, and
  413. to origin_circuit_t to be able to decrypt introduction points when
  414. receiving a v2 descriptor.
  415. - circuitlist.c: Changed _circuit_mark_for_close() to pass the secret
  416. cookie to rend_client_remove_intro_point() when an intro circ has failed.
  417. - circuituse.c: Changed circuit_get_open_circ_or_launch() to fetch a v2
  418. descriptor with the secret cookie, if no descriptor is available, or copy
  419. the secret cookie to the circuit, in case it dies later, so that it can
  420. be used to fetch a new descriptor.
  421. [July 9: Base version specified and running, but without fresh key.]
  422. Hidden service descriptor:
  423. (Requirements concerning the descriptor format are contained in /6/ and /7/.)
  424. The new v2 hidden service descriptor format looks like this:
  425. onion-address = h(public-key) + cookie
  426. descriptor-id = h(h(public-key) + h(time-period + cookie + relica))
  427. descriptor-content = {
  428. descriptor-id,
  429. version,
  430. public-key,
  431. h(time-period + cookie + replica),
  432. timestamp,
  433. protocol-versions,
  434. { introduction-points } encrypted with cookie
  435. } signed with private-key
  436. The "descriptor-id" needs to change periodically in order for the
  437. descriptor to be stored on changing nodes over time. It may only be
  438. computable by a hidden service provider and all of his clients to prevent
  439. unauthorized nodes from tracking the service activity by periodically
  440. checking whether there is a descriptor for this service. Finally, the
  441. hidden service directory needs to be able to verify that the hidden service
  442. provider is the true originator of the descriptor with the given ID.
  443. Therefore, "descriptor-id" is derived from the "public-key" of the hidden
  444. service provider, the current "time-period" which changes every 24 hours,
  445. a secret "cookie" shared between hidden service provider and clients, and
  446. a "replica" denoting the number of this non-consecutive replica. (The
  447. "time-period" is constructed in a way that time periods do not change at
  448. the same moment for all descriptors by deriving a value between 0:00 and
  449. 23:59 hours from h(public-key) and making the descriptors of this hidden
  450. service provider expire at that time of the day.) The "descriptor-id" is
  451. defined to be 160 bits long. [extending the "descriptor-id" length
  452. suggested by LØ]
  453. Only the hidden service provider and the clients are able to generate
  454. future "descriptor-ID"s. Hence, the "onion-address" is extended from now
  455. the hash value of "public-key" by the secret "cookie". The "public-key" is
  456. determined to be 80 bits long, whereas the "cookie" is dimensioned to be
  457. 120 bits long. This makes a total of 200 bits or 40 base32 chars, which is
  458. quite a lot to handle for a human, but necessary to provide sufficient
  459. protection against an adversary from generating a key pair with same
  460. "public-key" hash or guessing the "cookie".
  461. A hidden service directory can verify that a descriptor was created by the
  462. hidden service provider by checking if the "descriptor-id" corresponds to
  463. the "public-key" and if the signature can be verified with the
  464. "public-key".
  465. The "introduction-points" that are included in the descriptor are encrypted
  466. using the same "cookie" that is shared between hidden service provider and
  467. clients. [correction to use another key than h(time-period + cookie) as
  468. encryption key for introduction points made by LØ]
  469. A new text-based format is proposed for descriptors instead of an extension
  470. of the existing binary format for reasons of future extensibility.
  471. Security implications:
  472. The security implications of the proposed changes are grouped by the roles of
  473. nodes that could perform attacks or on which attacks could be performed.
  474. Attacks by authoritative directory nodes
  475. Authoritative directory nodes are no longer the single places in the
  476. network that know about a hidden service's activity and introduction
  477. points. Thus, they cannot perform attacks using this information, e.g.
  478. track a hidden service's activity or usage pattern or attack its
  479. introduction points. Formerly, it would only require a single corrupted
  480. authoritative directory operator to perform such an attack.
  481. Attacks by hidden service directory nodes
  482. A hidden service directory node could misuse a stored descriptor to track a
  483. hidden service's activity and usage pattern by clients. Though there is no
  484. countermeasure against this kind of attack, it is very expensive to track a
  485. certain hidden service over time. An attacker would need to run a large
  486. number of stable onion routers that work as hidden service directory nodes
  487. to have a good probability to become responsible for its changing
  488. descriptor IDs. For each period, the probability is:
  489. 1-(N-c choose r)/(N choose r) for N-c>=r and 1 otherwise, with N
  490. as total
  491. number of hidden service directories, c as compromised nodes, and r as
  492. number of replicas
  493. The hidden service directory nodes could try to make a certain hidden
  494. service unavailable to its clients. Therefore, they could discard all
  495. stored descriptors for that hidden service and reply to clients that there
  496. is no descriptor for the given ID or return an old or false descriptor
  497. content. The client would detect a false descriptor, because it could not
  498. contain a correct signature. But an old content or an empty reply could
  499. confuse the client. Therefore, the countermeasure is to replicate
  500. descriptors among a small number of hidden service directories, e.g. 5.
  501. The probability of a group of collaborating nodes to make a hidden service
  502. completely unavailable is in each period:
  503. (c choose r)/(N choose r) for c>=r and N>=r, and 0 otherwise,
  504. with N as total
  505. number of hidden service directories, c as compromised nodes, and r as
  506. number of replicas
  507. A hidden service directory could try to find out which introduction points
  508. are working on behalf of a hidden service. In contrast to the previous
  509. design, this is not possible anymore, because this information is encrypted
  510. to the clients of a hidden service.
  511. Attacks on hidden service directory nodes
  512. An anonymous attacker could try to swamp a hidden service directory with
  513. false descriptors for a given descriptor ID. This is prevented by requiring
  514. that descriptors are signed.
  515. Anonymous attackers could swamp a hidden service directory with correct
  516. descriptors for non-existing hidden services. There is no countermeasure
  517. against this attack. However, the creation of valid descriptors is more
  518. expensive than verification and storage in local memory. This should make
  519. this kind of attack unattractive.
  520. Attacks by introduction points
  521. Current or former introduction points could try to gain information on the
  522. hidden service they serve. But due to the fresh key pair that is used by
  523. the hidden service, this attack is not possible anymore.
  524. Attacks by clients
  525. Current or former clients could track a hidden service's activity, attack
  526. its introduction points, or determine the responsible hidden service
  527. directory nodes and attack them. There is nothing that could prevent them
  528. from doing so, because honest clients need the full descriptor content to
  529. establish a connection to the hidden service. At the moment, the only
  530. countermeasure against dishonest clients is to change the secret cookie and
  531. pass it only to the honest clients.
  532. Compatibility:
  533. The proposed design is meant to replace the current design for hidden service
  534. descriptors and their storage in the long run.
  535. There should be a first transition phase in which both, the current design
  536. and the proposed design are served in parallel. Onion routers should start
  537. serving as hidden service directories, and hidden service providers and
  538. clients should make use of the new design if both sides support it. Hidden
  539. service providers should be allowed to publish descriptors of the current
  540. format in parallel, and authoritative directories should continue storing and
  541. serving these descriptors.
  542. After the first transition phase, hidden service providers should stop
  543. publishing descriptors on authoritative directories, and hidden service
  544. clients should not try to fetch descriptors from the authoritative
  545. directories. However, the authoritative directories should continue serving
  546. hidden service descriptors for a second transition phase. As of this point,
  547. all v2 config options should be set to a default value of 1.
  548. After the second transition phase, the authoritative directories should stop
  549. serving hidden service descriptors.
  550. Specification:
  551. The proposed changes affect multiple sections in several specification
  552. documents that are only mentioned in the following. (As for now, all changes
  553. to specification documents are limited to the SVN branch 114-dist-storage.)
  554. tor.1.in
  555. Added the config options HSDir (/5/), PublishV2HidServDescriptors (/10/),
  556. and FetchV2HidServDescriptors (/13/).
  557. Added the files hostname2 and secret_cookie (/10/).
  558. dir-spec.txt
  559. 2.1 Added the flag hidden-service-dir to the router descriptor format
  560. (/5/).
  561. 3.2 Added the status flag HSDir to the vote and consensus status
  562. document format (/9/).
  563. 3.3 Added a rule for how an authority decides whether a router is assigned
  564. the flag HSDir (/9/).
  565. rend-spec.txt
  566. 0.4 Added history
  567. 1.1 Added requirement to create secret_cookie and hostname2 file (/10/).
  568. 1.2 Added the new v2 hidden service descriptor format (/6/, /12/ and
  569. /14/).
  570. 1.3 Instead of Bob's public key, the hidden service provider uses a
  571. freshly generated public key for every introduction point (/11/).
  572. 1.4 Added description of how to obtain a routing list of hidden service
  573. directories (/1/).
  574. 1.4 Added description of how to determine the responsible node(s) for a
  575. given descriptor ID (/2/).
  576. 1.4 Bob's OP does not only upload v0/v1 service descriptors to the
  577. authoritative directories, but also v2 service descriptors to the hidden
  578. service directories (/12/).
  579. 1.4 Added the requirement that requests need to be sent via Tor (/3/).
  580. 1.5 Added the new v2 onion address format (/13/).
  581. 1.6 Added the requirement that requests need to be sent via Tor (/3/).
  582. 1.6 Alice's OP downloads the service descriptors similarly as Bob's OP
  583. uploaded them in 1.4 (/13/).
  584. 1.6 Alice's OP parses the reply received from the hidden service directory
  585. (/14/).
  586. 1.8 Alice uses the public key that is included in the descriptor instead
  587. of Bob's permanent service key (/15/).
  588. 3.1: Added process of configuring a hidden service directory (/5/).
  589. 3.1: Added the decision on whether an onion router is confirmed to act as
  590. hidden service directory or not (/9/).
  591. 3.2: Added the requirement that requests need to be contained within
  592. BEGIN_DIR cells (/4/).
  593. 3.2: Added the acceptance of v2 publish requests (/6/).
  594. 3.3: Added the requirement that requests need to be contained within
  595. BEGIN_DIR cells (/4/).
  596. 3.3: Added the processing of v2 fetch requests (/7/).
  597. 3.3: Added the replication of v2 descriptors (/8/).
  598. Implementation:
  599. The proposed changes affect the following changes in the source code. (As for
  600. now, all changes to code are limited to the SVN branch 114-dist-storage.)
  601. container.h
  602. Added prototype for smartlist_digest_next_circular() (/2/).
  603. container.c
  604. Added implementation for smartlist_digest_next_circular() (/2/).
  605. crypto.h
  606. Added 3 prototypes according to the changes in crypto.c (various
  607. requirements).
  608. crypto.c
  609. Added implementation for crypto_cipher_encrypt_cbc() (/12/).
  610. Added implementation for crypto_cipher_decrypt_cbc() (/14/).
  611. Added implementation for base32_decode() (various requirements).
  612. circuitlist.c
  613. Changed _circuit_mark_for_close() to pass the secret cookie to
  614. rend_client_remove_intro_point() when an intro circ has failed (/15/).
  615. circuituse.c
  616. Changed circuit_get_open_circ_or_launch() to fetch a v2 descriptor with the
  617. secret cookie, if no descriptor is available, or copy the secret cookie to
  618. the circuit, in case it dies later, so that it can be used to fetch a new
  619. descriptor (/15/).
  620. config.c
  621. Added config options FetchV2HidServDescriptors (/13/), HSDir (/5/), and
  622. PublishV2HidServDescriptors (/10/).
  623. connection_edge.c
  624. Changed connection_ap_handshake_rewrite_and_attach() to fetch v2 service
  625. descriptors (/13/).
  626. Changed parse_extended_hostname() to accept both, current and v2 onion
  627. addresses (/13/).
  628. directory.c
  629. Added directory_post_to_hs_dir() (/12/).
  630. Added directory_get_from_hs_dir() (/13/).
  631. Changed directory_initiate_command() to also recognize v2 publish (/12/)
  632. and fetch (/13/) requests.
  633. Changed directory_send_command() to also prepare v2 publish (/12/) and
  634. fetch (/13/) requests.
  635. Changed connection_dir_client_reached_eof() to also parse v2 fetch replies
  636. (/14/).
  637. Changed directory_handle_command_get() to handle v2 fetch requests (/13/).
  638. Changed directory_handle_command_post() to handle v2 publish requests
  639. (/12/).
  640. dirserv.c
  641. Changed routerstatus_format_entry() to include the "HSDir" flag in vote and
  642. consensus status documents (/9/).
  643. Changed set_routerstatus_from_routerinfo() to set the "HSDir" flag (/9/).
  644. or.h
  645. Added constants DIR_PURPOSE_UPLOAD_RENDDESC_V2 (/12/) and
  646. DIR_PURPOSE_FETCH_RENDDESC_V2 (/13/).
  647. Added constant REND_DESC_ID_V2_LEN to reflect that v2 descriptor IDs are
  648. longer than v0/1 onion addresses (/6/, /7/, and /13/).
  649. Added rend_version and secret_cookie to edge_connection_t, to
  650. dir_connection_t, and to origin_circuit_t to be able to decrypt
  651. introduction points when receiving a v2 descriptor (/14/ and /15/).
  652. Added is_hs_dir member to routerinfo_t and to routerstatus_t (/9/).
  653. Added hs_dirs member to routerlist_t (/1/).
  654. Added FetchV2HidServDescriptors (/13/), HSDir (/5/), and
  655. PublishV2HidServDescriptors (/10/) to or_options_t.
  656. Added 7 new members to rend_service_descriptor_t to store v2-specific
  657. information (/12/, /14/, and /15/).
  658. Added 11 prototypes and changed the signature of 1 according to the
  659. changes in .c files (various requirements).
  660. rendclient.c
  661. Changed rend_client_introduction_acked() to copy the secret cookie in case
  662. the introduction point denied the request (/15/).
  663. Added rend_client_refetch_v2_renddesc() to fetch v2 service descriptors
  664. using the secret cookie (/13/).
  665. Changed rend_client_remove_intro_point() to copy the secret cookie if the
  666. local descriptor has expired or there are no introduction points left (/13/
  667. and /15/).
  668. rendcommon.c
  669. Added rend_compute_v2_descriptor_fields() to prepare the encoding of a v2
  670. descriptor (/12/).
  671. Added rend_compute_desc_id() to generate v2 descriptor IDs from v2 onion
  672. addresses (/13/).
  673. Added rend_encode_v2_descriptor() to encode a v2 descriptor (/12/).
  674. Changed rend_valid_service_id() to also consider v2 onion addresses as
  675. valid and return the version number of the request (1 or 2) (/13/).
  676. Changed rend_cache_lookup_entry to enable it to also lookup v2 descriptors
  677. (/13/).
  678. Added rend_cache_lookup_v2_dir() to allow a hidden service directory to
  679. look up a v2 descriptor in the local cache under its descriptor ID instead
  680. of its service ID (/7/).
  681. Moved the parsing part from rend_cache_store() to the new function
  682. rend_cache_store_parse() to reuse it for v2 descriptors (/6/).
  683. Added rend_cache_store_v2_client() to parse a v2 descriptor and parse the
  684. encrypted list of introduction points (/14/).
  685. Added rend_cache_store_v2_dir() to allow a hidden service directory to
  686. store a v2 descriptor in the local cache under its descriptor ID instead of
  687. its service ID (/6/).
  688. rendservice.c
  689. Extended rend_service_t by a member secret_cookie (/10/ and /12/).
  690. Added rend_get_hostname2() to assemble a v2 onion address (/10/).
  691. Changed rend_service_load_keys() to write a secret_cookie and a hostname2
  692. file (/10/).
  693. Changed upload_service_descriptor() to upload v2 hidden service
  694. descriptors, if configured (/12/).
  695. Changed rend_consider_services_upload() to also initiate the upload of v2
  696. descriptors, if configured (/12/).
  697. router.c
  698. Changed router_dump_router_to_string() to include the "hidden-service-dir"
  699. flag in a router descriptor if configured (/5/).
  700. routerlist.c
  701. Changed router_get_routerlist() to initialize routing list (/1/).
  702. Added get_responsible_hs_dir() to determine the router that is responsible
  703. for a given descriptor ID (/2/).
  704. routerparse.c
  705. Added 14 keywords to directory_keyword; 1 to parse the "hidden-service-dir"
  706. flag in router descriptors (/9/), 8 to parse v2 hidden service descriptors
  707. (/6/ and /14/), and 5 to parse the decrypted list of introduction points
  708. (/14/).
  709. Added an entry to routerdesc_token_table[] to parse the
  710. "hidden-service-directory" flag in router descriptors (/9/).
  711. Added desc_token_table[] to parse v2 hidden service descriptors (/6/ and
  712. /14/).
  713. Added ipo_token_table[] to parse the decrypted introduction points of v2
  714. hidden service descriptors (/14/).
  715. Changed router_parse_entry_from_string() to parse the "hidden-service-dir"
  716. flag in router descriptors (/9/).
  717. Changed routerstatus_parse_entry_from_string to parse the "HSDir" flag in
  718. vote and consensus status documents (/1/).
  719. Added rend_parse_v2_service_descriptor() to parse a v2 hidden service
  720. descriptor (/6/ and /14/).
  721. Added rend_decrypt_introduction_points() to decrypt and parse the list of
  722. introduction points (/14/).
  723. Test:
  724. The changes were tested via test functions in test.c for separate,
  725. short-running functionality and using an automatic validation based on
  726. PuppeTor.