dir-spec.txt 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. $Id$
  2. Tor directory protocol for 0.1.1.x series
  3. 0. Scope and preliminaries
  4. This document should eventually be merged into tor-spec.txt and replace
  5. the existing notes on directories.
  6. This is not a finalized version; what we actually wind up implementing
  7. may be very different from the system described here.
  8. 0.1. Goals
  9. There are several problems with the way Tor handles directories right
  10. now:
  11. 1. Directories are very large and use a lot of bandwidth.
  12. 2. Every directory server is a single point of failure.
  13. 3. Requiring every client to know every server won't scale.
  14. 4. Requiring every directory cache to know every server won't scale.
  15. 5. Our current "verified server" system is kind of nonsensical.
  16. 6. Getting more directory servers adds more points of failure and
  17. worsens possible partitioning attacks.
  18. This design tries to solve every problem except problems 3 and 4, and to
  19. be compatible with likely eventual solutions to problems 3 and 4.
  20. 1. Outline
  21. There is no longer any such thing as a "signed directory". Instead,
  22. directory servers sign a very compressed 'network status' object that
  23. lists the current descriptors and their status, and router descriptors
  24. continue to be self-signed by servers. Clients download network status
  25. listings periodically, and download router descriptors as needed. ORs
  26. upload descriptors relatively infrequently.
  27. There are multiple directory servers. Rather than doing anything
  28. complicated to coordinate themselves, clients simply rotate through them
  29. in order, and only use servers that most of the last several directory
  30. servers like.
  31. 2. Router descriptors
  32. The router descriptor format is unchanged from tor-spec.txt.
  33. ORs SHOULD generate a new router descriptor whenever any of the
  34. following events have occurred:
  35. - A period of time (18 hrs by default) has passed since the last
  36. time a descriptor was generated.
  37. - A descriptor field other than bandwidth or uptime has changed.
  38. - Bandwidth has changed by more than +/- 50% from the last time a
  39. descriptor was generated, and at least a given interval of time
  40. (20 mins by default) has passed since then.
  41. - Uptime has been reset.
  42. After generating a descriptor, ORs upload it to every directory
  43. server they know.
  44. 3. Network status
  45. Directory servers generate, sign, and compress a network-status document
  46. as needed. As an optimization, they may rate-limit the number of such
  47. documents generated to once every few seconds. Directory servers should
  48. rate-limit at least to the point where these documents are generated no
  49. faster than once per second.
  50. The network status document contains a preamble, a set of router status
  51. entries, and a signature, in that order.
  52. We use the same meta-format as used for directories and router descriptors
  53. in "tor-spec.txt".
  54. The preamble contains:
  55. "network-status-version" -- A document format version. For this
  56. specification, the version is "2".
  57. "dir-source" -- The hostname, current IP address, and directory
  58. port of the directory server, separated by spaces.
  59. "fingerprint" -- A base16-encoded hash of the signing key's
  60. fingerprint, with no additional spaces added.
  61. "contact" -- An arbitrary string describing how to contact the
  62. directory server's administrator. Administrators should include at
  63. least an email address and a PGP fingerprint.
  64. "dir-signing-key" -- The directory server's public signing key.
  65. "client-versions" -- A comma-separated list of recommended client versions.
  66. "server-versions" -- A comma-separated list of recommended server versions.
  67. "published" -- The publication time for this network-status object.
  68. "dir-options" -- A set of flags separated by spaces:
  69. "Names" if this directory server performs name bindings.
  70. "Versions" if this directory server recommends software versions.
  71. The dir-options entry is optional. The "-versions" entries are required if
  72. the "Versions" flag is present. The other entries are required and must
  73. appear exactly once. The "network-status-version" entry must appear first;
  74. the others may appear in any order.
  75. For each router, the router entry contains: (This format is designed for
  76. conciseness.)
  77. "r" -- followed by the following elements, separated by spaces:
  78. - The OR's nickname,
  79. - A hash of its identity key, encoded in base64, with trailing =
  80. signs removed.
  81. - A hash of its most recent descriptor, encoded in base64, with
  82. trailing = signs removed. (The hash is calculated as for
  83. computing the signature of a descriptor.)
  84. - The publication time of its most recent descriptor.
  85. - An IP
  86. - An OR port
  87. - A directory port (or "0" for none")
  88. "s" -- A series of space-separated status flags:
  89. "Exit" if the router is useful for building general-purpose exit
  90. circuits.
  91. "Stable" if the router tends to stay up for a long time.
  92. "Fast" if the router has high bandwidth.
  93. "Running" if the router is currently usable.
  94. "Named" if the router's identity-nickname mapping is canonical.
  95. "Valid" if the router has been 'validated'.
  96. "Authority" if the router is a directory authority.
  97. The "r" entry for each router must appear first and is required. The
  98. 's" entry is optional. Unrecognized flags, or extra elements on the
  99. "r" line must be ignored.
  100. The signature section contains:
  101. "directory-signature". A signature of the rest of the document using
  102. the directory server's signing key.
  103. We compress the network status list with zlib before transmitting it.
  104. 4. Directory server operation
  105. By default, directory servers remember all non-expired, non-superseded OR
  106. descriptors that they have seen.
  107. For each OR, a directory server remembers whether the OR was running and
  108. functional the last time they tried to connect to it, and possibly other
  109. liveness information.
  110. Directory server administrators may label some servers or IPs as
  111. blacklisted, and elect not to include them in their network-status lists.
  112. Thus, the network-status list includes all non-blacklisted,
  113. non-expired, non-superseded descriptors for ORs that the directory has
  114. observed at least once to be running.
  115. Directory server administrators may decide to support name binding. If
  116. they do, then they must maintain a file of nickname-to-identity-key
  117. mappings, and try to keep this file consistent with other directory
  118. servers. If they don't, they act as clients, and report bindings made by
  119. other directory servers (name X is bound to identity Y if at least one
  120. binding directory lists it, and no directory binds X to some other Y'.)
  121. The authoritative network-status published by a host should be available at:
  122. http://<hostname>/tor/status/authority.z
  123. An authoritative network-status published by another host with fingerprint
  124. <F> should be available at:
  125. http://<hostname>/tor/status/fp/<F>.z
  126. An authoritative network-status published by other hosts with fingerprints
  127. <F1>,<F2>,<F3> should be available at:
  128. http://<hostname>/tor/status/fp/<F1>+<F2>+<F3>.z
  129. The most recent network-status documents from all known authoritative
  130. directories, concatenated, should be available at:
  131. http://<hostname>/tor/status/all.z
  132. The most recent descriptor for a server whose identity key has a
  133. fingerprint of <F> should be available at:
  134. http://<hostname>/tor/server/fp/<F>.z
  135. The most recent descriptors for servers with fingerprints <F1>,<F2>,<F3>
  136. should be available at:
  137. http://<hostname>/tor/server/fp/<F1>+<F2>+<F3>.z
  138. The descriptor for a server whose digest (in hex) is <D> should be
  139. available at:
  140. http://<hostname>/tor/server/d/<D>.z
  141. The most recent descriptors with digests <D1>,<D2>,<D3> should be
  142. available at:
  143. http://<hostname>/tor/server/d/<D1>+<D2>+<D3>.z
  144. The most recent descriptor for this server should be at:
  145. http://<hostname>/tor/server/authority.z
  146. A concatenated set of the most recent descriptors for all known servers
  147. should be available at:
  148. http://<hostname>/tor/server/all.z
  149. For debugging, directories MAY expose non-compressed objects at URLs like
  150. the above, but without the final ".z".
  151. Clients MUST handle compressed concatenated information in two forms:
  152. - A concatenated list of zlib-compressed objects.
  153. - A zlib-compressed concatenated list of objects.
  154. Directory servers MAY generate either format: the former requires less
  155. CPU, but the latter requires less bandwidth.
  156. 4.1. Caching
  157. Directory caches (most ORs) regularly download network status documents,
  158. and republish them at a URL based on the directory server's identity key:
  159. http://<hostname>/tor/status/<identity fingerprint>.z
  160. A concatenated list of all network-status documents should be available at:
  161. http://<hostname>/tor/status/all.z
  162. 4.2. Compression
  163. 5. Client operation
  164. Every OP or OR, including directory servers, acts as a client to the
  165. directory protocol.
  166. Each client maintains a list of trusted directory servers. Periodically
  167. (currently every 20 minutes), the client downloads a new network status. It
  168. chooses the directory server from which its current information is most
  169. out-of-date, and retries on failure until it finds a running server.
  170. When choosing ORs to build circuits, clients proceed as follows:
  171. - A server is "listed" if it is listed by more than half of the "live"
  172. network status documents the clients have downloaded. (A network
  173. status is "live" if it is the most recently downloaded network status
  174. document for a given directory server, and the server is a directory
  175. server trusted by the client, and the network-status document is no
  176. more than D (say, 10) days old.)
  177. - A server is "valid" is it is listed as valid by more than half of the
  178. "live" downloaded" network-status document.
  179. - A server is "running" if it is listed as running by more than
  180. half of the "recent" downloaded network-status documents.
  181. (A network status is "recent" if it was published in the last
  182. 60 minutes. If there are fewer than 3 such documents, the most
  183. recently published 3 are "recent." If there are fewer than 3 in all,
  184. all are "recent.")
  185. Clients store network status documents so long as they are live.
  186. 5.1. Scheduling network status downloads
  187. This download scheduling algorithm implements the approach described above
  188. in a relatively low-state fashion. It reflects the current Tor
  189. implementation.
  190. Clients maintain a list of authorities; each client tries to keep the same
  191. list, in the same order.
  192. Periodically, on startup, and on HUP, clients check whether they need to
  193. download fresh network status documents. The approach is as follows:
  194. - If we have under X network status documents newer than OLD, we choose a
  195. member of the list at random and try download XX documents starting
  196. with that member's.
  197. - Otherwise, if we have no network status documents newer than NEW, we
  198. check to see which authority's document we retrieved most recently,
  199. and try to retrieve the next authority's document. If we can't, we
  200. try the next authority in sequence, and so on.
  201. 5.2. Managing naming
  202. In order to provide human-memorable names for individual server
  203. identities, some directory servers bind names to IDs. Clients handle
  204. names in two ways:
  205. If a client is encountering a name it has not mapped before:
  206. If all the "binding" networks-status documents the client has so far
  207. received same claim that the name binds to some identity X, and the
  208. client has received at least three network-status documents, the client
  209. maps the name to X.
  210. If a client is encountering a name it has mapped before:
  211. It uses the last-mapped identity value, unless all of the "binding"
  212. network status documents bind the name to some other identity.
  213. 5.3. Notes on what we do now.
  214. THIS SECTION SHOULD BE FOLDED INTO THE EARLIER SECTIONS; THEY ARE WRONG;
  215. THIS IS RIGHT.
  216. All downloaded networkstatuses are discarded once they are 10 days old (by
  217. published date).
  218. Authdirs download each others' networkstatus every
  219. AUTHORITY_NS_CACHE_INTERVAL minutes (currently 10).
  220. Directory caches download authorities' networkstatus every
  221. NONAUTHORITY_NS_CACHE_INTERVAL minutes (currently 10).
  222. Clients always try to replace any networkstatus received over
  223. NETWORKSTATUS_MAX_VALIDITY ago (currently 2 days). Also, when the most
  224. recently received networkstatus is more than
  225. NETWORKSTATUS_CLIENT_DL_INTERVAL (30 minutes) old, and we do not have any
  226. open directory connections fetching a networkstatus, clients try to
  227. download the networkstatus on their list after the most recently received
  228. networkstatus, skipping failed networkstatuses. A networkstatus is
  229. "failed" if NETWORKSTATUS_N_ALLOWABLE_FAILURES (3) attempts in a row have
  230. all failed.
  231. We do not update router statuses if we have less than half of the
  232. networkstatuses.
  233. A networkstatus is "live" if it is the most recent we have received signed
  234. by a given trusted authority.
  235. A networkstatus is "recent" if it is "live" and:
  236. - it was received in the last DEFAULT_RUNNING_INTERVAL (currently 60
  237. minutes)
  238. OR - it was one of the MIN_TO_INFLUENCE_RUNNING (3) most recently received
  239. networkstatuses.
  240. Authorities always believe their own opinion as to a router's status. For
  241. other tors:
  242. - a router is valid if more than half of the live networkstatuses think
  243. it's valid.
  244. - a router is named if more than half of the live networkstatuses from
  245. naming authorities think it's named, and they all think it has the
  246. same name.
  247. - a router is running if more than half of the recent networkstatuses
  248. think it's running.
  249. Everyone downloads router descriptors as follows:
  250. - If any networkstatus lists a more recently published routerdesc with a
  251. different descriptor digest, and no more than
  252. MAX_ROUTERDESC_DOWNLOAD_FAILURES attempts to retrieve that routerdesc
  253. have failed, then that routerdesc is "downloadable".
  254. - Every DirFetchInterval, or whenever a request for routerdescs returns
  255. no routerdescs, we launch a set of requests for all downloadable
  256. routerdescs. We divide the downloadable routerdescs into groups of no
  257. more than DL_PER_REQUEST, and send a request for each group to
  258. directory servers chosen independently.
  259. - We also launch a request as above when a request for routerdescs
  260. fails and we have no directory connections fetching routerdescs.
  261. TODO Specify here:
  262. - When to 0-out failure count for networkstatus?
  263. - Drop fallback to download-all. Also, always split download.
  264. - For versions: if you're listed by more than half of live versioning
  265. networkstatuses, good. if less than half of networkstatuses are live,
  266. don't do anything. If half are live, and half of less of the
  267. versioning ones list you, warn. Only warn once every 24 hours.
  268. - For names: warn if an unnamed router is specified by nickname.
  269. Rate-limit these warnings.
  270. - Also, don't believe N->K if another naming authdir says N->K'.
  271. - Revise naming rule: N->K is true if any naming directory says N->K,
  272. and no other naming directory says N->K' or N'->K.
  273. - Minimum info to build circuits.
  274. - Revise: always split requests when we have too little info to build
  275. circuits.
  276. - Describe when router is "out of date". (Any dirserver says so.)
  277. - Change rule from "do not launch new connections when one exists" to
  278. "do not request any fingerprint that we're currently requesting."
  279. - Launch new connections every minute, plus whenever a download fails.
  280. - Reset routerdesc failure count after 60 minutes, or when
  281. when network comes back on after absence.
  282. - Make "I didn't get the one I thought was most recent" a failure.
  283. - Retry these every 5 minutes if you're a client.
  284. - Mirrors should retry these harder and more often.
  285. - If we have a routerdesc for Bob, and he says, "I'm 0.1.0.x", don't
  286. fetch a new one if it was published in the last 2 hours. (??)
  287. - Describe what we do with old server versions.
  288. - If we have less than 16 to download, do not download unless 10 minutes
  289. have passed since last download.
  290. - Which descriptors do directory servers remember?
  291. 6. Remaining issues
  292. Client-knowledge partitioning is worrisome. Most versions of this don't
  293. seem to be worse than the Danezis-Murdoch tracing attack, since an
  294. attacker can't do more than deduce probable exits from entries (or vice
  295. versa). But what about when the client connects to A and B but in a
  296. different order? How bad can it be partitioned based on its knowledge?