dir-spec.txt 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471
  1. $Id$
  2. Tor directory protocol, version 3
  3. 0. Scope and preliminaries
  4. This directory protocol is used by Tor version 0.2.0.x-alpha and later.
  5. See dir-spec-v1.txt for information on the protocol used up to the
  6. 0.1.0.x series, and dir-spec-v2.txt for information on the protocol
  7. used by the 0.1.1.x and 0.1.2.x series.
  8. Caches and authorities must still support older versions of the
  9. directory protocols, until the versions of Tor that require them are
  10. finally out of commission. See Section XXXX on backward compatibility.
  11. This document merges and supersedes the following proposals:
  12. 101 Voting on the Tor Directory System
  13. 103 Splitting identity key from regularly used signing key
  14. 104 Long and Short Router Descriptors
  15. AS OF 14 JUNE 2007, THIS SPECIFICATION HAS NOT YET BEEN COMPLETELY
  16. IMPLEMENTED, OR COMPLETELY COMPLETED.
  17. XXX when to download certificates.
  18. XXX timeline
  19. XXX fill in XXXXs
  20. 0.1. History
  21. The earliest versions of Onion Routing shipped with a list of known
  22. routers and their keys. When the set of routers changed, users needed to
  23. fetch a new list.
  24. The Version 1 Directory protocol
  25. --------------------------------
  26. Early versions of Tor (0.0.2) introduced "Directory authorities": servers
  27. that served signed "directory" documents containing a list of signed
  28. "router descriptors", along with short summary of the status of each
  29. router. Thus, clients could get up-to-date information on the state of
  30. the network automatically, and be certain that the list they were getting
  31. was attested by a trusted directory authority.
  32. Later versions (0.0.8) added directory caches, which download
  33. directories from the authorities and serve them to clients. Non-caches
  34. fetch from the caches in preference to fetching from the authorities, thus
  35. distributing bandwidth requirements.
  36. Also added during the version 1 directory protocol were "router status"
  37. documents: short documents that listed only the up/down status of the
  38. routers on the network, rather than a complete list of all the
  39. descriptors. Clients and caches would fetch these documents far more
  40. frequently than they would fetch full directories.
  41. The Version 2 Directory Protocol
  42. --------------------------------
  43. During the Tor 0.1.1.x series, Tor revised its handling of directory
  44. documents in order to address two major problems:
  45. * Directories had grown quite large (over 1MB), and most directory
  46. downloads consisted mainly of router descriptors that clients
  47. already had.
  48. * Every directory authorities was a trust bottleneck: if a single
  49. directory authority lied, it could make clients believe for a time
  50. an arbitrarily distorted view of the Tor network. (Clients
  51. trusted the most recent signed document they downloaded.) Thus,
  52. adding more authorities would make the system less secure, not
  53. more.
  54. To address these, we extended the directory protocol so that
  55. authorities now published signed "network status" documents. Each
  56. network status listed, for every router in the network: a hash of its
  57. identity key, a hash of its most recent descriptor, and a summary of
  58. what the authority believed about its status. Clients would download
  59. the authorities' network status documents in turn, and believe
  60. statements about routers iff they were attested to by more than half of
  61. the authorities.
  62. Instead of downloading all router descriptors at once, clients
  63. downloaded only the descriptors that they did not have. Descriptors
  64. were indexed by their digests, in order to prevent malicious caches
  65. from giving different versions of a router descriptor to different
  66. clients.
  67. Routers began working harder to upload new descriptors only when their
  68. contents were substantially changed.
  69. 0.2. Goals of the version 3 protocol
  70. Version 3 of the Tor directory protocol tries to solve the following
  71. issues:
  72. * A great deal of bandwidth used to transmit router descriptors was
  73. used by two fields that are not actually used by Tor routers
  74. (namely read-history and write-history). We save about 60% by
  75. moving them into a separate document that most clients do not
  76. fetch or use.
  77. * It was possible under certain perverse circumstances for clients
  78. to download an unusual set of network status documents, thus
  79. partitioning themselves from clients who have a more recent and/or
  80. typical set of documents. Even under the best of circumstances,
  81. clients were sensitive to the ages of the network status documents
  82. they downloaded. Therefore, instead of having the clients
  83. correlate multiple network status documents, we have the
  84. authorities collectively vote on a single consensus network status
  85. document.
  86. * The most sensitive data in the entire network (the identity keys
  87. of the directory authorities) needed to be stored unencrypted so
  88. that the authorities can sign network-status documents on the fly.
  89. Now, the authorities' identity keys are stored offline, and used
  90. to certify medium-term signing keys that can be rotated.
  91. 0.3. Some Remaining questions
  92. Things we could solve on a v3 timeframe:
  93. The SHA-1 hash is showing its age. We should do something about our
  94. dependency on it. We could probably future-proof ourselves here in
  95. this revision, at least so far as documents from the authorities are
  96. concerned.
  97. Too many things about the authorities are hardcoded by IP.
  98. Perhaps we should start accepting longer identity keys for routers
  99. too.
  100. Things to solve eventually:
  101. Requiring every client to know about every router won't scale forever.
  102. Requiring every directory cache to know every router won't scale
  103. forever.
  104. 1. Outline
  105. There is a small set (say, around 5-10) of semi-trusted directory
  106. authorities. A default list of authorities is shipped with the Tor
  107. software. Users can change this list, but are encouraged not to do so,
  108. in order to avoid partitioning attacks.
  109. Every authority has a very-secret, long-term "Authority Identity Key".
  110. This is stored encrypted and/or offline, and is used to sign "key
  111. certificate" documents. Every key certificate contains a medium-term
  112. (3-12 months) "authority signing key", that is used by the authority to
  113. sign other directory information. (Note that the authority identity
  114. key is distinct from the router identity key that the authority uses
  115. in its role as an ordinary router.)
  116. Routers periodically upload signed "routers descriptors" to the
  117. directory authorities describing their keys, capabilities, and other
  118. information. Routers may also upload signed "extra info documents"
  119. containing information that is not required for the Tor protocol.
  120. Directory authorities serve router descriptors indexed by router
  121. identity, or by hash of the descriptor.
  122. Routers may act as directory caches to reduce load on the directory
  123. authorities. They announce this in their descriptors.
  124. Periodically, each directory authority periodically generates a view of
  125. the current descriptors and status for known routers. They send a
  126. signed summary of this view (a "status vote") to the other
  127. authorities. The authorities compute the result of this vote, and sign
  128. a "consensus status" document containing the result of the vote.
  129. Directory caches download, cache, and re-serve consensus documents.
  130. Clients, directory caches, and directory authorities all use consensus
  131. documents to find out when their list of routers is out-of-date.
  132. (Directory authorities also use vote statuses.) If it is, they download
  133. any missing router descriptors. Clients download missing descriptors
  134. from caches; caches and authorities download from authorities.
  135. Descriptors are downloaded by the hash of the descriptor, not by the
  136. server's identity key: this prevents servers from attacking clients by
  137. giving them descriptors nobody else uses.
  138. All directory information is uploaded and downloaded with HTTP.
  139. [Authorities also generate and caches also cache documents produced and
  140. used by earlier versions of this protocol; see section XXX for notes.]
  141. 1.1. What's different from version 2?
  142. Clients used to download a multiple network status documents,
  143. corresponding roughly to "status votes" above. They would compute the
  144. result of the vote on the client side.
  145. Authorities used to sign documents using the same private keys they used
  146. for their roles as routers. This forced them to keep these extremely
  147. sensitive keys in memory unencrypted.
  148. All of the information in extra-info documents used to be kept in the
  149. main descriptors.
  150. 1.2. Document meta-format
  151. Router descriptors, directories, and running-routers documents all obey the
  152. following lightweight extensible information format.
  153. The highest level object is a Document, which consists of one or more
  154. Items. Every Item begins with a KeywordLine, followed by zero or more
  155. Objects. A KeywordLine begins with a Keyword, optionally followed by
  156. whitespace and more non-newline characters, and ends with a newline. A
  157. Keyword is a sequence of one or more characters in the set [A-Za-z0-9-].
  158. An Object is a block of encoded data in pseudo-Open-PGP-style
  159. armor. (cf. RFC 2440)
  160. More formally:
  161. Document ::= (Item | NL)+
  162. Item ::= KeywordLine Object*
  163. KeywordLine ::= Keyword NL | Keyword WS ArgumentsChar+ NL
  164. Keyword = KeywordChar+
  165. KeywordChar ::= 'A' ... 'Z' | 'a' ... 'z' | '0' ... '9' | '-'
  166. ArgumentChar ::= any printing ASCII character except NL.
  167. WS = (SP | TAB)+
  168. Object ::= BeginLine Base-64-encoded-data EndLine
  169. BeginLine ::= "-----BEGIN " Keyword "-----" NL
  170. EndLine ::= "-----END " Keyword "-----" NL
  171. The BeginLine and EndLine of an Object must use the same keyword.
  172. When interpreting a Document, software MUST ignore any KeywordLine that
  173. starts with a keyword it doesn't recognize; future implementations MUST NOT
  174. require current clients to understand any KeywordLine not currently
  175. described.
  176. The "opt" keyword was used until Tor 0.1.2.5-alpha for non-critical future
  177. extensions. All implementations MUST ignore any item of the form "opt
  178. keyword ....." when they would not recognize "keyword ....."; and MUST
  179. treat "opt keyword ....." as synonymous with "keyword ......" when keyword
  180. is recognized.
  181. Implementations before 0.1.2.5-alpha rejected any document with a
  182. KeywordLine that started with a keyword that they didn't recognize.
  183. When generating documents that need to be read by older versions of Tor,
  184. implementations MUST prefix items not recognized by older versions of
  185. Tor with an "opt" until those versions of Tor are obsolete. [Note that
  186. key certificates, status vote documents, extra info documents, and
  187. status consensus documents will never by read by older versions of Tor.]
  188. Other implementations that want to extend Tor's directory format MAY
  189. introduce their own items. The keywords for extension items SHOULD start
  190. with the characters "x-" or "X-", to guarantee that they will not conflict
  191. with keywords used by future versions of Tor.
  192. In our document descriptions below, we tag Items with a multiplicity in
  193. brackets. Possible tags are:
  194. "At start, exactly once": These items MUST occur in every instance of
  195. the document type, and MUST appear exactly once, and MUST be the
  196. first item in their documents.
  197. "Exactly once": These items MUST occur exactly one time in every
  198. instance of the document type.
  199. "At end, exactly once": These items MUST occur in every instance of
  200. the document type, and MUST appear exactly once, and MUST be the
  201. last item in their documents.
  202. "At most once": These items MAY occur zero or one times in any
  203. instance of the document type, but MUST NOT occur more than once.
  204. "Any number": These items MAY occur zero, one, or more times in any
  205. instance of the document type.
  206. "Once or more": These items MUST occur at least once in any instance
  207. of the document type, and MAY occur more.
  208. 1.3. Signing documents
  209. Every signable document below is signed in a similar manner, using a
  210. given "Initial Item", a final "Signature Item", a digest algorithm, and
  211. a signing key.
  212. The Initial Item must be the first item in the document.
  213. The Signature Item has the following format:
  214. <signature item keyword> [arguments] NL SIGNATURE NL
  215. The "SIGNATURE" Object contains a signature (using the signing key) of
  216. the PKCS1-padded digest of the entire document, taken from the
  217. beginning of the Initial item, through the newline after the Signature
  218. Item's keyword and its arguments.
  219. Unless otherwise, the digest algorithm is SHA-1.
  220. All documents are invalid unless signed with the correct signing key.
  221. The "Digest" of a document, unless stated otherwise, is its digest *as
  222. signed by this signature scheme*.
  223. 2. Router operation and formats
  224. ORs SHOULD generate a new router descriptor and a new extra-info
  225. document whenever any of the following events have occurred:
  226. - A period of time (18 hrs by default) has passed since the last
  227. time a descriptor was generated.
  228. - A descriptor field other than bandwidth or uptime has changed.
  229. - Bandwidth has changed by more than +/- 50% from the last time a
  230. descriptor was generated, and at least a given interval of time
  231. (20 mins by default) has passed since then.
  232. - Its uptime has been reset (by restarting).
  233. After generating a descriptor, ORs upload them to every directory
  234. authority they know, by posting them (in order) to the URL
  235. http://<hostname:port>/tor/
  236. 2.1. Router descriptor format
  237. Router descriptors consist of the following items. For backward
  238. compatibility, there should be an extra NL at the end of each router
  239. descriptor.
  240. In lines that take multiple arguments, extra arguments SHOULD be
  241. accepted and ignored. Many of the nonterminals below are defined in
  242. section 2.3.
  243. "router" nickname address ORPort SOCKSPort DirPort NL
  244. [At start, exactly once.]
  245. Indicates the beginning of a router descriptor. "nickname" must be a
  246. valid router nickname as specified in 2.3. "address" must be an IPv4
  247. address in dotted-quad format. The last three numbers indicate the
  248. TCP ports at which this OR exposes functionality. ORPort is a port at
  249. which this OR accepts TLS connections for the main OR protocol;
  250. SOCKSPort is deprecated and should always be 0; and DirPort is the
  251. port at which this OR accepts directory-related HTTP connections. If
  252. any port is not supported, the value 0 is given instead of a port
  253. number. (At least one of DirPort and ORPort SHOULD be set;
  254. authorities MAY reject any descriptor with both DirPort and ORPort of
  255. 0.)
  256. "bandwidth" bandwidth-avg bandwidth-burst bandwidth-observed NL
  257. [Exactly once]
  258. Estimated bandwidth for this router, in bytes per second. The
  259. "average" bandwidth is the volume per second that the OR is willing to
  260. sustain over long periods; the "burst" bandwidth is the volume that
  261. the OR is willing to sustain in very short intervals. The "observed"
  262. value is an estimate of the capacity this server can handle. The
  263. server remembers the max bandwidth sustained output over any ten
  264. second period in the past day, and another sustained input. The
  265. "observed" value is the lesser of these two numbers.
  266. "platform" string NL
  267. [At most once]
  268. A human-readable string describing the system on which this OR is
  269. running. This MAY include the operating system, and SHOULD include
  270. the name and version of the software implementing the Tor protocol.
  271. "published" YYYY-MM-DD HH:MM:SS NL
  272. [Exactly once]
  273. The time, in GMT, when this descriptor (and its corresponding
  274. extra-info document if any) was generated.
  275. "fingerprint" fingerprint NL
  276. [At most once]
  277. A fingerprint (a HASH_LEN-byte of asn1 encoded public key, encoded in
  278. hex, with a single space after every 4 characters) for this router's
  279. identity key. A descriptor is considered invalid (and MUST be
  280. rejected) if the fingerprint line does not match the public key.
  281. [We didn't start parsing this line until Tor 0.1.0.6-rc; it should
  282. be marked with "opt" until earlier versions of Tor are obsolete.]
  283. "hibernating" bool NL
  284. [At most once]
  285. If the value is 1, then the Tor server was hibernating when the
  286. descriptor was published, and shouldn't be used to build circuits.
  287. [We didn't start parsing this line until Tor 0.1.0.6-rc; it should be
  288. marked with "opt" until earlier versions of Tor are obsolete.]
  289. "uptime" number NL
  290. [At most once]
  291. The number of seconds that this OR process has been running.
  292. "onion-key" NL a public key in PEM format
  293. [Exactly once]
  294. This key is used to encrypt EXTEND cells for this OR. The key MUST be
  295. accepted for at least 1 week after any new key is published in a
  296. subsequent descriptor. It MUST be 1024 bits.
  297. "signing-key" NL a public key in PEM format
  298. [Exactly once]
  299. The OR's long-term identity key. It MUST be 1024 bits.
  300. "accept" exitpattern NL
  301. "reject" exitpattern NL
  302. [Any number]
  303. These lines describe an "exit policy": the rules that an OR follows when
  304. deciding whether to allow a new stream to a given address. The
  305. 'exitpattern' syntax is described below. The rules are considered in
  306. order; if no rule matches, the address will be accepted. For clarity,
  307. the last such entry SHOULD be accept *:* or reject *:*.
  308. "router-signature" NL Signature NL
  309. [At end, exactly once]
  310. The "SIGNATURE" object contains a signature of the PKCS1-padded
  311. hash of the entire router descriptor, taken from the beginning of the
  312. "router" line, through the newline after the "router-signature" line.
  313. The router descriptor is invalid unless the signature is performed
  314. with the router's identity key.
  315. "contact" info NL
  316. [At most once]
  317. Describes a way to contact the server's administrator, preferably
  318. including an email address and a PGP key fingerprint.
  319. "family" names NL
  320. [At most once]
  321. 'Names' is a space-separated list of server nicknames or
  322. hexdigests. If two ORs list one another in their "family" entries,
  323. then OPs should treat them as a single OR for the purpose of path
  324. selection.
  325. For example, if node A's descriptor contains "family B", and node B's
  326. descriptor contains "family A", then node A and node B should never
  327. be used on the same circuit.
  328. "read-history" YYYY-MM-DD HH:MM:SS (NSEC s) NUM,NUM,NUM,NUM,NUM... NL
  329. [At most once]
  330. "write-history" YYYY-MM-DD HH:MM:SS (NSEC s) NUM,NUM,NUM,NUM,NUM... NL
  331. [At most once]
  332. Declare how much bandwidth the OR has used recently. Usage is divided
  333. into intervals of NSEC seconds. The YYYY-MM-DD HH:MM:SS field
  334. defines the end of the most recent interval. The numbers are the
  335. number of bytes used in the most recent intervals, ordered from
  336. oldest to newest.
  337. [We didn't start parsing these lines until Tor 0.1.0.6-rc; they should
  338. be marked with "opt" until earlier versions of Tor are obsolete.]
  339. [See also migration notes in section 2.2.1.]
  340. "eventdns" bool NL
  341. [At most once]
  342. Declare whether this version of Tor is using the newer enhanced
  343. dns logic. Versions of Tor with this field set to false SHOULD NOT
  344. be used for reverse hostname lookups.
  345. [All versions of Tor before 0.1.2.2-alpha should be assumed to have
  346. this option set to 0 if it is not present. All Tor versions at
  347. 0.1.2.2-alpha or later should be assumed to have this option set to
  348. 1 if it is not present. Until 0.1.2.1-alpha-dev, this option was
  349. not generated, even when the new DNS code was in use. Versions of Tor
  350. before 0.1.2.1-alpha-dev did not parse this option, so it should be
  351. marked "opt". The dnsworker logic has been removed, so this option
  352. should not be used by new server code. However, it can still be
  353. used, and should still be recognized by new code until Tor 0.1.2.x
  354. is obsolete.]
  355. "caches-extra-info" NL
  356. [At most once.]
  357. Present only if this router is a directory cache that provides
  358. extra-info documents.
  359. [Versions before 0.2.0.1-alpha don't recognize this, and versions
  360. before 0.1.2.5-alpha will reject descriptors containing it unless
  361. it is prefixed with "opt"; it should be so prefixed until these
  362. versions are obsolete.]
  363. "extra-info-digest" digest NL
  364. [At most once]
  365. "Digest" is a hex-encoded digest (using upper-case characters) of the
  366. router's extra-info document, as signed in the router's extra-info
  367. (that is, not including the signature). (If this field is absent, the
  368. router is not uploading a corresponding extra-info document.)
  369. [Versions before 0.2.0.1-alpha don't recognize this, and versions
  370. before 0.1.2.5-alpha will reject descriptors containing it unless
  371. it is prefixed with "opt"; it should be so prefixed until these
  372. versions are obsolete.]
  373. 2.2. Extra-info documents
  374. Extra-info documents consist of the following items:
  375. "extra-info" Nickname Fingerprint NL
  376. [At start, exactly once.]
  377. Identifies what router this is an extra info descriptor for.
  378. Fingerprint is encoded in hex (using upper-case letters), with
  379. no spaces.
  380. "published"
  381. [Exactly once.]
  382. The time, in GMT, when this document (and its corresponding router
  383. descriptor if any) was generated. It MUST match the published time
  384. in the corresponding router descriptor.
  385. "read-history" YYYY-MM-DD HH:MM:SS (NSEC s) NUM,NUM,NUM,NUM,NUM... NL
  386. [At most once.]
  387. "write-history" YYYY-MM-DD HH:MM:SS (NSEC s) NUM,NUM,NUM,NUM,NUM... NL
  388. [At most once.]
  389. As documented in 2.1 above. See migration notes in section 2.2.1.
  390. "router-signature" NL Signature NL
  391. [At end, exactly once.]
  392. A document signature as documented in section 1.3, using the
  393. initial item "extra-info" and the final item "router-signature",
  394. signed with the router's identity key.
  395. 2.2.1. Moving history fields to extra-info documents.
  396. Tools that want to use the read-history and write-history values SHOULD
  397. download extra-info documents as well as router descriptors. Such
  398. tools SHOULD accept history values from both sources; if they appear in
  399. both documents, the values in the extra-info documents are authoritative.
  400. At some future time, to save space, new versions of Tor will no longer
  401. generate router descriptors containing read-history or write-history.
  402. Tools should continue to accept read-history and write-history values
  403. in router descriptors produced by older versions of Tor.
  404. 2.3. Nonterminals in router descriptors
  405. nickname ::= between 1 and 19 alphanumeric characters, case-insensitive.
  406. hexdigest ::= a '$', followed by 20 hexadecimal characters.
  407. [Represents a server by the digest of its identity key.]
  408. exitpattern ::= addrspec ":" portspec
  409. portspec ::= "*" | port | port "-" port
  410. port ::= an integer between 1 and 65535, inclusive.
  411. [Some implementations incorrectly generate ports with value 0.
  412. Implementations SHOULD accept this, and SHOULD NOT generate it.
  413. Connections to port 0 are never permitted.]
  414. addrspec ::= "*" | ip4spec | ip6spec
  415. ipv4spec ::= ip4 | ip4 "/" num_ip4_bits | ip4 "/" ip4mask
  416. ip4 ::= an IPv4 address in dotted-quad format
  417. ip4mask ::= an IPv4 mask in dotted-quad format
  418. num_ip4_bits ::= an integer between 0 and 32
  419. ip6spec ::= ip6 | ip6 "/" num_ip6_bits
  420. ip6 ::= an IPv6 address, surrounded by square brackets.
  421. num_ip6_bits ::= an integer between 0 and 128
  422. bool ::= "0" | "1"
  423. 3. Formats produced by directory authorities.
  424. Every authority has two keys used in this protocol: a signing key, and
  425. an authority identity key. (Authorities also have a router identity
  426. key used in their role as a router and by earlier versions of the
  427. directory protocol.) The identity key is used from time to time to
  428. sign new key certificates using new signing keys; it is very sensitive.
  429. The signing key is used to sign key certificates and status documents.
  430. There are three kinds of documents generated by directory authorities:
  431. Key certificates
  432. Status votes
  433. Status consensuses
  434. Each is discussed below.
  435. 3.1. Key certificates
  436. Key certificates consist of the following items:
  437. "dir-key-certificate-version" version NL
  438. [At start, exactly once.]
  439. Determines the version of the key certificate. MUST be "3" for
  440. the protocol described in this document. Implementations MUST
  441. reject formats they don't understand.
  442. "fingerprint" fingerprint NL
  443. [Exactly once.]
  444. Hexadecimal encoding without spaces based on the authority's
  445. identity key.
  446. "dir-identity-key" NL a public key in PEM format
  447. [Exactly once.]
  448. The long-term authority identity key for this authority. This key
  449. SHOULD be at least 2048 bits long; it MUST NOT be shorter than
  450. 1024 bits.
  451. "dir-key-published" YYYY-MM-DD HH:MM:SS NL
  452. [Exactly once.]
  453. The time (in GMT) when this document and corresponding key were
  454. last generated.
  455. "dir-key-expires" YYYY-MM-DD HH:MM:SS NL
  456. [Exactly once.]
  457. A time (in GMT) after which this key is no longer valid.
  458. "dir-signing-key" NL a key in PEM format
  459. [Exactly once.]
  460. The directory server's public signing key. This key MUST be at
  461. least 1024 bits, and MAY be longer.
  462. "dir-key-certification" NL Signature NL
  463. [At end, exactly once.]
  464. A document signature as documented in section 1.3, using the
  465. initial item "dir-key-certificate-version" and the final item
  466. "dir-key-certification", signed with the authority identity key.
  467. Authorities MUST generate a new signing key and corresponding
  468. certificate before the key expires.
  469. 3.2. Vote and consensus status documents
  470. Votes and consensuses are more strictly formatted then other documents
  471. in this specification, since different authorities must be able to
  472. generate exactly the same consensus given the same set of votes.
  473. The procedure for deciding when to generate vote and consensus status
  474. documents are described in section XXX below.
  475. Status documents contain a preamble, an authority section, a list of
  476. router status entries, and one more footers signature, in that order.
  477. Unlike other formats described above, a SP in these documents must be a
  478. single space character (hex 20).
  479. Some items appear only in votes, and some items appear only in
  480. consensuses. Unless specified, items occur in both.
  481. The preamble contains the following items. They MUST occur in the
  482. order given here:
  483. "network-status-version" SP version NL.
  484. [At start, exactly once.]
  485. A document format version. For this specification, the version is
  486. "3".
  487. "vote-status" SP type NL
  488. [Exactly once.]
  489. The status MUST be "vote" or "consensus", depending on the type of
  490. the document.
  491. "published" SP YYYY-MM-DD SP HH:MM:SS NL
  492. [Exactly once for votes; does not occur in consensuses.]
  493. The publication time for this status document (if a vote).
  494. "valid-after" SP YYYY-MM-DD SP HH:MM:SS NL
  495. [Exactly once.]
  496. The start of the Interval for this vote. XXXX
  497. "fresh-until" SP YYYY-MM-DD SP HH:MM:SS NL
  498. [Exactly once.]
  499. XXXX
  500. "valid-until" SP YYYY-MM-DD SP HH:MM:SS NL
  501. [Exactly once.]
  502. The end of the Interval for this vote. XXXX
  503. "voting-delay" SP VoteSeconds SP DistSeconds NL
  504. [Exactly once.]
  505. XXXX
  506. "client-versions" SP VersionList NL
  507. [At most once.]
  508. A comma-separated list of recommended client versions, in
  509. ascending order. If absent, no opinion is held about client
  510. versions.
  511. "server-versions" SP VersionList NL
  512. [At most once.]
  513. A comma-separated list of recommended server versions, in
  514. ascending order. If absent, no opinion is held about server
  515. versions.
  516. "known-flags" SP FlagList NL
  517. [Exactly once.]
  518. A space-separated list of all of the flags that this document
  519. might contain. A flag is "known" either because the authority
  520. knows about them and might set them (if in a vote), or because
  521. enough votes were counted for the consensus for an authoritative
  522. opinion to have been formed about their status.
  523. The authority section of a vote contains the following items, followed
  524. in turn by the authority's current key certificate:
  525. "dir-source" SP nickname SP identity SP address SP IP SP dirport SP
  526. orport NL
  527. [Exactly once, at start]
  528. Describes this authority. The nickname is a convenient identifier
  529. for the authority. The identity is an uppercase hex fingerprint of
  530. the authority's current (v3 authority) identity key. The address is
  531. the server's hostname. The IP is the server's current IP address,
  532. and dirport is its current directory port. XXXXorport
  533. "contact" SP string NL
  534. [At most once.]
  535. An arbitrary string describing how to contact the directory
  536. server's administrator. Administrators should include at least an
  537. email address and a PGP fingerprint.
  538. The authority section of a consensus contains groups the following items,
  539. in the order given, with one group for each authority that contributed to
  540. the consensus, with groups sorted by authority identity digest:
  541. "dir-source" SP nickname SP identity SP address SP IP SP dirport SP
  542. orport NL
  543. [Exactly once, at start]
  544. As in the authority section of a vote.
  545. "contact" SP string NL
  546. [At most once.]
  547. As in the authority section of a vote.
  548. "vote-digest" SP digest NL
  549. [Exactly once.]
  550. A digest of the vote from the authority that contributed to this
  551. consensus, as signed (that is, not including the signature).
  552. (Hex, upper-case.)
  553. Each router status entry contains the following items. Router status
  554. entries are sorted in ascending order by identity digest.
  555. "r" SP nickname SP identity SP digest SP publication SP IP SP ORPort
  556. SP DirPort NL
  557. [At start, exactly once.]
  558. "Nickname" is the OR's nickname. "Identity" is a hash of its
  559. identity key, encoded in base64, with trailing equals sign(s)
  560. removed. "Digest" is a hash of its most recent descriptor as
  561. signed (that is, not including the signature), encoded in base64 as
  562. "identity". "Publication" is the
  563. publication time of its most recent descriptor, in the form
  564. YYYY-MM-DD HH:MM:SS, in GMT. "IP" is its current IP address;
  565. ORPort is its current OR port, "DirPort" is it's current directory
  566. port, or "0" for "none".
  567. "s" SP Flags NL
  568. [At most once.]
  569. A series of space-separated status flags, in alphabetical order.
  570. Currently documented flags are:
  571. "Authority" if the router is a directory authority.
  572. "BadExit" if the router is believed to be useless as an exit node
  573. (because its ISP censors it, because it is behind a restrictive
  574. proxy, or for some similar reason).
  575. "BadDirectory" if the router is believed to be useless as a
  576. directory cache (because its directory port isn't working,
  577. its bandwidth is always throttled, or for some similar
  578. reason).
  579. "Exit" if the router is useful for building general-purpose exit
  580. circuits.
  581. "Fast" if the router is suitable for high-bandwidth circuits.
  582. "Guard" if the router is suitable for use as an entry guard.
  583. "Named" if the router's identity-nickname mapping is canonical,
  584. and this authority binds names.
  585. "Stable" if the router is suitable for long-lived circuits.
  586. "Running" if the router is currently usable.
  587. "Valid" if the router has been 'validated'.
  588. "V2Dir" if the router implements the v2 directory protocol.
  589. "V3Dir" if the router implements this protocol.
  590. "v" SP version NL
  591. [At most once.]
  592. The version of the Tor protocol that this server is running. If
  593. the value begins with "Tor" SP, the rest of the string is a Tor
  594. version number, and the protocol is "The Tor protocol as supported
  595. by the given version of Tor." Otherwise, if the value begins with
  596. some other string, Tor has upgraded to a more sophisticated
  597. protocol versioning system, and the protocol is "a version of the
  598. Tor protocol more recent than any we recognize."
  599. The signature section contains the following item, which appears
  600. Exactly Once for a vote, and At Least Once for a consensus.
  601. "directory-signature" SP identity SP signing-key-digest NL Signature
  602. This is a signature of the status document, with the initial item
  603. "network-status-version", and the signature item
  604. "directory-signature", using the signing key. (In this case, we take
  605. the hash through the _space_ after directory-signature, not the
  606. newline: this ensures that all authorities sign the same thing.)
  607. "identity" is the hex-encoded digest of the authority identity key of
  608. the signing authority, and "signing-key-digest" is the hex-encoded
  609. digest of the current authority signing key of the signing authority.
  610. 3.3. Deciding how to vote.
  611. (This section describes how directory authorities choose which status
  612. flags to apply to routers, as of Tor 0.2.0.0-alpha-dev. Later directory
  613. authorities MAY do things differently, so long as clients keep working
  614. well. Clients MUST NOT depend on the exact behaviors in this section.)
  615. In the below definitions, a router is considered "active" if it is
  616. running, valid, and not hibernating.
  617. "Valid" -- a router is 'Valid' if it is running a version of Tor not
  618. known to be broken, and the directory authority has not blacklisted
  619. it as suspicious.
  620. "Named" -- Directory authority administrators may decide to support name
  621. binding. If they do, then they must maintain a file of
  622. nickname-to-identity-key mappings, and try to keep this file consistent
  623. with other directory authorities. If they don't, they act as clients, and
  624. report bindings made by other directory authorities (name X is bound to
  625. identity Y if at least one binding directory lists it, and no directory
  626. binds X to some other Y'.) A router is called 'Named' if the router
  627. believes the given name should be bound to the given key.
  628. "Running" -- A router is 'Running' if the authority managed to connect to
  629. it successfully within the last 30 minutes.
  630. "Stable" -- A router is 'Stable' if it is active, and either its
  631. uptime is at least the median uptime for known active routers, or
  632. its uptime is at least 30 days. Routers are never called stable if
  633. they are running a version of Tor known to drop circuits stupidly.
  634. (0.1.1.10-alpha through 0.1.1.16-rc are stupid this way.)
  635. "Fast" -- A router is 'Fast' if it is active, and its bandwidth is
  636. in the top 7/8ths for known active routers.
  637. "Guard" -- A router is a possible 'Guard' if it is 'Stable' and its
  638. bandwidth is above median for known active routers. If the total
  639. bandwidth of active non-BadExit Exit servers is less than one third
  640. of the total bandwidth of all active servers, no Exit is listed as
  641. a Guard.
  642. "Authority" -- A router is called an 'Authority' if the authority
  643. generating the network-status document believes it is an authority.
  644. "V2Dir" -- A router supports the v2 directory protocol if it has an open
  645. directory port, and it is running a version of the directory protocol that
  646. supports the functionality clients need. (Currently, this is
  647. 0.1.1.9-alpha or later.)
  648. "V3Dir" -- A router supports the v3 directory protocol if it has an open
  649. directory port, and it is running a version of the directory protocol that
  650. supports the functionality clients need. (Currently, this is
  651. 0.2.0.?????-alpha or later.)
  652. Directory server administrators may label some servers or IPs as
  653. blacklisted, and elect not to include them in their network-status lists.
  654. Thus, the network-status list includes all non-blacklisted,
  655. non-expired, non-superseded descriptors.
  656. 3.4. Computing a consensus from a set of votes
  657. Given a set of votes, authorities compute the contents of the consensus
  658. document as follows:
  659. The "valid-after", "valid-until", and "fresh-until" times are taken as
  660. the median of the respective values from all the votes.
  661. The times in the "voting-delay" line are taken as the median of the
  662. VoteSeconds and DistSeconds times in the votes.
  663. Known-flags is the union of all flags known by any voter.
  664. "client-versions" and "server-versions" are sorted in ascending
  665. order; A version is recommended in the consensus if it is recommended
  666. by more than half of the voting authorities that included a
  667. client-versions or server-versions lines in their votes.
  668. The authority item groups (dir-source, contact, fignerprint,
  669. vote-digest) are taken from the votes of the voting
  670. authorities. These groups are sorted by the digests of the
  671. authorities identity keys, in ascending order.
  672. A router status entry:
  673. * is included in the result if some router status entry with the same
  674. identity is included by more than half of the authorities (total
  675. authorities, not just those whose votes we have).
  676. * For any given identity, we include at most one router status entry.
  677. * A router entry has a flag set if that is included by more than half
  678. of the authorities who care about that flag.
  679. * Two router entries are "the same" if they have the same
  680. <descriptor digest, published time, nickname, IP, ports> tuple.
  681. We choose the tuple for a given router as whichever tuple appears
  682. for that router in the most votes. We break ties in favor of
  683. the more recently published.
  684. * The Named flag appears if it is included for this routerstatus by
  685. _any_ authority, and if all authorities that list it list the same
  686. nickname.
  687. * The version is given as whichever version is listed by the most
  688. voters, with ties decided in favor of more recent versions.
  689. The signatures at the end of a consensus document are sorted in
  690. ascending order by identity digest.
  691. 3.5. Detached signatures
  692. Assuming full connectivity, every authority should compute and sign the
  693. same consensus directory in each period. Therefore, it isn't necessary to
  694. download the consensus computed by each authority; instead, the
  695. authorities only push/fetch each others' signatures. A "detached
  696. signature" document contains items as follows:
  697. "consensus-digest" SP Digest NL
  698. [At start, at most once.]
  699. The digest of the consensus being signed.
  700. "valid-after" SP YYYY-MM-DD SP HH:MM:SS NL
  701. "fresh-until" SP YYYY-MM-DD SP HH:MM:SS NL
  702. "valid-until" SP YYYY-MM-DD SP HH:MM:SS NL
  703. [As in the consensus]
  704. "directory-signature"
  705. [As in the consensus; the signature object is the same as in the
  706. consensus document.]
  707. 4. Directory server operation
  708. All directory authorities and directory caches ("directory servers")
  709. implement this section, except as noted.
  710. 4.1. Accepting uploads (authorities only)
  711. When a router posts a signed descriptor to a directory authority, the
  712. authority first checks whether it is well-formed and correctly
  713. self-signed. If it is, the authority next verifies that the nickname
  714. question is already assigned to a router with a different public key.
  715. Finally, the authority MAY check that the router is not blacklisted
  716. because of its key, IP, or another reason.
  717. If the descriptor passes these tests, and the authority does not already
  718. have a descriptor for a router with this public key, it accepts the
  719. descriptor and remembers it.
  720. If the authority _does_ have a descriptor with the same public key, the
  721. newly uploaded descriptor is remembered if its publication time is more
  722. recent than the most recent old descriptor for that router, and either:
  723. - There are non-cosmetic differences between the old descriptor and the
  724. new one.
  725. - Enough time has passed between the descriptors' publication times.
  726. (Currently, 12 hours.)
  727. Differences between router descriptors are "non-cosmetic" if they would be
  728. sufficient to force an upload as described in section 2 above.
  729. Note that the "cosmetic difference" test only applies to uploaded
  730. descriptors, not to descriptors that the authority downloads from other
  731. authorities.
  732. When a router posts a signed extra-info document to a directory authority,
  733. the authority again checks it for well-formedness and correct signature,
  734. and checks that its matches the extra-info-digest in some router
  735. descriptor that it believes is currently useful. If so, it accepts it and
  736. stores it and serves it as requested. If not, it drops it.
  737. 4.2. Voting (authorities only)
  738. Authorities divide time into Intervals. Authority administrators SHOULD
  739. try to all pick the same interval length, and SHOULD pick intervals that
  740. are commonly used divisions of time (e.g., 5 minutes, 15 minutes, 30
  741. minutes, 60 minutes, 90 minutes). Voting intervals SHOULD be chosen to
  742. divide evenly into a 24-hour day.
  743. Authorities MUST take pains to ensure that their clocks remain accurate,
  744. for example by running NTP.
  745. The first voting period of each day begins at 00:00 (midnight) GMT. If
  746. the last period of the day would be truncated by one-half or more, it is
  747. merged with the second-to-last period.
  748. An authority SHOULD publish its vote immediately at the start of each voting
  749. period. It does this by making it available at
  750. http://<hostname>/tor/status-vote/current/authority.z
  751. and sending it in an HTTP POST request to each other authority at the URL
  752. http://<hostname>/tor/post/vote
  753. (Note that this requires the authority to settle upon and finalize its
  754. vote slightly before the start of the voting period.)
  755. If, VOTING_DELAY minutes after the voting period has begun, an authority
  756. does not have a current statement from another authority, the first
  757. authority retrieves the other's statement.
  758. Once an authority has a vote from another authority, it makes it available
  759. at
  760. http://<hostname>/tor/status-vote/current/<fp>.z
  761. where <fp> is the fingerprint of the other authority's identity key.
  762. The consensus status, along with as many signatures as the server
  763. currently knows, should be available at
  764. http://<hostname>/tor/status-vote/current/consensus.z
  765. All of the detached signatures it knows for consensus status should be
  766. available at:
  767. http://<hostname>/tor/status-vote/current/consensus-signatures.z
  768. Once an authority has computed and signed a consensus network status, it
  769. should send its detached signature to each other authority in an HTTP POST
  770. request to the URL:
  771. http://<hostname>/tor/post/consensus-signature
  772. [XXX Note why we support push-and-then-pull.]
  773. [XXX possible future features include support for downloading old
  774. consensuses.]
  775. [XXX Constants: VOTING_DELAY, CONSENSUS_DELAY]
  776. 4.3. Downloading consensus status documents (caches only)
  777. All directory servers (authorities and caches) try to keep a fresh
  778. set of network-status consensus documents to serve to clients. Every
  779. 15 minutes, or whenever the valid-until field on its most current
  780. consensus is about to expire
  781. [XXXX finish this section]
  782. 4.4. Downloading and storing router descriptors (authorities and caches)
  783. Periodically (currently, every 10 seconds), directory servers check
  784. whether there are any specific descriptors that they do not have and that
  785. they are not currently trying to download. Caches identify these
  786. descriptors by hash in the recent network-status consensus documents;
  787. authorities identify them by hash in vote (if publication date is more
  788. recent than the descriptor we currently have).
  789. [XXXX need a way to fetch descriptors ahead of the vote? v2 status docs can
  790. do that for now.]
  791. If so, the directory server launches requests to the authorities for these
  792. descriptors, such that each authority is only asked for descriptors listed
  793. in its most recent vote (if the requester is an authority) or in the
  794. consensus (if the requester is a cache). If we're an authority, and more
  795. than one authority lists the descriptor, we choose which to ask at random.
  796. If one of these downloads fails, we do not try to download that descriptor
  797. from the authority that failed to serve it again unless we receive a newer
  798. network-status (consensus or vote) from that authority that lists the same
  799. descriptor.
  800. Directory servers must potentially cache multiple descriptors for each
  801. router. Servers must not discard any descriptor listed by any recent
  802. consensus. If there is enough space to store additional descriptors,
  803. servers SHOULD try to hold those which clients are likely to download the
  804. most. (Currently, this is judged based on the interval for which each
  805. descriptor seemed newest.)
  806. [XXXX define recent]
  807. Authorities SHOULD NOT download descriptors for routers that they would
  808. immediately reject for reasons listed in 3.1.
  809. 4.5. Downloading and storing extra-info documents
  810. All authorities, and any cache that chooses to cache extra-info documents,
  811. and any client that uses extra-info documents, should implement this
  812. section.
  813. Note that generally, clients don't need extra-info documents.
  814. Periodically, the Tor instance checks whether it is missing any extra-info
  815. documents: in other words, if it has any router descriptors with an
  816. extra-info-digest field that does not match any of the extra-info
  817. documents currently held. If so, it downloads whatever extra-info
  818. documents are missing. Caches download from authorities; non-caches try
  819. to download from caches. We follow the same splitting and back-off rules
  820. as in 4.4 (if a cache) or 5.3 (if a client).
  821. 4.6. General-use HTTP URLs
  822. "Fingerprints" in these URLs are base-16-encoded SHA1 hashes.
  823. The most recent v3 consensus should be available at:
  824. http://<hostname>/tor/status-vote/current/consensus.z
  825. A concatenated set of all the current key certificates should be available
  826. at:
  827. http://<hostname>/tor/keys/all.z
  828. The key certificate for this server (if it is an authority) should be
  829. available at:
  830. http://<hostname>/tor/keys/authority.z
  831. The most recent descriptor for a server whose identity key has a
  832. fingerprint of <F> should be available at:
  833. http://<hostname>/tor/server/fp/<F>.z
  834. The most recent descriptors for servers with identity fingerprints
  835. <F1>,<F2>,<F3> should be available at:
  836. http://<hostname>/tor/server/fp/<F1>+<F2>+<F3>.z
  837. (NOTE: Implementations SHOULD NOT download descriptors by identity key
  838. fingerprint. This allows a corrupted server (in collusion with a cache) to
  839. provide a unique descriptor to a client, and thereby partition that client
  840. from the rest of the network.)
  841. The server descriptor with (descriptor) digest <D> (in hex) should be
  842. available at:
  843. http://<hostname>/tor/server/d/<D>.z
  844. The most recent descriptors with digests <D1>,<D2>,<D3> should be
  845. available at:
  846. http://<hostname>/tor/server/d/<D1>+<D2>+<D3>.z
  847. The most recent descriptor for this server should be at:
  848. http://<hostname>/tor/server/authority.z
  849. [Nothing in the Tor protocol uses this resource yet, but it is useful
  850. for debugging purposes. Also, the official Tor implementations
  851. (starting at 0.1.1.x) use this resource to test whether a server's
  852. own DirPort is reachable.]
  853. A concatenated set of the most recent descriptors for all known servers
  854. should be available at:
  855. http://<hostname>/tor/server/all.z
  856. Extra-info documents are available at the URLS
  857. http://<hostname>/tor/extra/d/...
  858. http://<hostname>/tor/extra/fp/...
  859. http://<hostname>/tor/extra/all[.z]
  860. http://<hostname>/tor/extra/authority[.z]
  861. (As for /tor/server/ URLs: supports fetching extra-info
  862. documents by their digest, by the fingerprint of their servers,
  863. or all at once. When serving by fingerprint, we serve the
  864. extra-info that corresponds to the descriptor we would serve by
  865. that fingerprint. Only directory authorities of version
  866. 0.2.0.1-alpha or later are guaranteed to support the first
  867. three classes of URLs. Caches may support them, and MUST
  868. support them if they have advertised "caches-extra-info".)
  869. For debugging, directories SHOULD expose non-compressed objects at URLs like
  870. the above, but without the final ".z".
  871. Clients MUST handle compressed concatenated information in two forms:
  872. - A concatenated list of zlib-compressed objects.
  873. - A zlib-compressed concatenated list of objects.
  874. Directory servers MAY generate either format: the former requires less
  875. CPU, but the latter requires less bandwidth.
  876. Clients SHOULD use upper case letters (A-F) when base16-encoding
  877. fingerprints. Servers MUST accept both upper and lower case fingerprints
  878. in requests.
  879. 5. Client operation: downloading information
  880. Every Tor that is not a directory server (that is, those that do
  881. not have a DirPort set) implements this section.
  882. 5.1. Downloading network-status documents
  883. Each client maintains a list of directory authorities. Insofar as
  884. possible, clients SHOULD all use the same list.
  885. Clients try to have a live consensus network-status document at all times.
  886. A network-status document is "live" if the time in its valid-until field
  887. has not passed.
  888. If a client is missing a live network-status document, it tries to fetch
  889. it from a directory cache (or from an authority if it knows no caches).
  890. On failure, the client waits briefly, then tries that network-status
  891. document again from another cache. The client does not build circuits
  892. until it has a live network-status consensus document, and it has
  893. descriptors for more than 1/4 of the routers that it believes are running.
  894. [XXXX handling clock skew at client side?]
  895. [XXXX fall-back to most recent?]
  896. (Note: clients can and should pick caches based on the network-status
  897. information they have: once they have first fetched network-status info
  898. from an authority, they should not need to go to the authority directly
  899. again.)
  900. 5.2. Downloading and storing router descriptors
  901. Clients try to have the best descriptor for each router. A descriptor is
  902. "best" if:
  903. * It is listed in the consensus network-status document.
  904. Periodically (currently every 10 seconds) clients check whether there are
  905. any "downloadable" descriptors. A descriptor is downloadable if:
  906. - It is the "best" descriptor for some router.
  907. - The descriptor was published at least 10 minutes in the past.
  908. (This prevents clients from trying to fetch descriptors that the
  909. mirrors have probably not yet retrieved and cached.)
  910. - The client does not currently have it.
  911. - The client is not currently trying to download it.
  912. - The client would not discard it immediately upon receiving it.
  913. - The client thinks it is running and valid (see 6.1 below).
  914. If at least 16 known routers have downloadable descriptors, or if
  915. enough time (currently 10 minutes) has passed since the last time the
  916. client tried to download descriptors, it launches requests for all
  917. downloadable descriptors, as described in 5.3 below.
  918. When a descriptor download fails, the client notes it, and does not
  919. consider the descriptor downloadable again until a certain amount of time
  920. has passed. (Currently 0 seconds for the first failure, 60 seconds for the
  921. second, 5 minutes for the third, 10 minutes for the fourth, and 1 day
  922. thereafter.) Periodically (currently once an hour) clients reset the
  923. failure count.
  924. Clients retain the most recent descriptor they have downloaded for each
  925. router so long as it is not too old (currently, 48 hours), OR so long as
  926. no better descriptor has been downloaded for the same router.
  927. [Versions of Tor before 0.1.2.3-alpha would discard descriptors simply for
  928. being published too far in the past.] [The code seems to discard
  929. descriptors in all cases after they're 5 days old. True? -RD]
  930. 5.3. Managing downloads
  931. When a client has no consensus network-status document, it downloads it
  932. from a randomly chosen authority. In all other cases, the client
  933. downloads from caches randomly chosen from among those believed to be V2
  934. directory servers. (This information comes from the network-status
  935. documents; see 6 below.)
  936. When downloading multiple router descriptors, the client chooses multiple
  937. mirrors so that:
  938. - At least 3 different mirrors are used, except when this would result
  939. in more than one request for under 4 descriptors.
  940. - No more than 128 descriptors are requested from a single mirror.
  941. - Otherwise, as few mirrors as possible are used.
  942. After choosing mirrors, the client divides the descriptors among them
  943. randomly.
  944. After receiving any response client MUST discard any network-status
  945. documents and descriptors that it did not request.
  946. 6. Using directory information
  947. Everyone besides directory authorities uses the approaches in this section
  948. to decide which servers to use and what their keys are likely to be.
  949. (Directory authorities just believe their own opinions, as in 3.1 above.)
  950. 6.1. Choosing routers for circuits.
  951. Circuits SHOULD NOT be built until the client has enough directory
  952. information: a live consensus network status [XXXX fallback?] and
  953. descriptors for at least 1/4 of the servers believed to be running.
  954. A server is "listed" if it is included by the consensus network-status
  955. document. Clients SHOULD NOT use unlisted servers.
  956. These flags are used as follows:
  957. - Clients SHOULD NOT use non-'Valid' or non-'Running' routers unless
  958. requested to do so.
  959. - Clients SHOULD NOT use non-'Fast' routers for any purpose other than
  960. very-low-bandwidth circuits (such as introduction circuits).
  961. - Clients SHOULD NOT use non-'Stable' routers for circuits that are
  962. likely to need to be open for a very long time (such as those used for
  963. IRC or SSH connections).
  964. - Clients SHOULD NOT choose non-'Guard' nodes when picking entry guard
  965. nodes.
  966. - Clients SHOULD NOT download directory information from non-'V2Dir'
  967. caches.
  968. 6.2. Managing naming
  969. [XXXX rewrite for v3]
  970. In order to provide human-memorable names for individual server
  971. identities, some directory servers bind names to IDs. Clients handle
  972. names in two ways:
  973. When a client encounters a name it has not mapped before:
  974. If all the live "Naming" network-status documents the client has
  975. claim that the name binds to some identity ID, and the client has at
  976. least three live network-status documents, the client maps the name to
  977. ID.
  978. When a user tries to refer to a router with a name that does not have a
  979. mapping under the above rules, the implementation SHOULD warn the user.
  980. After giving the warning, the implementation MAY use a router that at
  981. least one Naming authority maps the name to, so long as no other naming
  982. authority maps that name to a different router. If no Naming authority
  983. maps the name to a router, the implementation MAY use any router that
  984. advertises the name.
  985. Not every router needs a nickname. When a router doesn't configure a
  986. nickname, it publishes with the default nickname "Unnamed". Authorities
  987. SHOULD NOT ever mark a router with this nickname as Named; client software
  988. SHOULD NOT ever use a router in response to a user request for a router
  989. called "Unnamed".
  990. 6.3. Software versions
  991. An implementation of Tor SHOULD warn when it has fetched a consensus
  992. network-status, and it is running a software version not listed.
  993. 6.4. Warning about a router's status.
  994. If a router tries to publish its descriptor to a Naming authority
  995. that has its nickname mapped to another key, the router SHOULD
  996. warn the operator that it is either using the wrong key or is using
  997. an already claimed nickname.
  998. If a router has fetched a consensus document,, and the
  999. authorities do not publish a binding for the router's nickname, the
  1000. router MAY remind the operator that the chosen nickname is not
  1001. bound to this key at the authorities, and suggest contacting the
  1002. authority operators.
  1003. ...
  1004. 6.5. Router protocol versions
  1005. A client should believe that a router supports a given feature if that
  1006. feature is supported by the router or protocol versions in more than half
  1007. of the live networkstatus's "v" entries for that router. In other words,
  1008. if the "v" entries for some router are:
  1009. v Tor 0.0.8pre1 (from authority 1)
  1010. v Tor 0.1.2.11 (from authority 2)
  1011. v FutureProtocolDescription 99 (from authority 3)
  1012. then the client should believe that the router supports any feature
  1013. supported by 0.1.2.11.
  1014. This is currently equivalent to believing the median declared version for
  1015. a router in all live networkstatuses.
  1016. 7. Standards compliance
  1017. All clients and servers MUST support HTTP 1.0. Clients and servers MAY
  1018. support later versions of HTTP as well.
  1019. 7.1. HTTP headers
  1020. Servers MAY set the Content-Length: header. Servers SHOULD set
  1021. Content-Encoding to "deflate" or "identity".
  1022. Servers MAY include an X-Your-Address-Is: header, whose value is the
  1023. apparent IP address of the client connecting to them (as a dotted quad).
  1024. For directory connections tunneled over a BEGIN_DIR stream, servers SHOULD
  1025. report the IP from which the circuit carrying the BEGIN_DIR stream reached
  1026. them. [Servers before version 0.1.2.5-alpha reported 127.0.0.1 for all
  1027. BEGIN_DIR-tunneled connections.]
  1028. Servers SHOULD disable caching of multiple network statuses or multiple
  1029. router descriptors. Servers MAY enable caching of single descriptors,
  1030. single network statuses, the list of all router descriptors, a v1
  1031. directory, or a v1 running routers document. XXX mention times.
  1032. 7.2. HTTP status codes
  1033. XXX We should write down what return codes dirservers send in what situations.
  1034. 9. Backward compatibility and migration plans
  1035. Until Tor versions before 0.1.1.x are completely obsolete, directory
  1036. authorities should generate, and mirrors should download and cache, v1
  1037. directories and running-routers lists, and allow old clients to download
  1038. them. These documents and the rules for retrieving, serving, and caching
  1039. them are described in dir-spec-v1.txt.
  1040. Until Tor versions before 0.2.0.x are completely obsolete, directory
  1041. authorities should generate, mirrors should download and cache, v2
  1042. network-status documents, and allow old clients to download them.
  1043. Additionally, all directory servers and caches should download, store, and
  1044. serve any router descriptor that is required because of v2 network-status
  1045. documents. These documents and the rules for retrieving, serving, and
  1046. caching them are described in dir-spec-v1.txt.
  1047. A. Consensus-negotiation timeline.
  1048. Period begins: this is the Published time.
  1049. Everybody sends votes
  1050. Reconciliation: everybody tries to fetch missing votes.
  1051. consensus may exist at this point.
  1052. End of voting period:
  1053. everyone swaps signatures.
  1054. Now it's okay for caches to download
  1055. Now it's okay for clients to download.
  1056. Valid-after/valid-until switchover