dir-list-spec.txt 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. Tor Directory List Format
  2. Tim Wilson-Brown (teor)
  3. 1. Scope and Preliminaries
  4. This document describes the format of Tor's directory lists, which are
  5. compiled and hard-coded into the tor binary. There is currently one
  6. list: the fallback directory mirrors. This list is also parsed by other
  7. libraries, like stem and metrics-lib. Alternate Tor implementations can
  8. use this list to bootstrap from the latest public Tor directory
  9. information.
  10. The FallbackDir feature was introduced by proposal 210, and was first
  11. supported by Tor in Tor version 0.2.4.7-alpha. The first hard-coded
  12. list was shipped in 0.2.8.1-alpha.
  13. The hard-coded fallback directory list is located in the tor source
  14. repository at:
  15. src/or/fallback_dirs.inc
  16. This document describes version 2.0.0 and later of the directory list
  17. format.
  18. Legacy, semi-structured versions of the fallback list were released with
  19. Tor 0.2.8.1-alpha through Tor 0.3.1.9. We call this format version 1.
  20. Stem and Relay Search have parsers for this legacy format.
  21. 1.1. Format Overview
  22. A directory list is a C code fragment containing an array of C string
  23. constants. Each double-quoted C string constant is a valid torrc
  24. FallbackDir entry. Each entry contains various data fields.
  25. Directory lists do not include the C array's declaration, or the array's
  26. terminating NULL. Entries in directory lists do not include the
  27. FallbackDir torrc option. These are handled by the including C code.
  28. Directlry lists also include C-style comments and whitespace. The
  29. presence of whitespace may be significant, but the amount of whitespace
  30. is never significant. The type of whitespace is not significant to the
  31. C compiler or Tor C string parser. However, other parsers MAY rely on
  32. the distinction between newlines and spaces. (And that the only
  33. whitespace characters in the list are newlines and spaces.)
  34. The directory entry C string constants are split over multiple lines for
  35. readability. Structured C-style comments are used to provide additional
  36. data fields. This information is not used by Tor, but may be of interest
  37. to other libraries.
  38. The order of directory entries and data fields is not significant,
  39. except where noted below.
  40. 1.2. Acknowledgements
  41. The original fallback directory script and format was created by
  42. weasel. The current script uses code written by gsathya & karsten.
  43. This specification was revised after feedback from:
  44. Damian Johnson ("atagar")
  45. Iain R. Learmonth ("irl")
  46. 1.3. Format Versions
  47. The directory list format uses semantic versioning: https://semver.org
  48. In particular:
  49. * major versions are used for incompatible changes, like
  50. removing non-optional fields
  51. * minor versions are used for compatible changes, like adding
  52. fields
  53. * patch versions are for bug fixes, like fixing an
  54. incorrectly-formatted Summary item
  55. 1.0.0 - The legacy fallback directory list format
  56. 2.0.0 - Adds name and extrainfo structured comments, and section separator
  57. comments to make the list easier to parse.
  58. 2.1.0 - Adds a source list comment to the header.
  59. 1.4. Future Plans
  60. Tor also has an auth_dirs.inc file, but it is not yet in this format.
  61. Tor uses slightly different formats for authorities and fallback
  62. directory mirrors, so we will need to make some changes to tor so that
  63. it parses this format. (We will also need to add authority-specific
  64. information to this format.) See #24818 for details.
  65. We want to add a torrc option so operators can opt-in their relays as
  66. fallback directory mirrors. This gives us a signed opt-in confirmation.
  67. (We can also continue to accept whitelist entries, and do other checks.)
  68. We need to write a short proposal, and make some changes to tor and the
  69. fallback update script. See #24839 for details.
  70. 2. Format Details
  71. Directory lists contain the following sections:
  72. - List Header (exactly once)
  73. - List Generation (exactly once, may be empty)
  74. - Directory Entry (zero or more times)
  75. Each section (or entry) ends with a separator.
  76. 2.1. Nonterminals
  77. The following nonterminals are defined in the Onionoo details document
  78. specification:
  79. dir_address
  80. fingerprint
  81. nickname
  82. See https://metrics.torproject.org/onionoo.html#details
  83. The following nonterminals are defined in the "Tor directory protocol"
  84. specification in dir-spec.txt:
  85. Keyword
  86. ArgumentChar
  87. NL (newline)
  88. SP (space)
  89. bool (must not be confused with Onionoo's JSON "boolean")
  90. We derive the following nonterminals from Onionoo and dir-spec.txt:
  91. ipv4_or_port ::= port from an IPv4 or_addresses item
  92. The ipv4_or_port is the port part of an IPv4 address from the
  93. Onionoo or_addresses list.
  94. ipv6_or_address ::= an IPv6 or_addresses item
  95. The ipv6_or_address is an IPv6 address and port from the Onionoo
  96. or_addresses list. The address MAY be in the canonical RFC 5952
  97. IPv6 address format.
  98. A key-value pair:
  99. value ::= Zero or more ArgumentChar, excluding the following strings:
  100. * a double quotation mark (DQUOTE), and
  101. * the C comment terminators ("/*" and "*/").
  102. Note that the C++ comment ("//") and equals sign ("=") are
  103. not excluded, because they are reserved for future use in
  104. base64 values.
  105. key_value ::= Keyword "=" value
  106. We also define these additional nonterminals:
  107. number ::= An optional negative sign ("-"), followed by one or more
  108. numeric characters ([0-9]), with an optional decimal part
  109. (".", followed by one or more numeric characters).
  110. separator ::= "/*" SP+ "=====" SP+ "*/"
  111. 2.2. List Header
  112. The list header consists of a number of key-value pairs, embedded in
  113. C-style comments.
  114. 2.2.1 List Header Format
  115. "/*" SP+ "type=" Keyword SP+ "*/" SP* NL
  116. [At start, exactly once.]
  117. The type of directory entries in the list. Parsers SHOULD exit with
  118. an error if this is not the first line of the list, or if the value
  119. is anything other than "fallback".
  120. "/*" SP+ "version=" version_number SP+ "*/" SP* NL
  121. [In second position, exactly once.]
  122. The version of the directory list format.
  123. version_number is a semantic version, see the "Format Versions"
  124. section for details.
  125. Version 1.0.0 represents the undocumented, legacy fallback list
  126. format(s). Version 2.0.0 and later are documented by this
  127. specification.
  128. "/*" SP+ "timestamp=" number SP+ "*/" SP* NL
  129. [Exactly once.]
  130. A positive integer that indicates when this directory list was
  131. generated. This timestamp is guaranteed to increase for every
  132. version 2.0.0 and later directory list.
  133. The current timestamp format is YYYYMMDDHHMMSS, as an integer.
  134. "/*" SP+ "source=" Keyword SP+ "*/" SP* NL
  135. [Zero or one time.]
  136. The source of the directory entries in the list.
  137. As of version 2.1.0, the sources are:
  138. * "whitelist" - the fallback.whitelist file in the fallback-scripts
  139. repository. This is the default.
  140. * "fallback" - a fallback_dirs.inc file from a tor repository.
  141. Used in check_existing mode.
  142. This line was added in version 2.1.0 of this specification.
  143. "/*" SP+ key_value SP+ "*/" SP* NL
  144. [Zero or more times.]
  145. Future releases may include additional header fields. Parsers MUST NOT
  146. rely on the order of these additional fields. Additional header fields
  147. will be accompanied by a minor version increment.
  148. separator SP* NL
  149. The list header ends with the section separator.
  150. 2.3. List Generation
  151. The list generation information consists of human-readable prose
  152. describing the content and origin of this directory list. It is contained
  153. in zero or more C-style comments, and may contain multi-line comments and
  154. uncommented C code.
  155. In particular, this section may contain C-style comments that contain
  156. an equals ("=") character. It may also be entirely empty.
  157. Future releases may arbitrarily change the content of this section.
  158. Parsers MUST NOT rely on a version increment when the format changes.
  159. 2.3.1 List Generation Format
  160. In general, parsers MUST NOT rely on the format of this section.
  161. Parsers MAY rely on the following details:
  162. The list generation section MUST NOT be a valid directory entry.
  163. The list generation summary MUST end with a section separator:
  164. separator SP* NL
  165. There MUST NOT be any section separators in the list generation
  166. section, other than the terminating section separator.
  167. 2.4. Directory Entry
  168. A directory entry consists of a C string constant, and one or more
  169. C-style comments. The C string constant is a valid argument to the
  170. DirAuthority or FallbackDir torrc option. The section also contains
  171. additional key-value fields in C-style comments.
  172. The list of fallback entries does not include the directory
  173. authorities: they are in a separate list. (The Tor implementation combines
  174. these lists after parsing them, and applies the DirAuthorityFallbackRate
  175. to their weights.)
  176. 2.4.1 Directory Entry Format
  177. If a directory entry does not conform to this format, the entry SHOULD
  178. be ignored by parsers.
  179. DQUOTE dir_address SP+ "orport=" ipv4_or_port SP+
  180. "id=" fingerprint DQUOTE SP* NL
  181. [At start, exactly once, on a single line.]
  182. This line consists of the following fields:
  183. dir_address
  184. An IPv4 address and DirPort for this directory, as defined by
  185. Onionoo. In this format version, all IPv4 addresses and DirPorts
  186. are guaranteed to be non-zero. (For IPv4 addresses, this means
  187. that they are not equal to "0.0.0.0".)
  188. ipv4_or_port
  189. An IPv4 ORPort for this directory, derived from Onionoo. In this
  190. format version, all IPv4 ORPorts are guaranteed to be non-zero.
  191. fingerprint
  192. The relay fingerprint of this directory, as defined by Onionoo.
  193. All relay fingerprints are guaranteed to have one or more non-zero
  194. digits.
  195. Note:
  196. Each double-quoted C string line that occurs after the first line,
  197. starts with space inside the quotes. This is a requirement of the
  198. Tor implementation.
  199. DQUOTE SP+ "ipv6=" ipv6_or_address DQUOTE SP* NL
  200. [Zero or one time.]
  201. The IPv6 address and ORPort for this directory, as defined by
  202. Onionoo. If present, IPv6 addresses and ORPorts are guaranteed to be
  203. non-zero. (For IPv6 addresses, this means that they are not equal to
  204. "[::]".)
  205. DQUOTE SP+ "weight=" number DQUOTE SP* NL
  206. [Zero or one time.]
  207. A non-negative, real-numbered weight for this directory.
  208. The default fallback weight is 1.0, and the default
  209. DirAuthorityFallbackRate is 1.0 in legacy Tor versions, and 0.1 in
  210. recent Tor versions.
  211. weight was removed in version 2.0.0, but is documented because it
  212. may be of interest to libraries implementing Tor's fallaback
  213. behaviour.
  214. DQUOTE SP+ key_value DQUOTE SP* NL
  215. [Zero or more times.]
  216. Future releases may include additional data fields in double-quoted
  217. C string constants. Parsers MUST NOT rely on the order of these
  218. additional fields. Additional data fields will be accompanied by a
  219. minor version increment.
  220. "/*" SP+ "nickname=" nickname* SP+ "*/" SP* NL
  221. [Exactly once.]
  222. The nickname for this directory, as defined by Onionoo. An
  223. empty nickname indicates that the nickname is unknown.
  224. The first fallback list in the 2.0.0 format had nickname lines, but
  225. they were all empty.
  226. "/*" SP+ "extrainfo=" bool SP+ "*/" SP* NL
  227. [Exactly once.]
  228. An integer flag that indicates whether this directory caches
  229. extra-info documents. Set to 1 if the directory claimed that it
  230. cached extra-info documents in its descriptor when the list was
  231. created. 0 indicates that it did not, or its descriptor was not
  232. available.
  233. The first fallback list in the 2.0.0 format had extrainfo lines, but
  234. they were all zero.
  235. "/*" SP+ key_value SP+ "*/" SP* NL
  236. [Zero or more times.]
  237. Future releases may include additional data fields in C-style
  238. comments. Parsers MUST NOT rely on the order of these additional
  239. fields. Additional data fields will be accompanied by a minor version
  240. increment.
  241. separator SP* NL
  242. [Exactly once.]
  243. Each directory entry ends with the section separator.
  244. "," SP* NL
  245. [Exactly once.]
  246. The comma terminates the C string constant. (Multiple C string
  247. constants separated by whitespace or comments are coalesced by
  248. the C compiler.)
  249. 3. Usage Considerations
  250. This section contains recommended library behaviours. It does not affect
  251. the format of directory lists.
  252. 3.1. Caching
  253. The fallback list typically changes once every 6-12 months. The data in
  254. the list represents the state of the fallback directory entries when the
  255. list was created. Fallbacks can and do change their details over time.
  256. Libraries SHOULD parse and cache the most recent version of these lists
  257. during their build or release processes. Libraries MUST NOT retrieve the
  258. lists by default every time they are deployed or executed.
  259. The latest fallback list can be retrieved from:
  260. https://gitweb.torproject.org/tor.git/plain/src/or/fallback_dirs.inc
  261. Libraries MUST NOT rely on the availability of the server that hosts
  262. these lists.
  263. The list can also be retrieved using:
  264. git clone https://git.torproject.org/tor.git
  265. If you just want the latest list, you may wish to perform a shallow
  266. clone.
  267. 3.2. Retrieving Directory Information
  268. Some libraries retrieve directory documents directly from the Tor
  269. Directory Authorities. The directory authorities are designed to support
  270. Tor relay and client bootstrap, and MAY choose to rate-limit library
  271. access. Libraries MAY provide a user-agent in their requests, if they
  272. are not intended to support anonymous operation. (User agents are a
  273. fingerprinting vector.)
  274. Libraries SHOULD consider the potential load on the authorities, and
  275. whether other sources can meet their needs.
  276. Libraries that require high-uptime availablility of Tor directory
  277. information should investigate the following options:
  278. * OnionOO: https://metrics.torproject.org/onionoo.html
  279. * Third-party OnionOO mirrors are also available
  280. * CollecTor: https://collector.torproject.org/
  281. * Fallback Directory Mirrors
  282. Onionoo and CollecTor are typically updated every hour on a regular
  283. schedule. Fallbacks update their own directory information at random
  284. intervals, see dir-spec for details.
  285. 3.3. Fallback Reliability
  286. The fallback list is typically regenerated when the fallback failure
  287. rate exceeds 25%. Libraries SHOULD NOT rely on any particular fallback
  288. being available, or some proportion of fallbacks being available.
  289. Libraries that use fallbacks MAY wish to query an authority after a
  290. few fallback queries fail. For example, Tor clients try 3-4 fallbacks
  291. before trying an authority.
  292. A.1. Sample Data
  293. A sample version 2.0.0 fallback list is available here:
  294. https://trac.torproject.org/projects/tor/raw-attachment/ticket/22759/fallback_dirs_new_format_version.4.inc
  295. A sample transitional version 2.0.0 fallback list is available here:
  296. https://raw.githubusercontent.com/teor2345/tor/fallback-format-2-v4/src/or/fallback_dirs.inc
  297. A.1.1. Sample Fallback List Header
  298. /* type=fallback */
  299. /* version=2.0.0 */
  300. /* ===== */
  301. A.1.2. Sample Fallback List Generation
  302. /* Whitelist & blacklist excluded 1326 of 1513 candidates. */
  303. /* Checked IPv4 DirPorts served a consensus within 15.0s. */
  304. /*
  305. Final Count: 151 (Eligible 187, Target 392 (1963 * 0.20), Max 200)
  306. Excluded: 36 (Same Operator 27, Failed/Skipped Download 9, Excess 0)
  307. Bandwidth Range: 1.3 - 40.0 MByte/s
  308. */
  309. /*
  310. Onionoo Source: details Date: 2017-05-16 07:00:00 Version: 4.0
  311. URL: https:onionoo.torproject.orgdetails?fields=fingerprint%2Cnickname%2Ccontact%2Clast_changed_address_or_port%2Cconsensus_weight%2Cadvertised_bandwidth%2Cor_addresses%2Cdir_address%2Crecommended_version%2Cflags%2Ceffective_family%2Cplatform&flag=V2Dir&type=relay&last_seen_days=-0&first_seen_days=30-
  312. */
  313. /*
  314. Onionoo Source: uptime Date: 2017-05-16 07:00:00 Version: 4.0
  315. URL: https:onionoo.torproject.orguptime?first_seen_days=30-&flag=V2Dir&type=relay&last_seen_days=-0
  316. */
  317. /* ===== */
  318. A.1.3. Sample Fallback Entries
  319. "176.10.104.240:80 orport=443 id=0111BA9B604669E636FFD5B503F382A4B7AD6E80"
  320. /* nickname=foo */
  321. /* extrainfo=1 */
  322. /* ===== */
  323. ,
  324. "5.9.110.236:9030 orport=9001 id=0756B7CD4DFC8182BE23143FAC0642F515182CEB"
  325. " ipv6=[2a01:4f8:162:51e2::2]:9001"
  326. /* nickname= */
  327. /* extrainfo=0 */
  328. /* ===== */
  329. ,