or.h 88 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155
  1. /* Copyright (c) 2001 Matej Pfajfar.
  2. * Copyright (c) 2001-2004, Roger Dingledine.
  3. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  4. * Copyright (c) 2007-2018, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. /**
  7. * \file or.h
  8. * \brief Master header file for Tor-specific functionality.
  9. **/
  10. #ifndef TOR_OR_H
  11. #define TOR_OR_H
  12. #include "orconfig.h"
  13. #ifdef HAVE_UNISTD_H
  14. #include <unistd.h>
  15. #endif
  16. #ifdef HAVE_SIGNAL_H
  17. #include <signal.h>
  18. #endif
  19. #ifdef HAVE_NETDB_H
  20. #include <netdb.h>
  21. #endif
  22. #ifdef HAVE_SYS_PARAM_H
  23. #include <sys/param.h> /* FreeBSD needs this to know what version it is */
  24. #endif
  25. #include "lib/cc/torint.h"
  26. #ifdef HAVE_SYS_FCNTL_H
  27. #include <sys/fcntl.h>
  28. #endif
  29. #ifdef HAVE_FCNTL_H
  30. #include <fcntl.h>
  31. #endif
  32. #ifdef HAVE_SYS_IOCTL_H
  33. #include <sys/ioctl.h>
  34. #endif
  35. #ifdef HAVE_SYS_UN_H
  36. #include <sys/un.h>
  37. #endif
  38. #ifdef HAVE_SYS_STAT_H
  39. #include <sys/stat.h>
  40. #endif
  41. #ifdef HAVE_NETINET_IN_H
  42. #include <netinet/in.h>
  43. #endif
  44. #ifdef HAVE_ARPA_INET_H
  45. #include <arpa/inet.h>
  46. #endif
  47. #ifdef HAVE_ERRNO_H
  48. #include <errno.h>
  49. #endif
  50. #ifdef HAVE_TIME_H
  51. #include <time.h>
  52. #endif
  53. #ifdef _WIN32
  54. #include <winsock2.h>
  55. #include <io.h>
  56. #include <process.h>
  57. #include <direct.h>
  58. #include <windows.h>
  59. #endif /* defined(_WIN32) */
  60. #include "common/util.h"
  61. #include "lib/container/map.h"
  62. #include "lib/container/smartlist.h"
  63. #include "lib/crypt_ops/crypto.h"
  64. #include "lib/defs/dh_sizes.h"
  65. #include "lib/encoding/binascii.h"
  66. #include "lib/net/address.h"
  67. #include "ht.h"
  68. // These, more than other includes, are for keeping the other struct
  69. // definitions working. We should remove them when we minimize our includes.
  70. #include "or/entry_port_cfg_st.h"
  71. struct ed25519_public_key_t;
  72. struct curve25519_public_key_t;
  73. /* These signals are defined to help handle_control_signal work.
  74. */
  75. #ifndef SIGHUP
  76. #define SIGHUP 1
  77. #endif
  78. #ifndef SIGINT
  79. #define SIGINT 2
  80. #endif
  81. #ifndef SIGUSR1
  82. #define SIGUSR1 10
  83. #endif
  84. #ifndef SIGUSR2
  85. #define SIGUSR2 12
  86. #endif
  87. #ifndef SIGTERM
  88. #define SIGTERM 15
  89. #endif
  90. /* Controller signals start at a high number so we don't
  91. * conflict with system-defined signals. */
  92. #define SIGNEWNYM 129
  93. #define SIGCLEARDNSCACHE 130
  94. #define SIGHEARTBEAT 131
  95. #if (SIZEOF_CELL_T != 0)
  96. /* On Irix, stdlib.h defines a cell_t type, so we need to make sure
  97. * that our stuff always calls cell_t something different. */
  98. #define cell_t tor_cell_t
  99. #endif
  100. #ifdef ENABLE_TOR2WEB_MODE
  101. #define NON_ANONYMOUS_MODE_ENABLED 1
  102. #endif
  103. /** Helper macro: Given a pointer to to.base_, of type from*, return &to. */
  104. #define DOWNCAST(to, ptr) ((to*)SUBTYPE_P(ptr, to, base_))
  105. /** Length of longest allowable configured nickname. */
  106. #define MAX_NICKNAME_LEN 19
  107. /** Length of a router identity encoded as a hexadecimal digest, plus
  108. * possible dollar sign. */
  109. #define MAX_HEX_NICKNAME_LEN (HEX_DIGEST_LEN+1)
  110. /** Maximum length of verbose router identifier: dollar sign, hex ID digest,
  111. * equal sign or tilde, nickname. */
  112. #define MAX_VERBOSE_NICKNAME_LEN (1+HEX_DIGEST_LEN+1+MAX_NICKNAME_LEN)
  113. /** For HTTP parsing: Maximum number of bytes we'll accept in the headers
  114. * of an HTTP request or response. */
  115. #define MAX_HEADERS_SIZE 50000
  116. /** Maximum size, in bytes, of a single router descriptor uploaded to us
  117. * as a directory authority. Caches and clients fetch whatever descriptors
  118. * the authorities tell them to fetch, and don't care about size. */
  119. #define MAX_DESCRIPTOR_UPLOAD_SIZE 20000
  120. /** Maximum size of a single extrainfo document, as above. */
  121. #define MAX_EXTRAINFO_UPLOAD_SIZE 50000
  122. /** Minimum lifetime for an onion key in days. */
  123. #define MIN_ONION_KEY_LIFETIME_DAYS (1)
  124. /** Maximum lifetime for an onion key in days. */
  125. #define MAX_ONION_KEY_LIFETIME_DAYS (90)
  126. /** Default lifetime for an onion key in days. */
  127. #define DEFAULT_ONION_KEY_LIFETIME_DAYS (28)
  128. /** Minimum grace period for acceptance of an onion key in days.
  129. * The maximum value is defined in proposal #274 as being the current network
  130. * consensus parameter for "onion-key-rotation-days". */
  131. #define MIN_ONION_KEY_GRACE_PERIOD_DAYS (1)
  132. /** Default grace period for acceptance of an onion key in days. */
  133. #define DEFAULT_ONION_KEY_GRACE_PERIOD_DAYS (7)
  134. /** How often we should check the network consensus if it is time to rotate or
  135. * expire onion keys. */
  136. #define ONION_KEY_CONSENSUS_CHECK_INTERVAL (60*60)
  137. /** How often do we rotate TLS contexts? */
  138. #define MAX_SSL_KEY_LIFETIME_INTERNAL (2*60*60)
  139. /** How old do we allow a router to get before removing it
  140. * from the router list? In seconds. */
  141. #define ROUTER_MAX_AGE (60*60*48)
  142. /** How old can a router get before we (as a server) will no longer
  143. * consider it live? In seconds. */
  144. #define ROUTER_MAX_AGE_TO_PUBLISH (60*60*24)
  145. /** How old do we let a saved descriptor get before force-removing it? */
  146. #define OLD_ROUTER_DESC_MAX_AGE (60*60*24*5)
  147. /* Proxy client types */
  148. #define PROXY_NONE 0
  149. #define PROXY_CONNECT 1
  150. #define PROXY_SOCKS4 2
  151. #define PROXY_SOCKS5 3
  152. /* !!!! If there is ever a PROXY_* type over 3, we must grow the proxy_type
  153. * field in or_connection_t */
  154. /* Pluggable transport proxy type. Don't use this in or_connection_t,
  155. * instead use the actual underlying proxy type (see above). */
  156. #define PROXY_PLUGGABLE 4
  157. /** How many circuits do we want simultaneously in-progress to handle
  158. * a given stream? */
  159. #define MIN_CIRCUITS_HANDLING_STREAM 2
  160. /* These RELAY_COMMAND constants define values for relay cell commands, and
  161. * must match those defined in tor-spec.txt. */
  162. #define RELAY_COMMAND_BEGIN 1
  163. #define RELAY_COMMAND_DATA 2
  164. #define RELAY_COMMAND_END 3
  165. #define RELAY_COMMAND_CONNECTED 4
  166. #define RELAY_COMMAND_SENDME 5
  167. #define RELAY_COMMAND_EXTEND 6
  168. #define RELAY_COMMAND_EXTENDED 7
  169. #define RELAY_COMMAND_TRUNCATE 8
  170. #define RELAY_COMMAND_TRUNCATED 9
  171. #define RELAY_COMMAND_DROP 10
  172. #define RELAY_COMMAND_RESOLVE 11
  173. #define RELAY_COMMAND_RESOLVED 12
  174. #define RELAY_COMMAND_BEGIN_DIR 13
  175. #define RELAY_COMMAND_EXTEND2 14
  176. #define RELAY_COMMAND_EXTENDED2 15
  177. #define RELAY_COMMAND_ESTABLISH_INTRO 32
  178. #define RELAY_COMMAND_ESTABLISH_RENDEZVOUS 33
  179. #define RELAY_COMMAND_INTRODUCE1 34
  180. #define RELAY_COMMAND_INTRODUCE2 35
  181. #define RELAY_COMMAND_RENDEZVOUS1 36
  182. #define RELAY_COMMAND_RENDEZVOUS2 37
  183. #define RELAY_COMMAND_INTRO_ESTABLISHED 38
  184. #define RELAY_COMMAND_RENDEZVOUS_ESTABLISHED 39
  185. #define RELAY_COMMAND_INTRODUCE_ACK 40
  186. /* Reasons why an OR connection is closed. */
  187. #define END_OR_CONN_REASON_DONE 1
  188. #define END_OR_CONN_REASON_REFUSED 2 /* connection refused */
  189. #define END_OR_CONN_REASON_OR_IDENTITY 3
  190. #define END_OR_CONN_REASON_CONNRESET 4 /* connection reset by peer */
  191. #define END_OR_CONN_REASON_TIMEOUT 5
  192. #define END_OR_CONN_REASON_NO_ROUTE 6 /* no route to host/net */
  193. #define END_OR_CONN_REASON_IO_ERROR 7 /* read/write error */
  194. #define END_OR_CONN_REASON_RESOURCE_LIMIT 8 /* sockets, buffers, etc */
  195. #define END_OR_CONN_REASON_PT_MISSING 9 /* PT failed or not available */
  196. #define END_OR_CONN_REASON_MISC 10
  197. /* Reasons why we (or a remote OR) might close a stream. See tor-spec.txt for
  198. * documentation of these. The values must match. */
  199. #define END_STREAM_REASON_MISC 1
  200. #define END_STREAM_REASON_RESOLVEFAILED 2
  201. #define END_STREAM_REASON_CONNECTREFUSED 3
  202. #define END_STREAM_REASON_EXITPOLICY 4
  203. #define END_STREAM_REASON_DESTROY 5
  204. #define END_STREAM_REASON_DONE 6
  205. #define END_STREAM_REASON_TIMEOUT 7
  206. #define END_STREAM_REASON_NOROUTE 8
  207. #define END_STREAM_REASON_HIBERNATING 9
  208. #define END_STREAM_REASON_INTERNAL 10
  209. #define END_STREAM_REASON_RESOURCELIMIT 11
  210. #define END_STREAM_REASON_CONNRESET 12
  211. #define END_STREAM_REASON_TORPROTOCOL 13
  212. #define END_STREAM_REASON_NOTDIRECTORY 14
  213. #define END_STREAM_REASON_ENTRYPOLICY 15
  214. /* These high-numbered end reasons are not part of the official spec,
  215. * and are not intended to be put in relay end cells. They are here
  216. * to be more informative when sending back socks replies to the
  217. * application. */
  218. /* XXXX 256 is no longer used; feel free to reuse it. */
  219. /** We were unable to attach the connection to any circuit at all. */
  220. /* XXXX the ways we use this one don't make a lot of sense. */
  221. #define END_STREAM_REASON_CANT_ATTACH 257
  222. /** We can't connect to any directories at all, so we killed our streams
  223. * before they can time out. */
  224. #define END_STREAM_REASON_NET_UNREACHABLE 258
  225. /** This is a SOCKS connection, and the client used (or misused) the SOCKS
  226. * protocol in a way we couldn't handle. */
  227. #define END_STREAM_REASON_SOCKSPROTOCOL 259
  228. /** This is a transparent proxy connection, but we can't extract the original
  229. * target address:port. */
  230. #define END_STREAM_REASON_CANT_FETCH_ORIG_DEST 260
  231. /** This is a connection on the NATD port, and the destination IP:Port was
  232. * either ill-formed or out-of-range. */
  233. #define END_STREAM_REASON_INVALID_NATD_DEST 261
  234. /** The target address is in a private network (like 127.0.0.1 or 10.0.0.1);
  235. * you don't want to do that over a randomly chosen exit */
  236. #define END_STREAM_REASON_PRIVATE_ADDR 262
  237. /** This is an HTTP tunnel connection and the client used or misused HTTP in a
  238. * way we can't handle.
  239. */
  240. #define END_STREAM_REASON_HTTPPROTOCOL 263
  241. /** Bitwise-and this value with endreason to mask out all flags. */
  242. #define END_STREAM_REASON_MASK 511
  243. /** Bitwise-or this with the argument to control_event_stream_status
  244. * to indicate that the reason came from an END cell. */
  245. #define END_STREAM_REASON_FLAG_REMOTE 512
  246. /** Bitwise-or this with the argument to control_event_stream_status
  247. * to indicate that we already sent a CLOSED stream event. */
  248. #define END_STREAM_REASON_FLAG_ALREADY_SENT_CLOSED 1024
  249. /** Bitwise-or this with endreason to indicate that we already sent
  250. * a socks reply, and no further reply needs to be sent from
  251. * connection_mark_unattached_ap(). */
  252. #define END_STREAM_REASON_FLAG_ALREADY_SOCKS_REPLIED 2048
  253. /* 'type' values to use in RESOLVED cells. Specified in tor-spec.txt. */
  254. #define RESOLVED_TYPE_HOSTNAME 0
  255. #define RESOLVED_TYPE_IPV4 4
  256. #define RESOLVED_TYPE_IPV6 6
  257. #define RESOLVED_TYPE_ERROR_TRANSIENT 0xF0
  258. #define RESOLVED_TYPE_ERROR 0xF1
  259. /* Negative reasons are internal: we never send them in a DESTROY or TRUNCATE
  260. * call; they only go to the controller for tracking */
  261. /* Closing introduction point that were opened in parallel. */
  262. #define END_CIRC_REASON_IP_NOW_REDUNDANT -4
  263. /** Our post-timeout circuit time measurement period expired.
  264. * We must give up now */
  265. #define END_CIRC_REASON_MEASUREMENT_EXPIRED -3
  266. /** We couldn't build a path for this circuit. */
  267. #define END_CIRC_REASON_NOPATH -2
  268. /** Catch-all "other" reason for closing origin circuits. */
  269. #define END_CIRC_AT_ORIGIN -1
  270. /* Reasons why we (or a remote OR) might close a circuit. See tor-spec.txt
  271. * section 5.4 for documentation of these. */
  272. #define END_CIRC_REASON_MIN_ 0
  273. #define END_CIRC_REASON_NONE 0
  274. #define END_CIRC_REASON_TORPROTOCOL 1
  275. #define END_CIRC_REASON_INTERNAL 2
  276. #define END_CIRC_REASON_REQUESTED 3
  277. #define END_CIRC_REASON_HIBERNATING 4
  278. #define END_CIRC_REASON_RESOURCELIMIT 5
  279. #define END_CIRC_REASON_CONNECTFAILED 6
  280. #define END_CIRC_REASON_OR_IDENTITY 7
  281. #define END_CIRC_REASON_CHANNEL_CLOSED 8
  282. #define END_CIRC_REASON_FINISHED 9
  283. #define END_CIRC_REASON_TIMEOUT 10
  284. #define END_CIRC_REASON_DESTROYED 11
  285. #define END_CIRC_REASON_NOSUCHSERVICE 12
  286. #define END_CIRC_REASON_MAX_ 12
  287. /** Bitwise-OR this with the argument to circuit_mark_for_close() or
  288. * control_event_circuit_status() to indicate that the reason was
  289. * passed through from a destroy or truncate cell. */
  290. #define END_CIRC_REASON_FLAG_REMOTE 512
  291. /** Length of 'y' portion of 'y.onion' URL. */
  292. #define REND_SERVICE_ID_LEN_BASE32 16
  293. /** Length of 'y.onion' including '.onion' URL. */
  294. #define REND_SERVICE_ADDRESS_LEN (16+1+5)
  295. /** Length of a binary-encoded rendezvous service ID. */
  296. #define REND_SERVICE_ID_LEN 10
  297. /** Time period for which a v2 descriptor will be valid. */
  298. #define REND_TIME_PERIOD_V2_DESC_VALIDITY (24*60*60)
  299. /** Time period within which two sets of v2 descriptors will be uploaded in
  300. * parallel. */
  301. #define REND_TIME_PERIOD_OVERLAPPING_V2_DESCS (60*60)
  302. /** Number of non-consecutive replicas (i.e. distributed somewhere
  303. * in the ring) for a descriptor. */
  304. #define REND_NUMBER_OF_NON_CONSECUTIVE_REPLICAS 2
  305. /** Number of consecutive replicas for a descriptor. */
  306. #define REND_NUMBER_OF_CONSECUTIVE_REPLICAS 3
  307. /** Length of v2 descriptor ID (32 base32 chars = 160 bits). */
  308. #define REND_DESC_ID_V2_LEN_BASE32 BASE32_DIGEST_LEN
  309. /** Length of the base32-encoded secret ID part of versioned hidden service
  310. * descriptors. */
  311. #define REND_SECRET_ID_PART_LEN_BASE32 BASE32_DIGEST_LEN
  312. /** Length of the base32-encoded hash of an introduction point's
  313. * identity key. */
  314. #define REND_INTRO_POINT_ID_LEN_BASE32 BASE32_DIGEST_LEN
  315. /** Length of the descriptor cookie that is used for client authorization
  316. * to hidden services. */
  317. #define REND_DESC_COOKIE_LEN 16
  318. /** Length of the base64-encoded descriptor cookie that is used for
  319. * exchanging client authorization between hidden service and client. */
  320. #define REND_DESC_COOKIE_LEN_BASE64 22
  321. /** Length of client identifier in encrypted introduction points for hidden
  322. * service authorization type 'basic'. */
  323. #define REND_BASIC_AUTH_CLIENT_ID_LEN 4
  324. /** Multiple of the number of clients to which the real number of clients
  325. * is padded with fake clients for hidden service authorization type
  326. * 'basic'. */
  327. #define REND_BASIC_AUTH_CLIENT_MULTIPLE 16
  328. /** Length of client entry consisting of client identifier and encrypted
  329. * session key for hidden service authorization type 'basic'. */
  330. #define REND_BASIC_AUTH_CLIENT_ENTRY_LEN (REND_BASIC_AUTH_CLIENT_ID_LEN \
  331. + CIPHER_KEY_LEN)
  332. /** Maximum size of v2 hidden service descriptors. */
  333. #define REND_DESC_MAX_SIZE (20 * 1024)
  334. /** Legal characters for use in authorized client names for a hidden
  335. * service. */
  336. #define REND_LEGAL_CLIENTNAME_CHARACTERS \
  337. "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-_"
  338. /** Maximum length of authorized client names for a hidden service. */
  339. #define REND_CLIENTNAME_MAX_LEN 16
  340. /** Length of the rendezvous cookie that is used to connect circuits at the
  341. * rendezvous point. */
  342. #define REND_COOKIE_LEN DIGEST_LEN
  343. /** Client authorization type that a hidden service performs. */
  344. typedef enum rend_auth_type_t {
  345. REND_NO_AUTH = 0,
  346. REND_BASIC_AUTH = 1,
  347. REND_STEALTH_AUTH = 2,
  348. } rend_auth_type_t;
  349. /** Client-side configuration of authorization for a hidden service. */
  350. typedef struct rend_service_authorization_t {
  351. uint8_t descriptor_cookie[REND_DESC_COOKIE_LEN];
  352. char onion_address[REND_SERVICE_ADDRESS_LEN+1];
  353. rend_auth_type_t auth_type;
  354. } rend_service_authorization_t;
  355. /** Client- and server-side data that is used for hidden service connection
  356. * establishment. Not all fields contain data depending on where this struct
  357. * is used. */
  358. typedef struct rend_data_t {
  359. /* Hidden service protocol version of this base object. */
  360. uint32_t version;
  361. /** List of HSDir fingerprints on which this request has been sent to. This
  362. * contains binary identity digest of the directory of size DIGEST_LEN. */
  363. smartlist_t *hsdirs_fp;
  364. /** Rendezvous cookie used by both, client and service. */
  365. char rend_cookie[REND_COOKIE_LEN];
  366. /** Number of streams associated with this rendezvous circuit. */
  367. int nr_streams;
  368. } rend_data_t;
  369. typedef struct rend_data_v2_t {
  370. /* Rendezvous base data. */
  371. rend_data_t base_;
  372. /** Onion address (without the .onion part) that a client requests. */
  373. char onion_address[REND_SERVICE_ID_LEN_BASE32+1];
  374. /** Descriptor ID for each replicas computed from the onion address. If
  375. * the onion address is empty, this array MUST be empty. We keep them so
  376. * we know when to purge our entry in the last hsdir request table. */
  377. char descriptor_id[REND_NUMBER_OF_NON_CONSECUTIVE_REPLICAS][DIGEST_LEN];
  378. /** (Optional) descriptor cookie that is used by a client. */
  379. char descriptor_cookie[REND_DESC_COOKIE_LEN];
  380. /** Authorization type for accessing a service used by a client. */
  381. rend_auth_type_t auth_type;
  382. /** Descriptor ID for a client request. The control port command HSFETCH
  383. * uses this. It's set if the descriptor query should only use this
  384. * descriptor ID. */
  385. char desc_id_fetch[DIGEST_LEN];
  386. /** Hash of the hidden service's PK used by a service. */
  387. char rend_pk_digest[DIGEST_LEN];
  388. } rend_data_v2_t;
  389. /* From a base rend_data_t object <b>d</d>, return the v2 object. */
  390. static inline
  391. rend_data_v2_t *TO_REND_DATA_V2(const rend_data_t *d)
  392. {
  393. tor_assert(d);
  394. tor_assert(d->version == 2);
  395. return DOWNCAST(rend_data_v2_t, d);
  396. }
  397. /* Stub because we can't include hs_ident.h. */
  398. struct hs_ident_edge_conn_t;
  399. struct hs_ident_dir_conn_t;
  400. struct hs_ident_circuit_t;
  401. typedef struct hsdir_index_t hsdir_index_t;
  402. /** Time interval for tracking replays of DH public keys received in
  403. * INTRODUCE2 cells. Used only to avoid launching multiple
  404. * simultaneous attempts to connect to the same rendezvous point. */
  405. #define REND_REPLAY_TIME_INTERVAL (5 * 60)
  406. /** Used to indicate which way a cell is going on a circuit. */
  407. typedef enum {
  408. CELL_DIRECTION_IN=1, /**< The cell is moving towards the origin. */
  409. CELL_DIRECTION_OUT=2, /**< The cell is moving away from the origin. */
  410. } cell_direction_t;
  411. /** Initial value for both sides of a circuit transmission window when the
  412. * circuit is initialized. Measured in cells. */
  413. #define CIRCWINDOW_START 1000
  414. #define CIRCWINDOW_START_MIN 100
  415. #define CIRCWINDOW_START_MAX 1000
  416. /** Amount to increment a circuit window when we get a circuit SENDME. */
  417. #define CIRCWINDOW_INCREMENT 100
  418. /** Initial value on both sides of a stream transmission window when the
  419. * stream is initialized. Measured in cells. */
  420. #define STREAMWINDOW_START 500
  421. #define STREAMWINDOW_START_MAX 500
  422. /** Amount to increment a stream window when we get a stream SENDME. */
  423. #define STREAMWINDOW_INCREMENT 50
  424. /** Maximum number of queued cells on a circuit for which we are the
  425. * midpoint before we give up and kill it. This must be >= circwindow
  426. * to avoid killing innocent circuits, and >= circwindow*2 to give
  427. * leaky-pipe a chance of working someday. The ORCIRC_MAX_MIDDLE_KILL_THRESH
  428. * ratio controls the margin of error between emitting a warning and
  429. * killing the circuit.
  430. */
  431. #define ORCIRC_MAX_MIDDLE_CELLS (CIRCWINDOW_START_MAX*2)
  432. /** Ratio of hard (circuit kill) to soft (warning) thresholds for the
  433. * ORCIRC_MAX_MIDDLE_CELLS tests.
  434. */
  435. #define ORCIRC_MAX_MIDDLE_KILL_THRESH (1.1f)
  436. /* Cell commands. These values are defined in tor-spec.txt. */
  437. #define CELL_PADDING 0
  438. #define CELL_CREATE 1
  439. #define CELL_CREATED 2
  440. #define CELL_RELAY 3
  441. #define CELL_DESTROY 4
  442. #define CELL_CREATE_FAST 5
  443. #define CELL_CREATED_FAST 6
  444. #define CELL_VERSIONS 7
  445. #define CELL_NETINFO 8
  446. #define CELL_RELAY_EARLY 9
  447. #define CELL_CREATE2 10
  448. #define CELL_CREATED2 11
  449. #define CELL_PADDING_NEGOTIATE 12
  450. #define CELL_VPADDING 128
  451. #define CELL_CERTS 129
  452. #define CELL_AUTH_CHALLENGE 130
  453. #define CELL_AUTHENTICATE 131
  454. #define CELL_AUTHORIZE 132
  455. #define CELL_COMMAND_MAX_ 132
  456. /** How long to test reachability before complaining to the user. */
  457. #define TIMEOUT_UNTIL_UNREACHABILITY_COMPLAINT (20*60)
  458. /** Legal characters in a nickname. */
  459. #define LEGAL_NICKNAME_CHARACTERS \
  460. "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
  461. /** Name to use in client TLS certificates if no nickname is given. Once
  462. * Tor 0.1.2.x is obsolete, we can remove this. */
  463. #define DEFAULT_CLIENT_NICKNAME "client"
  464. /** Name chosen by routers that don't configure nicknames */
  465. #define UNNAMED_ROUTER_NICKNAME "Unnamed"
  466. /** Number of bytes in a SOCKS4 header. */
  467. #define SOCKS4_NETWORK_LEN 8
  468. /*
  469. * Relay payload:
  470. * Relay command [1 byte]
  471. * Recognized [2 bytes]
  472. * Stream ID [2 bytes]
  473. * Partial SHA-1 [4 bytes]
  474. * Length [2 bytes]
  475. * Relay payload [498 bytes]
  476. */
  477. /** Number of bytes in a cell, minus cell header. */
  478. #define CELL_PAYLOAD_SIZE 509
  479. /** Number of bytes in a cell transmitted over the network, in the longest
  480. * form */
  481. #define CELL_MAX_NETWORK_SIZE 514
  482. /** Maximum length of a header on a variable-length cell. */
  483. #define VAR_CELL_MAX_HEADER_SIZE 7
  484. static int get_cell_network_size(int wide_circ_ids);
  485. static inline int get_cell_network_size(int wide_circ_ids)
  486. {
  487. return wide_circ_ids ? CELL_MAX_NETWORK_SIZE : CELL_MAX_NETWORK_SIZE - 2;
  488. }
  489. static int get_var_cell_header_size(int wide_circ_ids);
  490. static inline int get_var_cell_header_size(int wide_circ_ids)
  491. {
  492. return wide_circ_ids ? VAR_CELL_MAX_HEADER_SIZE :
  493. VAR_CELL_MAX_HEADER_SIZE - 2;
  494. }
  495. static int get_circ_id_size(int wide_circ_ids);
  496. static inline int get_circ_id_size(int wide_circ_ids)
  497. {
  498. return wide_circ_ids ? 4 : 2;
  499. }
  500. /** Number of bytes in a relay cell's header (not including general cell
  501. * header). */
  502. #define RELAY_HEADER_SIZE (1+2+2+4+2)
  503. /** Largest number of bytes that can fit in a relay cell payload. */
  504. #define RELAY_PAYLOAD_SIZE (CELL_PAYLOAD_SIZE-RELAY_HEADER_SIZE)
  505. /** Identifies a circuit on an or_connection */
  506. typedef uint32_t circid_t;
  507. /** Identifies a stream on a circuit */
  508. typedef uint16_t streamid_t;
  509. /* channel_t typedef; struct channel_s is in channel.h */
  510. typedef struct channel_s channel_t;
  511. /* channel_listener_t typedef; struct channel_listener_s is in channel.h */
  512. typedef struct channel_listener_s channel_listener_t;
  513. /* TLS channel stuff */
  514. typedef struct channel_tls_s channel_tls_t;
  515. /* circuitmux_t typedef; struct circuitmux_s is in circuitmux.h */
  516. typedef struct circuitmux_s circuitmux_t;
  517. typedef struct cell_t cell_t;
  518. typedef struct var_cell_t var_cell_t;
  519. typedef struct packed_cell_t packed_cell_t;
  520. typedef struct cell_queue_t cell_queue_t;
  521. typedef struct destroy_cell_t destroy_cell_t;
  522. typedef struct destroy_cell_queue_t destroy_cell_queue_t;
  523. typedef struct ext_or_cmd_t ext_or_cmd_t;
  524. /** Beginning of a RELAY cell payload. */
  525. typedef struct {
  526. uint8_t command; /**< The end-to-end relay command. */
  527. uint16_t recognized; /**< Used to tell whether cell is for us. */
  528. streamid_t stream_id; /**< Which stream is this cell associated with? */
  529. char integrity[4]; /**< Used to tell whether cell is corrupted. */
  530. uint16_t length; /**< How long is the payload body? */
  531. } relay_header_t;
  532. typedef struct socks_request_t socks_request_t;
  533. typedef struct entry_port_cfg_t entry_port_cfg_t;
  534. typedef struct server_port_cfg_t server_port_cfg_t;
  535. /** Minimum length of the random part of an AUTH_CHALLENGE cell. */
  536. #define OR_AUTH_CHALLENGE_LEN 32
  537. /**
  538. * @name Certificate types for CERTS cells.
  539. *
  540. * These values are defined by the protocol, and affect how an X509
  541. * certificate in a CERTS cell is interpreted and used.
  542. *
  543. * @{ */
  544. /** A certificate that authenticates a TLS link key. The subject key
  545. * must match the key used in the TLS handshake; it must be signed by
  546. * the identity key. */
  547. #define OR_CERT_TYPE_TLS_LINK 1
  548. /** A self-signed identity certificate. The subject key must be a
  549. * 1024-bit RSA key. */
  550. #define OR_CERT_TYPE_ID_1024 2
  551. /** A certificate that authenticates a key used in an AUTHENTICATE cell
  552. * in the v3 handshake. The subject key must be a 1024-bit RSA key; it
  553. * must be signed by the identity key */
  554. #define OR_CERT_TYPE_AUTH_1024 3
  555. /* DOCDOC */
  556. #define OR_CERT_TYPE_RSA_ED_CROSSCERT 7
  557. /**@}*/
  558. /** The first supported type of AUTHENTICATE cell. It contains
  559. * a bunch of structures signed with an RSA1024 key. The signed
  560. * structures include a HMAC using negotiated TLS secrets, and a digest
  561. * of all cells sent or received before the AUTHENTICATE cell (including
  562. * the random server-generated AUTH_CHALLENGE cell).
  563. */
  564. #define AUTHTYPE_RSA_SHA256_TLSSECRET 1
  565. /** As AUTHTYPE_RSA_SHA256_TLSSECRET, but instead of using the
  566. * negotiated TLS secrets, uses exported keying material from the TLS
  567. * session as described in RFC 5705.
  568. *
  569. * Not used by today's tors, since everything that supports this
  570. * also supports ED25519_SHA256_5705, which is better.
  571. **/
  572. #define AUTHTYPE_RSA_SHA256_RFC5705 2
  573. /** As AUTHTYPE_RSA_SHA256_RFC5705, but uses an Ed25519 identity key to
  574. * authenticate. */
  575. #define AUTHTYPE_ED25519_SHA256_RFC5705 3
  576. /*
  577. * NOTE: authchallenge_type_is_better() relies on these AUTHTYPE codes
  578. * being sorted in order of preference. If we someday add one with
  579. * a higher numerical value that we don't like as much, we should revise
  580. * authchallenge_type_is_better().
  581. */
  582. /** The length of the part of the AUTHENTICATE cell body that the client and
  583. * server can generate independently (when using RSA_SHA256_TLSSECRET). It
  584. * contains everything except the client's timestamp, the client's randomly
  585. * generated nonce, and the signature. */
  586. #define V3_AUTH_FIXED_PART_LEN (8+(32*6))
  587. /** The length of the part of the AUTHENTICATE cell body that the client
  588. * signs. */
  589. #define V3_AUTH_BODY_LEN (V3_AUTH_FIXED_PART_LEN + 8 + 16)
  590. typedef struct or_handshake_certs_t or_handshake_certs_t;
  591. typedef struct or_handshake_state_t or_handshake_state_t;
  592. /** Length of Extended ORPort connection identifier. */
  593. #define EXT_OR_CONN_ID_LEN DIGEST_LEN /* 20 */
  594. /*
  595. * OR_CONN_HIGHWATER and OR_CONN_LOWWATER moved from connection_or.c so
  596. * channeltls.c can see them too.
  597. */
  598. /** When adding cells to an OR connection's outbuf, keep adding until the
  599. * outbuf is at least this long, or we run out of cells. */
  600. #define OR_CONN_HIGHWATER (32*1024)
  601. /** Add cells to an OR connection's outbuf whenever the outbuf's data length
  602. * drops below this size. */
  603. #define OR_CONN_LOWWATER (16*1024)
  604. typedef struct connection_t connection_t;
  605. typedef struct control_connection_t control_connection_t;
  606. typedef struct dir_connection_t dir_connection_t;
  607. typedef struct edge_connection_t edge_connection_t;
  608. typedef struct entry_connection_t entry_connection_t;
  609. typedef struct listener_connection_t listener_connection_t;
  610. typedef struct or_connection_t or_connection_t;
  611. /** Cast a connection_t subtype pointer to a connection_t **/
  612. #define TO_CONN(c) (&(((c)->base_)))
  613. /** Cast a entry_connection_t subtype pointer to a connection_t **/
  614. #define ENTRY_TO_CONN(c) (TO_CONN(ENTRY_TO_EDGE_CONN(c)))
  615. typedef struct addr_policy_t addr_policy_t;
  616. typedef struct cached_dir_t cached_dir_t;
  617. /** Enum used to remember where a signed_descriptor_t is stored and how to
  618. * manage the memory for signed_descriptor_body. */
  619. typedef enum {
  620. /** The descriptor isn't stored on disk at all: the copy in memory is
  621. * canonical; the saved_offset field is meaningless. */
  622. SAVED_NOWHERE=0,
  623. /** The descriptor is stored in the cached_routers file: the
  624. * signed_descriptor_body is meaningless; the signed_descriptor_len and
  625. * saved_offset are used to index into the mmaped cache file. */
  626. SAVED_IN_CACHE,
  627. /** The descriptor is stored in the cached_routers.new file: the
  628. * signed_descriptor_body and saved_offset fields are both set. */
  629. /* FFFF (We could also mmap the file and grow the mmap as needed, or
  630. * lazy-load the descriptor text by using seek and read. We don't, for
  631. * now.)
  632. */
  633. SAVED_IN_JOURNAL
  634. } saved_location_t;
  635. #define saved_location_bitfield_t ENUM_BF(saved_location_t)
  636. /** Enumeration: what directory object is being downloaded?
  637. * This determines which schedule is selected to perform the download. */
  638. typedef enum {
  639. DL_SCHED_GENERIC = 0,
  640. DL_SCHED_CONSENSUS = 1,
  641. DL_SCHED_BRIDGE = 2,
  642. } download_schedule_t;
  643. #define download_schedule_bitfield_t ENUM_BF(download_schedule_t)
  644. /** Enumeration: is the download schedule for downloading from an authority,
  645. * or from any available directory mirror?
  646. * During bootstrap, "any" means a fallback (or an authority, if there
  647. * are no fallbacks).
  648. * When we have a valid consensus, "any" means any directory server. */
  649. typedef enum {
  650. DL_WANT_ANY_DIRSERVER = 0,
  651. DL_WANT_AUTHORITY = 1,
  652. } download_want_authority_t;
  653. #define download_want_authority_bitfield_t \
  654. ENUM_BF(download_want_authority_t)
  655. /** Enumeration: do we want to increment the schedule position each time a
  656. * connection is attempted (these attempts can be concurrent), or do we want
  657. * to increment the schedule position after a connection fails? */
  658. typedef enum {
  659. DL_SCHED_INCREMENT_FAILURE = 0,
  660. DL_SCHED_INCREMENT_ATTEMPT = 1,
  661. } download_schedule_increment_t;
  662. #define download_schedule_increment_bitfield_t \
  663. ENUM_BF(download_schedule_increment_t)
  664. typedef struct download_status_t download_status_t;
  665. /** If n_download_failures is this high, the download can never happen. */
  666. #define IMPOSSIBLE_TO_DOWNLOAD 255
  667. /** The max size we expect router descriptor annotations we create to
  668. * be. We'll accept larger ones if we see them on disk, but we won't
  669. * create any that are larger than this. */
  670. #define ROUTER_ANNOTATION_BUF_LEN 256
  671. typedef struct signed_descriptor_t signed_descriptor_t;
  672. /** A signed integer representing a country code. */
  673. typedef int16_t country_t;
  674. /** Flags used to summarize the declared protocol versions of a relay,
  675. * so we don't need to parse them again and again. */
  676. typedef struct protover_summary_flags_t {
  677. /** True iff we have a proto line for this router, or a versions line
  678. * from which we could infer the protocols. */
  679. unsigned int protocols_known:1;
  680. /** True iff this router has a version or protocol list that allows it to
  681. * accept EXTEND2 cells. This requires Relay=2. */
  682. unsigned int supports_extend2_cells:1;
  683. /** True iff this router has a protocol list that allows it to negotiate
  684. * ed25519 identity keys on a link handshake with us. This
  685. * requires LinkAuth=3. */
  686. unsigned int supports_ed25519_link_handshake_compat:1;
  687. /** True iff this router has a protocol list that allows it to negotiate
  688. * ed25519 identity keys on a link handshake, at all. This requires some
  689. * LinkAuth=X for X >= 3. */
  690. unsigned int supports_ed25519_link_handshake_any:1;
  691. /** True iff this router has a protocol list that allows it to be an
  692. * introduction point supporting ed25519 authentication key which is part of
  693. * the v3 protocol detailed in proposal 224. This requires HSIntro=4. */
  694. unsigned int supports_ed25519_hs_intro : 1;
  695. /** True iff this router has a protocol list that allows it to be an hidden
  696. * service directory supporting version 3 as seen in proposal 224. This
  697. * requires HSDir=2. */
  698. unsigned int supports_v3_hsdir : 1;
  699. /** True iff this router has a protocol list that allows it to be an hidden
  700. * service rendezvous point supporting version 3 as seen in proposal 224.
  701. * This requires HSRend=2. */
  702. unsigned int supports_v3_rendezvous_point: 1;
  703. } protover_summary_flags_t;
  704. typedef struct routerinfo_t routerinfo_t;
  705. typedef struct extrainfo_t extrainfo_t;
  706. typedef struct routerstatus_t routerstatus_t;
  707. typedef struct microdesc_t microdesc_t;
  708. typedef struct node_t node_t;
  709. typedef struct vote_microdesc_hash_t vote_microdesc_hash_t;
  710. typedef struct vote_routerstatus_t vote_routerstatus_t;
  711. typedef struct document_signature_t document_signature_t;
  712. typedef struct networkstatus_voter_info_t networkstatus_voter_info_t;
  713. typedef struct networkstatus_sr_info_t networkstatus_sr_info_t;
  714. /** Enumerates recognized flavors of a consensus networkstatus document. All
  715. * flavors of a consensus are generated from the same set of votes, but they
  716. * present different types information to different versions of Tor. */
  717. typedef enum {
  718. FLAV_NS = 0,
  719. FLAV_MICRODESC = 1,
  720. } consensus_flavor_t;
  721. /** How many different consensus flavors are there? */
  722. #define N_CONSENSUS_FLAVORS ((int)(FLAV_MICRODESC)+1)
  723. typedef struct networkstatus_t networkstatus_t;
  724. typedef struct ns_detached_signatures_t ns_detached_signatures_t;
  725. typedef struct desc_store_t desc_store_t;
  726. typedef struct routerlist_t routerlist_t;
  727. typedef struct extend_info_t extend_info_t;
  728. typedef struct authority_cert_t authority_cert_t;
  729. /** Bitfield enum type listing types of information that directory authorities
  730. * can be authoritative about, and that directory caches may or may not cache.
  731. *
  732. * Note that the granularity here is based on authority granularity and on
  733. * cache capabilities. Thus, one particular bit may correspond in practice to
  734. * a few types of directory info, so long as every authority that pronounces
  735. * officially about one of the types prounounces officially about all of them,
  736. * and so long as every cache that caches one of them caches all of them.
  737. */
  738. typedef enum {
  739. NO_DIRINFO = 0,
  740. /** Serves/signs v3 directory information: votes, consensuses, certs */
  741. V3_DIRINFO = 1 << 2,
  742. /** Serves bridge descriptors. */
  743. BRIDGE_DIRINFO = 1 << 4,
  744. /** Serves extrainfo documents. */
  745. EXTRAINFO_DIRINFO=1 << 5,
  746. /** Serves microdescriptors. */
  747. MICRODESC_DIRINFO=1 << 6,
  748. } dirinfo_type_t;
  749. #define ALL_DIRINFO ((dirinfo_type_t)((1<<7)-1))
  750. #define ONION_HANDSHAKE_TYPE_TAP 0x0000
  751. #define ONION_HANDSHAKE_TYPE_FAST 0x0001
  752. #define ONION_HANDSHAKE_TYPE_NTOR 0x0002
  753. #define MAX_ONION_HANDSHAKE_TYPE 0x0002
  754. typedef struct onion_handshake_state_t onion_handshake_state_t;
  755. typedef struct relay_crypto_t relay_crypto_t;
  756. typedef struct crypt_path_t crypt_path_t;
  757. typedef struct crypt_path_reference_t crypt_path_reference_t;
  758. #define CPATH_KEY_MATERIAL_LEN (20*2+16*2)
  759. typedef struct cpath_build_state_t cpath_build_state_t;
  760. struct create_cell_t;
  761. /** Entry in the cell stats list of a circuit; used only if CELL_STATS
  762. * events are enabled. */
  763. typedef struct testing_cell_stats_entry_t {
  764. uint8_t command; /**< cell command number. */
  765. /** Waiting time in centiseconds if this event is for a removed cell,
  766. * or 0 if this event is for adding a cell to the queue. 22 bits can
  767. * store more than 11 hours, enough to assume that a circuit with this
  768. * delay would long have been closed. */
  769. unsigned int waiting_time:22;
  770. unsigned int removed:1; /**< 0 for added to, 1 for removed from queue. */
  771. unsigned int exitward:1; /**< 0 for app-ward, 1 for exit-ward. */
  772. } testing_cell_stats_entry_t;
  773. typedef struct circuit_t circuit_t;
  774. typedef struct origin_circuit_t origin_circuit_t;
  775. typedef struct or_circuit_t or_circuit_t;
  776. /** Largest number of relay_early cells that we can send on a given
  777. * circuit. */
  778. #define MAX_RELAY_EARLY_CELLS_PER_CIRCUIT 8
  779. typedef enum path_state_t path_state_t;
  780. #define path_state_bitfield_t ENUM_BF(path_state_t)
  781. #if REND_COOKIE_LEN != DIGEST_LEN
  782. #error "The REND_TOKEN_LEN macro assumes REND_COOKIE_LEN == DIGEST_LEN"
  783. #endif
  784. #define REND_TOKEN_LEN DIGEST_LEN
  785. /** Convert a circuit subtype to a circuit_t. */
  786. #define TO_CIRCUIT(x) (&((x)->base_))
  787. /** @name Isolation flags
  788. Ways to isolate client streams
  789. @{
  790. */
  791. /** Isolate based on destination port */
  792. #define ISO_DESTPORT (1u<<0)
  793. /** Isolate based on destination address */
  794. #define ISO_DESTADDR (1u<<1)
  795. /** Isolate based on SOCKS authentication */
  796. #define ISO_SOCKSAUTH (1u<<2)
  797. /** Isolate based on client protocol choice */
  798. #define ISO_CLIENTPROTO (1u<<3)
  799. /** Isolate based on client address */
  800. #define ISO_CLIENTADDR (1u<<4)
  801. /** Isolate based on session group (always on). */
  802. #define ISO_SESSIONGRP (1u<<5)
  803. /** Isolate based on newnym epoch (always on). */
  804. #define ISO_NYM_EPOCH (1u<<6)
  805. /** Isolate all streams (Internal only). */
  806. #define ISO_STREAM (1u<<7)
  807. /**@}*/
  808. /** Default isolation level for ports. */
  809. #define ISO_DEFAULT (ISO_CLIENTADDR|ISO_SOCKSAUTH|ISO_SESSIONGRP|ISO_NYM_EPOCH)
  810. /** Indicates that we haven't yet set a session group on a port_cfg_t. */
  811. #define SESSION_GROUP_UNSET -1
  812. /** Session group reserved for directory connections */
  813. #define SESSION_GROUP_DIRCONN -2
  814. /** Session group reserved for resolve requests launched by a controller */
  815. #define SESSION_GROUP_CONTROL_RESOLVE -3
  816. /** First automatically allocated session group number */
  817. #define SESSION_GROUP_FIRST_AUTO -4
  818. typedef struct port_cfg_t port_cfg_t;
  819. typedef struct routerset_t routerset_t;
  820. /** A magic value for the (Socks|OR|...)Port options below, telling Tor
  821. * to pick its own port. */
  822. #define CFG_AUTO_PORT 0xc4005e
  823. /** Enumeration of outbound address configuration types:
  824. * Exit-only, OR-only, or both */
  825. typedef enum {OUTBOUND_ADDR_EXIT, OUTBOUND_ADDR_OR,
  826. OUTBOUND_ADDR_EXIT_AND_OR,
  827. OUTBOUND_ADDR_MAX} outbound_addr_t;
  828. struct config_line_t;
  829. /** Configuration options for a Tor process. */
  830. typedef struct {
  831. uint32_t magic_;
  832. /** What should the tor process actually do? */
  833. enum {
  834. CMD_RUN_TOR=0, CMD_LIST_FINGERPRINT, CMD_HASH_PASSWORD,
  835. CMD_VERIFY_CONFIG, CMD_RUN_UNITTESTS, CMD_DUMP_CONFIG,
  836. CMD_KEYGEN,
  837. CMD_KEY_EXPIRATION,
  838. } command;
  839. char *command_arg; /**< Argument for command-line option. */
  840. struct config_line_t *Logs; /**< New-style list of configuration lines
  841. * for logs */
  842. int LogTimeGranularity; /**< Log resolution in milliseconds. */
  843. int LogMessageDomains; /**< Boolean: Should we log the domain(s) in which
  844. * each log message occurs? */
  845. int TruncateLogFile; /**< Boolean: Should we truncate the log file
  846. before we start writing? */
  847. char *SyslogIdentityTag; /**< Identity tag to add for syslog logging. */
  848. char *AndroidIdentityTag; /**< Identity tag to add for Android logging. */
  849. char *DebugLogFile; /**< Where to send verbose log messages. */
  850. char *DataDirectory_option; /**< Where to store long-term data, as
  851. * configured by the user. */
  852. char *DataDirectory; /**< Where to store long-term data, as modified. */
  853. int DataDirectoryGroupReadable; /**< Boolean: Is the DataDirectory g+r? */
  854. char *KeyDirectory_option; /**< Where to store keys, as
  855. * configured by the user. */
  856. char *KeyDirectory; /**< Where to store keys data, as modified. */
  857. int KeyDirectoryGroupReadable; /**< Boolean: Is the KeyDirectory g+r? */
  858. char *CacheDirectory_option; /**< Where to store cached data, as
  859. * configured by the user. */
  860. char *CacheDirectory; /**< Where to store cached data, as modified. */
  861. int CacheDirectoryGroupReadable; /**< Boolean: Is the CacheDirectory g+r? */
  862. char *Nickname; /**< OR only: nickname of this onion router. */
  863. char *Address; /**< OR only: configured address for this onion router. */
  864. char *PidFile; /**< Where to store PID of Tor process. */
  865. routerset_t *ExitNodes; /**< Structure containing nicknames, digests,
  866. * country codes and IP address patterns of ORs to
  867. * consider as exits. */
  868. routerset_t *EntryNodes;/**< Structure containing nicknames, digests,
  869. * country codes and IP address patterns of ORs to
  870. * consider as entry points. */
  871. int StrictNodes; /**< Boolean: When none of our EntryNodes or ExitNodes
  872. * are up, or we need to access a node in ExcludeNodes,
  873. * do we just fail instead? */
  874. routerset_t *ExcludeNodes;/**< Structure containing nicknames, digests,
  875. * country codes and IP address patterns of ORs
  876. * not to use in circuits. But see StrictNodes
  877. * above. */
  878. routerset_t *ExcludeExitNodes;/**< Structure containing nicknames, digests,
  879. * country codes and IP address patterns of
  880. * ORs not to consider as exits. */
  881. /** Union of ExcludeNodes and ExcludeExitNodes */
  882. routerset_t *ExcludeExitNodesUnion_;
  883. int DisableAllSwap; /**< Boolean: Attempt to call mlockall() on our
  884. * process for all current and future memory. */
  885. struct config_line_t *ExitPolicy; /**< Lists of exit policy components. */
  886. int ExitPolicyRejectPrivate; /**< Should we not exit to reserved private
  887. * addresses, and our own published addresses?
  888. */
  889. int ExitPolicyRejectLocalInterfaces; /**< Should we not exit to local
  890. * interface addresses?
  891. * Includes OutboundBindAddresses and
  892. * configured ports. */
  893. int ReducedExitPolicy; /**<Should we use the Reduced Exit Policy? */
  894. struct config_line_t *SocksPolicy; /**< Lists of socks policy components */
  895. struct config_line_t *DirPolicy; /**< Lists of dir policy components */
  896. /** Local address to bind outbound sockets */
  897. struct config_line_t *OutboundBindAddress;
  898. /** Local address to bind outbound relay sockets */
  899. struct config_line_t *OutboundBindAddressOR;
  900. /** Local address to bind outbound exit sockets */
  901. struct config_line_t *OutboundBindAddressExit;
  902. /** Addresses derived from the various OutboundBindAddress lines.
  903. * [][0] is IPv4, [][1] is IPv6
  904. */
  905. tor_addr_t OutboundBindAddresses[OUTBOUND_ADDR_MAX][2];
  906. /** Directory server only: which versions of
  907. * Tor should we tell users to run? */
  908. struct config_line_t *RecommendedVersions;
  909. struct config_line_t *RecommendedClientVersions;
  910. struct config_line_t *RecommendedServerVersions;
  911. struct config_line_t *RecommendedPackages;
  912. /** Whether dirservers allow router descriptors with private IPs. */
  913. int DirAllowPrivateAddresses;
  914. /** Whether routers accept EXTEND cells to routers with private IPs. */
  915. int ExtendAllowPrivateAddresses;
  916. char *User; /**< Name of user to run Tor as. */
  917. /** Ports to listen on for OR connections. */
  918. struct config_line_t *ORPort_lines;
  919. /** Ports to listen on for extended OR connections. */
  920. struct config_line_t *ExtORPort_lines;
  921. /** Ports to listen on for SOCKS connections. */
  922. struct config_line_t *SocksPort_lines;
  923. /** Ports to listen on for transparent pf/netfilter connections. */
  924. struct config_line_t *TransPort_lines;
  925. char *TransProxyType; /**< What kind of transparent proxy
  926. * implementation are we using? */
  927. /** Parsed value of TransProxyType. */
  928. enum {
  929. TPT_DEFAULT,
  930. TPT_PF_DIVERT,
  931. TPT_IPFW,
  932. TPT_TPROXY,
  933. } TransProxyType_parsed;
  934. /** Ports to listen on for transparent natd connections. */
  935. struct config_line_t *NATDPort_lines;
  936. /** Ports to listen on for HTTP Tunnel connections. */
  937. struct config_line_t *HTTPTunnelPort_lines;
  938. struct config_line_t *ControlPort_lines; /**< Ports to listen on for control
  939. * connections. */
  940. /** List of Unix Domain Sockets to listen on for control connections. */
  941. struct config_line_t *ControlSocket;
  942. int ControlSocketsGroupWritable; /**< Boolean: Are control sockets g+rw? */
  943. int UnixSocksGroupWritable; /**< Boolean: Are SOCKS Unix sockets g+rw? */
  944. /** Ports to listen on for directory connections. */
  945. struct config_line_t *DirPort_lines;
  946. /** Ports to listen on for DNS requests. */
  947. struct config_line_t *DNSPort_lines;
  948. /* MaxMemInQueues value as input by the user. We clean this up to be
  949. * MaxMemInQueues. */
  950. uint64_t MaxMemInQueues_raw;
  951. uint64_t MaxMemInQueues;/**< If we have more memory than this allocated
  952. * for queues and buffers, run the OOM handler */
  953. /** Above this value, consider ourselves low on RAM. */
  954. uint64_t MaxMemInQueues_low_threshold;
  955. /** @name port booleans
  956. *
  957. * Derived booleans: For server ports and ControlPort, true iff there is a
  958. * non-listener port on an AF_INET or AF_INET6 address of the given type
  959. * configured in one of the _lines options above.
  960. * For client ports, also true if there is a unix socket configured.
  961. * If you are checking for client ports, you may want to use:
  962. * SocksPort_set || TransPort_set || NATDPort_set || DNSPort_set ||
  963. * HTTPTunnelPort_set
  964. * rather than SocksPort_set.
  965. *
  966. * @{
  967. */
  968. unsigned int ORPort_set : 1;
  969. unsigned int SocksPort_set : 1;
  970. unsigned int TransPort_set : 1;
  971. unsigned int NATDPort_set : 1;
  972. unsigned int ControlPort_set : 1;
  973. unsigned int DirPort_set : 1;
  974. unsigned int DNSPort_set : 1;
  975. unsigned int ExtORPort_set : 1;
  976. unsigned int HTTPTunnelPort_set : 1;
  977. /**@}*/
  978. int AssumeReachable; /**< Whether to publish our descriptor regardless. */
  979. int AuthoritativeDir; /**< Boolean: is this an authoritative directory? */
  980. int V3AuthoritativeDir; /**< Boolean: is this an authoritative directory
  981. * for version 3 directories? */
  982. int VersioningAuthoritativeDir; /**< Boolean: is this an authoritative
  983. * directory that's willing to recommend
  984. * versions? */
  985. int BridgeAuthoritativeDir; /**< Boolean: is this an authoritative directory
  986. * that aggregates bridge descriptors? */
  987. /** If set on a bridge relay, it will include this value on a new
  988. * "bridge-distribution-request" line in its bridge descriptor. */
  989. char *BridgeDistribution;
  990. /** If set on a bridge authority, it will answer requests on its dirport
  991. * for bridge statuses -- but only if the requests use this password. */
  992. char *BridgePassword;
  993. /** If BridgePassword is set, this is a SHA256 digest of the basic http
  994. * authenticator for it. Used so we can do a time-independent comparison. */
  995. char *BridgePassword_AuthDigest_;
  996. int UseBridges; /**< Boolean: should we start all circuits with a bridge? */
  997. struct config_line_t *Bridges; /**< List of bootstrap bridge addresses. */
  998. struct config_line_t *ClientTransportPlugin; /**< List of client
  999. transport plugins. */
  1000. struct config_line_t *ServerTransportPlugin; /**< List of client
  1001. transport plugins. */
  1002. /** List of TCP/IP addresses that transports should listen at. */
  1003. struct config_line_t *ServerTransportListenAddr;
  1004. /** List of options that must be passed to pluggable transports. */
  1005. struct config_line_t *ServerTransportOptions;
  1006. int BridgeRelay; /**< Boolean: are we acting as a bridge relay? We make
  1007. * this explicit so we can change how we behave in the
  1008. * future. */
  1009. /** Boolean: if we know the bridge's digest, should we get new
  1010. * descriptors from the bridge authorities or from the bridge itself? */
  1011. int UpdateBridgesFromAuthority;
  1012. int AvoidDiskWrites; /**< Boolean: should we never cache things to disk?
  1013. * Not used yet. */
  1014. int ClientOnly; /**< Boolean: should we never evolve into a server role? */
  1015. int ReducedConnectionPadding; /**< Boolean: Should we try to keep connections
  1016. open shorter and pad them less against
  1017. connection-level traffic analysis? */
  1018. /** Autobool: if auto, then connection padding will be negotiated by client
  1019. * and server. If 0, it will be fully disabled. If 1, the client will still
  1020. * pad to the server regardless of server support. */
  1021. int ConnectionPadding;
  1022. /** To what authority types do we publish our descriptor? Choices are
  1023. * "v1", "v2", "v3", "bridge", or "". */
  1024. smartlist_t *PublishServerDescriptor;
  1025. /** A bitfield of authority types, derived from PublishServerDescriptor. */
  1026. dirinfo_type_t PublishServerDescriptor_;
  1027. /** Boolean: do we publish hidden service descriptors to the HS auths? */
  1028. int PublishHidServDescriptors;
  1029. int FetchServerDescriptors; /**< Do we fetch server descriptors as normal? */
  1030. int FetchHidServDescriptors; /**< and hidden service descriptors? */
  1031. int MinUptimeHidServDirectoryV2; /**< As directory authority, accept hidden
  1032. * service directories after what time? */
  1033. int FetchUselessDescriptors; /**< Do we fetch non-running descriptors too? */
  1034. int AllDirActionsPrivate; /**< Should every directory action be sent
  1035. * through a Tor circuit? */
  1036. /** Run in 'tor2web mode'? (I.e. only make client connections to hidden
  1037. * services, and use a single hop for all hidden-service-related
  1038. * circuits.) */
  1039. int Tor2webMode;
  1040. /** A routerset that should be used when picking RPs for HS circuits. */
  1041. routerset_t *Tor2webRendezvousPoints;
  1042. /** A routerset that should be used when picking middle nodes for HS
  1043. * circuits. */
  1044. routerset_t *HSLayer2Nodes;
  1045. /** A routerset that should be used when picking third-hop nodes for HS
  1046. * circuits. */
  1047. routerset_t *HSLayer3Nodes;
  1048. /** Onion Services in HiddenServiceSingleHopMode make one-hop (direct)
  1049. * circuits between the onion service server, and the introduction and
  1050. * rendezvous points. (Onion service descriptors are still posted using
  1051. * 3-hop paths, to avoid onion service directories blocking the service.)
  1052. * This option makes every hidden service instance hosted by
  1053. * this tor instance a Single Onion Service.
  1054. * HiddenServiceSingleHopMode requires HiddenServiceNonAnonymousMode to be
  1055. * set to 1.
  1056. * Use rend_service_allow_non_anonymous_connection() or
  1057. * rend_service_reveal_startup_time() instead of using this option directly.
  1058. */
  1059. int HiddenServiceSingleHopMode;
  1060. /* Makes hidden service clients and servers non-anonymous on this tor
  1061. * instance. Allows the non-anonymous HiddenServiceSingleHopMode. Enables
  1062. * non-anonymous behaviour in the hidden service protocol.
  1063. * Use rend_service_non_anonymous_mode_enabled() instead of using this option
  1064. * directly.
  1065. */
  1066. int HiddenServiceNonAnonymousMode;
  1067. int ConnLimit; /**< Demanded minimum number of simultaneous connections. */
  1068. int ConnLimit_; /**< Maximum allowed number of simultaneous connections. */
  1069. int ConnLimit_high_thresh; /**< start trying to lower socket usage if we
  1070. * have this many. */
  1071. int ConnLimit_low_thresh; /**< try to get down to here after socket
  1072. * exhaustion. */
  1073. int RunAsDaemon; /**< If true, run in the background. (Unix only) */
  1074. int FascistFirewall; /**< Whether to prefer ORs reachable on open ports. */
  1075. smartlist_t *FirewallPorts; /**< Which ports our firewall allows
  1076. * (strings). */
  1077. /** IP:ports our firewall allows. */
  1078. struct config_line_t *ReachableAddresses;
  1079. struct config_line_t *ReachableORAddresses; /**< IP:ports for OR conns. */
  1080. struct config_line_t *ReachableDirAddresses; /**< IP:ports for Dir conns. */
  1081. int ConstrainedSockets; /**< Shrink xmit and recv socket buffers. */
  1082. uint64_t ConstrainedSockSize; /**< Size of constrained buffers. */
  1083. /** Whether we should drop exit streams from Tors that we don't know are
  1084. * relays. One of "0" (never refuse), "1" (always refuse), or "-1" (do
  1085. * what the consensus says, defaulting to 'refuse' if the consensus says
  1086. * nothing). */
  1087. int RefuseUnknownExits;
  1088. /** Application ports that require all nodes in circ to have sufficient
  1089. * uptime. */
  1090. smartlist_t *LongLivedPorts;
  1091. /** Application ports that are likely to be unencrypted and
  1092. * unauthenticated; we reject requests for them to prevent the
  1093. * user from screwing up and leaking plaintext secrets to an
  1094. * observer somewhere on the Internet. */
  1095. smartlist_t *RejectPlaintextPorts;
  1096. /** Related to RejectPlaintextPorts above, except this config option
  1097. * controls whether we warn (in the log and via a controller status
  1098. * event) every time a risky connection is attempted. */
  1099. smartlist_t *WarnPlaintextPorts;
  1100. /** Should we try to reuse the same exit node for a given host */
  1101. smartlist_t *TrackHostExits;
  1102. int TrackHostExitsExpire; /**< Number of seconds until we expire an
  1103. * addressmap */
  1104. struct config_line_t *AddressMap; /**< List of address map directives. */
  1105. int AutomapHostsOnResolve; /**< If true, when we get a resolve request for a
  1106. * hostname ending with one of the suffixes in
  1107. * <b>AutomapHostsSuffixes</b>, map it to a
  1108. * virtual address. */
  1109. /** List of suffixes for <b>AutomapHostsOnResolve</b>. The special value
  1110. * "." means "match everything." */
  1111. smartlist_t *AutomapHostsSuffixes;
  1112. int RendPostPeriod; /**< How often do we post each rendezvous service
  1113. * descriptor? Remember to publish them independently. */
  1114. int KeepalivePeriod; /**< How often do we send padding cells to keep
  1115. * connections alive? */
  1116. int SocksTimeout; /**< How long do we let a socks connection wait
  1117. * unattached before we fail it? */
  1118. int LearnCircuitBuildTimeout; /**< If non-zero, we attempt to learn a value
  1119. * for CircuitBuildTimeout based on timeout
  1120. * history. Use circuit_build_times_disabled()
  1121. * rather than checking this value directly. */
  1122. int CircuitBuildTimeout; /**< Cull non-open circuits that were born at
  1123. * least this many seconds ago. Used until
  1124. * adaptive algorithm learns a new value. */
  1125. int CircuitsAvailableTimeout; /**< Try to have an open circuit for at
  1126. least this long after last activity */
  1127. int CircuitStreamTimeout; /**< If non-zero, detach streams from circuits
  1128. * and try a new circuit if the stream has been
  1129. * waiting for this many seconds. If zero, use
  1130. * our default internal timeout schedule. */
  1131. int MaxOnionQueueDelay; /*< DOCDOC */
  1132. int NewCircuitPeriod; /**< How long do we use a circuit before building
  1133. * a new one? */
  1134. int MaxCircuitDirtiness; /**< Never use circs that were first used more than
  1135. this interval ago. */
  1136. uint64_t BandwidthRate; /**< How much bandwidth, on average, are we willing
  1137. * to use in a second? */
  1138. uint64_t BandwidthBurst; /**< How much bandwidth, at maximum, are we willing
  1139. * to use in a second? */
  1140. uint64_t MaxAdvertisedBandwidth; /**< How much bandwidth are we willing to
  1141. * tell other nodes we have? */
  1142. uint64_t RelayBandwidthRate; /**< How much bandwidth, on average, are we
  1143. * willing to use for all relayed conns? */
  1144. uint64_t RelayBandwidthBurst; /**< How much bandwidth, at maximum, will we
  1145. * use in a second for all relayed conns? */
  1146. uint64_t PerConnBWRate; /**< Long-term bw on a single TLS conn, if set. */
  1147. uint64_t PerConnBWBurst; /**< Allowed burst on a single TLS conn, if set. */
  1148. int NumCPUs; /**< How many CPUs should we try to use? */
  1149. struct config_line_t *RendConfigLines; /**< List of configuration lines
  1150. * for rendezvous services. */
  1151. struct config_line_t *HidServAuth; /**< List of configuration lines for
  1152. * client-side authorizations for hidden
  1153. * services */
  1154. char *ContactInfo; /**< Contact info to be published in the directory. */
  1155. int HeartbeatPeriod; /**< Log heartbeat messages after this many seconds
  1156. * have passed. */
  1157. int MainloopStats; /**< Log main loop statistics as part of the
  1158. * heartbeat messages. */
  1159. char *HTTPProxy; /**< hostname[:port] to use as http proxy, if any. */
  1160. tor_addr_t HTTPProxyAddr; /**< Parsed IPv4 addr for http proxy, if any. */
  1161. uint16_t HTTPProxyPort; /**< Parsed port for http proxy, if any. */
  1162. char *HTTPProxyAuthenticator; /**< username:password string, if any. */
  1163. char *HTTPSProxy; /**< hostname[:port] to use as https proxy, if any. */
  1164. tor_addr_t HTTPSProxyAddr; /**< Parsed addr for https proxy, if any. */
  1165. uint16_t HTTPSProxyPort; /**< Parsed port for https proxy, if any. */
  1166. char *HTTPSProxyAuthenticator; /**< username:password string, if any. */
  1167. char *Socks4Proxy; /**< hostname:port to use as a SOCKS4 proxy, if any. */
  1168. tor_addr_t Socks4ProxyAddr; /**< Derived from Socks4Proxy. */
  1169. uint16_t Socks4ProxyPort; /**< Derived from Socks4Proxy. */
  1170. char *Socks5Proxy; /**< hostname:port to use as a SOCKS5 proxy, if any. */
  1171. tor_addr_t Socks5ProxyAddr; /**< Derived from Sock5Proxy. */
  1172. uint16_t Socks5ProxyPort; /**< Derived from Socks5Proxy. */
  1173. char *Socks5ProxyUsername; /**< Username for SOCKS5 authentication, if any */
  1174. char *Socks5ProxyPassword; /**< Password for SOCKS5 authentication, if any */
  1175. /** List of configuration lines for replacement directory authorities.
  1176. * If you just want to replace one class of authority at a time,
  1177. * use the "Alternate*Authority" options below instead. */
  1178. struct config_line_t *DirAuthorities;
  1179. /** List of fallback directory servers */
  1180. struct config_line_t *FallbackDir;
  1181. /** Whether to use the default hard-coded FallbackDirs */
  1182. int UseDefaultFallbackDirs;
  1183. /** Weight to apply to all directory authority rates if considering them
  1184. * along with fallbackdirs */
  1185. double DirAuthorityFallbackRate;
  1186. /** If set, use these main (currently v3) directory authorities and
  1187. * not the default ones. */
  1188. struct config_line_t *AlternateDirAuthority;
  1189. /** If set, use these bridge authorities and not the default one. */
  1190. struct config_line_t *AlternateBridgeAuthority;
  1191. struct config_line_t *MyFamily_lines; /**< Declared family for this OR. */
  1192. struct config_line_t *MyFamily; /**< Declared family for this OR,
  1193. normalized */
  1194. struct config_line_t *NodeFamilies; /**< List of config lines for
  1195. * node families */
  1196. smartlist_t *NodeFamilySets; /**< List of parsed NodeFamilies values. */
  1197. struct config_line_t *AuthDirBadExit; /**< Address policy for descriptors to
  1198. * mark as bad exits. */
  1199. struct config_line_t *AuthDirReject; /**< Address policy for descriptors to
  1200. * reject. */
  1201. struct config_line_t *AuthDirInvalid; /**< Address policy for descriptors to
  1202. * never mark as valid. */
  1203. /** @name AuthDir...CC
  1204. *
  1205. * Lists of country codes to mark as BadExit, or Invalid, or to
  1206. * reject entirely.
  1207. *
  1208. * @{
  1209. */
  1210. smartlist_t *AuthDirBadExitCCs;
  1211. smartlist_t *AuthDirInvalidCCs;
  1212. smartlist_t *AuthDirRejectCCs;
  1213. /**@}*/
  1214. int AuthDirListBadExits; /**< True iff we should list bad exits,
  1215. * and vote for all other exits as good. */
  1216. int AuthDirMaxServersPerAddr; /**< Do not permit more than this
  1217. * number of servers per IP address. */
  1218. int AuthDirHasIPv6Connectivity; /**< Boolean: are we on IPv6? */
  1219. int AuthDirPinKeys; /**< Boolean: Do we enforce key-pinning? */
  1220. /** If non-zero, always vote the Fast flag for any relay advertising
  1221. * this amount of capacity or more. */
  1222. uint64_t AuthDirFastGuarantee;
  1223. /** If non-zero, this advertised capacity or more is always sufficient
  1224. * to satisfy the bandwidth requirement for the Guard flag. */
  1225. uint64_t AuthDirGuardBWGuarantee;
  1226. char *AccountingStart; /**< How long is the accounting interval, and when
  1227. * does it start? */
  1228. uint64_t AccountingMax; /**< How many bytes do we allow per accounting
  1229. * interval before hibernation? 0 for "never
  1230. * hibernate." */
  1231. /** How do we determine when our AccountingMax has been reached?
  1232. * "max" for when in or out reaches AccountingMax
  1233. * "sum" for when in plus out reaches AccountingMax
  1234. * "in" for when in reaches AccountingMax
  1235. * "out" for when out reaches AccountingMax */
  1236. char *AccountingRule_option;
  1237. enum { ACCT_MAX, ACCT_SUM, ACCT_IN, ACCT_OUT } AccountingRule;
  1238. /** Base64-encoded hash of accepted passwords for the control system. */
  1239. struct config_line_t *HashedControlPassword;
  1240. /** As HashedControlPassword, but not saved. */
  1241. struct config_line_t *HashedControlSessionPassword;
  1242. int CookieAuthentication; /**< Boolean: do we enable cookie-based auth for
  1243. * the control system? */
  1244. char *CookieAuthFile; /**< Filesystem location of a ControlPort
  1245. * authentication cookie. */
  1246. char *ExtORPortCookieAuthFile; /**< Filesystem location of Extended
  1247. * ORPort authentication cookie. */
  1248. int CookieAuthFileGroupReadable; /**< Boolean: Is the CookieAuthFile g+r? */
  1249. int ExtORPortCookieAuthFileGroupReadable; /**< Boolean: Is the
  1250. * ExtORPortCookieAuthFile g+r? */
  1251. int LeaveStreamsUnattached; /**< Boolean: Does Tor attach new streams to
  1252. * circuits itself (0), or does it expect a controller
  1253. * to cope? (1) */
  1254. int DisablePredictedCircuits; /**< Boolean: does Tor preemptively
  1255. * make circuits in the background (0),
  1256. * or not (1)? */
  1257. /** Process specifier for a controller that ‘owns’ this Tor
  1258. * instance. Tor will terminate if its owning controller does. */
  1259. char *OwningControllerProcess;
  1260. /** FD specifier for a controller that owns this Tor instance. */
  1261. int OwningControllerFD;
  1262. int ShutdownWaitLength; /**< When we get a SIGINT and we're a server, how
  1263. * long do we wait before exiting? */
  1264. char *SafeLogging; /**< Contains "relay", "1", "0" (meaning no scrubbing). */
  1265. /* Derived from SafeLogging */
  1266. enum {
  1267. SAFELOG_SCRUB_ALL, SAFELOG_SCRUB_RELAY, SAFELOG_SCRUB_NONE
  1268. } SafeLogging_;
  1269. int Sandbox; /**< Boolean: should sandboxing be enabled? */
  1270. int SafeSocks; /**< Boolean: should we outright refuse application
  1271. * connections that use socks4 or socks5-with-local-dns? */
  1272. int ProtocolWarnings; /**< Boolean: when other parties screw up the Tor
  1273. * protocol, is it a warn or an info in our logs? */
  1274. int TestSocks; /**< Boolean: when we get a socks connection, do we loudly
  1275. * log whether it was DNS-leaking or not? */
  1276. int HardwareAccel; /**< Boolean: Should we enable OpenSSL hardware
  1277. * acceleration where available? */
  1278. /** Token Bucket Refill resolution in milliseconds. */
  1279. int TokenBucketRefillInterval;
  1280. char *AccelName; /**< Optional hardware acceleration engine name. */
  1281. char *AccelDir; /**< Optional hardware acceleration engine search dir. */
  1282. /** Boolean: Do we try to enter from a smallish number
  1283. * of fixed nodes? */
  1284. int UseEntryGuards_option;
  1285. /** Internal variable to remember whether we're actually acting on
  1286. * UseEntryGuards_option -- when we're a non-anonymous Tor2web client or
  1287. * Single Onion Service, it is always false, otherwise we use the value of
  1288. * UseEntryGuards_option. */
  1289. int UseEntryGuards;
  1290. int NumEntryGuards; /**< How many entry guards do we try to establish? */
  1291. /** If 1, we use any guardfraction information we see in the
  1292. * consensus. If 0, we don't. If -1, let the consensus parameter
  1293. * decide. */
  1294. int UseGuardFraction;
  1295. int NumDirectoryGuards; /**< How many dir guards do we try to establish?
  1296. * If 0, use value from NumEntryGuards. */
  1297. int NumPrimaryGuards; /**< How many primary guards do we want? */
  1298. int RephistTrackTime; /**< How many seconds do we keep rephist info? */
  1299. /** Should we always fetch our dir info on the mirror schedule (which
  1300. * means directly from the authorities) no matter our other config? */
  1301. int FetchDirInfoEarly;
  1302. /** Should we fetch our dir info at the start of the consensus period? */
  1303. int FetchDirInfoExtraEarly;
  1304. int DirCache; /**< Cache all directory documents and accept requests via
  1305. * tunnelled dir conns from clients. If 1, enabled (default);
  1306. * If 0, disabled. */
  1307. char *VirtualAddrNetworkIPv4; /**< Address and mask to hand out for virtual
  1308. * MAPADDRESS requests for IPv4 addresses */
  1309. char *VirtualAddrNetworkIPv6; /**< Address and mask to hand out for virtual
  1310. * MAPADDRESS requests for IPv6 addresses */
  1311. int ServerDNSSearchDomains; /**< Boolean: If set, we don't force exit
  1312. * addresses to be FQDNs, but rather search for them in
  1313. * the local domains. */
  1314. int ServerDNSDetectHijacking; /**< Boolean: If true, check for DNS failure
  1315. * hijacking. */
  1316. int ServerDNSRandomizeCase; /**< Boolean: Use the 0x20-hack to prevent
  1317. * DNS poisoning attacks. */
  1318. char *ServerDNSResolvConfFile; /**< If provided, we configure our internal
  1319. * resolver from the file here rather than from
  1320. * /etc/resolv.conf (Unix) or the registry (Windows). */
  1321. char *DirPortFrontPage; /**< This is a full path to a file with an html
  1322. disclaimer. This allows a server administrator to show
  1323. that they're running Tor and anyone visiting their server
  1324. will know this without any specialized knowledge. */
  1325. int DisableDebuggerAttachment; /**< Currently Linux only specific attempt to
  1326. disable ptrace; needs BSD testing. */
  1327. /** Boolean: if set, we start even if our resolv.conf file is missing
  1328. * or broken. */
  1329. int ServerDNSAllowBrokenConfig;
  1330. /** Boolean: if set, then even connections to private addresses will get
  1331. * rate-limited. */
  1332. int CountPrivateBandwidth;
  1333. smartlist_t *ServerDNSTestAddresses; /**< A list of addresses that definitely
  1334. * should be resolvable. Used for
  1335. * testing our DNS server. */
  1336. int EnforceDistinctSubnets; /**< If true, don't allow multiple routers in the
  1337. * same network zone in the same circuit. */
  1338. int AllowNonRFC953Hostnames; /**< If true, we allow connections to hostnames
  1339. * with weird characters. */
  1340. /** If true, we try resolving hostnames with weird characters. */
  1341. int ServerDNSAllowNonRFC953Hostnames;
  1342. /** If true, we try to download extra-info documents (and we serve them,
  1343. * if we are a cache). For authorities, this is always true. */
  1344. int DownloadExtraInfo;
  1345. /** If true, we're configured to collect statistics on clients
  1346. * requesting network statuses from us as directory. */
  1347. int DirReqStatistics_option;
  1348. /** Internal variable to remember whether we're actually acting on
  1349. * DirReqStatistics_option -- yes if it's set and we're a server, else no. */
  1350. int DirReqStatistics;
  1351. /** If true, the user wants us to collect statistics on port usage. */
  1352. int ExitPortStatistics;
  1353. /** If true, the user wants us to collect connection statistics. */
  1354. int ConnDirectionStatistics;
  1355. /** If true, the user wants us to collect cell statistics. */
  1356. int CellStatistics;
  1357. /** If true, the user wants us to collect padding statistics. */
  1358. int PaddingStatistics;
  1359. /** If true, the user wants us to collect statistics as entry node. */
  1360. int EntryStatistics;
  1361. /** If true, the user wants us to collect statistics as hidden service
  1362. * directory, introduction point, or rendezvous point. */
  1363. int HiddenServiceStatistics_option;
  1364. /** Internal variable to remember whether we're actually acting on
  1365. * HiddenServiceStatistics_option -- yes if it's set and we're a server,
  1366. * else no. */
  1367. int HiddenServiceStatistics;
  1368. /** If true, include statistics file contents in extra-info documents. */
  1369. int ExtraInfoStatistics;
  1370. /** If true, do not believe anybody who tells us that a domain resolves
  1371. * to an internal address, or that an internal address has a PTR mapping.
  1372. * Helps avoid some cross-site attacks. */
  1373. int ClientDNSRejectInternalAddresses;
  1374. /** If true, do not accept any requests to connect to internal addresses
  1375. * over randomly chosen exits. */
  1376. int ClientRejectInternalAddresses;
  1377. /** If true, clients may connect over IPv4. If false, they will avoid
  1378. * connecting over IPv4. We enforce this for OR and Dir connections. */
  1379. int ClientUseIPv4;
  1380. /** If true, clients may connect over IPv6. If false, they will avoid
  1381. * connecting over IPv4. We enforce this for OR and Dir connections.
  1382. * Use fascist_firewall_use_ipv6() instead of accessing this value
  1383. * directly. */
  1384. int ClientUseIPv6;
  1385. /** If true, prefer an IPv6 OR port over an IPv4 one for entry node
  1386. * connections. If auto, bridge clients prefer IPv6, and other clients
  1387. * prefer IPv4. Use node_ipv6_or_preferred() instead of accessing this value
  1388. * directly. */
  1389. int ClientPreferIPv6ORPort;
  1390. /** If true, prefer an IPv6 directory port over an IPv4 one for direct
  1391. * directory connections. If auto, bridge clients prefer IPv6, and other
  1392. * clients prefer IPv4. Use fascist_firewall_prefer_ipv6_dirport() instead of
  1393. * accessing this value directly. */
  1394. int ClientPreferIPv6DirPort;
  1395. /** The length of time that we think a consensus should be fresh. */
  1396. int V3AuthVotingInterval;
  1397. /** The length of time we think it will take to distribute votes. */
  1398. int V3AuthVoteDelay;
  1399. /** The length of time we think it will take to distribute signatures. */
  1400. int V3AuthDistDelay;
  1401. /** The number of intervals we think a consensus should be valid. */
  1402. int V3AuthNIntervalsValid;
  1403. /** Should advertise and sign consensuses with a legacy key, for key
  1404. * migration purposes? */
  1405. int V3AuthUseLegacyKey;
  1406. /** Location of bandwidth measurement file */
  1407. char *V3BandwidthsFile;
  1408. /** Location of guardfraction file */
  1409. char *GuardfractionFile;
  1410. /** Authority only: key=value pairs that we add to our networkstatus
  1411. * consensus vote on the 'params' line. */
  1412. char *ConsensusParams;
  1413. /** Authority only: minimum number of measured bandwidths we must see
  1414. * before we only believe measured bandwidths to assign flags. */
  1415. int MinMeasuredBWsForAuthToIgnoreAdvertised;
  1416. /** The length of time that we think an initial consensus should be fresh.
  1417. * Only altered on testing networks. */
  1418. int TestingV3AuthInitialVotingInterval;
  1419. /** The length of time we think it will take to distribute initial votes.
  1420. * Only altered on testing networks. */
  1421. int TestingV3AuthInitialVoteDelay;
  1422. /** The length of time we think it will take to distribute initial
  1423. * signatures. Only altered on testing networks.*/
  1424. int TestingV3AuthInitialDistDelay;
  1425. /** Offset in seconds added to the starting time for consensus
  1426. voting. Only altered on testing networks. */
  1427. int TestingV3AuthVotingStartOffset;
  1428. /** If an authority has been around for less than this amount of time, it
  1429. * does not believe its reachability information is accurate. Only
  1430. * altered on testing networks. */
  1431. int TestingAuthDirTimeToLearnReachability;
  1432. /** Clients don't download any descriptor this recent, since it will
  1433. * probably not have propagated to enough caches. Only altered on testing
  1434. * networks. */
  1435. int TestingEstimatedDescriptorPropagationTime;
  1436. /** Schedule for when servers should download things in general. Only
  1437. * altered on testing networks. */
  1438. int TestingServerDownloadInitialDelay;
  1439. /** Schedule for when clients should download things in general. Only
  1440. * altered on testing networks. */
  1441. int TestingClientDownloadInitialDelay;
  1442. /** Schedule for when servers should download consensuses. Only altered
  1443. * on testing networks. */
  1444. int TestingServerConsensusDownloadInitialDelay;
  1445. /** Schedule for when clients should download consensuses. Only altered
  1446. * on testing networks. */
  1447. int TestingClientConsensusDownloadInitialDelay;
  1448. /** Schedule for when clients should download consensuses from authorities
  1449. * if they are bootstrapping (that is, they don't have a usable, reasonably
  1450. * live consensus). Only used by clients fetching from a list of fallback
  1451. * directory mirrors.
  1452. *
  1453. * This schedule is incremented by (potentially concurrent) connection
  1454. * attempts, unlike other schedules, which are incremented by connection
  1455. * failures. Only altered on testing networks. */
  1456. int ClientBootstrapConsensusAuthorityDownloadInitialDelay;
  1457. /** Schedule for when clients should download consensuses from fallback
  1458. * directory mirrors if they are bootstrapping (that is, they don't have a
  1459. * usable, reasonably live consensus). Only used by clients fetching from a
  1460. * list of fallback directory mirrors.
  1461. *
  1462. * This schedule is incremented by (potentially concurrent) connection
  1463. * attempts, unlike other schedules, which are incremented by connection
  1464. * failures. Only altered on testing networks. */
  1465. int ClientBootstrapConsensusFallbackDownloadInitialDelay;
  1466. /** Schedule for when clients should download consensuses from authorities
  1467. * if they are bootstrapping (that is, they don't have a usable, reasonably
  1468. * live consensus). Only used by clients which don't have or won't fetch
  1469. * from a list of fallback directory mirrors.
  1470. *
  1471. * This schedule is incremented by (potentially concurrent) connection
  1472. * attempts, unlike other schedules, which are incremented by connection
  1473. * failures. Only altered on testing networks. */
  1474. int ClientBootstrapConsensusAuthorityOnlyDownloadInitialDelay;
  1475. /** Schedule for when clients should download bridge descriptors. Only
  1476. * altered on testing networks. */
  1477. int TestingBridgeDownloadInitialDelay;
  1478. /** Schedule for when clients should download bridge descriptors when they
  1479. * have no running bridges. Only altered on testing networks. */
  1480. int TestingBridgeBootstrapDownloadInitialDelay;
  1481. /** When directory clients have only a few descriptors to request, they
  1482. * batch them until they have more, or until this amount of time has
  1483. * passed. Only altered on testing networks. */
  1484. int TestingClientMaxIntervalWithoutRequest;
  1485. /** How long do we let a directory connection stall before expiring
  1486. * it? Only altered on testing networks. */
  1487. int TestingDirConnectionMaxStall;
  1488. /** How many simultaneous in-progress connections will we make when trying
  1489. * to fetch a consensus before we wait for one to complete, timeout, or
  1490. * error out? Only altered on testing networks. */
  1491. int ClientBootstrapConsensusMaxInProgressTries;
  1492. /** If true, we take part in a testing network. Change the defaults of a
  1493. * couple of other configuration options and allow to change the values
  1494. * of certain configuration options. */
  1495. int TestingTorNetwork;
  1496. /** Minimum value for the Exit flag threshold on testing networks. */
  1497. uint64_t TestingMinExitFlagThreshold;
  1498. /** Minimum value for the Fast flag threshold on testing networks. */
  1499. uint64_t TestingMinFastFlagThreshold;
  1500. /** Relays in a testing network which should be voted Exit
  1501. * regardless of exit policy. */
  1502. routerset_t *TestingDirAuthVoteExit;
  1503. int TestingDirAuthVoteExitIsStrict;
  1504. /** Relays in a testing network which should be voted Guard
  1505. * regardless of uptime and bandwidth. */
  1506. routerset_t *TestingDirAuthVoteGuard;
  1507. int TestingDirAuthVoteGuardIsStrict;
  1508. /** Relays in a testing network which should be voted HSDir
  1509. * regardless of uptime and DirPort. */
  1510. routerset_t *TestingDirAuthVoteHSDir;
  1511. int TestingDirAuthVoteHSDirIsStrict;
  1512. /** Enable CONN_BW events. Only altered on testing networks. */
  1513. int TestingEnableConnBwEvent;
  1514. /** Enable CELL_STATS events. Only altered on testing networks. */
  1515. int TestingEnableCellStatsEvent;
  1516. /** If true, and we have GeoIP data, and we're a bridge, keep a per-country
  1517. * count of how many client addresses have contacted us so that we can help
  1518. * the bridge authority guess which countries have blocked access to us. */
  1519. int BridgeRecordUsageByCountry;
  1520. /** Optionally, IPv4 and IPv6 GeoIP data. */
  1521. char *GeoIPFile;
  1522. char *GeoIPv6File;
  1523. /** Autobool: if auto, then any attempt to Exclude{Exit,}Nodes a particular
  1524. * country code will exclude all nodes in ?? and A1. If true, all nodes in
  1525. * ?? and A1 are excluded. Has no effect if we don't know any GeoIP data. */
  1526. int GeoIPExcludeUnknown;
  1527. /** If true, SIGHUP should reload the torrc. Sometimes controllers want
  1528. * to make this false. */
  1529. int ReloadTorrcOnSIGHUP;
  1530. /* The main parameter for picking circuits within a connection.
  1531. *
  1532. * If this value is positive, when picking a cell to relay on a connection,
  1533. * we always relay from the circuit whose weighted cell count is lowest.
  1534. * Cells are weighted exponentially such that if one cell is sent
  1535. * 'CircuitPriorityHalflife' seconds before another, it counts for half as
  1536. * much.
  1537. *
  1538. * If this value is zero, we're disabling the cell-EWMA algorithm.
  1539. *
  1540. * If this value is negative, we're using the default approach
  1541. * according to either Tor or a parameter set in the consensus.
  1542. */
  1543. double CircuitPriorityHalflife;
  1544. /** Set to true if the TestingTorNetwork configuration option is set.
  1545. * This is used so that options_validate() has a chance to realize that
  1546. * the defaults have changed. */
  1547. int UsingTestNetworkDefaults_;
  1548. /** If 1, we try to use microdescriptors to build circuits. If 0, we don't.
  1549. * If -1, Tor decides. */
  1550. int UseMicrodescriptors;
  1551. /** File where we should write the ControlPort. */
  1552. char *ControlPortWriteToFile;
  1553. /** Should that file be group-readable? */
  1554. int ControlPortFileGroupReadable;
  1555. #define MAX_MAX_CLIENT_CIRCUITS_PENDING 1024
  1556. /** Maximum number of non-open general-purpose origin circuits to allow at
  1557. * once. */
  1558. int MaxClientCircuitsPending;
  1559. /** If 1, we always send optimistic data when it's supported. If 0, we
  1560. * never use it. If -1, we do what the consensus says. */
  1561. int OptimisticData;
  1562. /** If 1, we accept and launch no external network connections, except on
  1563. * control ports. */
  1564. int DisableNetwork;
  1565. /**
  1566. * Parameters for path-bias detection.
  1567. * @{
  1568. * These options override the default behavior of Tor's (**currently
  1569. * experimental**) path bias detection algorithm. To try to find broken or
  1570. * misbehaving guard nodes, Tor looks for nodes where more than a certain
  1571. * fraction of circuits through that guard fail to get built.
  1572. *
  1573. * The PathBiasCircThreshold option controls how many circuits we need to
  1574. * build through a guard before we make these checks. The
  1575. * PathBiasNoticeRate, PathBiasWarnRate and PathBiasExtremeRate options
  1576. * control what fraction of circuits must succeed through a guard so we
  1577. * won't write log messages. If less than PathBiasExtremeRate circuits
  1578. * succeed *and* PathBiasDropGuards is set to 1, we disable use of that
  1579. * guard.
  1580. *
  1581. * When we have seen more than PathBiasScaleThreshold circuits through a
  1582. * guard, we scale our observations by 0.5 (governed by the consensus) so
  1583. * that new observations don't get swamped by old ones.
  1584. *
  1585. * By default, or if a negative value is provided for one of these options,
  1586. * Tor uses reasonable defaults from the networkstatus consensus document.
  1587. * If no defaults are available there, these options default to 150, .70,
  1588. * .50, .30, 0, and 300 respectively.
  1589. */
  1590. int PathBiasCircThreshold;
  1591. double PathBiasNoticeRate;
  1592. double PathBiasWarnRate;
  1593. double PathBiasExtremeRate;
  1594. int PathBiasDropGuards;
  1595. int PathBiasScaleThreshold;
  1596. /** @} */
  1597. /**
  1598. * Parameters for path-bias use detection
  1599. * @{
  1600. * Similar to the above options, these options override the default behavior
  1601. * of Tor's (**currently experimental**) path use bias detection algorithm.
  1602. *
  1603. * Where as the path bias parameters govern thresholds for successfully
  1604. * building circuits, these four path use bias parameters govern thresholds
  1605. * only for circuit usage. Circuits which receive no stream usage are not
  1606. * counted by this detection algorithm. A used circuit is considered
  1607. * successful if it is capable of carrying streams or otherwise receiving
  1608. * well-formed responses to RELAY cells.
  1609. *
  1610. * By default, or if a negative value is provided for one of these options,
  1611. * Tor uses reasonable defaults from the networkstatus consensus document.
  1612. * If no defaults are available there, these options default to 20, .80,
  1613. * .60, and 100, respectively.
  1614. */
  1615. int PathBiasUseThreshold;
  1616. double PathBiasNoticeUseRate;
  1617. double PathBiasExtremeUseRate;
  1618. int PathBiasScaleUseThreshold;
  1619. /** @} */
  1620. int IPv6Exit; /**< Do we support exiting to IPv6 addresses? */
  1621. /** Fraction: */
  1622. double PathsNeededToBuildCircuits;
  1623. /** What expiry time shall we place on our SSL certs? "0" means we
  1624. * should guess a suitable value. */
  1625. int SSLKeyLifetime;
  1626. /** How long (seconds) do we keep a guard before picking a new one? */
  1627. int GuardLifetime;
  1628. /** Is this an exit node? This is a tristate, where "1" means "yes, and use
  1629. * the default exit policy if none is given" and "0" means "no; exit policy
  1630. * is 'reject *'" and "auto" (-1) means "same as 1, but warn the user."
  1631. *
  1632. * XXXX Eventually, the default will be 0. */
  1633. int ExitRelay;
  1634. /** For how long (seconds) do we declare our signing keys to be valid? */
  1635. int SigningKeyLifetime;
  1636. /** For how long (seconds) do we declare our link keys to be valid? */
  1637. int TestingLinkCertLifetime;
  1638. /** For how long (seconds) do we declare our auth keys to be valid? */
  1639. int TestingAuthKeyLifetime;
  1640. /** How long before signing keys expire will we try to make a new one? */
  1641. int TestingSigningKeySlop;
  1642. /** How long before link keys expire will we try to make a new one? */
  1643. int TestingLinkKeySlop;
  1644. /** How long before auth keys expire will we try to make a new one? */
  1645. int TestingAuthKeySlop;
  1646. /** Force use of offline master key features: never generate a master
  1647. * ed25519 identity key except from tor --keygen */
  1648. int OfflineMasterKey;
  1649. enum {
  1650. FORCE_PASSPHRASE_AUTO=0,
  1651. FORCE_PASSPHRASE_ON,
  1652. FORCE_PASSPHRASE_OFF
  1653. } keygen_force_passphrase;
  1654. int use_keygen_passphrase_fd;
  1655. int keygen_passphrase_fd;
  1656. int change_key_passphrase;
  1657. char *master_key_fname;
  1658. /** Autobool: Do we try to retain capabilities if we can? */
  1659. int KeepBindCapabilities;
  1660. /** Maximum total size of unparseable descriptors to log during the
  1661. * lifetime of this Tor process.
  1662. */
  1663. uint64_t MaxUnparseableDescSizeToLog;
  1664. /** Bool (default: 1): Switch for the shared random protocol. Only
  1665. * relevant to a directory authority. If off, the authority won't
  1666. * participate in the protocol. If on (default), a flag is added to the
  1667. * vote indicating participation. */
  1668. int AuthDirSharedRandomness;
  1669. /** If 1, we skip all OOS checks. */
  1670. int DisableOOSCheck;
  1671. /** Autobool: Should we include Ed25519 identities in extend2 cells?
  1672. * If -1, we should do whatever the consensus parameter says. */
  1673. int ExtendByEd25519ID;
  1674. /** Bool (default: 1): When testing routerinfos as a directory authority,
  1675. * do we enforce Ed25519 identity match? */
  1676. /* NOTE: remove this option someday. */
  1677. int AuthDirTestEd25519LinkKeys;
  1678. /** Bool (default: 0): Tells if a %include was used on torrc */
  1679. int IncludeUsed;
  1680. /** The seconds after expiration which we as a relay should keep old
  1681. * consensuses around so that we can generate diffs from them. If 0,
  1682. * use the default. */
  1683. int MaxConsensusAgeForDiffs;
  1684. /** Bool (default: 0). Tells Tor to never try to exec another program.
  1685. */
  1686. int NoExec;
  1687. /** Have the KIST scheduler run every X milliseconds. If less than zero, do
  1688. * not use the KIST scheduler but use the old vanilla scheduler instead. If
  1689. * zero, do what the consensus says and fall back to using KIST as if this is
  1690. * set to "10 msec" if the consensus doesn't say anything. */
  1691. int KISTSchedRunInterval;
  1692. /** A multiplier for the KIST per-socket limit calculation. */
  1693. double KISTSockBufSizeFactor;
  1694. /** The list of scheduler type string ordered by priority that is first one
  1695. * has to be tried first. Default: KIST,KISTLite,Vanilla */
  1696. smartlist_t *Schedulers;
  1697. /* An ordered list of scheduler_types mapped from Schedulers. */
  1698. smartlist_t *SchedulerTypes_;
  1699. /** List of files that were opened by %include in torrc and torrc-defaults */
  1700. smartlist_t *FilesOpenedByIncludes;
  1701. /** If true, Tor shouldn't install any posix signal handlers, since it is
  1702. * running embedded inside another process.
  1703. */
  1704. int DisableSignalHandlers;
  1705. /** Autobool: Is the circuit creation DoS mitigation subsystem enabled? */
  1706. int DoSCircuitCreationEnabled;
  1707. /** Minimum concurrent connection needed from one single address before any
  1708. * defense is used. */
  1709. int DoSCircuitCreationMinConnections;
  1710. /** Circuit rate used to refill the token bucket. */
  1711. int DoSCircuitCreationRate;
  1712. /** Maximum allowed burst of circuits. Reaching that value, the address is
  1713. * detected as malicious and a defense might be used. */
  1714. int DoSCircuitCreationBurst;
  1715. /** When an address is marked as malicous, what defense should be used
  1716. * against it. See the dos_cc_defense_type_t enum. */
  1717. int DoSCircuitCreationDefenseType;
  1718. /** For how much time (in seconds) the defense is applicable for a malicious
  1719. * address. A random time delta is added to the defense time of an address
  1720. * which will be between 1 second and half of this value. */
  1721. int DoSCircuitCreationDefenseTimePeriod;
  1722. /** Autobool: Is the DoS connection mitigation subsystem enabled? */
  1723. int DoSConnectionEnabled;
  1724. /** Maximum concurrent connection allowed per address. */
  1725. int DoSConnectionMaxConcurrentCount;
  1726. /** When an address is reaches the maximum count, what defense should be
  1727. * used against it. See the dos_conn_defense_type_t enum. */
  1728. int DoSConnectionDefenseType;
  1729. /** Autobool: Do we refuse single hop client rendezvous? */
  1730. int DoSRefuseSingleHopClientRendezvous;
  1731. } or_options_t;
  1732. #define LOG_PROTOCOL_WARN (get_protocol_warning_severity_level())
  1733. typedef struct or_state_t or_state_t;
  1734. #define MAX_SOCKS_ADDR_LEN 256
  1735. /********************************* circuitbuild.c **********************/
  1736. /** How many hops does a general-purpose circuit have by default? */
  1737. #define DEFAULT_ROUTE_LEN 3
  1738. /* Circuit Build Timeout "public" structures. */
  1739. /** Precision multiplier for the Bw weights */
  1740. #define BW_WEIGHT_SCALE 10000
  1741. #define BW_MIN_WEIGHT_SCALE 1
  1742. #define BW_MAX_WEIGHT_SCALE INT32_MAX
  1743. typedef struct circuit_build_times_s circuit_build_times_t;
  1744. /********************************* config.c ***************************/
  1745. /********************************* connection_edge.c *************************/
  1746. /** Enumerates possible origins of a client-side address mapping. */
  1747. typedef enum {
  1748. /** We're remapping this address because the controller told us to. */
  1749. ADDRMAPSRC_CONTROLLER,
  1750. /** We're remapping this address because of an AutomapHostsOnResolve
  1751. * configuration. */
  1752. ADDRMAPSRC_AUTOMAP,
  1753. /** We're remapping this address because our configuration (via torrc, the
  1754. * command line, or a SETCONF command) told us to. */
  1755. ADDRMAPSRC_TORRC,
  1756. /** We're remapping this address because we have TrackHostExit configured,
  1757. * and we want to remember to use the same exit next time. */
  1758. ADDRMAPSRC_TRACKEXIT,
  1759. /** We're remapping this address because we got a DNS resolution from a
  1760. * Tor server that told us what its value was. */
  1761. ADDRMAPSRC_DNS,
  1762. /** No remapping has occurred. This isn't a possible value for an
  1763. * addrmap_entry_t; it's used as a null value when we need to answer "Why
  1764. * did this remapping happen." */
  1765. ADDRMAPSRC_NONE
  1766. } addressmap_entry_source_t;
  1767. #define addressmap_entry_source_bitfield_t ENUM_BF(addressmap_entry_source_t)
  1768. #define WRITE_STATS_INTERVAL (24*60*60)
  1769. /********************************* dirvote.c ************************/
  1770. typedef struct vote_timing_t vote_timing_t;
  1771. /********************************* microdesc.c *************************/
  1772. typedef struct microdesc_cache_t microdesc_cache_t;
  1773. /********************************* rendcommon.c ***************************/
  1774. typedef struct rend_authorized_client_t rend_authorized_client_t;
  1775. typedef struct rend_encoded_v2_service_descriptor_t
  1776. rend_encoded_v2_service_descriptor_t;
  1777. /** The maximum number of non-circuit-build-timeout failures a hidden
  1778. * service client will tolerate while trying to build a circuit to an
  1779. * introduction point. See also rend_intro_point_t.unreachable_count. */
  1780. #define MAX_INTRO_POINT_REACHABILITY_FAILURES 5
  1781. /** The minimum and maximum number of distinct INTRODUCE2 cells which a
  1782. * hidden service's introduction point will receive before it begins to
  1783. * expire. */
  1784. #define INTRO_POINT_MIN_LIFETIME_INTRODUCTIONS 16384
  1785. /* Double the minimum value so the interval is [min, min * 2]. */
  1786. #define INTRO_POINT_MAX_LIFETIME_INTRODUCTIONS \
  1787. (INTRO_POINT_MIN_LIFETIME_INTRODUCTIONS * 2)
  1788. /** The minimum number of seconds that an introduction point will last
  1789. * before expiring due to old age. (If it receives
  1790. * INTRO_POINT_LIFETIME_INTRODUCTIONS INTRODUCE2 cells, it may expire
  1791. * sooner.)
  1792. *
  1793. * XXX Should this be configurable? */
  1794. #define INTRO_POINT_LIFETIME_MIN_SECONDS (18*60*60)
  1795. /** The maximum number of seconds that an introduction point will last
  1796. * before expiring due to old age.
  1797. *
  1798. * XXX Should this be configurable? */
  1799. #define INTRO_POINT_LIFETIME_MAX_SECONDS (24*60*60)
  1800. /** The maximum number of circuit creation retry we do to an intro point
  1801. * before giving up. We try to reuse intro point that fails during their
  1802. * lifetime so this is a hard limit on the amount of time we do that. */
  1803. #define MAX_INTRO_POINT_CIRCUIT_RETRIES 3
  1804. typedef struct rend_intro_point_t rend_intro_point_t;
  1805. typedef struct rend_service_descriptor_t rend_service_descriptor_t;
  1806. /********************************* routerlist.c ***************************/
  1807. typedef struct dir_server_t dir_server_t;
  1808. #define RELAY_REQUIRED_MIN_BANDWIDTH (75*1024)
  1809. #define BRIDGE_REQUIRED_MIN_BANDWIDTH (50*1024)
  1810. #define ROUTER_MAX_DECLARED_BANDWIDTH INT32_MAX
  1811. typedef struct tor_version_t tor_version_t;
  1812. #endif /* !defined(TOR_OR_H) */