dir-spec.txt 59 KB

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