rend-spec-v3.txt 107 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526
  1. Tor Rendezvous Specification - Version 3
  2. This document specifies how the hidden service version 3 protocol works. This
  3. text used to be proposal 224-rend-spec-ng.txt.
  4. Table of contents:
  5. 0. Hidden services: overview and preliminaries.
  6. 0.1. Improvements over previous versions.
  7. 0.2. Notation and vocabulary
  8. 0.3. Cryptographic building blocks
  9. 0.4. Protocol building blocks [BUILDING-BLOCKS]
  10. 0.5. Assigned relay cell types
  11. 0.6. Acknowledgments
  12. 1. Protocol overview
  13. 1.1. View from 10,000 feet
  14. 1.2. In more detail: naming hidden services [NAMING]
  15. 1.3. In more detail: Access control [IMD:AC]
  16. 1.4. In more detail: Distributing hidden service descriptors. [IMD:DIST]
  17. 1.5. In more detail: Scaling to multiple hosts
  18. 1.6. In more detail: Backward compatibility with older hidden service
  19. 1.7. In more detail: Keeping crypto keys offline
  20. 1.8. In more detail: Encryption Keys And Replay Resistance
  21. 1.9. In more detail: A menagerie of keys
  22. 1.9.1. In even more detail: Client authorization [CLIENT-AUTH]
  23. 2. Generating and publishing hidden service descriptors [HSDIR]
  24. 2.1. Deriving blinded keys and subcredentials [SUBCRED]
  25. 2.2. Locating, uploading, and downloading hidden service descriptors
  26. 2.2.1. Dividing time into periods [TIME-PERIODS]
  27. 2.2.2. When to publish a hidden service descriptor [WHEN-HSDESC]
  28. 2.2.3. Where to publish a hidden service descriptor [WHERE-HSDESC]
  29. 2.2.4. Using time periods and SRVs to fetch/upload HS descriptors
  30. 2.2.5. Expiring hidden service descriptors [EXPIRE-DESC]
  31. 2.2.6. URLs for anonymous uploading and downloading
  32. 2.3. Publishing shared random values [PUB-SHAREDRANDOM]
  33. 2.3.1. Client behavior in the absense of shared random values
  34. 2.3.2. Hidden services and changing shared random values
  35. 2.4. Hidden service descriptors: outer wrapper [DESC-OUTER]
  36. 2.5. Hidden service descriptors: encryption format [HS-DESC-ENC]
  37. 2.5.1. First layer of encryption [HS-DESC-FIRST-LAYER]
  38. 2.5.1.1. First layer encryption logic
  39. 2.5.1.2. First layer plaintext format
  40. 2.5.1.3. Client behavior
  41. 2.5.1.4. Obfuscating the number of authorized clients
  42. 2.5.2. Second layer of encryption [HS-DESC-SECOND-LAYER]
  43. 2.5.2.1. Second layer encryption keys
  44. 2.5.2.2. Second layer plaintext format
  45. 2.5.3. Deriving hidden service descriptor encryption keys [HS-DESC-ENCRYPTION-KEYS]
  46. 3. The introduction protocol [INTRO-PROTOCOL]
  47. 3.1. Registering an introduction point [REG_INTRO_POINT]
  48. 3.1.1. Extensible ESTABLISH_INTRO protocol. [EST_INTRO]
  49. 3.1.2. Registering an introduction point on a legacy Tor node [LEGACY_EST_INTRO]
  50. 3.1.3. Acknowledging establishment of introduction point [INTRO_ESTABLISHED]
  51. 3.2. Sending an INTRODUCE1 cell to the introduction point. [SEND_INTRO1]
  52. 3.2.1. INTRODUCE1 cell format [FMT_INTRO1]
  53. 3.2.2. INTRODUCE_ACK cell format. [INTRO_ACK]
  54. 3.3. Processing an INTRODUCE2 cell at the hidden service. [PROCESS_INTRO2]
  55. 3.3.1. Introduction handshake encryption requirements [INTRO-HANDSHAKE-REQS]
  56. 3.3.2. Example encryption handshake: ntor with extra data [NTOR-WITH-EXTRA-DATA]
  57. 3.4. Authentication during the introduction phase. [INTRO-AUTH]
  58. 3.4.1. Ed25519-based authentication.
  59. 4. The rendezvous protocol
  60. 4.1. Establishing a rendezvous point [EST_REND_POINT]
  61. 4.2. Joining to a rendezvous point [JOIN_REND]
  62. 4.2.1. Key expansion
  63. 4.3. Using legacy hosts as rendezvous points
  64. 5. Encrypting data between client and host
  65. 6. Encoding onion addresses [ONIONADDRESS]
  66. 7. Open Questions:
  67. -1. Draft notes
  68. This document describes a proposed design and specification for
  69. hidden services in Tor version 0.2.5.x or later. It's a replacement
  70. for the current rend-spec.txt, rewritten for clarity and for improved
  71. design.
  72. Look for the string "TODO" below: it describes gaps or uncertainties
  73. in the design.
  74. Change history:
  75. 2013-11-29: Proposal first numbered. Some TODO and XXX items remain.
  76. 2014-01-04: Clarify some unclear sections.
  77. 2014-01-21: Fix a typo.
  78. 2014-02-20: Move more things to the revised certificate format in the
  79. new updated proposal 220.
  80. 2015-05-26: Fix two typos.
  81. 0. Hidden services: overview and preliminaries.
  82. Hidden services aim to provide responder anonymity for bidirectional
  83. stream-based communication on the Tor network. Unlike regular Tor
  84. connections, where the connection initiator receives anonymity but
  85. the responder does not, hidden services attempt to provide
  86. bidirectional anonymity.
  87. Participants:
  88. Operator -- A person running a hidden service
  89. Host, "Server" -- The Tor software run by the operator to provide
  90. a hidden service.
  91. User -- A person contacting a hidden service.
  92. Client -- The Tor software running on the User's computer
  93. Hidden Service Directory (HSDir) -- A Tor node that hosts signed
  94. statements from hidden service hosts so that users can make
  95. contact with them.
  96. Introduction Point -- A Tor node that accepts connection requests
  97. for hidden services and anonymously relays those requests to the
  98. hidden service.
  99. Rendezvous Point -- A Tor node to which clients and servers
  100. connect and which relays traffic between them.
  101. 0.1. Improvements over previous versions.
  102. Here is a list of improvements of this proposal over the legacy hidden
  103. services:
  104. a) Better crypto (replaced SHA1/DH/RSA1024 with SHA3/ed25519/curve25519)
  105. b) Improved directory protocol leaking less to directory servers.
  106. c) Improved directory protocol with smaller surface for targeted attacks.
  107. d) Better onion address security against impersonation.
  108. e) More extensible introduction/rendezvous protocol.
  109. f) Offline keys for onion services
  110. g) Advanced client authorization
  111. 0.2. Notation and vocabulary
  112. Unless specified otherwise, all multi-octet integers are big-endian.
  113. We write sequences of bytes in two ways:
  114. 1. A sequence of two-digit hexadecimal values in square brackets,
  115. as in [AB AD 1D EA].
  116. 2. A string of characters enclosed in quotes, as in "Hello". The
  117. characters in these strings are encoded in their ascii
  118. representations; strings are NOT nul-terminated unless
  119. explicitly described as NUL terminated.
  120. We use the words "byte" and "octet" interchangeably.
  121. We use the vertical bar | to denote concatenation.
  122. We use INT_N(val) to denote the network (big-endian) encoding of the
  123. unsigned integer "val" in N bytes. For example, INT_4(1337) is [00 00
  124. 05 39]. Values are truncated like so: val % (2 ^ (N * 8)). For example,
  125. INT_4(42) is 42 % 4294967296 (32 bit).
  126. 0.3. Cryptographic building blocks
  127. This specification uses the following cryptographic building blocks:
  128. * A pseudorandom number generator backed by a strong entropy source.
  129. The output of the PRNG should always be hashed before being posted on
  130. the network to avoid leaking raw PRNG bytes to the network
  131. (see [PRNG-REFS]).
  132. * A stream cipher STREAM(iv, k) where iv is a nonce of length
  133. S_IV_LEN bytes and k is a key of length S_KEY_LEN bytes.
  134. * A public key signature system SIGN_KEYGEN()->seckey, pubkey;
  135. SIGN_SIGN(seckey,msg)->sig; and SIGN_CHECK(pubkey, sig, msg) ->
  136. { "OK", "BAD" }; where secret keys are of length SIGN_SECKEY_LEN
  137. bytes, public keys are of length SIGN_PUBKEY_LEN bytes, and
  138. signatures are of length SIGN_SIG_LEN bytes.
  139. This signature system must also support key blinding operations
  140. as discussed in appendix [KEYBLIND] and in section [SUBCRED]:
  141. SIGN_BLIND_SECKEY(seckey, blind)->seckey2 and
  142. SIGN_BLIND_PUBKEY(pubkey, blind)->pubkey2 .
  143. * A public key agreement system "PK", providing
  144. PK_KEYGEN()->seckey, pubkey; PK_VALID(pubkey) -> {"OK", "BAD"};
  145. and PK_HANDSHAKE(seckey, pubkey)->output; where secret keys are
  146. of length PK_SECKEY_LEN bytes, public keys are of length
  147. PK_PUBKEY_LEN bytes, and the handshake produces outputs of
  148. length PK_OUTPUT_LEN bytes.
  149. * A cryptographic hash function H(d), which should be preimage and
  150. collision resistant. It produces hashes of length HASH_LEN
  151. bytes.
  152. * A cryptographic message authentication code MAC(key,msg) that
  153. produces outputs of length MAC_LEN bytes.
  154. * A key derivation function KDF(message, n) that outputs n bytes.
  155. As a first pass, I suggest:
  156. * Instantiate STREAM with AES256-CTR.
  157. * Instantiate SIGN with Ed25519 and the blinding protocol in
  158. [KEYBLIND].
  159. * Instantiate PK with Curve25519.
  160. * Instantiate H with SHA3-256.
  161. * Instantiate KDF with SHAKE-256.
  162. * Instantiate MAC(key=k, message=m) with H(k_len | k | m),
  163. where k_len is htonll(len(k)).
  164. For legacy purposes, we specify compatibility with older versions of
  165. the Tor introduction point and rendezvous point protocols. These used
  166. RSA1024, DH1024, AES128, and SHA1, as discussed in
  167. rend-spec.txt.
  168. As in [proposal 220], all signatures are generated not over strings
  169. themselves, but over those strings prefixed with a distinguishing
  170. value.
  171. 0.4. Protocol building blocks [BUILDING-BLOCKS]
  172. In sections below, we need to transmit the locations and identities
  173. of Tor nodes. We do so in the link identification format used by
  174. EXTEND2 cells in the Tor protocol.
  175. NSPEC (Number of link specifiers) [1 byte]
  176. NSPEC times:
  177. LSTYPE (Link specifier type) [1 byte]
  178. LSLEN (Link specifier length) [1 byte]
  179. LSPEC (Link specifier) [LSLEN bytes]
  180. Link specifier types are as described in tor-spec.txt. Every set of
  181. link specifiers MUST include at minimum specifiers of type [00]
  182. (TLS-over-TCP, IPv4), [02] (legacy node identity) and [03] (ed25519
  183. identity key).
  184. As of 0.4.1.1-alpha, Tor includes both IPv4 and IPv6 link specifiers
  185. in v3 onion service protocol link specifier lists. All available
  186. addresses SHOULD be included as link specifiers, regardless of the
  187. address that Tor actually used to connect/extend to the remote relay.
  188. We also incorporate Tor's circuit extension handshakes, as used in
  189. the CREATE2 and CREATED2 cells described in tor-spec.txt. In these
  190. handshakes, a client who knows a public key for a server sends a
  191. message and receives a message from that server. Once the exchange is
  192. done, the two parties have a shared set of forward-secure key
  193. material, and the client knows that nobody else shares that key
  194. material unless they control the secret key corresponding to the
  195. server's public key.
  196. 0.5. Assigned relay cell types
  197. These relay cell types are reserved for use in the hidden service
  198. protocol.
  199. 32 -- RELAY_COMMAND_ESTABLISH_INTRO
  200. Sent from hidden service host to introduction point;
  201. establishes introduction point. Discussed in
  202. [REG_INTRO_POINT].
  203. 33 -- RELAY_COMMAND_ESTABLISH_RENDEZVOUS
  204. Sent from client to rendezvous point; creates rendezvous
  205. point. Discussed in [EST_REND_POINT].
  206. 34 -- RELAY_COMMAND_INTRODUCE1
  207. Sent from client to introduction point; requests
  208. introduction. Discussed in [SEND_INTRO1]
  209. 35 -- RELAY_COMMAND_INTRODUCE2
  210. Sent from introduction point to hidden service host; requests
  211. introduction. Same format as INTRODUCE1. Discussed in
  212. [FMT_INTRO1] and [PROCESS_INTRO2]
  213. 36 -- RELAY_COMMAND_RENDEZVOUS1
  214. Sent from hidden service host to rendezvous point;
  215. attempts to join host's circuit to
  216. client's circuit. Discussed in [JOIN_REND]
  217. 37 -- RELAY_COMMAND_RENDEZVOUS2
  218. Sent from rendezvous point to client;
  219. reports join of host's circuit to
  220. client's circuit. Discussed in [JOIN_REND]
  221. 38 -- RELAY_COMMAND_INTRO_ESTABLISHED
  222. Sent from introduction point to hidden service host;
  223. reports status of attempt to establish introduction
  224. point. Discussed in [INTRO_ESTABLISHED]
  225. 39 -- RELAY_COMMAND_RENDEZVOUS_ESTABLISHED
  226. Sent from rendezvous point to client; acknowledges
  227. receipt of ESTABLISH_RENDEZVOUS cell. Discussed in
  228. [EST_REND_POINT]
  229. 40 -- RELAY_COMMAND_INTRODUCE_ACK
  230. Sent from introduction point to client; acknowledges
  231. receipt of INTRODUCE1 cell and reports success/failure.
  232. Discussed in [INTRO_ACK]
  233. 0.6. Acknowledgments
  234. This design includes ideas from many people, including
  235. Christopher Baines,
  236. Daniel J. Bernstein,
  237. Matthew Finkel,
  238. Ian Goldberg,
  239. George Kadianakis,
  240. Aniket Kate,
  241. Tanja Lange,
  242. Robert Ransom,
  243. Roger Dingledine,
  244. Aaron Johnson,
  245. Tim Wilson-Brown ("teor"),
  246. special (John Brooks),
  247. s7r
  248. It's based on Tor's original hidden service design by Roger
  249. Dingledine, Nick Mathewson, and Paul Syverson, and on improvements to
  250. that design over the years by people including
  251. Tobias Kamm,
  252. Thomas Lauterbach,
  253. Karsten Loesing,
  254. Alessandro Preite Martinez,
  255. Robert Ransom,
  256. Ferdinand Rieger,
  257. Christoph Weingarten,
  258. Christian Wilms,
  259. We wouldn't be able to do any of this work without good attack
  260. designs from researchers including
  261. Alex Biryukov,
  262. Lasse Øverlier,
  263. Ivan Pustogarov,
  264. Paul Syverson
  265. Ralf-Philipp Weinmann,
  266. See [ATTACK-REFS] for their papers.
  267. Several of these ideas have come from conversations with
  268. Christian Grothoff,
  269. Brian Warner,
  270. Zooko Wilcox-O'Hearn,
  271. And if this document makes any sense at all, it's thanks to
  272. editing help from
  273. Matthew Finkel
  274. George Kadianakis,
  275. Peter Palfrader,
  276. Tim Wilson-Brown ("teor"),
  277. [XXX Acknowledge the huge bunch of people working on 8106.]
  278. [XXX Acknowledge the huge bunch of people working on 8244.]
  279. Please forgive me if I've missed you; please forgive me if I've
  280. misunderstood your best ideas here too.
  281. 1. Protocol overview
  282. In this section, we outline the hidden service protocol. This section
  283. omits some details in the name of simplicity; those are given more
  284. fully below, when we specify the protocol in more detail.
  285. 1.1. View from 10,000 feet
  286. A hidden service host prepares to offer a hidden service by choosing
  287. several Tor nodes to serve as its introduction points. It builds
  288. circuits to those nodes, and tells them to forward introduction
  289. requests to it using those circuits.
  290. Once introduction points have been picked, the host builds a set of
  291. documents called "hidden service descriptors" (or just "descriptors"
  292. for short) and uploads them to a set of HSDir nodes. These documents
  293. list the hidden service's current introduction points and describe
  294. how to make contact with the hidden service.
  295. When a client wants to connect to a hidden service, it first chooses
  296. a Tor node at random to be its "rendezvous point" and builds a
  297. circuit to that rendezvous point. If the client does not have an
  298. up-to-date descriptor for the service, it contacts an appropriate
  299. HSDir and requests such a descriptor.
  300. The client then builds an anonymous circuit to one of the hidden
  301. service's introduction points listed in its descriptor, and gives the
  302. introduction point an introduction request to pass to the hidden
  303. service. This introduction request includes the target rendezvous
  304. point and the first part of a cryptographic handshake.
  305. Upon receiving the introduction request, the hidden service host
  306. makes an anonymous circuit to the rendezvous point and completes the
  307. cryptographic handshake. The rendezvous point connects the two
  308. circuits, and the cryptographic handshake gives the two parties a
  309. shared key and proves to the client that it is indeed talking to the
  310. hidden service.
  311. Once the two circuits are joined, the client can send Tor RELAY cells
  312. to the server. RELAY_BEGIN cells open streams to an external process
  313. or processes configured by the server; RELAY_DATA cells are used to
  314. communicate data on those streams, and so forth.
  315. 1.2. In more detail: naming hidden services [NAMING]
  316. A hidden service's name is its long term master identity key. This is
  317. encoded as a hostname by encoding the entire key in Base 32, including a
  318. version byte and a checksum, and then appending the string ".onion" at the
  319. end. The result is a 56-character domain name.
  320. (This is a change from older versions of the hidden service protocol,
  321. where we used an 80-bit truncated SHA1 hash of a 1024 bit RSA key.)
  322. The names in this format are distinct from earlier names because of
  323. their length. An older name might look like:
  324. unlikelynamefora.onion
  325. yyhws9optuwiwsns.onion
  326. And a new name following this specification might look like:
  327. l5satjgud6gucryazcyvyvhuxhr74u6ygigiuyixe3a6ysis67ororad.onion
  328. Please see section [ONIONADDRESS] for the encoding specification.
  329. 1.3. In more detail: Access control [IMD:AC]
  330. Access control for a hidden service is imposed at multiple points through
  331. the process above. Furthermore, there is also the option to impose
  332. additional client authorization access control using pre-shared secrets
  333. exchanged out-of-band between the hidden service and its clients.
  334. The first stage of access control happens when downloading HS descriptors.
  335. Specifically, in order to download a descriptor, clients must know which
  336. blinded signing key was used to sign it. (See the next section for more info
  337. on key blinding.)
  338. To learn the introduction points, clients must decrypt the body of the
  339. hidden service descriptor. To do so, clients must know the _unblinded_
  340. public key of the service, which makes the descriptor unuseable by entities
  341. without that knowledge (e.g. HSDirs that don't know the onion address).
  342. Also, if optional client authorization is enabled, hidden service
  343. descriptors are superencrypted using each authorized user's identity x25519
  344. key, to further ensure that unauthorized entities cannot decrypt it.
  345. In order to make the introduction point send a rendezvous request to the
  346. service, the client needs to use the per-introduction-point authentication
  347. key found in the hidden service descriptor.
  348. The final level of access control happens at the server itself, which may
  349. decide to respond or not respond to the client's request depending on the
  350. contents of the request. The protocol is extensible at this point: at a
  351. minimum, the server requires that the client demonstrate knowledge of the
  352. contents of the encrypted portion of the hidden service descriptor. If
  353. optional client authorization is enabled, the service may additionally
  354. require the client to prove knowledge of a pre-shared private key.
  355. (NOTE: client authorization is not implemented as of 0.3.2.1-alpha.)
  356. 1.4. In more detail: Distributing hidden service descriptors. [IMD:DIST]
  357. Periodically, hidden service descriptors become stored at different
  358. locations to prevent a single directory or small set of directories
  359. from becoming a good DoS target for removing a hidden service.
  360. For each period, the Tor directory authorities agree upon a
  361. collaboratively generated random value. (See section 2.3 for a
  362. description of how to incorporate this value into the voting
  363. practice; generating the value is described in other proposals,
  364. including [SHAREDRANDOM-REFS].) That value, combined with hidden service
  365. directories' public identity keys, determines each HSDir's position
  366. in the hash ring for descriptors made in that period.
  367. Each hidden service's descriptors are placed into the ring in
  368. positions based on the key that was used to sign them. Note that
  369. hidden service descriptors are not signed with the services' public
  370. keys directly. Instead, we use a key-blinding system [KEYBLIND] to
  371. create a new key-of-the-day for each hidden service. Any client that
  372. knows the hidden service's credential can derive these blinded
  373. signing keys for a given period. It should be impossible to derive
  374. the blinded signing key lacking that credential.
  375. The body of each descriptor is also encrypted with a key derived from
  376. the credential.
  377. To avoid a "thundering herd" problem where every service generates
  378. and uploads a new descriptor at the start of each period, each
  379. descriptor comes online at a time during the period that depends on
  380. its blinded signing key. The keys for the last period remain valid
  381. until the new keys come online.
  382. 1.5. In more detail: Scaling to multiple hosts
  383. This design is compatible with our current approaches for scaling hidden
  384. services. Specifically, hidden service operators can use onionbalance to
  385. achieve high availability between multiple nodes on the HSDir
  386. layer. Furthermore, operators can use proposal 255 to load balance their
  387. hidden services on the introduction layer. See [SCALING-REFS] for further
  388. discussions on this topic and alternative designs.
  389. 1.6. In more detail: Backward compatibility with older hidden service
  390. protocols
  391. This design is incompatible with the clients, server, and hsdir node
  392. protocols from older versions of the hidden service protocol as
  393. described in rend-spec.txt. On the other hand, it is designed to
  394. enable the use of older Tor nodes as rendezvous points and
  395. introduction points.
  396. 1.7. In more detail: Keeping crypto keys offline
  397. In this design, a hidden service's secret identity key may be
  398. stored offline. It's used only to generate blinded signing keys,
  399. which are used to sign descriptor signing keys.
  400. In order to operate a hidden service, the operator can generate in
  401. advance a number of blinded signing keys and descriptor signing
  402. keys (and their credentials; see [DESC-OUTER] and [HS-DESC-ENC]
  403. below), and their corresponding descriptor encryption keys, and
  404. export those to the hidden service hosts.
  405. As a result, in the scenario where the Hidden Service gets
  406. compromised, the adversary can only impersonate it for a limited
  407. period of time (depending on how many signing keys were generated
  408. in advance).
  409. It's important to not send the private part of the blinded signing
  410. key to the Hidden Service since an attacker can derive from it the
  411. secret master identity key. The secret blinded signing key should
  412. only be used to create credentials for the descriptor signing keys.
  413. (NOTE: although the protocol allows them, offline keys are not
  414. implemented as of 0.3.2.1-alpha.)
  415. 1.8. In more detail: Encryption Keys And Replay Resistance
  416. To avoid replays of an introduction request by an introduction point,
  417. a hidden service host must never accept the same request
  418. twice. Earlier versions of the hidden service design used an
  419. authenticated timestamp here, but including a view of the current
  420. time can create a problematic fingerprint. (See proposal 222 for more
  421. discussion.)
  422. 1.9. In more detail: A menagerie of keys
  423. [In the text below, an "encryption keypair" is roughly "a keypair you
  424. can do Diffie-Hellman with" and a "signing keypair" is roughly "a
  425. keypair you can do ECDSA with."]
  426. Public/private keypairs defined in this document:
  427. Master (hidden service) identity key -- A master signing keypair
  428. used as the identity for a hidden service. This key is long
  429. term and not used on its own to sign anything; it is only used
  430. to generate blinded signing keys as described in [KEYBLIND]
  431. and [SUBCRED]. The public key is encoded in the ".onion"
  432. address according to [NAMING].
  433. Blinded signing key -- A keypair derived from the identity key,
  434. used to sign descriptor signing keys. It changes periodically for
  435. each service. Clients who know a 'credential' consisting of the
  436. service's public identity key and an optional secret can derive
  437. the public blinded identity key for a service. This key is used
  438. as an index in the DHT-like structure of the directory system
  439. (see [SUBCRED]).
  440. Descriptor signing key -- A key used to sign hidden service
  441. descriptors. This is signed by blinded signing keys. Unlike
  442. blinded signing keys and master identity keys, the secret part
  443. of this key must be stored online by hidden service hosts. The
  444. public part of this key is included in the unencrypted section
  445. of HS descriptors (see [DESC-OUTER]).
  446. Introduction point authentication key -- A short-term signing
  447. keypair used to identify a hidden service to a given
  448. introduction point. A fresh keypair is made for each
  449. introduction point; these are used to sign the request that a
  450. hidden service host makes when establishing an introduction
  451. point, so that clients who know the public component of this key
  452. can get their introduction requests sent to the right
  453. service. No keypair is ever used with more than one introduction
  454. point. (previously called a "service key" in rend-spec.txt)
  455. Introduction point encryption key -- A short-term encryption
  456. keypair used when establishing connections via an introduction
  457. point. Plays a role analogous to Tor nodes' onion keys. A fresh
  458. keypair is made for each introduction point.
  459. Symmetric keys defined in this document:
  460. Descriptor encryption keys -- A symmetric encryption key used to
  461. encrypt the body of hidden service descriptors. Derived from the
  462. current period and the hidden service credential.
  463. Public/private keypairs defined elsewhere:
  464. Onion key -- Short-term encryption keypair
  465. (Node) identity key
  466. Symmetric key-like things defined elsewhere:
  467. KH from circuit handshake -- An unpredictable value derived as
  468. part of the Tor circuit extension handshake, used to tie a request
  469. to a particular circuit.
  470. 1.9.1. In even more detail: Client authorization keys [CLIENT-AUTH]
  471. When client authorization is enabled, each authorized client of a hidden
  472. service has two more assymetric keypairs which are shared with the hidden
  473. service. An entity without those keys is not able to use the hidden
  474. service. Throughout this document, we assume that these pre-shared keys are
  475. exchanged between the hidden service and its clients in a secure out-of-band
  476. fashion.
  477. Specifically, each authorized client possesses:
  478. - An x25519 keypair used to compute decryption keys that allow the client to
  479. decrypt the hidden service descriptor. See [HS-DESC-ENC].
  480. - An ed25519 keypair which allows the client to compute signatures which
  481. prove to the hidden service that the client is authorized. These
  482. signatures are inserted into the INTRODUCE1 cell, and without them the
  483. introduction to the hidden service cannot be completed. See [INTRO-AUTH].
  484. The right way to exchange these keys is to have the client generate keys and
  485. send the corresponding public keys to the hidden service out-of-band. An
  486. easier but less secure way of doing this exchange would be to have the
  487. hidden service generate the keypairs and pass the corresponding private keys
  488. to its clients. See section [CLIENT-AUTH-MGMT] for more details on how these
  489. keys should be managed.
  490. [TODO: Also specify stealth client authorization.]
  491. (NOTE: client authorization is not implemented as of 0.3.2.1-alpha.)
  492. 2. Generating and publishing hidden service descriptors [HSDIR]
  493. Hidden service descriptors follow the same metaformat as other Tor
  494. directory objects. They are published anonymously to Tor servers with the
  495. HSDir flag, HSDir=2 protocol version and tor version >= 0.3.0.8 (because a
  496. bug was fixed in this version).
  497. 2.1. Deriving blinded keys and subcredentials [SUBCRED]
  498. In each time period (see [TIME-PERIODS] for a definition of time
  499. periods), a hidden service host uses a different blinded private key
  500. to sign its directory information, and clients use a different
  501. blinded public key as the index for fetching that information.
  502. For a candidate for a key derivation method, see Appendix [KEYBLIND].
  503. Additionally, clients and hosts derive a subcredential for each
  504. period. Knowledge of the subcredential is needed to decrypt hidden
  505. service descriptors for each period and to authenticate with the
  506. hidden service host in the introduction process. Unlike the
  507. credential, it changes each period. Knowing the subcredential, even
  508. in combination with the blinded private key, does not enable the
  509. hidden service host to derive the main credential--therefore, it is
  510. safe to put the subcredential on the hidden service host while
  511. leaving the hidden service's private key offline.
  512. The subcredential for a period is derived as:
  513. subcredential = H("subcredential" | credential | blinded-public-key).
  514. In the above formula, credential corresponds to:
  515. credential = H("credential" | public-identity-key)
  516. where public-identity-key is the public identity master key of the hidden
  517. service.
  518. 2.2. Locating, uploading, and downloading hidden service descriptors
  519. [HASHRING]
  520. To avoid attacks where a hidden service's descriptor is easily
  521. targeted for censorship, we store them at different directories over
  522. time, and use shared random values to prevent those directories from
  523. being predictable far in advance.
  524. Which Tor servers hosts a hidden service depends on:
  525. * the current time period,
  526. * the daily subcredential,
  527. * the hidden service directories' public keys,
  528. * a shared random value that changes in each time period,
  529. * a set of network-wide networkstatus consensus parameters.
  530. (Consensus parameters are integer values voted on by authorities
  531. and published in the consensus documents, described in
  532. dir-spec.txt, section 3.3.)
  533. Below we explain in more detail.
  534. 2.2.1. Dividing time into periods [TIME-PERIODS]
  535. To prevent a single set of hidden service directory from becoming a
  536. target by adversaries looking to permanently censor a hidden service,
  537. hidden service descriptors are uploaded to different locations that
  538. change over time.
  539. The length of a "time period" is controlled by the consensus
  540. parameter 'hsdir-interval', and is a number of minutes between 30 and
  541. 14400 (10 days). The default time period length is 1440 (one day).
  542. Time periods start at the Unix epoch (Jan 1, 1970), and are computed by
  543. taking the number of minutes since the epoch and dividing by the time
  544. period. However, we want our time periods to start at 12:00UTC every day, so
  545. we subtract a "rotation time offset" of 12*60 minutes from the number of
  546. minutes since the epoch, before dividing by the time period (effectively
  547. making "our" epoch start at Jan 1, 1970 12:00UTC).
  548. Example: If the current time is 2016-04-13 11:15:01 UTC, making the seconds
  549. since the epoch 1460546101, and the number of minutes since the epoch
  550. 24342435. We then subtract the "rotation time offset" of 12*60 minutes from
  551. the minutes since the epoch, to get 24341715. If the current time period
  552. length is 1440 minutes, by doing the division we see that we are currently
  553. in time period number 16903.
  554. Specifically, time period #16903 began 16903*1440*60 + (12*60*60) seconds
  555. after the epoch, at 2016-04-12 12:00 UTC, and ended at 16904*1440*60 +
  556. (12*60*60) seconds after the epoch, at 2016-04-13 12:00 UTC.
  557. 2.2.2. When to publish a hidden service descriptor [WHEN-HSDESC]
  558. Hidden services periodically publish their descriptor to the responsible
  559. HSDirs. The set of responsible HSDirs is determined as specified in
  560. [WHERE-HSDESC].
  561. Specifically, everytime a hidden service publishes its descriptor, it also
  562. sets up a timer for a random time between 60 minutes and 120 minutes in the
  563. future. When the timer triggers, the hidden service needs to publish its
  564. descriptor again to the responsible HSDirs for that time period.
  565. [TODO: Control republish period using a consensus parameter?]
  566. 2.2.2.1. Overlapping descriptors
  567. Hidden services need to upload multiple descriptors so that they can be
  568. reachable to clients with older or newer consensuses than them. Services
  569. need to upload their descriptors to the HSDirs _before_ the beginning of
  570. each upcoming time period, so that they are readily available for clients to
  571. fetch them. Furthermore, services should keep uploading their old descriptor
  572. even after the end of a time period, so that they can be reachable by
  573. clients that still have consensuses from the previous time period.
  574. Hence, services maintain two active descriptors at every point. Clients on
  575. the other hand, don't have a notion of overlapping descriptors, and instead
  576. always download the descriptor for the current time period and shared random
  577. value. It's the job of the service to ensure that descriptors will be
  578. available for all clients. See section [FETCHUPLOADDESC] for how this is
  579. achieved.
  580. [TODO: What to do when we run multiple hidden services in a single host?]
  581. 2.2.3. Where to publish a hidden service descriptor [WHERE-HSDESC]
  582. This section specifies how the HSDir hash ring is formed at any given
  583. time. Whenever a time value is needed (e.g. to get the current time period
  584. number), we assume that clients and services use the valid-after time from
  585. their latest live consensus.
  586. The following consensus parameters control where a hidden service
  587. descriptor is stored;
  588. hsdir_n_replicas = an integer in range [1,16] with default value 2.
  589. hsdir_spread_fetch = an integer in range [1,128] with default value 3.
  590. hsdir_spread_store = an integer in range [1,128] with default value 4.
  591. (Until 0.3.2.8-rc, the default was 3.)
  592. To determine where a given hidden service descriptor will be stored
  593. in a given period, after the blinded public key for that period is
  594. derived, the uploading or downloading party calculates:
  595. for replicanum in 1...hsdir_n_replicas:
  596. hs_index(replicanum) = H("store-at-idx" |
  597. blinded_public_key |
  598. INT_8(replicanum) |
  599. INT_8(period_length) |
  600. INT_8(period_num) )
  601. where blinded_public_key is specified in section [KEYBLIND], period_length
  602. is the length of the time period in minutes, and period_num is calculated
  603. using the current consensus "valid-after" as specified in section
  604. [TIME-PERIODS].
  605. Then, for each node listed in the current consensus with the HSDirV3 flag,
  606. we compute a directory index for that node as:
  607. hsdir_index(node) = H("node-idx" | node_identity |
  608. shared_random_value |
  609. INT_8(period_num) |
  610. INT_8(period_length) )
  611. where shared_random_value is the shared value generated by the authorities
  612. in section [PUB-SHAREDRANDOM], and node_identity is the ed25519 identity
  613. key of the node.
  614. Finally, for replicanum in 1...hsdir_n_replicas, the hidden service
  615. host uploads descriptors to the first hsdir_spread_store nodes whose
  616. indices immediately follow hs_index(replicanum). If any of those
  617. nodes have already been selected for a lower-numbered replica of the
  618. service, any nodes already chosen are disregarded (i.e. skipped over)
  619. when choosing a replica's hsdir_spread_store nodes.
  620. When choosing an HSDir to download from, clients choose randomly from
  621. among the first hsdir_spread_fetch nodes after the indices. (Note
  622. that, in order to make the system better tolerate disappearing
  623. HSDirs, hsdir_spread_fetch may be less than hsdir_spread_store.)
  624. Again, nodes from lower-numbered replicas are disregarded when
  625. choosing the spread for a replica.
  626. 2.2.4. Using time periods and SRVs to fetch/upload HS descriptors [FETCHUPLOADDESC]
  627. Hidden services and clients need to make correct use of time periods (TP)
  628. and shared random values (SRVs) to successfuly fetch and upload
  629. descriptors. Furthermore, to avoid problems with skewed clocks, both clients
  630. and services use the 'valid-after' time of a live consensus as a way to take
  631. decisions with regards to uploading and fetching descriptors. By using the
  632. consensus times as the ground truth here, we minimize the desynchronization
  633. of clients and services due to system clock. Whenever time-based decisions
  634. are taken in this section, assume that they are consensus times and not
  635. system times.
  636. As [PUB-SHAREDRANDOM] specifies, consensuses contain two shared random
  637. values (the current one and the previous one). Hidden services and clients
  638. are asked to match these shared random values with descriptor time periods
  639. and use the right SRV when fetching/uploading descriptors. This section
  640. attempts to precisely specify how this works.
  641. Let's start with an illustration of the system:
  642. +------------------------------------------------------------------+
  643. | |
  644. | 00:00 12:00 00:00 12:00 00:00 12:00 |
  645. | SRV#1 TP#1 SRV#2 TP#2 SRV#3 TP#3 |
  646. | |
  647. | $==========|-----------$===========|-----------$===========| |
  648. | |
  649. | |
  650. +------------------------------------------------------------------+
  651. Legend: [TP#1 = Time Period #1]
  652. [SRV#1 = Shared Random Value #1]
  653. ["$" = descriptor rotation moment]
  654. 2.2.4.1. Client behavior for fetching descriptors [CLIENTFETCH]
  655. And here is how clients use TPs and SRVs to fetch descriptors:
  656. Clients always aim to synchronize their TP with SRV, so they always want to
  657. use TP#N with SRV#N: To achieve this wrt time periods, clients always use
  658. the current time period when fetching descriptors. Now wrt SRVs, if a client
  659. is in the time segment between a new time period and a new SRV (i.e. the
  660. segments drawn with "-") it uses the current SRV, else if the client is in a
  661. time segment between a new SRV and a new time period (i.e. the segments
  662. drawn with "="), it uses the previous SRV.
  663. Example:
  664. +------------------------------------------------------------------+
  665. | |
  666. | 00:00 12:00 00:00 12:00 00:00 12:00 |
  667. | SRV#1 TP#1 SRV#2 TP#2 SRV#3 TP#3 |
  668. | |
  669. | $==========|-----------$===========|-----------$===========| |
  670. | ^ ^ |
  671. | C1 C2 |
  672. +------------------------------------------------------------------+
  673. If a client (C1) is at 13:00 right after TP#1, then it will use TP#1 and
  674. SRV#1 for fetching descriptors. Also, if a client (C2) is at 01:00 right
  675. after SRV#2, it will still use TP#1 and SRV#1.
  676. 2.2.4.2. Service behavior for uploading descriptors [SERVICEUPLOAD]
  677. As discussed above, services maintain two active descriptors at any time. We
  678. call these the "first" and "second" service descriptors. Services rotate
  679. their descriptor everytime they receive a consensus with a valid_after time
  680. past the next SRV calculation time. They rotate their descriptors by
  681. discarding their first descriptor, pushing the second descriptor to the
  682. first, and rebuilding their second descriptor with the latest data.
  683. Services like clients also employ a different logic for picking SRV and TP
  684. values based on their position in the graph above. Here is the logic:
  685. 2.2.4.2.1. First descriptor upload logic [FIRSTDESCUPLOAD]
  686. Here is the service logic for uploading its first descriptor:
  687. When a service is in the time segment between a new time period a new SRV
  688. (i.e. the segments drawn with "-"), it uses the previous time period and
  689. previous SRV for uploading its first descriptor: that's meant to cover
  690. for clients that have a consensus that is still in the previous time period.
  691. Example: Consider in the above illustration that the service is at 13:00
  692. right after TP#1. It will upload its first descriptor using TP#0 and SRV#0.
  693. So if a client still has a 11:00 consensus it will be able to access it
  694. based on the client logic above.
  695. Now if a service is in the time segment between a new SRV and a new time
  696. period (i.e. the segments drawn with "=") it uses the current time period
  697. and the previous SRV for its first descriptor: that's meant to cover clients
  698. with an up-to-date consensus in the same time period as the service.
  699. Example:
  700. +------------------------------------------------------------------+
  701. | |
  702. | 00:00 12:00 00:00 12:00 00:00 12:00 |
  703. | SRV#1 TP#1 SRV#2 TP#2 SRV#3 TP#3 |
  704. | |
  705. | $==========|-----------$===========|-----------$===========| |
  706. | ^ |
  707. | S |
  708. +------------------------------------------------------------------+
  709. Consider that the service is at 01:00 right after SRV#2: it will upload its
  710. first descriptor using TP#1 and SRV#1.
  711. 2.2.4.2.2. Second descriptor upload logic [SECONDDESCUPLOAD]
  712. Here is the service logic for uploading its second descriptor:
  713. When a service is in the time segment between a new time period a new SRV
  714. (i.e. the segments drawn with "-"), it uses the current time period and
  715. current SRV for uploading its second descriptor: that's meant to cover for
  716. clients that have an up-to-date consensus on the same TP as the service.
  717. Example: Consider in the above illustration that the service is at 13:00
  718. right after TP#1: it will upload its second descriptor using TP#1 and SRV#1.
  719. Now if a service is in the time segment between a new SRV and a new time
  720. period (i.e. the segments drawn with "=") it uses the next time period and
  721. the current SRV for its second descriptor: that's meant to cover clients
  722. with a newer consensus than the service (in the next time period).
  723. Example:
  724. +------------------------------------------------------------------+
  725. | |
  726. | 00:00 12:00 00:00 12:00 00:00 12:00 |
  727. | SRV#1 TP#1 SRV#2 TP#2 SRV#3 TP#3 |
  728. | |
  729. | $==========|-----------$===========|-----------$===========| |
  730. | ^ |
  731. | S |
  732. +------------------------------------------------------------------+
  733. Consider that the service is at 01:00 right after SRV#2: it will upload its
  734. second descriptor using TP#2 and SRV#2.
  735. 2.2.5. Expiring hidden service descriptors [EXPIRE-DESC]
  736. Hidden services set their descriptor's "descriptor-lifetime" field to 180
  737. minutes (3 hours). Hidden services ensure that their descriptor will remain
  738. valid in the HSDir caches, by republishing their descriptors periodically as
  739. specified in [WHEN-HSDESC].
  740. Hidden services MUST also keep their introduction circuits alive for as long
  741. as descriptors including those intro points are valid (even if that's after
  742. the time period has changed).
  743. 2.2.6. URLs for anonymous uploading and downloading
  744. Hidden service descriptors conforming to this specification are uploaded
  745. with an HTTP POST request to the URL /tor/hs/<version>/publish relative to
  746. the hidden service directory's root, and downloaded with an HTTP GET
  747. request for the URL /tor/hs/<version>/<z> where <z> is a base64 encoding of
  748. the hidden service's blinded public key and <version> is the protocol
  749. version which is "3" in this case.
  750. These requests must be made anonymously, on circuits not used for
  751. anything else.
  752. 2.2.7. Client-side validation of onion addresses
  753. When a Tor client receives a prop224 onion address from the user, it
  754. MUST first validate the onion address before attempting to connect or
  755. fetch its descriptor. If the validation fails, the client MUST
  756. refuse to connect.
  757. As part of the address validation, Tor clients should check that the
  758. underlying ed25519 key does not have a torsion component. If Tor accepted
  759. ed25519 keys with torsion components, attackers could create multiple
  760. equivalent onion addresses for a single ed25519 key, which would map to the
  761. same service. We want to avoid that because it could lead to phishing
  762. attacks and surprising behaviors (e.g. imagine a browser plugin that blocks
  763. onion addresses, but could be bypassed using an equivalent onion address
  764. with a torsion component).
  765. The right way for clients to detect such fraudulent addresses (which should
  766. only occur malevolently and never natutally) is to extract the ed25519
  767. public key from the onion address and multiply it by the ed25519 group order
  768. and ensure that the result is the ed25519 identity element. For more
  769. details, please see [TORSION-REFS].
  770. 2.3. Publishing shared random values [PUB-SHAREDRANDOM]
  771. Our design for limiting the predictability of HSDir upload locations
  772. relies on a shared random value (SRV) that isn't predictable in advance or
  773. too influenceable by an attacker. The authorities must run a protocol
  774. to generate such a value at least once per hsdir period. Here we
  775. describe how they publish these values; the procedure they use to
  776. generate them can change independently of the rest of this
  777. specification. For more information see [SHAREDRANDOM-REFS].
  778. According to proposal 250, we add two new lines in consensuses:
  779. "shared-rand-previous-value" SP NUM_REVEALS SP VALUE NL
  780. "shared-rand-current-value" SP NUM_REVEALS SP VALUE NL
  781. 2.3.1. Client behavior in the absense of shared random values
  782. If the previous or current shared random value cannot be found in a
  783. consensus, then Tor clients and services need to generate their own random
  784. value for use when choosing HSDirs.
  785. To do so, Tor clients and services use:
  786. SRV = H("shared-random-disaster" | INT_8(period_length) | INT_8(period_num))
  787. where period_length is the length of a time period in minutes, period_num is
  788. calculated as specified in [TIME-PERIODS] for the wanted shared random value
  789. that could not be found originally.
  790. 2.3.2. Hidden services and changing shared random values
  791. It's theoretically possible that the consensus shared random values will
  792. change or disappear in the middle of a time period because of directory
  793. authorities dropping offline or misbehaving.
  794. To avoid client reachability issues in this rare event, hidden services
  795. should use the new shared random values to find the new responsible HSDirs
  796. and upload their descriptors there.
  797. XXX How long should they upload descriptors there for?
  798. 2.4. Hidden service descriptors: outer wrapper [DESC-OUTER]
  799. The format for a hidden service descriptor is as follows, using the
  800. meta-format from dir-spec.txt.
  801. "hs-descriptor" SP version-number NL
  802. [At start, exactly once.]
  803. The version-number is a 32 bit unsigned integer indicating the version
  804. of the descriptor. Current version is "3".
  805. "descriptor-lifetime" SP LifetimeMinutes NL
  806. [Exactly once]
  807. The lifetime of a descriptor in minutes. An HSDir SHOULD expire the
  808. hidden service descriptor at least LifetimeMinutes after it was
  809. uploaded.
  810. The LifetimeMinutes field can take values between 30 and 720 (12
  811. hours).
  812. "descriptor-signing-key-cert" NL certificate NL
  813. [Exactly once.]
  814. The 'certificate' field contains a certificate in the format from
  815. proposal 220, wrapped with "-----BEGIN ED25519 CERT-----". The
  816. certificate cross-certifies the short-term descriptor signing key with
  817. the blinded public key. The certificate type must be [08], and the
  818. blinded public key must be present as the signing-key extension.
  819. "revision-counter" SP Integer NL
  820. [Exactly once.]
  821. The revision number of the descriptor. If an HSDir receives a
  822. second descriptor for a key that it already has a descriptor for,
  823. it should retain and serve the descriptor with the higher
  824. revision-counter.
  825. (Checking for monotonically increasing revision-counter values
  826. prevents an attacker from replacing a newer descriptor signed by
  827. a given key with a copy of an older version.)
  828. "superencrypted" NL encrypted-string
  829. [Exactly once.]
  830. An encrypted blob, whose format is discussed in [HS-DESC-ENC] below. The
  831. blob is base64 encoded and enclosed in -----BEGIN MESSAGE---- and
  832. ----END MESSAGE---- wrappers. (The resulting document does not end with
  833. a newline character.)
  834. "signature" SP signature NL
  835. [exactly once, at end.]
  836. A signature of all previous fields, using the signing key in the
  837. descriptor-signing-key-cert line, prefixed by the string "Tor onion
  838. service descriptor sig v3". We use a separate key for signing, so that
  839. the hidden service host does not need to have its private blinded key
  840. online.
  841. HSDirs accept hidden service descriptors of up to 50k bytes (a consensus
  842. parameter should also be introduced to control this value).
  843. 2.5. Hidden service descriptors: encryption format [HS-DESC-ENC]
  844. Hidden service descriptors are protected by two layers of encryption.
  845. Clients need to decrypt both layers to connect to the hidden service.
  846. The first layer of encryption provides confidentiality against entities who
  847. don't know the public key of the hidden service (e.g. HSDirs), while the
  848. second layer of encryption is only useful when client authorization is enabled
  849. and protects against entities that do not possess valid client credentials.
  850. 2.5.1. First layer of encryption [HS-DESC-FIRST-LAYER]
  851. The first layer of HS descriptor encryption is designed to protect
  852. descriptor confidentiality against entities who don't know the public
  853. identity key of the hidden service.
  854. 2.5.1.1. First layer encryption logic
  855. The encryption keys and format for the first layer of encryption are
  856. generated as specified in [HS-DESC-ENCRYPTION-KEYS] with customization
  857. parameters:
  858. SECRET_DATA = blinded-public-key
  859. STRING_CONSTANT = "hsdir-superencrypted-data"
  860. The encryption scheme in [HS-DESC-ENCRYPTION-KEYS] uses the service
  861. credential which is derived from the public identity key (see [SUBCRED]) to
  862. ensure that only entities who know the public identity key can decrypt the
  863. first descriptor layer.
  864. The ciphertext is placed on the "superencrypted" field of the descriptor.
  865. Before encryption the plaintext is padded with NUL bytes to the nearest
  866. multiple of 10k bytes.
  867. 2.5.1.2. First layer plaintext format
  868. After clients decrypt the first layer of encryption, they need to parse the
  869. plaintext to get to the second layer ciphertext which is contained in the
  870. "encrypted" field.
  871. If client auth is enabled, the hidden service generates a fresh
  872. descriptor_cookie key (32 random bytes) and encrypts it using each
  873. authorized client's identity x25519 key. Authorized clients can use the
  874. descriptor cookie to decrypt the second layer of encryption. Our encryption
  875. scheme requires the hidden service to also generate an ephemeral x25519
  876. keypair for each new descriptor.
  877. If client auth is disabled, fake data is placed in each of the fields below
  878. to obfuscate whether client authorization is enabled.
  879. Here are all the supported fields:
  880. "desc-auth-type" SP type NL
  881. [Exactly once]
  882. This field contains the type of authorization used to protect the
  883. descriptor. The only recognized type is "x25519" and specifies the
  884. encryption scheme described in this section.
  885. If client authorization is disabled, the value here should be "x25519".
  886. "desc-auth-ephemeral-key" SP key NL
  887. [Exactly once]
  888. This field contains an ephemeral x25519 public key generated by the
  889. hidden service and encoded in base64. The key is used by the encryption
  890. scheme below.
  891. If client authorization is disabled, the value here should be a fresh
  892. x25519 pubkey that will remain unused.
  893. "auth-client" SP client-id SP iv SP encrypted-cookie
  894. [Any number]
  895. (NOTE: client authorization is not implemented as of 0.3.2.1-alpha.)
  896. When client authorization is enabled, the hidden service inserts an
  897. "auth-client" line for each of its authorized clients. If client
  898. authorization is disabled, the fields here can be populated with random
  899. data of the right size (that's 8 bytes for 'client-id', 16 bytes for 'iv'
  900. and 16 bytes for 'encrypted-cookie' all encoded with base64).
  901. When client authorization is enabled, each "auth-client" line contains
  902. the descriptor cookie encrypted to each individual client. We assume that
  903. each authorized client possesses a pre-shared x25519 keypair which is
  904. used to decrypt the descriptor cookie.
  905. We now describe the descriptor cookie encryption scheme. Here are the
  906. relevant keys:
  907. client_x = private x25519 key of authorized client
  908. client_X = public x25519 key of authorized client
  909. hs_y = private key of ephemeral x25519 keypair of hidden service
  910. hs_Y = public key of ephemeral x25519 keypair of hidden service
  911. descriptor_cookie = descriptor cookie used to encrypt the descriptor
  912. And here is what the hidden service computes:
  913. SECRET_SEED = x25519(hs_y, client_X)
  914. KEYS = KDF(subcredential | SECRET_SEED, 40)
  915. CLIENT-ID = fist 8 bytes of KEYS
  916. COOKIE-KEY = last 32 bytes of KEYS
  917. Here is a description of the fields in the "auth-client" line:
  918. - The "client-id" field is CLIENT-ID from above encoded in base64.
  919. - The "iv" field is 16 random bytes encoded in base64.
  920. - The "encrypted-cookie" field contains the descriptor cookie ciphertext
  921. as follows and is encoded in base64:
  922. encrypted-cookie = STREAM(iv, COOKIE-KEY) XOR descriptor_cookie
  923. See section [FIRST-LAYER-CLIENT-BEHAVIOR] for the client-side logic of
  924. how to decrypt the descriptor cookie.
  925. "encrypted" NL encrypted-string
  926. [Exactly once]
  927. An encrypted blob containing the second layer ciphertext, whose format is
  928. discussed in [HS-DESC-SECOND-LAYER] below. The blob is base64 encoded
  929. and enclosed in -----BEGIN MESSAGE---- and ----END MESSAGE---- wrappers.
  930. 2.5.1.3. Client behavior [FIRST-LAYER-CLIENT-BEHAVIOR]
  931. The goal of clients at this stage is to decrypt the "encrypted" field as
  932. described in [HS-DESC-SECOND-LAYER].
  933. If client authorization is enabled, authorized clients need to extract the
  934. descriptor cookie to proceed with decryption of the second layer as
  935. follows:
  936. An authorized client parsing the first layer of an encrypted descriptor,
  937. extracts the ephemeral key from "desc-auth-ephemeral-key" and calculates
  938. CLIENT-ID and COOKIE-KEY as described in the section above using their
  939. x25519 private key. The client then uses CLIENT-ID to find the right
  940. "auth-client" field which contains the ciphertext of the descriptor
  941. cookie. The client then uses COOKIE-KEY and the iv to decrypt the
  942. descriptor_cookie, which is used to decrypt the second layer of descriptor
  943. encryption as described in [HS-DESC-SECOND-LAYER].
  944. 2.5.1.4. Hiding client authorization data
  945. Hidden services should avoid leaking whether client authorization is
  946. enabled or how many authorized clients there are.
  947. Hence even when client authorization is disabled, the hidden service adds
  948. fake "desc-auth-type", "desc-auth-ephemeral-key" and "auth-client" lines to
  949. the descriptor, as described in [HS-DESC-FIRST-LAYER].
  950. The hidden service also avoids leaking the number of authorized clients by
  951. adding fake "auth-client" entries to its descriptor. Specifically,
  952. descriptors always contain a number of authorized clients that is a
  953. multiple of 16 by adding fake "auth-client" entries if needed.
  954. [XXX consider randomization of the value 16]
  955. Clients MUST accept descriptors with any number of "auth-client" lines as
  956. long as the total descriptor size is within the max limit of 50k (also
  957. controlled with a consensus parameter).
  958. 2.5.2. Second layer of encryption [HS-DESC-SECOND-LAYER]
  959. The second layer of descriptor encryption is designed to protect descriptor
  960. confidentiality against unauthorized clients. If client authorization is
  961. enabled, it's encrypted using the descriptor_cookie, and contains needed
  962. information for connecting to the hidden service, like the list of its
  963. introduction points.
  964. If client authorization is disabled, then the second layer of HS encryption
  965. does not offer any additional security, but is still used.
  966. 2.5.2.1. Second layer encryption keys
  967. The encryption keys and format for the second layer of encryption are
  968. generated as specified in [HS-DESC-ENCRYPTION-KEYS] with customization
  969. parameters as follows:
  970. SECRET_DATA = blinded-public-key | descriptor_cookie
  971. STRING_CONSTANT = "hsdir-encrypted-data"
  972. If client authorization is disabled the 'descriptor_cookie' field is left blank.
  973. The ciphertext is placed on the "encrypted" field of the descriptor.
  974. 2.5.2.2. Second layer plaintext format
  975. After decrypting the second layer ciphertext, clients can finally learn the
  976. list of intro points etc. The plaintext has the following format:
  977. "create2-formats" SP formats NL
  978. [Exactly once]
  979. A space-separated list of integers denoting CREATE2 cell format numbers
  980. that the server recognizes. Must include at least ntor as described in
  981. tor-spec.txt. See tor-spec section 5.1 for a list of recognized
  982. handshake types.
  983. "intro-auth-required" SP types NL
  984. [At most once]
  985. A space-separated list of introduction-layer authentication types; see
  986. section [INTRO-AUTH] for more info. A client that does not support at
  987. least one of these authentication types will not be able to contact the
  988. host. Recognized types are: 'password' and 'ed25519'.
  989. "single-onion-service"
  990. [None or at most once]
  991. If present, this line indicates that the service is a Single Onion
  992. Service (see prop260 for more details about that type of service). This
  993. field has been introduced in 0.3.0 meaning 0.2.9 service don't include
  994. this.
  995. Followed by zero or more introduction points as follows (see section
  996. [NUM_INTRO_POINT] below for accepted values):
  997. "introduction-point" SP link-specifiers NL
  998. [Exactly once per introduction point at start of introduction
  999. point section]
  1000. The link-specifiers is a base64 encoding of a link specifier
  1001. block in the format described in BUILDING-BLOCKS.
  1002. As of 0.4.1.1-alpha, services include both IPv4 and IPv6 link
  1003. specifiers in descriptors. All available addresses SHOULD be
  1004. included in the descriptor, regardless of the address that the
  1005. onion service actually used to connect/extend to the intro
  1006. point.
  1007. The client SHOULD NOT reject any LSTYPE fields which it doesn't
  1008. recognize; instead, it should use them verbatim in its EXTEND
  1009. request to the introduction point.
  1010. The client MAY perform basic validity checks on the link
  1011. specifiers in the descriptor. These checks SHOULD NOT leak
  1012. detailed information about the client's version, configuration,
  1013. or consensus. (See 3.3 for service link specifier handling.)
  1014. "onion-key" SP "ntor" SP key NL
  1015. [Exactly once per introduction point]
  1016. The key is a base64 encoded curve25519 public key which is the onion
  1017. key of the introduction point Tor node used for the ntor handshake
  1018. when a client extends to it.
  1019. "auth-key" NL certificate NL
  1020. [Exactly once per introduction point]
  1021. The certificate is a proposal 220 certificate wrapped in
  1022. "-----BEGIN ED25519 CERT-----", cross-certifying the descriptor
  1023. signing key with the introduction point authentication key, which
  1024. is included in the mandatory signing-key extension. The certificate
  1025. type must be [09].
  1026. "enc-key" SP "ntor" SP key NL
  1027. [Exactly once per introduction point]
  1028. The key is a base64 encoded curve25519 public key used to encrypt
  1029. the introduction request to service.
  1030. "enc-key-cert" NL certificate NL
  1031. [Exactly once per introduction point]
  1032. Cross-certification of the descriptor signing key by the encryption
  1033. key.
  1034. For "ntor" keys, certificate is a proposal 220 certificate wrapped
  1035. in "-----BEGIN ED25519 CERT-----" armor, cross-certifying the
  1036. descriptor signing key with the ed25519 equivalent of a curve25519
  1037. public encryption key derived using the process in proposal 228
  1038. appendix A. The certificate type must be [0B], and the signing-key
  1039. extension is mandatory.
  1040. "legacy-key" NL key NL
  1041. [None or at most once per introduction point]
  1042. The key is an ASN.1 encoded RSA public key in PEM format used for a
  1043. legacy introduction point as described in [LEGACY_EST_INTRO].
  1044. This field is only present if the introduction point only supports
  1045. legacy protocol (v2) that is <= 0.2.9 or the protocol version value
  1046. "HSIntro 3".
  1047. "legacy-key-cert" NL certificate NL
  1048. [None or at most once per introduction point]
  1049. MUST be present if "legacy-key" is present.
  1050. The certificate is a proposal 220 RSA->Ed cross-certificate wrapped
  1051. in "-----BEGIN CROSSCERT-----" armor, cross-certifying the
  1052. descriptor signing key with the RSA public key found in
  1053. "legacy-key".
  1054. To remain compatible with future revisions to the descriptor format,
  1055. clients should ignore unrecognized lines in the descriptor.
  1056. Other encryption and authentication key formats are allowed; clients
  1057. should ignore ones they do not recognize.
  1058. Clients who manage to extract the introduction points of the hidden service
  1059. can prroceed with the introduction protocol as specified in [INTRO-PROTOCOL].
  1060. 2.5.3. Deriving hidden service descriptor encryption keys [HS-DESC-ENCRYPTION-KEYS]
  1061. In this section we present the generic encryption format for hidden service
  1062. descriptors. We use the same encryption format in both encryption layers,
  1063. hence we introduce two customization parameters SECRET_DATA and
  1064. STRING_CONSTANT which vary between the layers.
  1065. The SECRET_DATA parameter specifies the secret data that are used during
  1066. encryption key generation, while STRING_CONSTANT is merely a string constant
  1067. that is used as part of the KDF.
  1068. Here is the key generation logic:
  1069. SALT = 16 bytes from H(random), changes each time we rebuld the
  1070. descriptor even if the content of the descriptor hasn't changed.
  1071. (So that we don't leak whether the intro point list etc. changed)
  1072. secret_input = SECRET_DATA | subcredential | INT_8(revision_counter)
  1073. keys = KDF(secret_input | salt | STRING_CONSTANT, S_KEY_LEN + S_IV_LEN + MAC_KEY_LEN)
  1074. SECRET_KEY = first S_KEY_LEN bytes of keys
  1075. SECRET_IV = next S_IV_LEN bytes of keys
  1076. MAC_KEY = last MAC_KEY_LEN bytes of keys
  1077. The encrypted data has the format:
  1078. SALT hashed random bytes from above [16 bytes]
  1079. ENCRYPTED The ciphertext [variable]
  1080. MAC MAC of both above fields [32 bytes]
  1081. The final encryption format is ENCRYPTED = STREAM(SECRET_IV,SECRET_KEY) XOR Plaintext
  1082. 2.5.4. Number of introduction points [NUM_INTRO_POINT]
  1083. This section defines how many introduction points an hidden service
  1084. descriptor can have at minimum, by default and the maximum:
  1085. Minimum: 0 - Default: 3 - Maximum: 20
  1086. A value of 0 would means that the service is still alive but doesn't want
  1087. to be reached by any client at the moment. Note that the descriptor size
  1088. increases considerably as more introduction points are added.
  1089. The reason for a maximum value of 20 is to give enough scalability to tools
  1090. like OnionBalance to be able to load balance up to 120 servers (20 x 6
  1091. HSDirs) but also in order for the descriptor size to not overwhelmed hidden
  1092. service directories with user defined values that could be gigantic.
  1093. 3. The introduction protocol [INTRO-PROTOCOL]
  1094. The introduction protocol proceeds in three steps.
  1095. First, a hidden service host builds an anonymous circuit to a Tor
  1096. node and registers that circuit as an introduction point.
  1097. Single Onion Services attempt to build a non-anonymous single-hop circuit,
  1098. but use an anonymous 3-hop circuit if:
  1099. * the intro point is on an address that is configured as unreachable via
  1100. a direct connection, or
  1101. * the initial attempt to connect to the intro point over a single-hop
  1102. circuit fails, and they are retrying the intro point connection.
  1103. [After 'First' and before 'Second', the hidden service publishes its
  1104. introduction points and associated keys, and the client fetches
  1105. them as described in section [HSDIR] above.]
  1106. Second, a client builds an anonymous circuit to the introduction
  1107. point, and sends an introduction request.
  1108. Third, the introduction point relays the introduction request along
  1109. the introduction circuit to the hidden service host, and acknowledges
  1110. the introduction request to the client.
  1111. 3.1. Registering an introduction point [REG_INTRO_POINT]
  1112. 3.1.1. Extensible ESTABLISH_INTRO protocol. [EST_INTRO]
  1113. When a hidden service is establishing a new introduction point, it
  1114. sends an ESTABLISH_INTRO cell with the following contents:
  1115. AUTH_KEY_TYPE [1 byte]
  1116. AUTH_KEY_LEN [2 bytes]
  1117. AUTH_KEY [AUTH_KEY_LEN bytes]
  1118. N_EXTENSIONS [1 byte]
  1119. N_EXTENSIONS times:
  1120. EXT_FIELD_TYPE [1 byte]
  1121. EXT_FIELD_LEN [1 byte]
  1122. EXT_FIELD [EXT_FIELD_LEN bytes]
  1123. HANDSHAKE_AUTH [MAC_LEN bytes]
  1124. SIG_LEN [2 bytes]
  1125. SIG [SIG_LEN bytes]
  1126. The AUTH_KEY_TYPE field indicates the type of the introduction point
  1127. authentication key and the type of the MAC to use in
  1128. HANDSHAKE_AUTH. Recognized types are:
  1129. [00, 01] -- Reserved for legacy introduction cells; see
  1130. [LEGACY_EST_INTRO below]
  1131. [02] -- Ed25519; SHA3-256.
  1132. The AUTH_KEY_LEN field determines the length of the AUTH_KEY
  1133. field. The AUTH_KEY field contains the public introduction point
  1134. authentication key.
  1135. The EXT_FIELD_TYPE, EXT_FIELD_LEN, EXT_FIELD entries are reserved for
  1136. future extensions to the introduction protocol. Extensions with
  1137. unrecognized EXT_FIELD_TYPE values must be ignored.
  1138. The HANDSHAKE_AUTH field contains the MAC of all earlier fields in
  1139. the cell using as its key the shared per-circuit material ("KH")
  1140. generated during the circuit extension protocol; see tor-spec.txt
  1141. section 5.2, "Setting circuit keys". It prevents replays of
  1142. ESTABLISH_INTRO cells.
  1143. SIG_LEN is the length of the signature.
  1144. SIG is a signature, using AUTH_KEY, of all contents of the cell, up
  1145. to but not including SIG. These contents are prefixed with the string
  1146. "Tor establish-intro cell v1".
  1147. Upon receiving an ESTABLISH_INTRO cell, a Tor node first decodes the
  1148. key and the signature, and checks the signature. The node must reject
  1149. the ESTABLISH_INTRO cell and destroy the circuit in these cases:
  1150. * If the key type is unrecognized
  1151. * If the key is ill-formatted
  1152. * If the signature is incorrect
  1153. * If the HANDSHAKE_AUTH value is incorrect
  1154. * If the circuit is already a rendezvous circuit.
  1155. * If the circuit is already an introduction circuit.
  1156. [TODO: some scalability designs fail there.]
  1157. * If the key is already in use by another circuit.
  1158. Otherwise, the node must associate the key with the circuit, for use
  1159. later in INTRODUCE1 cells.
  1160. 3.1.2. Registering an introduction point on a legacy Tor node
  1161. [LEGACY_EST_INTRO]
  1162. Tor nodes should also support an older version of the ESTABLISH_INTRO
  1163. cell, first documented in rend-spec.txt. New hidden service hosts
  1164. must use this format when establishing introduction points at older
  1165. Tor nodes that do not support the format above in [EST_INTRO].
  1166. In this older protocol, an ESTABLISH_INTRO cell contains:
  1167. KEY_LEN [2 bytes]
  1168. KEY [KEY_LEN bytes]
  1169. HANDSHAKE_AUTH [20 bytes]
  1170. SIG [variable, up to end of relay payload]
  1171. The KEY_LEN variable determines the length of the KEY field.
  1172. The KEY field is the ASN1-encoded legacy RSA public key that was also
  1173. included in the hidden service descriptor.
  1174. The HANDSHAKE_AUTH field contains the SHA1 digest of (KH | "INTRODUCE").
  1175. The SIG field contains an RSA signature, using PKCS1 padding, of all
  1176. earlier fields.
  1177. Older versions of Tor always use a 1024-bit RSA key for these introduction
  1178. authentication keys.
  1179. 3.1.3. Acknowledging establishment of introduction point [INTRO_ESTABLISHED]
  1180. After setting up an introduction circuit, the introduction point reports its
  1181. status back to the hidden service host with an INTRO_ESTABLISHED cell.
  1182. The INTRO_ESTABLISHED cell has the following contents:
  1183. N_EXTENSIONS [1 byte]
  1184. N_EXTENSIONS times:
  1185. EXT_FIELD_TYPE [1 byte]
  1186. EXT_FIELD_LEN [1 byte]
  1187. EXT_FIELD [EXT_FIELD_LEN bytes]
  1188. Older versions of Tor send back an empty INTRO_ESTABLISHED cell instead.
  1189. Services must accept an empty INTRO_ESTABLISHED cell from a legacy relay.
  1190. 3.2. Sending an INTRODUCE1 cell to the introduction point. [SEND_INTRO1]
  1191. In order to participate in the introduction protocol, a client must
  1192. know the following:
  1193. * An introduction point for a service.
  1194. * The introduction authentication key for that introduction point.
  1195. * The introduction encryption key for that introduction point.
  1196. The client sends an INTRODUCE1 cell to the introduction point,
  1197. containing an identifier for the service, an identifier for the
  1198. encryption key that the client intends to use, and an opaque blob to
  1199. be relayed to the hidden service host.
  1200. In reply, the introduction point sends an INTRODUCE_ACK cell back to
  1201. the client, either informing it that its request has been delivered,
  1202. or that its request will not succeed.
  1203. [TODO: specify what tor should do when receiving a malformed cell. Drop it?
  1204. Kill circuit? This goes for all possible cells.]
  1205. 3.2.1. INTRODUCE1 cell format [FMT_INTRO1]
  1206. When a client is connecting to an introduction point, INTRODUCE1 cells
  1207. should be of the form:
  1208. LEGACY_KEY_ID [20 bytes]
  1209. AUTH_KEY_TYPE [1 byte]
  1210. AUTH_KEY_LEN [2 bytes]
  1211. AUTH_KEY [AUTH_KEY_LEN bytes]
  1212. N_EXTENSIONS [1 byte]
  1213. N_EXTENSIONS times:
  1214. EXT_FIELD_TYPE [1 byte]
  1215. EXT_FIELD_LEN [1 byte]
  1216. EXT_FIELD [EXT_FIELD_LEN bytes]
  1217. ENCRYPTED [Up to end of relay payload]
  1218. AUTH_KEY_TYPE is defined as in [EST_INTRO]. Currently, the only value of
  1219. AUTH_KEY_TYPE for this cell is an Ed25519 public key [02].
  1220. The LEGACY_KEY_ID field is used to distinguish between legacy and new style
  1221. INTRODUCE1 cells. In new style INTRODUCE1 cells, LEGACY_KEY_ID is 20 zero
  1222. bytes. Upon receiving an INTRODUCE1 cell, the introduction point checks the
  1223. LEGACY_KEY_ID field. If LEGACY_KEY_ID is non-zero, the INTRODUCE1 cell
  1224. should be handled as a legacy INTRODUCE1 cell by the intro point.
  1225. Upon receiving a INTRODUCE1 cell, the introduction point checks
  1226. whether AUTH_KEY matches the introduction point authentication key for an
  1227. active introduction circuit. If so, the introduction point sends an
  1228. INTRODUCE2 cell with exactly the same contents to the service, and sends an
  1229. INTRODUCE_ACK response to the client.
  1230. 3.2.2. INTRODUCE_ACK cell format. [INTRO_ACK]
  1231. An INTRODUCE_ACK cell has the following fields:
  1232. STATUS [2 bytes]
  1233. N_EXTENSIONS [1 bytes]
  1234. N_EXTENSIONS times:
  1235. EXT_FIELD_TYPE [1 byte]
  1236. EXT_FIELD_LEN [1 byte]
  1237. EXT_FIELD [EXT_FIELD_LEN bytes]
  1238. Recognized status values are:
  1239. [00 00] -- Success: cell relayed to hidden service host.
  1240. [00 01] -- Failure: service ID not recognized
  1241. [00 02] -- Bad message format
  1242. [00 03] -- Can't relay cell to service
  1243. 3.3. Processing an INTRODUCE2 cell at the hidden service. [PROCESS_INTRO2]
  1244. Upon receiving an INTRODUCE2 cell, the hidden service host checks whether
  1245. the AUTH_KEY or LEGACY_KEY_ID field matches the keys for this
  1246. introduction circuit.
  1247. The service host then checks whether it has received a cell with these
  1248. contents or rendezvous cookie before. If it has, it silently drops it as a
  1249. replay. (It must maintain a replay cache for as long as it accepts cells
  1250. with the same encryption key. Note that the encryption format below should
  1251. be non-malleable.)
  1252. If the cell is not a replay, it decrypts the ENCRYPTED field,
  1253. establishes a shared key with the client, and authenticates the whole
  1254. contents of the cell as having been unmodified since they left the
  1255. client. There may be multiple ways of decrypting the ENCRYPTED field,
  1256. depending on the chosen type of the encryption key. Requirements for
  1257. an introduction handshake protocol are described in
  1258. [INTRO-HANDSHAKE-REQS]. We specify one below in section
  1259. [NTOR-WITH-EXTRA-DATA].
  1260. The decrypted plaintext must have the form:
  1261. RENDEZVOUS_COOKIE [20 bytes]
  1262. N_EXTENSIONS [1 byte]
  1263. N_EXTENSIONS times:
  1264. EXT_FIELD_TYPE [1 byte]
  1265. EXT_FIELD_LEN [1 byte]
  1266. EXT_FIELD [EXT_FIELD_LEN bytes]
  1267. ONION_KEY_TYPE [1 bytes]
  1268. ONION_KEY_LEN [2 bytes]
  1269. ONION_KEY [ONION_KEY_LEN bytes]
  1270. NSPEC (Number of link specifiers) [1 byte]
  1271. NSPEC times:
  1272. LSTYPE (Link specifier type) [1 byte]
  1273. LSLEN (Link specifier length) [1 byte]
  1274. LSPEC (Link specifier) [LSLEN bytes]
  1275. PAD (optional padding) [up to end of plaintext]
  1276. Upon processing this plaintext, the hidden service makes sure that
  1277. any required authentication is present in the extension fields, and
  1278. then extends a rendezvous circuit to the node described in the LSPEC
  1279. fields, using the ONION_KEY to complete the extension. As mentioned
  1280. in [BUILDING-BLOCKS], the "TLS-over-TCP, IPv4" and "Legacy node
  1281. identity" specifiers must be present.
  1282. As of 0.4.1.1-alpha, clients include both IPv4 and IPv6 link specifiers
  1283. in INTRODUCE1 cells. All available addresses SHOULD be included in the
  1284. cell, regardless of the address that the client actually used to extend
  1285. to the rendezvous point.
  1286. The hidden service should handle invalid or unrecognised link specifiers
  1287. the same way as clients do in section 2.5.2.2. In particular, services
  1288. MAY perform basic validity checks on link specifiers, and SHOULD NOT
  1289. reject unrecognised link specifiers, to avoid information leaks.
  1290. The ONION_KEY_TYPE field is:
  1291. [01] NTOR: ONION_KEY is 32 bytes long.
  1292. The ONION_KEY field describes the onion key that must be used when
  1293. extending to the rendezvous point. It must be of a type listed as
  1294. supported in the hidden service descriptor.
  1295. When using a legacy introduction point, the INTRODUCE cells must be padded
  1296. to a certain length using the PAD field in the encrypted portion.
  1297. Upon receiving a well-formed INTRODUCE2 cell, the hidden service host
  1298. will have:
  1299. * The information needed to connect to the client's chosen
  1300. rendezvous point.
  1301. * The second half of a handshake to authenticate and establish a
  1302. shared key with the hidden service client.
  1303. * A set of shared keys to use for end-to-end encryption.
  1304. 3.3.1. Introduction handshake encryption requirements [INTRO-HANDSHAKE-REQS]
  1305. When decoding the encrypted information in an INTRODUCE2 cell, a
  1306. hidden service host must be able to:
  1307. * Decrypt additional information included in the INTRODUCE2 cell,
  1308. to include the rendezvous token and the information needed to
  1309. extend to the rendezvous point.
  1310. * Establish a set of shared keys for use with the client.
  1311. * Authenticate that the cell has not been modified since the client
  1312. generated it.
  1313. Note that the old TAP-derived protocol of the previous hidden service
  1314. design achieved the first two requirements, but not the third.
  1315. 3.3.2. Example encryption handshake: ntor with extra data
  1316. [NTOR-WITH-EXTRA-DATA]
  1317. [TODO: relocate this]
  1318. This is a variant of the ntor handshake (see tor-spec.txt, section
  1319. 5.1.4; see proposal 216; and see "Anonymity and one-way
  1320. authentication in key-exchange protocols" by Goldberg, Stebila, and
  1321. Ustaoglu).
  1322. It behaves the same as the ntor handshake, except that, in addition
  1323. to negotiating forward secure keys, it also provides a means for
  1324. encrypting non-forward-secure data to the server (in this case, to
  1325. the hidden service host) as part of the handshake.
  1326. Notation here is as in section 5.1.4 of tor-spec.txt, which defines
  1327. the ntor handshake.
  1328. The PROTOID for this variant is "tor-hs-ntor-curve25519-sha3-256-1".
  1329. We also use the following tweak values:
  1330. t_hsenc = PROTOID | ":hs_key_extract"
  1331. t_hsverify = PROTOID | ":hs_verify"
  1332. t_hsmac = PROTOID | ":hs_mac"
  1333. m_hsexpand = PROTOID | ":hs_key_expand"
  1334. To make an INTRODUCE1 cell, the client must know a public encryption
  1335. key B for the hidden service on this introduction circuit. The client
  1336. generates a single-use keypair:
  1337. x,X = KEYGEN()
  1338. and computes:
  1339. intro_secret_hs_input = EXP(B,x) | AUTH_KEY | X | B | PROTOID
  1340. info = m_hsexpand | subcredential
  1341. hs_keys = KDF(intro_secret_hs_input | t_hsenc | info, S_KEY_LEN+MAC_LEN)
  1342. ENC_KEY = hs_keys[0:S_KEY_LEN]
  1343. MAC_KEY = hs_keys[S_KEY_LEN:S_KEY_LEN+MAC_KEY_LEN]
  1344. and sends, as the ENCRYPTED part of the INTRODUCE1 cell:
  1345. CLIENT_PK [PK_PUBKEY_LEN bytes]
  1346. ENCRYPTED_DATA [Padded to length of plaintext]
  1347. MAC [MAC_LEN bytes]
  1348. Substituting those fields into the INTRODUCE1 cell body format
  1349. described in [FMT_INTRO1] above, we have
  1350. LEGACY_KEY_ID [20 bytes]
  1351. AUTH_KEY_TYPE [1 byte]
  1352. AUTH_KEY_LEN [2 bytes]
  1353. AUTH_KEY [AUTH_KEY_LEN bytes]
  1354. N_EXTENSIONS [1 bytes]
  1355. N_EXTENSIONS times:
  1356. EXT_FIELD_TYPE [1 byte]
  1357. EXT_FIELD_LEN [1 byte]
  1358. EXT_FIELD [EXT_FIELD_LEN bytes]
  1359. ENCRYPTED:
  1360. CLIENT_PK [PK_PUBKEY_LEN bytes]
  1361. ENCRYPTED_DATA [Padded to length of plaintext]
  1362. MAC [MAC_LEN bytes]
  1363. (This format is as documented in [FMT_INTRO1] above, except that here
  1364. we describe how to build the ENCRYPTED portion.)
  1365. Here, the encryption key plays the role of B in the regular ntor
  1366. handshake, and the AUTH_KEY field plays the role of the node ID.
  1367. The CLIENT_PK field is the public key X. The ENCRYPTED_DATA field is
  1368. the message plaintext, encrypted with the symmetric key ENC_KEY. The
  1369. MAC field is a MAC of all of the cell from the AUTH_KEY through the
  1370. end of ENCRYPTED_DATA, using the MAC_KEY value as its key.
  1371. To process this format, the hidden service checks PK_VALID(CLIENT_PK)
  1372. as necessary, and then computes ENC_KEY and MAC_KEY as the client did
  1373. above, except using EXP(CLIENT_PK,b) in the calculation of
  1374. intro_secret_hs_input. The service host then checks whether the MAC is
  1375. correct. If it is invalid, it drops the cell. Otherwise, it computes
  1376. the plaintext by decrypting ENCRYPTED_DATA.
  1377. The hidden service host now completes the service side of the
  1378. extended ntor handshake, as described in tor-spec.txt section 5.1.4,
  1379. with the modified PROTOID as given above. To be explicit, the hidden
  1380. service host generates a keypair of y,Y = KEYGEN(), and uses its
  1381. introduction point encryption key 'b' to computes:
  1382. intro_secret_hs_input = EXP(X,b) | AUTH_KEY | X | B | PROTOID
  1383. info = m_hsexpand | subcredential
  1384. hs_keys = KDF(intro_secret_hs_input | t_hsenc | info, S_KEY_LEN+MAC_LEN)
  1385. HS_DEC_KEY = hs_keys[0:S_KEY_LEN]
  1386. HS_MAC_KEY = hs_keys[S_KEY_LEN:S_KEY_LEN+MAC_KEY_LEN]
  1387. (The above are used to check the MAC and then decrypt the
  1388. encrypted data.)
  1389. rend_secret_hs_input = EXP(X,y) | EXP(X,b) | AUTH_KEY | B | X | Y | PROTOID
  1390. NTOR_KEY_SEED = MAC(rend_secret_hs_input, t_hsenc)
  1391. verify = MAC(rend_secret_hs_input, t_hsverify)
  1392. auth_input = verify | AUTH_KEY | B | Y | X | PROTOID | "Server"
  1393. AUTH_INPUT_MAC = MAC(auth_input, t_hsmac)
  1394. (The above are used to finish the ntor handshake.)
  1395. The server's handshake reply is:
  1396. SERVER_PK Y [PK_PUBKEY_LEN bytes]
  1397. AUTH AUTH_INPUT_MAC [MAC_LEN bytes]
  1398. These fields will be sent to the client in a RENDEZVOUS1 cell using the
  1399. HANDSHAKE_INFO element (see [JOIN_REND]).
  1400. The hidden service host now also knows the keys generated by the
  1401. handshake, which it will use to encrypt and authenticate data
  1402. end-to-end between the client and the server. These keys are as
  1403. computed in tor-spec.txt section 5.1.4.
  1404. 3.4. Authentication during the introduction phase. [INTRO-AUTH]
  1405. Hidden services may restrict access only to authorized users.
  1406. One mechanism to do so is the credential mechanism, where only users who
  1407. know the credential for a hidden service may connect at all.
  1408. 3.4.1. Ed25519-based authentication.
  1409. To authenticate with an Ed25519 private key, the user must include an
  1410. extension field in the encrypted part of the INTRODUCE1 cell with an
  1411. EXT_FIELD_TYPE type of [02] and the contents:
  1412. Nonce [16 bytes]
  1413. Pubkey [32 bytes]
  1414. Signature [64 bytes]
  1415. Nonce is a random value. Pubkey is the public key that will be used
  1416. to authenticate. [TODO: should this be an identifier for the public
  1417. key instead?] Signature is the signature, using Ed25519, of:
  1418. "hidserv-userauth-ed25519"
  1419. Nonce (same as above)
  1420. Pubkey (same as above)
  1421. AUTH_KEY (As in the INTRODUCE1 cell)
  1422. The hidden service host checks this by seeing whether it recognizes
  1423. and would accept a signature from the provided public key. If it
  1424. would, then it checks whether the signature is correct. If it is,
  1425. then the correct user has authenticated.
  1426. Replay prevention on the whole cell is sufficient to prevent replays
  1427. on the authentication.
  1428. Users SHOULD NOT use the same public key with multiple hidden
  1429. services.
  1430. 4. The rendezvous protocol
  1431. Before connecting to a hidden service, the client first builds a
  1432. circuit to an arbitrarily chosen Tor node (known as the rendezvous
  1433. point), and sends an ESTABLISH_RENDEZVOUS cell. The hidden service
  1434. later connects to the same node and sends a RENDEZVOUS cell. Once
  1435. this has occurred, the relay forwards the contents of the RENDEZVOUS
  1436. cell to the client, and joins the two circuits together.
  1437. Single Onion Services attempt to build a non-anonymous single-hop circuit,
  1438. but use an anonymous 3-hop circuit if:
  1439. * the rend point is on an address that is configured as unreachable via
  1440. a direct connection, or
  1441. * the initial attempt to connect to the rend point over a single-hop
  1442. circuit fails, and they are retrying the rend point connection.
  1443. 4.1. Establishing a rendezvous point [EST_REND_POINT]
  1444. The client sends the rendezvous point a RELAY_COMMAND_ESTABLISH_RENDEZVOUS
  1445. cell containing a 20-byte value.
  1446. RENDEZVOUS_COOKIE [20 bytes]
  1447. Rendezvous points MUST ignore any extra bytes in an
  1448. ESTABLISH_RENDEZVOUS cell. (Older versions of Tor did not.)
  1449. The rendezvous cookie is an arbitrary 20-byte value, chosen randomly
  1450. by the client. The client SHOULD choose a new rendezvous cookie for
  1451. each new connection attempt. If the rendezvous cookie is already in
  1452. use on an existing circuit, the rendezvous point should reject it and
  1453. destroy the circuit.
  1454. Upon receiving an ESTABLISH_RENDEZVOUS cell, the rendezvous point associates
  1455. the cookie with the circuit on which it was sent. It replies to the client
  1456. with an empty RENDEZVOUS_ESTABLISHED cell to indicate success. Clients MUST
  1457. ignore any extra bytes in a RENDEZVOUS_ESTABLISHED cell.
  1458. The client MUST NOT use the circuit which sent the cell for any
  1459. purpose other than rendezvous with the given location-hidden service.
  1460. The client should establish a rendezvous point BEFORE trying to
  1461. connect to a hidden service.
  1462. 4.2. Joining to a rendezvous point [JOIN_REND]
  1463. To complete a rendezvous, the hidden service host builds a circuit to
  1464. the rendezvous point and sends a RENDEZVOUS1 cell containing:
  1465. RENDEZVOUS_COOKIE [20 bytes]
  1466. HANDSHAKE_INFO [variable; depends on handshake type
  1467. used.]
  1468. where RENDEZVOUS_COOKIE is the cookie suggested by the client during the
  1469. introduction (see [PROCESS_INTRO2]) and HANDSHAKE_INFO is defined in
  1470. [NTOR-WITH-EXTRA-DATA].
  1471. If the cookie matches the rendezvous cookie set on any
  1472. not-yet-connected circuit on the rendezvous point, the rendezvous
  1473. point connects the two circuits, and sends a RENDEZVOUS2 cell to the
  1474. client containing the HANDSHAKE_INFO field of the RENDEZVOUS1 cell.
  1475. Upon receiving the RENDEZVOUS2 cell, the client verifies that HANDSHAKE_INFO
  1476. correctly completes a handshake. To do so, the client parses SERVER_PK from
  1477. HANDSHAKE_INFO and reverses the final operations of section
  1478. [NTOR-WITH-EXTRA-DATA] as shown here:
  1479. rend_secret_hs_input = EXP(Y,x) | EXP(B,x) | AUTH_KEY | B | X | Y | PROTOID
  1480. NTOR_KEY_SEED = MAC(ntor_secret_input, t_hsenc)
  1481. verify = MAC(ntor_secret_input, t_hsverify)
  1482. auth_input = verify | AUTH_KEY | B | Y | X | PROTOID | "Server"
  1483. AUTH_INPUT_MAC = MAC(auth_input, t_hsmac)
  1484. Finally the client verifies that the received AUTH field of HANDSHAKE_INFO
  1485. is equal to the computed AUTH_INPUT_MAC.
  1486. Now both parties use the handshake output to derive shared keys for use on
  1487. the circuit as specified in the section below:
  1488. 4.2.1. Key expansion
  1489. The hidden service and its client need to derive crypto keys from the
  1490. NTOR_KEY_SEED part of the handshake output. To do so, they use the KDF
  1491. construction as follows:
  1492. K = KDF(NTOR_KEY_SEED | m_hsexpand, HASH_LEN * 2 + S_KEY_LEN * 2)
  1493. The first HASH_LEN bytes of K form the forward digest Df; the next HASH_LEN
  1494. bytes form the backward digest Db; the next S_KEY_LEN bytes form Kf, and the
  1495. final S_KEY_LEN bytes form Kb. Excess bytes from K are discarded.
  1496. Subsequently, the rendezvous point passes relay cells, unchanged, from each
  1497. of the two circuits to the other. When Alice's OP sends RELAY cells along
  1498. the circuit, it authenticates with Df, and encrypts them with the Kf, then
  1499. with all of the keys for the ORs in Alice's side of the circuit; and when
  1500. Alice's OP receives RELAY cells from the circuit, it decrypts them with the
  1501. keys for the ORs in Alice's side of the circuit, then decrypts them with Kb,
  1502. and checks integrity with Db. Bob's OP does the same, with Kf and Kb
  1503. interchanged.
  1504. [TODO: Should we encrypt HANDSHAKE_INFO as we did INTRODUCE2
  1505. contents? It's not necessary, but it could be wise. Similarly, we
  1506. should make it extensible.]
  1507. 4.3. Using legacy hosts as rendezvous points
  1508. The behavior of ESTABLISH_RENDEZVOUS is unchanged from older versions
  1509. of this protocol, except that relays should now ignore unexpected
  1510. bytes at the end.
  1511. Old versions of Tor required that RENDEZVOUS cell payloads be exactly
  1512. 168 bytes long. All shorter rendezvous payloads should be padded to
  1513. this length with random bytes, to make them difficult to distinguish from
  1514. older protocols at the rendezvous point.
  1515. Relays older than 0.2.9.1 should not be used for rendezvous points by next
  1516. generation onion services because they enforce too-strict length checks to
  1517. rendezvous cells. Hence the "HSRend" protocol from proposal#264 should be
  1518. used to select relays for rendezvous points.
  1519. 5. Encrypting data between client and host
  1520. A successfully completed handshake, as embedded in the
  1521. INTRODUCE/RENDEZVOUS cells, gives the client and hidden service host
  1522. a shared set of keys Kf, Kb, Df, Db, which they use for sending
  1523. end-to-end traffic encryption and authentication as in the regular
  1524. Tor relay encryption protocol, applying encryption with these keys
  1525. before other encryption, and decrypting with these keys before other
  1526. decryption. The client encrypts with Kf and decrypts with Kb; the
  1527. service host does the opposite.
  1528. 6. Encoding onion addresses [ONIONADDRESS]
  1529. The onion address of a hidden service includes its identity public key, a
  1530. version field and a basic checksum. All this information is then base32
  1531. encoded as shown below:
  1532. onion_address = base32(PUBKEY | CHECKSUM | VERSION) + ".onion"
  1533. CHECKSUM = H(".onion checksum" | PUBKEY | VERSION)[:2]
  1534. where:
  1535. - PUBKEY is the 32 bytes ed25519 master pubkey of the hidden service.
  1536. - VERSION is an one byte version field (default value '\x03')
  1537. - ".onion checksum" is a constant string
  1538. - CHECKSUM is truncated to two bytes before inserting it in onion_address
  1539. Here are a few example addresses:
  1540. pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion
  1541. sp3k262uwy4r2k3ycr5awluarykdpag6a7y33jxop4cs2lu5uz5sseqd.onion
  1542. xa4r2iadxm55fbnqgwwi5mymqdcofiu3w6rpbtqn7b2dyn7mgwj64jyd.onion
  1543. For more information about this encoding, please see our discussion thread
  1544. at [ONIONADDRESS-REFS].
  1545. 7. Open Questions:
  1546. Scaling hidden services is hard. There are on-going discussions that
  1547. you might be able to help with. See [SCALING-REFS].
  1548. How can we improve the HSDir unpredictability design proposed in
  1549. [SHAREDRANDOM]? See [SHAREDRANDOM-REFS] for discussion.
  1550. How can hidden service addresses become memorable while retaining
  1551. their self-authenticating and decentralized nature? See
  1552. [HUMANE-HSADDRESSES-REFS] for some proposals; many more are possible.
  1553. Hidden Services are pretty slow. Both because of the lengthy setup
  1554. procedure and because the final circuit has 6 hops. How can we make
  1555. the Hidden Service protocol faster? See [PERFORMANCE-REFS] for some
  1556. suggestions.
  1557. References:
  1558. [KEYBLIND-REFS]:
  1559. https://trac.torproject.org/projects/tor/ticket/8106
  1560. https://lists.torproject.org/pipermail/tor-dev/2012-September/004026.html
  1561. [KEYBLIND-PROOF]:
  1562. https://lists.torproject.org/pipermail/tor-dev/2013-December/005943.html
  1563. [SHAREDRANDOM-REFS]:
  1564. https://gitweb.torproject.org/torspec.git/tree/proposals/250-commit-reveal-consensus.txt
  1565. https://trac.torproject.org/projects/tor/ticket/8244
  1566. [SCALING-REFS]:
  1567. https://lists.torproject.org/pipermail/tor-dev/2013-October/005556.html
  1568. [HUMANE-HSADDRESSES-REFS]:
  1569. https://gitweb.torproject.org/torspec.git/blob/HEAD:/proposals/ideas/xxx-onion-nyms.txt
  1570. http://archives.seul.org/or/dev/Dec-2011/msg00034.html
  1571. [PERFORMANCE-REFS]:
  1572. "Improving Efficiency and Simplicity of Tor circuit
  1573. establishment and hidden services" by Overlier, L., and
  1574. P. Syverson
  1575. [TODO: Need more here! Do we have any? :( ]
  1576. [ATTACK-REFS]:
  1577. "Trawling for Tor Hidden Services: Detection, Measurement,
  1578. Deanonymization" by Alex Biryukov, Ivan Pustogarov,
  1579. Ralf-Philipp Weinmann
  1580. "Locating Hidden Servers" by Lasse Øverlier and Paul
  1581. Syverson
  1582. [ED25519-REFS]:
  1583. "High-speed high-security signatures" by Daniel
  1584. J. Bernstein, Niels Duif, Tanja Lange, Peter Schwabe, and
  1585. Bo-Yin Yang. http://cr.yp.to/papers.html#ed25519
  1586. [ED25519-B-REF]:
  1587. https://tools.ietf.org/html/draft-josefsson-eddsa-ed25519-03#section-5:
  1588. [PRNG-REFS]:
  1589. http://projectbullrun.org/dual-ec/ext-rand.html
  1590. https://lists.torproject.org/pipermail/tor-dev/2015-November/009954.html
  1591. [SRV-TP-REFS]:
  1592. https://lists.torproject.org/pipermail/tor-dev/2016-April/010759.html
  1593. [VANITY-REFS]:
  1594. https://github.com/Yawning/horse25519
  1595. [ONIONADDRESS-REFS]:
  1596. https://lists.torproject.org/pipermail/tor-dev/2017-January/011816.html
  1597. [TORSION-REFS]:
  1598. https://lists.torproject.org/pipermail/tor-dev/2017-April/012164.html
  1599. https://getmonero.org/2017/05/17/disclosure-of-a-major-bug-in-cryptonote-based-currencies.html
  1600. Appendix A. Signature scheme with key blinding [KEYBLIND]
  1601. A.1. Key derivation overview
  1602. As described in [IMD:DIST] and [SUBCRED] above, we require a "key
  1603. blinding" system that works (roughly) as follows:
  1604. There is a master keypair (sk, pk).
  1605. Given the keypair and a nonce n, there is a derivation function
  1606. that gives a new blinded keypair (sk_n, pk_n). This keypair can
  1607. be used for signing.
  1608. Given only the public key and the nonce, there is a function
  1609. that gives pk_n.
  1610. Without knowing pk, it is not possible to derive pk_n; without
  1611. knowing sk, it is not possible to derive sk_n.
  1612. It's possible to check that a signature was made with sk_n while
  1613. knowing only pk_n.
  1614. Someone who sees a large number of blinded public keys and
  1615. signatures made using those public keys can't tell which
  1616. signatures and which blinded keys were derived from the same
  1617. master keypair.
  1618. You can't forge signatures.
  1619. [TODO: Insert a more rigorous definition and better references.]
  1620. A.2. Tor's key derivation scheme
  1621. We propose the following scheme for key blinding, based on Ed25519.
  1622. (This is an ECC group, so remember that scalar multiplication is the
  1623. trapdoor function, and it's defined in terms of iterated point
  1624. addition. See the Ed25519 paper [Reference ED25519-REFS] for a fairly
  1625. clear writeup.)
  1626. Let B be the ed25519 basepoint as found in section 5 of [ED25519-B-REF]:
  1627. B = (15112221349535400772501151409588531511454012693041857206046113283949847762202,
  1628. 46316835694926478169428394003475163141307993866256225615783033603165251855960)
  1629. Assume B has prime order l, so lB=0. Let a master keypair be written as
  1630. (a,A), where a is the private key and A is the public key (A=aB).
  1631. To derive the key for a nonce N and an optional secret s, compute the
  1632. blinding factor like this:
  1633. h = H(BLIND_STRING | A | s | B | N)
  1634. BLIND_STRING = "Derive temporary signing key" | INT_1(0)
  1635. N = "key-blind" | INT_8(period-number) | INT_8(period_length)
  1636. B = "(1511[...]2202, 4631[...]5960)"
  1637. then clamp the blinding factor 'h' according to the ed25519 spec:
  1638. h[0] &= 248;
  1639. h[31] &= 63;
  1640. h[31] |= 64;
  1641. and do the key derivation as follows:
  1642. private key for the period:
  1643. a' = h a mod l
  1644. RH' = SHA-512(RH_BLIND_STRING | RH)[:32]
  1645. RH_BLIND_STRING = "Derive temporary signing key hash input"
  1646. public key for the period:
  1647. A' = h A = (ha)B
  1648. Generating a signature of M: given a deterministic random-looking r
  1649. (see EdDSA paper), take R=rB, S=r+hash(R,A',M)ah mod l. Send signature
  1650. (R,S) and public key A'.
  1651. Verifying the signature: Check whether SB = R+hash(R,A',M)A'.
  1652. (If the signature is valid,
  1653. SB = (r + hash(R,A',M)ah)B
  1654. = rB + (hash(R,A',M)ah)B
  1655. = R + hash(R,A',M)A' )
  1656. This boils down to regular Ed25519 with key pair (a', A').
  1657. See [KEYBLIND-REFS] for an extensive discussion on this scheme and
  1658. possible alternatives. Also, see [KEYBLIND-PROOF] for a security
  1659. proof of this scheme.
  1660. Appendix B. Selecting nodes [PICKNODES]
  1661. Picking introduction points
  1662. Picking rendezvous points
  1663. Building paths
  1664. Reusing circuits
  1665. (TODO: This needs a writeup)
  1666. Appendix C. Recommendations for searching for vanity .onions [VANITY]
  1667. EDITORIAL NOTE: The author thinks that it's silly to brute-force the
  1668. keyspace for a key that, when base-32 encoded, spells out the name of
  1669. your website. It also feels a bit dangerous to me. If you train your
  1670. users to connect to
  1671. llamanymityx4fi3l6x2gyzmtmgxjyqyorj9qsb5r543izcwymle.onion
  1672. I worry that you're making it easier for somebody to trick them into
  1673. connecting to
  1674. llamanymityb4sqi0ta0tsw6uovyhwlezkcrmczeuzdvfauuemle.onion
  1675. Nevertheless, people are probably going to try to do this, so here's a
  1676. decent algorithm to use.
  1677. To search for a public key with some criterion X:
  1678. Generate a random (sk,pk) pair.
  1679. While pk does not satisfy X:
  1680. Add the number 8 to sk
  1681. Add the point 8*B to pk
  1682. Return sk, pk.
  1683. We add 8 and 8*B, rather than 1 and B, so that sk is always a valid
  1684. Curve25519 private key, with the lowest 3 bits equal to 0.
  1685. This algorithm is safe [source: djb, personal communication] [TODO:
  1686. Make sure I understood correctly!] so long as only the final (sk,pk)
  1687. pair is used, and all previous values are discarded.
  1688. To parallelize this algorithm, start with an independent (sk,pk) pair
  1689. generated for each independent thread, and let each search proceed
  1690. independently.
  1691. See [VANITY-REFS] for a reference implementation of this vanity .onion
  1692. search scheme.
  1693. Appendix D. Numeric values reserved in this document
  1694. [TODO: collect all the lists of commands and values mentioned above]
  1695. Appendix E. Reserved numbers
  1696. We reserve these certificate type values for Ed25519 certificates:
  1697. [08] short-term descriptor signing key, signed with blinded
  1698. public key. (Section 2.4)
  1699. [09] intro point authentication key, cross-certifying the descriptor
  1700. signing key. (Section 2.5)
  1701. [0B] ed25519 key derived from the curve25519 intro point encryption key,
  1702. cross-certifying the descriptor signing key. (Section 2.5)
  1703. Note: The value "0A" is skipped because it's reserved for the onion key
  1704. cross-certifying ntor identity key from proposal 228.
  1705. Appendix F. Hidden service directory format [HIDSERVDIR-FORMAT]
  1706. This appendix section specifies the contents of the HiddenServiceDir directory:
  1707. - "hostname" [FILE]
  1708. This file contains the onion address of the onion service.
  1709. - "private_key_ed25519" [FILE]
  1710. This file contains the private master ed25519 key of the onion service.
  1711. [TODO: Offline keys]
  1712. - "./authorized_clients/" [DIRECTORY]
  1713. "./authorized_clients/alice.auth" [FILE]
  1714. "./authorized_clients/bob.auth" [FILE]
  1715. "./authorized_clients/charlie.auth" [FILE]
  1716. If client authorization is enabled, this directory MUST contain a ".auth"
  1717. file for each authorized client. Each such file contains the public key of
  1718. the respective client. The files are transmitted to the service operator by
  1719. the client.
  1720. See section [CLIENT-AUTH-MGMT] for more details and the format of the client file.
  1721. (NOTE: client authorization is not implemented as of 0.3.2.1-alpha.)
  1722. Appendix G. Managing authorized client data [CLIENT-AUTH-MGMT]
  1723. Hidden services and clients can configure their authorized client data either
  1724. using the torrc, or using the control port. This section presents a suggested
  1725. scheme for configuring client authorization. Please see appendix
  1726. [HIDSERVDIR-FORMAT] for more information about relevant hidden service files.
  1727. (NOTE: client authorization is not implemented as of 0.3.2.1-alpha.)
  1728. G.1. Configuring client authorization using torrc
  1729. G.1.1. Hidden Service side configuration
  1730. A hidden service that wants to enable client authorization, needs to
  1731. populate the "authorized_clients/" directory of its HiddenServiceDir
  1732. directory with the ".auth" files of its authorized clients.
  1733. When Tor starts up with a configured onion service, Tor checks its
  1734. <HiddenServiceDir>/authorized_clients/ directory for ".auth" files, and if
  1735. any recognized and parseable such files are found, then client
  1736. authorization becomes activated for that service.
  1737. G.1.2. Service-side bookkeeping
  1738. This section contains more details on how onion services should be keeping
  1739. track of their client ".auth" files.
  1740. For the "descriptor" authentication type, the ".auth" file MUST contain
  1741. the x25519 public key of that client. Here is a suggested file format:
  1742. <auth-type>:<key-type>:<base32-encoded-public-key>
  1743. Here is an an example:
  1744. descriptor:x25519:OM7TGIVRYMY6PFX6GAC6ATRTA5U6WW6U7A4ZNHQDI6OVL52XVV2Q
  1745. Tor SHOULD ignore lines it does not recognize.
  1746. Tor SHOULD ignore files that don't use the ".auth" suffix.
  1747. G.1.3. Client side configuration
  1748. A client who wants to register client authorization data for onion
  1749. services needs to add the following line to their torrc to indicate the
  1750. directory which hosts ".auth_private" files containing client-side
  1751. credentials for onion services:
  1752. ClientOnionAuthDir <DIR>
  1753. The <DIR> contains a file with the suffix ".auth_private" for each onion
  1754. service the client is authorized with. Tor should scan the directory for
  1755. ".auth_private" files to find which onion services require client
  1756. authorization from this client.
  1757. For the "descriptor" auth-type, a ".auth_private" file contains the
  1758. private x25519 key:
  1759. <onion-address>:descriptor:x25519:<base32-encoded-privkey>
  1760. The keypair used for client authorization is created by a third party tool
  1761. for which the public key needs to be transferred to the service operator
  1762. in a secure out-of-band way. The third party tool SHOULD add appropriate
  1763. headers to the private key file to ensure that users won't accidentally
  1764. give out their private key.
  1765. G.2. Configuring client authorization using the control port
  1766. G.2.1. Service side
  1767. A hidden service also has the option to configure authorized clients
  1768. using the control port. The idea is that hidden service operators can use
  1769. controller utilities that manage their access control instead of using
  1770. the filesystem to register client keys.
  1771. Specifically, we require a new control port command ADD_ONION_CLIENT_AUTH
  1772. which is able to register x25519/ed25519 public keys tied to a specific
  1773. authorized client.
  1774. [XXX figure out control port command format]
  1775. Hidden services who use the control port interface for client auth need
  1776. to perform their own key management.
  1777. G.2.2. Client side
  1778. There should also be a control port interface for clients to register
  1779. authorization data for hidden services without having to use the
  1780. torrc. It should allow both generation of client authorization private
  1781. keys, and also to import client authorization data provided by a hidden
  1782. service
  1783. This way, Tor Browser can present "Generate client auth keys" and "Import
  1784. client auth keys" dialogs to users when they try to visit a hidden service
  1785. that is protected by client authorization.
  1786. Specifically, we require two new control port commands:
  1787. IMPORT_ONION_CLIENT_AUTH_DATA
  1788. GENERATE_ONION_CLIENT_AUTH_DATA
  1789. which import and generate client authorization data respectively.
  1790. [XXX how does key management work here?]
  1791. [XXX what happens when people use both the control port interface and the
  1792. filesystem interface?]
  1793. Appendix F. Two methods for managing revision counters.
  1794. Implementations MAY generate revision counters in any way they please,
  1795. so long as they are monotonically increasing over the lifetime of each
  1796. blinded public key. But to avoid fingerprinting, implementors SHOULD
  1797. choose a strategy also used by other Tor implementations. Here we
  1798. describe two, and additionally list some strategies that implementors
  1799. should NOT use.
  1800. F.1. Increment-on-generation
  1801. This is the simplest strategy, and the one used by Tor through at
  1802. least version 0.3.4.0-alpha.
  1803. Whenever using a new blinded key, the service records the
  1804. highest revision counter it has used with that key. When generating
  1805. a descriptor, the service uses the smallest non-negative number
  1806. higher than any number it has already used.
  1807. In other words, the revision counters under this system start fresh
  1808. with each blinded key as 0, 1, 2, 3, and so on.
  1809. F.2. Encrypted time in period
  1810. This scheme is what we recommend for situations when multiple
  1811. service instances need to coordinate their revision counters,
  1812. without an actual coordination mechanism.
  1813. Let T be the number of seconds that have elapsed since the descriptor
  1814. became valid, plus 1. (T must be at least 1.) Implementations can use the
  1815. number of seconds since the start time of the shared random protocol run
  1816. that corresponds to this descriptor.
  1817. Let S be a secret that all the service providers share. For
  1818. example, it could be the private signing key corresponding to the
  1819. current blinded key.
  1820. Let K be an AES-256 key, generated as
  1821. K = H("rev-counter-generation" | S)
  1822. Use K, and AES in counter mode with IV=0, to generate a stream of T
  1823. * 2 bytes. Consider these bytes as a sequence of T 16-bit
  1824. little-endian words. Add these words.
  1825. Let the sum of these words be the revision counter.
  1826. Cryptowiki attributes roughly this scheme to G. Bebek in:
  1827. G. Bebek. Anti-tamper database research: Inference control
  1828. techniques. Technical Report EECS 433 Final Report, Case
  1829. Western Reserve University, November 2002.
  1830. Although we believe it is suitable for use in this application, it
  1831. is not a perfect order-preserving encryption algorithm (and all
  1832. order-preserving encryption has weaknesses). Please think twice
  1833. before using it for anything else.
  1834. (This scheme can be optimized pretty easily by caching the encryption of
  1835. X*1, X*2, X*3, etc for some well chosen X.)
  1836. For a slow reference implementation, see src/test/ope_ref.py in the
  1837. Tor source repository. [XXXX for now, see the same file in Nick's
  1838. "ope_hax" branch -- it isn't merged yet.]
  1839. This scheme is not currently implemented in Tor.
  1840. F.X. Some revision-counter strategies to avoid
  1841. Though it might be tempting, implementations SHOULD NOT use the
  1842. current time or the current time within the period directly as their
  1843. revision counter -- doing so leaks their view of the current time,
  1844. which can be used to link the onion service to other services run on
  1845. the same host.
  1846. Similarly, implementations SHOULD NOT let the revision counter
  1847. increase forever without resetting it -- doing so links the service
  1848. across changes in the blinded public key.