hs_client.c 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620
  1. /* Copyright (c) 2016-2017, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. /**
  4. * \file hs_client.c
  5. * \brief Implement next generation hidden service client functionality
  6. **/
  7. #define HS_CLIENT_PRIVATE
  8. #include "or.h"
  9. #include "circpathbias.h"
  10. #include "circuitbuild.h"
  11. #include "circuitlist.h"
  12. #include "circuituse.h"
  13. #include "config.h"
  14. #include "connection.h"
  15. #include "connection_edge.h"
  16. #include "container.h"
  17. #include "crypto_rand.h"
  18. #include "crypto_util.h"
  19. #include "directory.h"
  20. #include "hs_cache.h"
  21. #include "hs_cell.h"
  22. #include "hs_circuit.h"
  23. #include "hs_client.h"
  24. #include "hs_control.h"
  25. #include "hs_descriptor.h"
  26. #include "hs_ident.h"
  27. #include "hs_ntor.h"
  28. #include "networkstatus.h"
  29. #include "nodelist.h"
  30. #include "reasons.h"
  31. #include "rendclient.h"
  32. #include "router.h"
  33. #include "routerset.h"
  34. #include "dir_connection_st.h"
  35. #include "entry_connection_st.h"
  36. /* Return a human-readable string for the client fetch status code. */
  37. static const char *
  38. fetch_status_to_string(hs_client_fetch_status_t status)
  39. {
  40. switch (status) {
  41. case HS_CLIENT_FETCH_ERROR:
  42. return "Internal error";
  43. case HS_CLIENT_FETCH_LAUNCHED:
  44. return "Descriptor fetch launched";
  45. case HS_CLIENT_FETCH_HAVE_DESC:
  46. return "Already have descriptor";
  47. case HS_CLIENT_FETCH_NO_HSDIRS:
  48. return "No more HSDir available to query";
  49. case HS_CLIENT_FETCH_NOT_ALLOWED:
  50. return "Fetching descriptors is not allowed";
  51. case HS_CLIENT_FETCH_MISSING_INFO:
  52. return "Missing directory information";
  53. case HS_CLIENT_FETCH_PENDING:
  54. return "Pending descriptor fetch";
  55. default:
  56. return "(Unknown client fetch status code)";
  57. }
  58. }
  59. /* Return true iff tor should close the SOCKS request(s) for the descriptor
  60. * fetch that ended up with this given status code. */
  61. static int
  62. fetch_status_should_close_socks(hs_client_fetch_status_t status)
  63. {
  64. switch (status) {
  65. case HS_CLIENT_FETCH_NO_HSDIRS:
  66. /* No more HSDir to query, we can't complete the SOCKS request(s). */
  67. case HS_CLIENT_FETCH_ERROR:
  68. /* The fetch triggered an internal error. */
  69. case HS_CLIENT_FETCH_NOT_ALLOWED:
  70. /* Client is not allowed to fetch (FetchHidServDescriptors 0). */
  71. goto close;
  72. case HS_CLIENT_FETCH_MISSING_INFO:
  73. case HS_CLIENT_FETCH_HAVE_DESC:
  74. case HS_CLIENT_FETCH_PENDING:
  75. case HS_CLIENT_FETCH_LAUNCHED:
  76. /* The rest doesn't require tor to close the SOCKS request(s). */
  77. goto no_close;
  78. }
  79. no_close:
  80. return 0;
  81. close:
  82. return 1;
  83. }
  84. /* Cancel all descriptor fetches currently in progress. */
  85. static void
  86. cancel_descriptor_fetches(void)
  87. {
  88. smartlist_t *conns =
  89. connection_list_by_type_state(CONN_TYPE_DIR, DIR_PURPOSE_FETCH_HSDESC);
  90. SMARTLIST_FOREACH_BEGIN(conns, connection_t *, conn) {
  91. const hs_ident_dir_conn_t *ident = TO_DIR_CONN(conn)->hs_ident;
  92. if (BUG(ident == NULL)) {
  93. /* A directory connection fetching a service descriptor can't have an
  94. * empty hidden service identifier. */
  95. continue;
  96. }
  97. log_debug(LD_REND, "Marking for close a directory connection fetching "
  98. "a hidden service descriptor for service %s.",
  99. safe_str_client(ed25519_fmt(&ident->identity_pk)));
  100. connection_mark_for_close(conn);
  101. } SMARTLIST_FOREACH_END(conn);
  102. /* No ownership of the objects in this list. */
  103. smartlist_free(conns);
  104. log_info(LD_REND, "Hidden service client descriptor fetches cancelled.");
  105. }
  106. /* Get all connections that are waiting on a circuit and flag them back to
  107. * waiting for a hidden service descriptor for the given service key
  108. * service_identity_pk. */
  109. static void
  110. flag_all_conn_wait_desc(const ed25519_public_key_t *service_identity_pk)
  111. {
  112. tor_assert(service_identity_pk);
  113. smartlist_t *conns =
  114. connection_list_by_type_state(CONN_TYPE_AP, AP_CONN_STATE_CIRCUIT_WAIT);
  115. SMARTLIST_FOREACH_BEGIN(conns, connection_t *, conn) {
  116. edge_connection_t *edge_conn;
  117. if (BUG(!CONN_IS_EDGE(conn))) {
  118. continue;
  119. }
  120. edge_conn = TO_EDGE_CONN(conn);
  121. if (edge_conn->hs_ident &&
  122. ed25519_pubkey_eq(&edge_conn->hs_ident->identity_pk,
  123. service_identity_pk)) {
  124. connection_ap_mark_as_non_pending_circuit(TO_ENTRY_CONN(conn));
  125. conn->state = AP_CONN_STATE_RENDDESC_WAIT;
  126. }
  127. } SMARTLIST_FOREACH_END(conn);
  128. smartlist_free(conns);
  129. }
  130. /* Remove tracked HSDir requests from our history for this hidden service
  131. * identity public key. */
  132. static void
  133. purge_hid_serv_request(const ed25519_public_key_t *identity_pk)
  134. {
  135. char base64_blinded_pk[ED25519_BASE64_LEN + 1];
  136. ed25519_public_key_t blinded_pk;
  137. tor_assert(identity_pk);
  138. /* Get blinded pubkey of hidden service. It is possible that we just moved
  139. * to a new time period meaning that we won't be able to purge the request
  140. * from the previous time period. That is fine because they will expire at
  141. * some point and we don't care about those anymore. */
  142. hs_build_blinded_pubkey(identity_pk, NULL, 0,
  143. hs_get_time_period_num(0), &blinded_pk);
  144. if (BUG(ed25519_public_to_base64(base64_blinded_pk, &blinded_pk) < 0)) {
  145. return;
  146. }
  147. /* Purge last hidden service request from cache for this blinded key. */
  148. hs_purge_hid_serv_from_last_hid_serv_requests(base64_blinded_pk);
  149. }
  150. /* Return true iff there is at least one pending directory descriptor request
  151. * for the service identity_pk. */
  152. static int
  153. directory_request_is_pending(const ed25519_public_key_t *identity_pk)
  154. {
  155. int ret = 0;
  156. smartlist_t *conns =
  157. connection_list_by_type_purpose(CONN_TYPE_DIR, DIR_PURPOSE_FETCH_HSDESC);
  158. SMARTLIST_FOREACH_BEGIN(conns, connection_t *, conn) {
  159. const hs_ident_dir_conn_t *ident = TO_DIR_CONN(conn)->hs_ident;
  160. if (BUG(ident == NULL)) {
  161. /* A directory connection fetching a service descriptor can't have an
  162. * empty hidden service identifier. */
  163. continue;
  164. }
  165. if (!ed25519_pubkey_eq(identity_pk, &ident->identity_pk)) {
  166. continue;
  167. }
  168. ret = 1;
  169. break;
  170. } SMARTLIST_FOREACH_END(conn);
  171. /* No ownership of the objects in this list. */
  172. smartlist_free(conns);
  173. return ret;
  174. }
  175. /* We failed to fetch a descriptor for the service with <b>identity_pk</b>
  176. * because of <b>status</b>. Find all pending SOCKS connections for this
  177. * service that are waiting on the descriptor and close them with
  178. * <b>reason</b>. */
  179. static void
  180. close_all_socks_conns_waiting_for_desc(const ed25519_public_key_t *identity_pk,
  181. hs_client_fetch_status_t status,
  182. int reason)
  183. {
  184. unsigned int count = 0;
  185. time_t now = approx_time();
  186. smartlist_t *conns =
  187. connection_list_by_type_state(CONN_TYPE_AP, AP_CONN_STATE_RENDDESC_WAIT);
  188. SMARTLIST_FOREACH_BEGIN(conns, connection_t *, base_conn) {
  189. entry_connection_t *entry_conn = TO_ENTRY_CONN(base_conn);
  190. const edge_connection_t *edge_conn = ENTRY_TO_EDGE_CONN(entry_conn);
  191. /* Only consider the entry connections that matches the service for which
  192. * we tried to get the descriptor */
  193. if (!edge_conn->hs_ident ||
  194. !ed25519_pubkey_eq(identity_pk,
  195. &edge_conn->hs_ident->identity_pk)) {
  196. continue;
  197. }
  198. assert_connection_ok(base_conn, now);
  199. /* Unattach the entry connection which will close for the reason. */
  200. connection_mark_unattached_ap(entry_conn, reason);
  201. count++;
  202. } SMARTLIST_FOREACH_END(base_conn);
  203. if (count > 0) {
  204. char onion_address[HS_SERVICE_ADDR_LEN_BASE32 + 1];
  205. hs_build_address(identity_pk, HS_VERSION_THREE, onion_address);
  206. log_notice(LD_REND, "Closed %u streams for service %s.onion "
  207. "for reason %s. Fetch status: %s.",
  208. count, safe_str_client(onion_address),
  209. stream_end_reason_to_string(reason),
  210. fetch_status_to_string(status));
  211. }
  212. /* No ownership of the object(s) in this list. */
  213. smartlist_free(conns);
  214. }
  215. /* Find all pending SOCKS connection waiting for a descriptor and retry them
  216. * all. This is called when the directory information changed. */
  217. static void
  218. retry_all_socks_conn_waiting_for_desc(void)
  219. {
  220. smartlist_t *conns =
  221. connection_list_by_type_state(CONN_TYPE_AP, AP_CONN_STATE_RENDDESC_WAIT);
  222. SMARTLIST_FOREACH_BEGIN(conns, connection_t *, base_conn) {
  223. hs_client_fetch_status_t status;
  224. const edge_connection_t *edge_conn =
  225. ENTRY_TO_EDGE_CONN(TO_ENTRY_CONN(base_conn));
  226. /* Ignore non HS or non v3 connection. */
  227. if (edge_conn->hs_ident == NULL) {
  228. continue;
  229. }
  230. /* In this loop, we will possibly try to fetch a descriptor for the
  231. * pending connections because we just got more directory information.
  232. * However, the refetch process can cleanup all SOCKS request so the same
  233. * service if an internal error happens. Thus, we can end up with closed
  234. * connections in our list. */
  235. if (base_conn->marked_for_close) {
  236. continue;
  237. }
  238. /* XXX: There is an optimization we could do which is that for a service
  239. * key, we could check if we can fetch and remember that decision. */
  240. /* Order a refetch in case it works this time. */
  241. status = hs_client_refetch_hsdesc(&edge_conn->hs_ident->identity_pk);
  242. if (BUG(status == HS_CLIENT_FETCH_HAVE_DESC)) {
  243. /* This case is unique because it can NOT happen in theory. Once we get
  244. * a new descriptor, the HS client subsystem is notified immediately and
  245. * the connections waiting for it are handled which means the state will
  246. * change from renddesc wait state. Log this and continue to next
  247. * connection. */
  248. continue;
  249. }
  250. /* In the case of an error, either all SOCKS connections have been
  251. * closed or we are still missing directory information. Leave the
  252. * connection in renddesc wait state so when we get more info, we'll be
  253. * able to try it again. */
  254. } SMARTLIST_FOREACH_END(base_conn);
  255. /* We don't have ownership of those objects. */
  256. smartlist_free(conns);
  257. }
  258. /* A v3 HS circuit successfully connected to the hidden service. Update the
  259. * stream state at <b>hs_conn_ident</b> appropriately. */
  260. static void
  261. note_connection_attempt_succeeded(const hs_ident_edge_conn_t *hs_conn_ident)
  262. {
  263. tor_assert(hs_conn_ident);
  264. /* Remove from the hid serv cache all requests for that service so we can
  265. * query the HSDir again later on for various reasons. */
  266. purge_hid_serv_request(&hs_conn_ident->identity_pk);
  267. /* The v2 subsystem cleans up the intro point time out flag at this stage.
  268. * We don't try to do it here because we still need to keep intact the intro
  269. * point state for future connections. Even though we are able to connect to
  270. * the service, doesn't mean we should reset the timed out intro points.
  271. *
  272. * It is not possible to have successfully connected to an intro point
  273. * present in our cache that was on error or timed out. Every entry in that
  274. * cache have a 2 minutes lifetime so ultimately the intro point(s) state
  275. * will be reset and thus possible to be retried. */
  276. }
  277. /* Given the pubkey of a hidden service in <b>onion_identity_pk</b>, fetch its
  278. * descriptor by launching a dir connection to <b>hsdir</b>. Return a
  279. * hs_client_fetch_status_t status code depending on how it went. */
  280. static hs_client_fetch_status_t
  281. directory_launch_v3_desc_fetch(const ed25519_public_key_t *onion_identity_pk,
  282. const routerstatus_t *hsdir)
  283. {
  284. uint64_t current_time_period = hs_get_time_period_num(0);
  285. ed25519_public_key_t blinded_pubkey;
  286. char base64_blinded_pubkey[ED25519_BASE64_LEN + 1];
  287. hs_ident_dir_conn_t hs_conn_dir_ident;
  288. int retval;
  289. tor_assert(hsdir);
  290. tor_assert(onion_identity_pk);
  291. /* Get blinded pubkey */
  292. hs_build_blinded_pubkey(onion_identity_pk, NULL, 0,
  293. current_time_period, &blinded_pubkey);
  294. /* ...and base64 it. */
  295. retval = ed25519_public_to_base64(base64_blinded_pubkey, &blinded_pubkey);
  296. if (BUG(retval < 0)) {
  297. return HS_CLIENT_FETCH_ERROR;
  298. }
  299. /* Copy onion pk to a dir_ident so that we attach it to the dir conn */
  300. hs_ident_dir_conn_init(onion_identity_pk, &blinded_pubkey,
  301. &hs_conn_dir_ident);
  302. /* Setup directory request */
  303. directory_request_t *req =
  304. directory_request_new(DIR_PURPOSE_FETCH_HSDESC);
  305. directory_request_set_routerstatus(req, hsdir);
  306. directory_request_set_indirection(req, DIRIND_ANONYMOUS);
  307. directory_request_set_resource(req, base64_blinded_pubkey);
  308. directory_request_fetch_set_hs_ident(req, &hs_conn_dir_ident);
  309. directory_initiate_request(req);
  310. directory_request_free(req);
  311. log_info(LD_REND, "Descriptor fetch request for service %s with blinded "
  312. "key %s to directory %s",
  313. safe_str_client(ed25519_fmt(onion_identity_pk)),
  314. safe_str_client(base64_blinded_pubkey),
  315. safe_str_client(routerstatus_describe(hsdir)));
  316. /* Fire a REQUESTED event on the control port. */
  317. hs_control_desc_event_requested(onion_identity_pk, base64_blinded_pubkey,
  318. hsdir);
  319. /* Cleanup memory. */
  320. memwipe(&blinded_pubkey, 0, sizeof(blinded_pubkey));
  321. memwipe(base64_blinded_pubkey, 0, sizeof(base64_blinded_pubkey));
  322. memwipe(&hs_conn_dir_ident, 0, sizeof(hs_conn_dir_ident));
  323. return HS_CLIENT_FETCH_LAUNCHED;
  324. }
  325. /** Return the HSDir we should use to fetch the descriptor of the hidden
  326. * service with identity key <b>onion_identity_pk</b>. */
  327. STATIC routerstatus_t *
  328. pick_hsdir_v3(const ed25519_public_key_t *onion_identity_pk)
  329. {
  330. int retval;
  331. char base64_blinded_pubkey[ED25519_BASE64_LEN + 1];
  332. uint64_t current_time_period = hs_get_time_period_num(0);
  333. smartlist_t *responsible_hsdirs;
  334. ed25519_public_key_t blinded_pubkey;
  335. routerstatus_t *hsdir_rs = NULL;
  336. tor_assert(onion_identity_pk);
  337. responsible_hsdirs = smartlist_new();
  338. /* Get blinded pubkey of hidden service */
  339. hs_build_blinded_pubkey(onion_identity_pk, NULL, 0,
  340. current_time_period, &blinded_pubkey);
  341. /* ...and base64 it. */
  342. retval = ed25519_public_to_base64(base64_blinded_pubkey, &blinded_pubkey);
  343. if (BUG(retval < 0)) {
  344. return NULL;
  345. }
  346. /* Get responsible hsdirs of service for this time period */
  347. hs_get_responsible_hsdirs(&blinded_pubkey, current_time_period,
  348. 0, 1, responsible_hsdirs);
  349. log_debug(LD_REND, "Found %d responsible HSDirs and about to pick one.",
  350. smartlist_len(responsible_hsdirs));
  351. /* Pick an HSDir from the responsible ones. The ownership of
  352. * responsible_hsdirs is given to this function so no need to free it. */
  353. hsdir_rs = hs_pick_hsdir(responsible_hsdirs, base64_blinded_pubkey);
  354. return hsdir_rs;
  355. }
  356. /** Fetch a v3 descriptor using the given <b>onion_identity_pk</b>.
  357. *
  358. * On success, HS_CLIENT_FETCH_LAUNCHED is returned. Otherwise, an error from
  359. * hs_client_fetch_status_t is returned. */
  360. MOCK_IMPL(STATIC hs_client_fetch_status_t,
  361. fetch_v3_desc, (const ed25519_public_key_t *onion_identity_pk))
  362. {
  363. routerstatus_t *hsdir_rs =NULL;
  364. tor_assert(onion_identity_pk);
  365. hsdir_rs = pick_hsdir_v3(onion_identity_pk);
  366. if (!hsdir_rs) {
  367. log_info(LD_REND, "Couldn't pick a v3 hsdir.");
  368. return HS_CLIENT_FETCH_NO_HSDIRS;
  369. }
  370. return directory_launch_v3_desc_fetch(onion_identity_pk, hsdir_rs);
  371. }
  372. /* Make sure that the given v3 origin circuit circ is a valid correct
  373. * introduction circuit. This will BUG() on any problems and hard assert if
  374. * the anonymity of the circuit is not ok. Return 0 on success else -1 where
  375. * the circuit should be mark for closed immediately. */
  376. static int
  377. intro_circ_is_ok(const origin_circuit_t *circ)
  378. {
  379. int ret = 0;
  380. tor_assert(circ);
  381. if (BUG(TO_CIRCUIT(circ)->purpose != CIRCUIT_PURPOSE_C_INTRODUCING &&
  382. TO_CIRCUIT(circ)->purpose != CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT &&
  383. TO_CIRCUIT(circ)->purpose != CIRCUIT_PURPOSE_C_INTRODUCE_ACKED)) {
  384. ret = -1;
  385. }
  386. if (BUG(circ->hs_ident == NULL)) {
  387. ret = -1;
  388. }
  389. if (BUG(!hs_ident_intro_circ_is_valid(circ->hs_ident))) {
  390. ret = -1;
  391. }
  392. /* This can stop the tor daemon but we want that since if we don't have
  393. * anonymity on this circuit, something went really wrong. */
  394. assert_circ_anonymity_ok(circ, get_options());
  395. return ret;
  396. }
  397. /* Find a descriptor intro point object that matches the given ident in the
  398. * given descriptor desc. Return NULL if not found. */
  399. static const hs_desc_intro_point_t *
  400. find_desc_intro_point_by_ident(const hs_ident_circuit_t *ident,
  401. const hs_descriptor_t *desc)
  402. {
  403. const hs_desc_intro_point_t *intro_point = NULL;
  404. tor_assert(ident);
  405. tor_assert(desc);
  406. SMARTLIST_FOREACH_BEGIN(desc->encrypted_data.intro_points,
  407. const hs_desc_intro_point_t *, ip) {
  408. if (ed25519_pubkey_eq(&ident->intro_auth_pk,
  409. &ip->auth_key_cert->signed_key)) {
  410. intro_point = ip;
  411. break;
  412. }
  413. } SMARTLIST_FOREACH_END(ip);
  414. return intro_point;
  415. }
  416. /* Find a descriptor intro point object from the descriptor object desc that
  417. * matches the given legacy identity digest in legacy_id. Return NULL if not
  418. * found. */
  419. static hs_desc_intro_point_t *
  420. find_desc_intro_point_by_legacy_id(const char *legacy_id,
  421. const hs_descriptor_t *desc)
  422. {
  423. hs_desc_intro_point_t *ret_ip = NULL;
  424. tor_assert(legacy_id);
  425. tor_assert(desc);
  426. /* We will go over every intro point and try to find which one is linked to
  427. * that circuit. Those lists are small so it's not that expensive. */
  428. SMARTLIST_FOREACH_BEGIN(desc->encrypted_data.intro_points,
  429. hs_desc_intro_point_t *, ip) {
  430. SMARTLIST_FOREACH_BEGIN(ip->link_specifiers,
  431. const hs_desc_link_specifier_t *, lspec) {
  432. /* Not all tor node have an ed25519 identity key so we still rely on the
  433. * legacy identity digest. */
  434. if (lspec->type != LS_LEGACY_ID) {
  435. continue;
  436. }
  437. if (fast_memneq(legacy_id, lspec->u.legacy_id, DIGEST_LEN)) {
  438. break;
  439. }
  440. /* Found it. */
  441. ret_ip = ip;
  442. goto end;
  443. } SMARTLIST_FOREACH_END(lspec);
  444. } SMARTLIST_FOREACH_END(ip);
  445. end:
  446. return ret_ip;
  447. }
  448. /* Send an INTRODUCE1 cell along the intro circuit and populate the rend
  449. * circuit identifier with the needed key material for the e2e encryption.
  450. * Return 0 on success, -1 if there is a transient error such that an action
  451. * has been taken to recover and -2 if there is a permanent error indicating
  452. * that both circuits were closed. */
  453. static int
  454. send_introduce1(origin_circuit_t *intro_circ,
  455. origin_circuit_t *rend_circ)
  456. {
  457. int status;
  458. char onion_address[HS_SERVICE_ADDR_LEN_BASE32 + 1];
  459. const ed25519_public_key_t *service_identity_pk = NULL;
  460. const hs_desc_intro_point_t *ip;
  461. tor_assert(rend_circ);
  462. if (intro_circ_is_ok(intro_circ) < 0) {
  463. goto perm_err;
  464. }
  465. service_identity_pk = &intro_circ->hs_ident->identity_pk;
  466. /* For logging purposes. There will be a time where the hs_ident will have a
  467. * version number but for now there is none because it's all v3. */
  468. hs_build_address(service_identity_pk, HS_VERSION_THREE, onion_address);
  469. log_info(LD_REND, "Sending INTRODUCE1 cell to service %s on circuit %u",
  470. safe_str_client(onion_address), TO_CIRCUIT(intro_circ)->n_circ_id);
  471. /* 1) Get descriptor from our cache. */
  472. const hs_descriptor_t *desc =
  473. hs_cache_lookup_as_client(service_identity_pk);
  474. if (desc == NULL || !hs_client_any_intro_points_usable(service_identity_pk,
  475. desc)) {
  476. log_info(LD_REND, "Request to %s %s. Trying to fetch a new descriptor.",
  477. safe_str_client(onion_address),
  478. (desc) ? "didn't have usable intro points" :
  479. "didn't have a descriptor");
  480. hs_client_refetch_hsdesc(service_identity_pk);
  481. /* We just triggered a refetch, make sure every connections are back
  482. * waiting for that descriptor. */
  483. flag_all_conn_wait_desc(service_identity_pk);
  484. /* We just asked for a refetch so this is a transient error. */
  485. goto tran_err;
  486. }
  487. /* We need to find which intro point in the descriptor we are connected to
  488. * on intro_circ. */
  489. ip = find_desc_intro_point_by_ident(intro_circ->hs_ident, desc);
  490. if (BUG(ip == NULL)) {
  491. /* If we can find a descriptor from this introduction circuit ident, we
  492. * must have a valid intro point object. Permanent error. */
  493. goto perm_err;
  494. }
  495. /* Send the INTRODUCE1 cell. */
  496. if (hs_circ_send_introduce1(intro_circ, rend_circ, ip,
  497. desc->subcredential) < 0) {
  498. /* Unable to send the cell, the intro circuit has been marked for close so
  499. * this is a permanent error. */
  500. tor_assert_nonfatal(TO_CIRCUIT(intro_circ)->marked_for_close);
  501. goto perm_err;
  502. }
  503. /* Cell has been sent successfully. Copy the introduction point
  504. * authentication and encryption key in the rendezvous circuit identifier so
  505. * we can compute the ntor keys when we receive the RENDEZVOUS2 cell. */
  506. memcpy(&rend_circ->hs_ident->intro_enc_pk, &ip->enc_key,
  507. sizeof(rend_circ->hs_ident->intro_enc_pk));
  508. ed25519_pubkey_copy(&rend_circ->hs_ident->intro_auth_pk,
  509. &intro_circ->hs_ident->intro_auth_pk);
  510. /* Now, we wait for an ACK or NAK on this circuit. */
  511. circuit_change_purpose(TO_CIRCUIT(intro_circ),
  512. CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT);
  513. /* Set timestamp_dirty, because circuit_expire_building expects it to
  514. * specify when a circuit entered the _C_INTRODUCE_ACK_WAIT state. */
  515. TO_CIRCUIT(intro_circ)->timestamp_dirty = time(NULL);
  516. pathbias_count_use_attempt(intro_circ);
  517. /* Success. */
  518. status = 0;
  519. goto end;
  520. perm_err:
  521. /* Permanent error: it is possible that the intro circuit was closed prior
  522. * because we weren't able to send the cell. Make sure we don't double close
  523. * it which would result in a warning. */
  524. if (!TO_CIRCUIT(intro_circ)->marked_for_close) {
  525. circuit_mark_for_close(TO_CIRCUIT(intro_circ), END_CIRC_REASON_INTERNAL);
  526. }
  527. circuit_mark_for_close(TO_CIRCUIT(rend_circ), END_CIRC_REASON_INTERNAL);
  528. status = -2;
  529. goto end;
  530. tran_err:
  531. status = -1;
  532. end:
  533. memwipe(onion_address, 0, sizeof(onion_address));
  534. return status;
  535. }
  536. /* Using the introduction circuit circ, setup the authentication key of the
  537. * intro point this circuit has extended to. */
  538. static void
  539. setup_intro_circ_auth_key(origin_circuit_t *circ)
  540. {
  541. const hs_descriptor_t *desc;
  542. const hs_desc_intro_point_t *ip;
  543. tor_assert(circ);
  544. desc = hs_cache_lookup_as_client(&circ->hs_ident->identity_pk);
  545. if (BUG(desc == NULL)) {
  546. /* Opening intro circuit without the descriptor is no good... */
  547. goto end;
  548. }
  549. /* We will go over every intro point and try to find which one is linked to
  550. * that circuit. Those lists are small so it's not that expensive. */
  551. ip = find_desc_intro_point_by_legacy_id(
  552. circ->build_state->chosen_exit->identity_digest, desc);
  553. if (ip) {
  554. /* We got it, copy its authentication key to the identifier. */
  555. ed25519_pubkey_copy(&circ->hs_ident->intro_auth_pk,
  556. &ip->auth_key_cert->signed_key);
  557. goto end;
  558. }
  559. /* Reaching this point means we didn't find any intro point for this circuit
  560. * which is not suppose to happen. */
  561. tor_assert_nonfatal_unreached();
  562. end:
  563. return;
  564. }
  565. /* Called when an introduction circuit has opened. */
  566. static void
  567. client_intro_circ_has_opened(origin_circuit_t *circ)
  568. {
  569. tor_assert(circ);
  570. tor_assert(TO_CIRCUIT(circ)->purpose == CIRCUIT_PURPOSE_C_INTRODUCING);
  571. log_info(LD_REND, "Introduction circuit %u has opened. Attaching streams.",
  572. (unsigned int) TO_CIRCUIT(circ)->n_circ_id);
  573. /* This is an introduction circuit so we'll attach the correct
  574. * authentication key to the circuit identifier so it can be identified
  575. * properly later on. */
  576. setup_intro_circ_auth_key(circ);
  577. connection_ap_attach_pending(1);
  578. }
  579. /* Called when a rendezvous circuit has opened. */
  580. static void
  581. client_rendezvous_circ_has_opened(origin_circuit_t *circ)
  582. {
  583. tor_assert(circ);
  584. tor_assert(TO_CIRCUIT(circ)->purpose == CIRCUIT_PURPOSE_C_ESTABLISH_REND);
  585. const extend_info_t *rp_ei = circ->build_state->chosen_exit;
  586. /* Check that we didn't accidentally choose a node that does not understand
  587. * the v3 rendezvous protocol */
  588. if (rp_ei) {
  589. const node_t *rp_node = node_get_by_id(rp_ei->identity_digest);
  590. if (rp_node) {
  591. if (BUG(!node_supports_v3_rendezvous_point(rp_node))) {
  592. return;
  593. }
  594. }
  595. }
  596. log_info(LD_REND, "Rendezvous circuit has opened to %s.",
  597. safe_str_client(extend_info_describe(rp_ei)));
  598. /* Ignore returned value, nothing we can really do. On failure, the circuit
  599. * will be marked for close. */
  600. hs_circ_send_establish_rendezvous(circ);
  601. /* Register rend circuit in circuitmap if it's still alive. */
  602. if (!TO_CIRCUIT(circ)->marked_for_close) {
  603. hs_circuitmap_register_rend_circ_client_side(circ,
  604. circ->hs_ident->rendezvous_cookie);
  605. }
  606. }
  607. /* This is an helper function that convert a descriptor intro point object ip
  608. * to a newly allocated extend_info_t object fully initialized. Return NULL if
  609. * we can't convert it for which chances are that we are missing or malformed
  610. * link specifiers. */
  611. STATIC extend_info_t *
  612. desc_intro_point_to_extend_info(const hs_desc_intro_point_t *ip)
  613. {
  614. extend_info_t *ei;
  615. smartlist_t *lspecs = smartlist_new();
  616. tor_assert(ip);
  617. /* We first encode the descriptor link specifiers into the binary
  618. * representation which is a trunnel object. */
  619. SMARTLIST_FOREACH_BEGIN(ip->link_specifiers,
  620. const hs_desc_link_specifier_t *, desc_lspec) {
  621. link_specifier_t *lspec = hs_desc_lspec_to_trunnel(desc_lspec);
  622. smartlist_add(lspecs, lspec);
  623. } SMARTLIST_FOREACH_END(desc_lspec);
  624. /* Explicitly put the direct connection option to 0 because this is client
  625. * side and there is no such thing as a non anonymous client. */
  626. ei = hs_get_extend_info_from_lspecs(lspecs, &ip->onion_key, 0);
  627. SMARTLIST_FOREACH(lspecs, link_specifier_t *, ls, link_specifier_free(ls));
  628. smartlist_free(lspecs);
  629. return ei;
  630. }
  631. /* Return true iff the intro point ip for the service service_pk is usable.
  632. * This function checks if the intro point is in the client intro state cache
  633. * and checks at the failures. It is considered usable if:
  634. * - No error happened (INTRO_POINT_FAILURE_GENERIC)
  635. * - It is not flagged as timed out (INTRO_POINT_FAILURE_TIMEOUT)
  636. * - The unreachable count is lower than
  637. * MAX_INTRO_POINT_REACHABILITY_FAILURES (INTRO_POINT_FAILURE_UNREACHABLE)
  638. */
  639. static int
  640. intro_point_is_usable(const ed25519_public_key_t *service_pk,
  641. const hs_desc_intro_point_t *ip)
  642. {
  643. const hs_cache_intro_state_t *state;
  644. tor_assert(service_pk);
  645. tor_assert(ip);
  646. state = hs_cache_client_intro_state_find(service_pk,
  647. &ip->auth_key_cert->signed_key);
  648. if (state == NULL) {
  649. /* This means we've never encountered any problem thus usable. */
  650. goto usable;
  651. }
  652. if (state->error) {
  653. log_info(LD_REND, "Intro point with auth key %s had an error. Not usable",
  654. safe_str_client(ed25519_fmt(&ip->auth_key_cert->signed_key)));
  655. goto not_usable;
  656. }
  657. if (state->timed_out) {
  658. log_info(LD_REND, "Intro point with auth key %s timed out. Not usable",
  659. safe_str_client(ed25519_fmt(&ip->auth_key_cert->signed_key)));
  660. goto not_usable;
  661. }
  662. if (state->unreachable_count >= MAX_INTRO_POINT_REACHABILITY_FAILURES) {
  663. log_info(LD_REND, "Intro point with auth key %s unreachable. Not usable",
  664. safe_str_client(ed25519_fmt(&ip->auth_key_cert->signed_key)));
  665. goto not_usable;
  666. }
  667. usable:
  668. return 1;
  669. not_usable:
  670. return 0;
  671. }
  672. /* Using a descriptor desc, return a newly allocated extend_info_t object of a
  673. * randomly picked introduction point from its list. Return NULL if none are
  674. * usable. */
  675. STATIC extend_info_t *
  676. client_get_random_intro(const ed25519_public_key_t *service_pk)
  677. {
  678. extend_info_t *ei = NULL, *ei_excluded = NULL;
  679. smartlist_t *usable_ips = NULL;
  680. const hs_descriptor_t *desc;
  681. const hs_desc_encrypted_data_t *enc_data;
  682. const or_options_t *options = get_options();
  683. /* Calculate the onion address for logging purposes */
  684. char onion_address[HS_SERVICE_ADDR_LEN_BASE32 + 1];
  685. tor_assert(service_pk);
  686. desc = hs_cache_lookup_as_client(service_pk);
  687. /* Assume the service is v3 if the descriptor is missing. This is ok,
  688. * because we only use the address in log messages */
  689. hs_build_address(service_pk,
  690. desc ? desc->plaintext_data.version : HS_VERSION_THREE,
  691. onion_address);
  692. if (desc == NULL || !hs_client_any_intro_points_usable(service_pk,
  693. desc)) {
  694. log_info(LD_REND, "Unable to randomly select an introduction point "
  695. "for service %s because descriptor %s. We can't connect.",
  696. safe_str_client(onion_address),
  697. (desc) ? "doesn't have any usable intro points"
  698. : "is missing (assuming v3 onion address)");
  699. goto end;
  700. }
  701. enc_data = &desc->encrypted_data;
  702. usable_ips = smartlist_new();
  703. smartlist_add_all(usable_ips, enc_data->intro_points);
  704. while (smartlist_len(usable_ips) != 0) {
  705. int idx;
  706. const hs_desc_intro_point_t *ip;
  707. /* Pick a random intro point and immediately remove it from the usable
  708. * list so we don't pick it again if we have to iterate more. */
  709. idx = crypto_rand_int(smartlist_len(usable_ips));
  710. ip = smartlist_get(usable_ips, idx);
  711. smartlist_del(usable_ips, idx);
  712. /* We need to make sure we have a usable intro points which is in a good
  713. * state in our cache. */
  714. if (!intro_point_is_usable(service_pk, ip)) {
  715. continue;
  716. }
  717. /* Generate an extend info object from the intro point object. */
  718. ei = desc_intro_point_to_extend_info(ip);
  719. if (ei == NULL) {
  720. /* We can get here for instance if the intro point is a private address
  721. * and we aren't allowed to extend to those. */
  722. log_info(LD_REND, "Unable to select introduction point with auth key %s "
  723. "for service %s, because we could not extend to it.",
  724. safe_str_client(ed25519_fmt(&ip->auth_key_cert->signed_key)),
  725. safe_str_client(onion_address));
  726. continue;
  727. }
  728. /* Test the pick against ExcludeNodes. */
  729. if (routerset_contains_extendinfo(options->ExcludeNodes, ei)) {
  730. /* If this pick is in the ExcludeNodes list, we keep its reference so if
  731. * we ever end up not being able to pick anything else and StrictNodes is
  732. * unset, we'll use it. */
  733. if (ei_excluded) {
  734. /* If something was already here free it. After the loop is gone we
  735. * will examine the last excluded intro point, and that's fine since
  736. * that's random anyway */
  737. extend_info_free(ei_excluded);
  738. }
  739. ei_excluded = ei;
  740. continue;
  741. }
  742. /* Good pick! Let's go with this. */
  743. goto end;
  744. }
  745. /* Reaching this point means a couple of things. Either we can't use any of
  746. * the intro point listed because the IP address can't be extended to or it
  747. * is listed in the ExcludeNodes list. In the later case, if StrictNodes is
  748. * set, we are forced to not use anything. */
  749. ei = ei_excluded;
  750. if (options->StrictNodes) {
  751. log_warn(LD_REND, "Every introduction point for service %s is in the "
  752. "ExcludeNodes set and StrictNodes is set. We can't connect.",
  753. safe_str_client(onion_address));
  754. extend_info_free(ei);
  755. ei = NULL;
  756. } else {
  757. log_fn(LOG_PROTOCOL_WARN, LD_REND, "Every introduction point for service "
  758. "%s is unusable or we can't extend to it. We can't connect.",
  759. safe_str_client(onion_address));
  760. }
  761. end:
  762. smartlist_free(usable_ips);
  763. memwipe(onion_address, 0, sizeof(onion_address));
  764. return ei;
  765. }
  766. /* For this introduction circuit, we'll look at if we have any usable
  767. * introduction point left for this service. If so, we'll use the circuit to
  768. * re-extend to a new intro point. Else, we'll close the circuit and its
  769. * corresponding rendezvous circuit. Return 0 if we are re-extending else -1
  770. * if we are closing the circuits.
  771. *
  772. * This is called when getting an INTRODUCE_ACK cell with a NACK. */
  773. static int
  774. close_or_reextend_intro_circ(origin_circuit_t *intro_circ)
  775. {
  776. int ret = -1;
  777. const hs_descriptor_t *desc;
  778. origin_circuit_t *rend_circ;
  779. tor_assert(intro_circ);
  780. desc = hs_cache_lookup_as_client(&intro_circ->hs_ident->identity_pk);
  781. if (BUG(desc == NULL)) {
  782. /* We can't continue without a descriptor. */
  783. goto close;
  784. }
  785. /* We still have the descriptor, great! Let's try to see if we can
  786. * re-extend by looking up if there are any usable intro points. */
  787. if (!hs_client_any_intro_points_usable(&intro_circ->hs_ident->identity_pk,
  788. desc)) {
  789. goto close;
  790. }
  791. /* Try to re-extend now. */
  792. if (hs_client_reextend_intro_circuit(intro_circ) < 0) {
  793. goto close;
  794. }
  795. /* Success on re-extending. Don't return an error. */
  796. ret = 0;
  797. goto end;
  798. close:
  799. /* Change the intro circuit purpose before so we don't report an intro point
  800. * failure again triggering an extra descriptor fetch. The circuit can
  801. * already be closed on failure to re-extend. */
  802. if (!TO_CIRCUIT(intro_circ)->marked_for_close) {
  803. circuit_change_purpose(TO_CIRCUIT(intro_circ),
  804. CIRCUIT_PURPOSE_C_INTRODUCE_ACKED);
  805. circuit_mark_for_close(TO_CIRCUIT(intro_circ), END_CIRC_REASON_FINISHED);
  806. }
  807. /* Close the related rendezvous circuit. */
  808. rend_circ = hs_circuitmap_get_rend_circ_client_side(
  809. intro_circ->hs_ident->rendezvous_cookie);
  810. /* The rendezvous circuit might have collapsed while the INTRODUCE_ACK was
  811. * inflight so we can't expect one every time. */
  812. if (rend_circ) {
  813. circuit_mark_for_close(TO_CIRCUIT(rend_circ), END_CIRC_REASON_FINISHED);
  814. }
  815. end:
  816. return ret;
  817. }
  818. /* Called when we get an INTRODUCE_ACK success status code. Do the appropriate
  819. * actions for the rendezvous point and finally close intro_circ. */
  820. static void
  821. handle_introduce_ack_success(origin_circuit_t *intro_circ)
  822. {
  823. origin_circuit_t *rend_circ = NULL;
  824. tor_assert(intro_circ);
  825. log_info(LD_REND, "Received INTRODUCE_ACK ack! Informing rendezvous");
  826. /* Get the rendezvous circuit for this rendezvous cookie. */
  827. uint8_t *rendezvous_cookie = intro_circ->hs_ident->rendezvous_cookie;
  828. rend_circ =
  829. hs_circuitmap_get_established_rend_circ_client_side(rendezvous_cookie);
  830. if (rend_circ == NULL) {
  831. log_warn(LD_REND, "Can't find any rendezvous circuit. Stopping");
  832. goto end;
  833. }
  834. assert_circ_anonymity_ok(rend_circ, get_options());
  835. /* It is possible to get a RENDEZVOUS2 cell before the INTRODUCE_ACK which
  836. * means that the circuit will be joined and already transmitting data. In
  837. * that case, simply skip the purpose change and close the intro circuit
  838. * like it should be. */
  839. if (TO_CIRCUIT(rend_circ)->purpose == CIRCUIT_PURPOSE_C_REND_JOINED) {
  840. goto end;
  841. }
  842. circuit_change_purpose(TO_CIRCUIT(rend_circ),
  843. CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED);
  844. /* Set timestamp_dirty, because circuit_expire_building expects it to
  845. * specify when a circuit entered the
  846. * CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED state. */
  847. TO_CIRCUIT(rend_circ)->timestamp_dirty = time(NULL);
  848. end:
  849. /* We don't need the intro circuit anymore. It did what it had to do! */
  850. circuit_change_purpose(TO_CIRCUIT(intro_circ),
  851. CIRCUIT_PURPOSE_C_INTRODUCE_ACKED);
  852. circuit_mark_for_close(TO_CIRCUIT(intro_circ), END_CIRC_REASON_FINISHED);
  853. /* XXX: Close pending intro circuits we might have in parallel. */
  854. return;
  855. }
  856. /* Called when we get an INTRODUCE_ACK failure status code. Depending on our
  857. * failure cache status, either close the circuit or re-extend to a new
  858. * introduction point. */
  859. static void
  860. handle_introduce_ack_bad(origin_circuit_t *circ, int status)
  861. {
  862. tor_assert(circ);
  863. log_info(LD_REND, "Received INTRODUCE_ACK nack by %s. Reason: %u",
  864. safe_str_client(extend_info_describe(circ->build_state->chosen_exit)),
  865. status);
  866. /* It's a NAK. The introduction point didn't relay our request. */
  867. circuit_change_purpose(TO_CIRCUIT(circ), CIRCUIT_PURPOSE_C_INTRODUCING);
  868. /* Note down this failure in the intro point failure cache. Depending on how
  869. * many times we've tried this intro point, close it or reextend. */
  870. hs_cache_client_intro_state_note(&circ->hs_ident->identity_pk,
  871. &circ->hs_ident->intro_auth_pk,
  872. INTRO_POINT_FAILURE_GENERIC);
  873. }
  874. /* Called when we get an INTRODUCE_ACK on the intro circuit circ. The encoded
  875. * cell is in payload of length payload_len. Return 0 on success else a
  876. * negative value. The circuit is either close or reuse to re-extend to a new
  877. * introduction point. */
  878. static int
  879. handle_introduce_ack(origin_circuit_t *circ, const uint8_t *payload,
  880. size_t payload_len)
  881. {
  882. int status, ret = -1;
  883. tor_assert(circ);
  884. tor_assert(circ->build_state);
  885. tor_assert(circ->build_state->chosen_exit);
  886. assert_circ_anonymity_ok(circ, get_options());
  887. tor_assert(payload);
  888. status = hs_cell_parse_introduce_ack(payload, payload_len);
  889. switch (status) {
  890. case HS_CELL_INTRO_ACK_SUCCESS:
  891. ret = 0;
  892. handle_introduce_ack_success(circ);
  893. goto end;
  894. case HS_CELL_INTRO_ACK_FAILURE:
  895. case HS_CELL_INTRO_ACK_BADFMT:
  896. case HS_CELL_INTRO_ACK_NORELAY:
  897. handle_introduce_ack_bad(circ, status);
  898. /* We are going to see if we have to close the circuits (IP and RP) or we
  899. * can re-extend to a new intro point. */
  900. ret = close_or_reextend_intro_circ(circ);
  901. break;
  902. default:
  903. log_info(LD_PROTOCOL, "Unknown INTRODUCE_ACK status code %u from %s",
  904. status,
  905. safe_str_client(extend_info_describe(circ->build_state->chosen_exit)));
  906. break;
  907. }
  908. end:
  909. return ret;
  910. }
  911. /* Called when we get a RENDEZVOUS2 cell on the rendezvous circuit circ. The
  912. * encoded cell is in payload of length payload_len. Return 0 on success or a
  913. * negative value on error. On error, the circuit is marked for close. */
  914. STATIC int
  915. handle_rendezvous2(origin_circuit_t *circ, const uint8_t *payload,
  916. size_t payload_len)
  917. {
  918. int ret = -1;
  919. curve25519_public_key_t server_pk;
  920. uint8_t auth_mac[DIGEST256_LEN] = {0};
  921. uint8_t handshake_info[CURVE25519_PUBKEY_LEN + sizeof(auth_mac)] = {0};
  922. hs_ntor_rend_cell_keys_t keys;
  923. const hs_ident_circuit_t *ident;
  924. tor_assert(circ);
  925. tor_assert(payload);
  926. /* Make things easier. */
  927. ident = circ->hs_ident;
  928. tor_assert(ident);
  929. if (hs_cell_parse_rendezvous2(payload, payload_len, handshake_info,
  930. sizeof(handshake_info)) < 0) {
  931. goto err;
  932. }
  933. /* Get from the handshake info the SERVER_PK and AUTH_MAC. */
  934. memcpy(&server_pk, handshake_info, CURVE25519_PUBKEY_LEN);
  935. memcpy(auth_mac, handshake_info + CURVE25519_PUBKEY_LEN, sizeof(auth_mac));
  936. /* Generate the handshake info. */
  937. if (hs_ntor_client_get_rendezvous1_keys(&ident->intro_auth_pk,
  938. &ident->rendezvous_client_kp,
  939. &ident->intro_enc_pk, &server_pk,
  940. &keys) < 0) {
  941. log_info(LD_REND, "Unable to compute the rendezvous keys.");
  942. goto err;
  943. }
  944. /* Critical check, make sure that the MAC matches what we got with what we
  945. * computed just above. */
  946. if (!hs_ntor_client_rendezvous2_mac_is_good(&keys, auth_mac)) {
  947. log_info(LD_REND, "Invalid MAC in RENDEZVOUS2. Rejecting cell.");
  948. goto err;
  949. }
  950. /* Setup the e2e encryption on the circuit and finalize its state. */
  951. if (hs_circuit_setup_e2e_rend_circ(circ, keys.ntor_key_seed,
  952. sizeof(keys.ntor_key_seed), 0) < 0) {
  953. log_info(LD_REND, "Unable to setup the e2e encryption.");
  954. goto err;
  955. }
  956. /* Success. Hidden service connection finalized! */
  957. ret = 0;
  958. goto end;
  959. err:
  960. circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_TORPROTOCOL);
  961. end:
  962. memwipe(&keys, 0, sizeof(keys));
  963. return ret;
  964. }
  965. /* Return true iff the client can fetch a descriptor for this service public
  966. * identity key and status_out if not NULL is untouched. If the client can
  967. * _not_ fetch the descriptor and if status_out is not NULL, it is set with
  968. * the fetch status code. */
  969. static unsigned int
  970. can_client_refetch_desc(const ed25519_public_key_t *identity_pk,
  971. hs_client_fetch_status_t *status_out)
  972. {
  973. hs_client_fetch_status_t status;
  974. tor_assert(identity_pk);
  975. /* Are we configured to fetch descriptors? */
  976. if (!get_options()->FetchHidServDescriptors) {
  977. log_warn(LD_REND, "We received an onion address for a hidden service "
  978. "descriptor but we are configured to not fetch.");
  979. status = HS_CLIENT_FETCH_NOT_ALLOWED;
  980. goto cannot;
  981. }
  982. /* Without a live consensus we can't do any client actions. It is needed to
  983. * compute the hashring for a service. */
  984. if (!networkstatus_get_live_consensus(approx_time())) {
  985. log_info(LD_REND, "Can't fetch descriptor for service %s because we "
  986. "are missing a live consensus. Stalling connection.",
  987. safe_str_client(ed25519_fmt(identity_pk)));
  988. status = HS_CLIENT_FETCH_MISSING_INFO;
  989. goto cannot;
  990. }
  991. if (!router_have_minimum_dir_info()) {
  992. log_info(LD_REND, "Can't fetch descriptor for service %s because we "
  993. "dont have enough descriptors. Stalling connection.",
  994. safe_str_client(ed25519_fmt(identity_pk)));
  995. status = HS_CLIENT_FETCH_MISSING_INFO;
  996. goto cannot;
  997. }
  998. /* Check if fetching a desc for this HS is useful to us right now */
  999. {
  1000. const hs_descriptor_t *cached_desc = NULL;
  1001. cached_desc = hs_cache_lookup_as_client(identity_pk);
  1002. if (cached_desc && hs_client_any_intro_points_usable(identity_pk,
  1003. cached_desc)) {
  1004. log_info(LD_GENERAL, "We would fetch a v3 hidden service descriptor "
  1005. "but we already have a usable descriptor.");
  1006. status = HS_CLIENT_FETCH_HAVE_DESC;
  1007. goto cannot;
  1008. }
  1009. }
  1010. /* Don't try to refetch while we have a pending request for it. */
  1011. if (directory_request_is_pending(identity_pk)) {
  1012. log_info(LD_REND, "Already a pending directory request. Waiting on it.");
  1013. status = HS_CLIENT_FETCH_PENDING;
  1014. goto cannot;
  1015. }
  1016. /* Yes, client can fetch! */
  1017. return 1;
  1018. cannot:
  1019. if (status_out) {
  1020. *status_out = status;
  1021. }
  1022. return 0;
  1023. }
  1024. /* ========== */
  1025. /* Public API */
  1026. /* ========== */
  1027. /** A circuit just finished connecting to a hidden service that the stream
  1028. * <b>conn</b> has been waiting for. Let the HS subsystem know about this. */
  1029. void
  1030. hs_client_note_connection_attempt_succeeded(const edge_connection_t *conn)
  1031. {
  1032. tor_assert(connection_edge_is_rendezvous_stream(conn));
  1033. if (BUG(conn->rend_data && conn->hs_ident)) {
  1034. log_warn(LD_BUG, "Stream had both rend_data and hs_ident..."
  1035. "Prioritizing hs_ident");
  1036. }
  1037. if (conn->hs_ident) { /* It's v3: pass it to the prop224 handler */
  1038. note_connection_attempt_succeeded(conn->hs_ident);
  1039. return;
  1040. } else if (conn->rend_data) { /* It's v2: pass it to the legacy handler */
  1041. rend_client_note_connection_attempt_ended(conn->rend_data);
  1042. return;
  1043. }
  1044. }
  1045. /* With the given encoded descriptor in desc_str and the service key in
  1046. * service_identity_pk, decode the descriptor and set the desc pointer with a
  1047. * newly allocated descriptor object.
  1048. *
  1049. * Return 0 on success else a negative value and desc is set to NULL. */
  1050. int
  1051. hs_client_decode_descriptor(const char *desc_str,
  1052. const ed25519_public_key_t *service_identity_pk,
  1053. hs_descriptor_t **desc)
  1054. {
  1055. int ret;
  1056. uint8_t subcredential[DIGEST256_LEN];
  1057. ed25519_public_key_t blinded_pubkey;
  1058. tor_assert(desc_str);
  1059. tor_assert(service_identity_pk);
  1060. tor_assert(desc);
  1061. /* Create subcredential for this HS so that we can decrypt */
  1062. {
  1063. uint64_t current_time_period = hs_get_time_period_num(0);
  1064. hs_build_blinded_pubkey(service_identity_pk, NULL, 0, current_time_period,
  1065. &blinded_pubkey);
  1066. hs_get_subcredential(service_identity_pk, &blinded_pubkey, subcredential);
  1067. }
  1068. /* Parse descriptor */
  1069. ret = hs_desc_decode_descriptor(desc_str, subcredential, desc);
  1070. memwipe(subcredential, 0, sizeof(subcredential));
  1071. if (ret < 0) {
  1072. log_warn(LD_GENERAL, "Could not parse received descriptor as client.");
  1073. if (get_options()->SafeLogging_ == SAFELOG_SCRUB_NONE) {
  1074. log_warn(LD_GENERAL, "%s", escaped(desc_str));
  1075. }
  1076. goto err;
  1077. }
  1078. /* Make sure the descriptor signing key cross certifies with the computed
  1079. * blinded key. Without this validation, anyone knowing the subcredential
  1080. * and onion address can forge a descriptor. */
  1081. tor_cert_t *cert = (*desc)->plaintext_data.signing_key_cert;
  1082. if (tor_cert_checksig(cert,
  1083. &blinded_pubkey, approx_time()) < 0) {
  1084. log_warn(LD_GENERAL, "Descriptor signing key certificate signature "
  1085. "doesn't validate with computed blinded key: %s",
  1086. tor_cert_describe_signature_status(cert));
  1087. goto err;
  1088. }
  1089. return 0;
  1090. err:
  1091. return -1;
  1092. }
  1093. /* Return true iff there are at least one usable intro point in the service
  1094. * descriptor desc. */
  1095. int
  1096. hs_client_any_intro_points_usable(const ed25519_public_key_t *service_pk,
  1097. const hs_descriptor_t *desc)
  1098. {
  1099. tor_assert(service_pk);
  1100. tor_assert(desc);
  1101. SMARTLIST_FOREACH_BEGIN(desc->encrypted_data.intro_points,
  1102. const hs_desc_intro_point_t *, ip) {
  1103. if (intro_point_is_usable(service_pk, ip)) {
  1104. goto usable;
  1105. }
  1106. } SMARTLIST_FOREACH_END(ip);
  1107. return 0;
  1108. usable:
  1109. return 1;
  1110. }
  1111. /** Launch a connection to a hidden service directory to fetch a hidden
  1112. * service descriptor using <b>identity_pk</b> to get the necessary keys.
  1113. *
  1114. * A hs_client_fetch_status_t code is returned. */
  1115. int
  1116. hs_client_refetch_hsdesc(const ed25519_public_key_t *identity_pk)
  1117. {
  1118. hs_client_fetch_status_t status;
  1119. tor_assert(identity_pk);
  1120. if (!can_client_refetch_desc(identity_pk, &status)) {
  1121. return status;
  1122. }
  1123. /* Try to fetch the desc and if we encounter an unrecoverable error, mark
  1124. * the desc as unavailable for now. */
  1125. status = fetch_v3_desc(identity_pk);
  1126. if (fetch_status_should_close_socks(status)) {
  1127. close_all_socks_conns_waiting_for_desc(identity_pk, status,
  1128. END_STREAM_REASON_RESOLVEFAILED);
  1129. /* Remove HSDir fetch attempts so that we can retry later if the user
  1130. * wants us to regardless of if we closed any connections. */
  1131. purge_hid_serv_request(identity_pk);
  1132. }
  1133. return status;
  1134. }
  1135. /* This is called when we are trying to attach an AP connection to these
  1136. * hidden service circuits from connection_ap_handshake_attach_circuit().
  1137. * Return 0 on success, -1 for a transient error that is actions were
  1138. * triggered to recover or -2 for a permenent error where both circuits will
  1139. * marked for close.
  1140. *
  1141. * The following supports every hidden service version. */
  1142. int
  1143. hs_client_send_introduce1(origin_circuit_t *intro_circ,
  1144. origin_circuit_t *rend_circ)
  1145. {
  1146. return (intro_circ->hs_ident) ? send_introduce1(intro_circ, rend_circ) :
  1147. rend_client_send_introduction(intro_circ,
  1148. rend_circ);
  1149. }
  1150. /* Called when the client circuit circ has been established. It can be either
  1151. * an introduction or rendezvous circuit. This function handles all hidden
  1152. * service versions. */
  1153. void
  1154. hs_client_circuit_has_opened(origin_circuit_t *circ)
  1155. {
  1156. tor_assert(circ);
  1157. /* Handle both version. v2 uses rend_data and v3 uses the hs circuit
  1158. * identifier hs_ident. Can't be both. */
  1159. switch (TO_CIRCUIT(circ)->purpose) {
  1160. case CIRCUIT_PURPOSE_C_INTRODUCING:
  1161. if (circ->hs_ident) {
  1162. client_intro_circ_has_opened(circ);
  1163. } else {
  1164. rend_client_introcirc_has_opened(circ);
  1165. }
  1166. break;
  1167. case CIRCUIT_PURPOSE_C_ESTABLISH_REND:
  1168. if (circ->hs_ident) {
  1169. client_rendezvous_circ_has_opened(circ);
  1170. } else {
  1171. rend_client_rendcirc_has_opened(circ);
  1172. }
  1173. break;
  1174. default:
  1175. tor_assert_nonfatal_unreached();
  1176. }
  1177. }
  1178. /* Called when we receive a RENDEZVOUS_ESTABLISHED cell. Change the state of
  1179. * the circuit to CIRCUIT_PURPOSE_C_REND_READY. Return 0 on success else a
  1180. * negative value and the circuit marked for close. */
  1181. int
  1182. hs_client_receive_rendezvous_acked(origin_circuit_t *circ,
  1183. const uint8_t *payload, size_t payload_len)
  1184. {
  1185. tor_assert(circ);
  1186. tor_assert(payload);
  1187. (void) payload_len;
  1188. if (TO_CIRCUIT(circ)->purpose != CIRCUIT_PURPOSE_C_ESTABLISH_REND) {
  1189. log_warn(LD_PROTOCOL, "Got a RENDEZVOUS_ESTABLISHED but we were not "
  1190. "expecting one. Closing circuit.");
  1191. goto err;
  1192. }
  1193. log_info(LD_REND, "Received an RENDEZVOUS_ESTABLISHED. This circuit is "
  1194. "now ready for rendezvous.");
  1195. circuit_change_purpose(TO_CIRCUIT(circ), CIRCUIT_PURPOSE_C_REND_READY);
  1196. /* Set timestamp_dirty, because circuit_expire_building expects it to
  1197. * specify when a circuit entered the _C_REND_READY state. */
  1198. TO_CIRCUIT(circ)->timestamp_dirty = time(NULL);
  1199. /* From a path bias point of view, this circuit is now successfully used.
  1200. * Waiting any longer opens us up to attacks from malicious hidden services.
  1201. * They could induce the client to attempt to connect to their hidden
  1202. * service and never reply to the client's rend requests */
  1203. pathbias_mark_use_success(circ);
  1204. /* If we already have the introduction circuit built, make sure we send
  1205. * the INTRODUCE cell _now_ */
  1206. connection_ap_attach_pending(1);
  1207. return 0;
  1208. err:
  1209. circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_TORPROTOCOL);
  1210. return -1;
  1211. }
  1212. /* This is called when a descriptor has arrived following a fetch request and
  1213. * has been stored in the client cache. Every entry connection that matches
  1214. * the service identity key in the ident will get attached to the hidden
  1215. * service circuit. */
  1216. void
  1217. hs_client_desc_has_arrived(const hs_ident_dir_conn_t *ident)
  1218. {
  1219. time_t now = time(NULL);
  1220. smartlist_t *conns = NULL;
  1221. tor_assert(ident);
  1222. conns = connection_list_by_type_state(CONN_TYPE_AP,
  1223. AP_CONN_STATE_RENDDESC_WAIT);
  1224. SMARTLIST_FOREACH_BEGIN(conns, connection_t *, base_conn) {
  1225. const hs_descriptor_t *desc;
  1226. entry_connection_t *entry_conn = TO_ENTRY_CONN(base_conn);
  1227. const edge_connection_t *edge_conn = ENTRY_TO_EDGE_CONN(entry_conn);
  1228. /* Only consider the entry connections that matches the service for which
  1229. * we just fetched its descriptor. */
  1230. if (!edge_conn->hs_ident ||
  1231. !ed25519_pubkey_eq(&ident->identity_pk,
  1232. &edge_conn->hs_ident->identity_pk)) {
  1233. continue;
  1234. }
  1235. assert_connection_ok(base_conn, now);
  1236. /* We were just called because we stored the descriptor for this service
  1237. * so not finding a descriptor means we have a bigger problem. */
  1238. desc = hs_cache_lookup_as_client(&ident->identity_pk);
  1239. if (BUG(desc == NULL)) {
  1240. goto end;
  1241. }
  1242. if (!hs_client_any_intro_points_usable(&ident->identity_pk, desc)) {
  1243. log_info(LD_REND, "Hidden service descriptor is unusable. "
  1244. "Closing streams.");
  1245. connection_mark_unattached_ap(entry_conn,
  1246. END_STREAM_REASON_RESOLVEFAILED);
  1247. /* We are unable to use the descriptor so remove the directory request
  1248. * from the cache so the next connection can try again. */
  1249. note_connection_attempt_succeeded(edge_conn->hs_ident);
  1250. goto end;
  1251. }
  1252. log_info(LD_REND, "Descriptor has arrived. Launching circuits.");
  1253. /* Because the connection can now proceed to opening circuit and
  1254. * ultimately connect to the service, reset those timestamp so the
  1255. * connection is considered "fresh" and can continue without being closed
  1256. * too early. */
  1257. base_conn->timestamp_created = now;
  1258. base_conn->timestamp_last_read_allowed = now;
  1259. base_conn->timestamp_last_write_allowed = now;
  1260. /* Change connection's state into waiting for a circuit. */
  1261. base_conn->state = AP_CONN_STATE_CIRCUIT_WAIT;
  1262. connection_ap_mark_as_pending_circuit(entry_conn);
  1263. } SMARTLIST_FOREACH_END(base_conn);
  1264. end:
  1265. /* We don't have ownership of the objects in this list. */
  1266. smartlist_free(conns);
  1267. }
  1268. /* Return a newly allocated extend_info_t for a randomly chosen introduction
  1269. * point for the given edge connection identifier ident. Return NULL if we
  1270. * can't pick any usable introduction points. */
  1271. extend_info_t *
  1272. hs_client_get_random_intro_from_edge(const edge_connection_t *edge_conn)
  1273. {
  1274. tor_assert(edge_conn);
  1275. return (edge_conn->hs_ident) ?
  1276. client_get_random_intro(&edge_conn->hs_ident->identity_pk) :
  1277. rend_client_get_random_intro(edge_conn->rend_data);
  1278. }
  1279. /* Called when get an INTRODUCE_ACK cell on the introduction circuit circ.
  1280. * Return 0 on success else a negative value is returned. The circuit will be
  1281. * closed or reuse to extend again to another intro point. */
  1282. int
  1283. hs_client_receive_introduce_ack(origin_circuit_t *circ,
  1284. const uint8_t *payload, size_t payload_len)
  1285. {
  1286. int ret = -1;
  1287. tor_assert(circ);
  1288. tor_assert(payload);
  1289. if (TO_CIRCUIT(circ)->purpose != CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT) {
  1290. log_warn(LD_PROTOCOL, "Unexpected INTRODUCE_ACK on circuit %u.",
  1291. (unsigned int) TO_CIRCUIT(circ)->n_circ_id);
  1292. circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_TORPROTOCOL);
  1293. goto end;
  1294. }
  1295. ret = (circ->hs_ident) ? handle_introduce_ack(circ, payload, payload_len) :
  1296. rend_client_introduction_acked(circ, payload,
  1297. payload_len);
  1298. /* For path bias: This circuit was used successfully. NACK or ACK counts. */
  1299. pathbias_mark_use_success(circ);
  1300. end:
  1301. return ret;
  1302. }
  1303. /* Called when get a RENDEZVOUS2 cell on the rendezvous circuit circ. Return
  1304. * 0 on success else a negative value is returned. The circuit will be closed
  1305. * on error. */
  1306. int
  1307. hs_client_receive_rendezvous2(origin_circuit_t *circ,
  1308. const uint8_t *payload, size_t payload_len)
  1309. {
  1310. int ret = -1;
  1311. tor_assert(circ);
  1312. tor_assert(payload);
  1313. /* Circuit can possibly be in both state because we could receive a
  1314. * RENDEZVOUS2 cell before the INTRODUCE_ACK has been received. */
  1315. if (TO_CIRCUIT(circ)->purpose != CIRCUIT_PURPOSE_C_REND_READY &&
  1316. TO_CIRCUIT(circ)->purpose != CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED) {
  1317. log_warn(LD_PROTOCOL, "Unexpected RENDEZVOUS2 cell on circuit %u. "
  1318. "Closing circuit.",
  1319. (unsigned int) TO_CIRCUIT(circ)->n_circ_id);
  1320. circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_TORPROTOCOL);
  1321. goto end;
  1322. }
  1323. log_info(LD_REND, "Got RENDEZVOUS2 cell from hidden service on circuit %u.",
  1324. TO_CIRCUIT(circ)->n_circ_id);
  1325. ret = (circ->hs_ident) ? handle_rendezvous2(circ, payload, payload_len) :
  1326. rend_client_receive_rendezvous(circ, payload,
  1327. payload_len);
  1328. end:
  1329. return ret;
  1330. }
  1331. /* Extend the introduction circuit circ to another valid introduction point
  1332. * for the hidden service it is trying to connect to, or mark it and launch a
  1333. * new circuit if we can't extend it. Return 0 on success or possible
  1334. * success. Return -1 and mark the introduction circuit for close on permanent
  1335. * failure.
  1336. *
  1337. * On failure, the caller is responsible for marking the associated rendezvous
  1338. * circuit for close. */
  1339. int
  1340. hs_client_reextend_intro_circuit(origin_circuit_t *circ)
  1341. {
  1342. int ret = -1;
  1343. extend_info_t *ei;
  1344. tor_assert(circ);
  1345. ei = (circ->hs_ident) ?
  1346. client_get_random_intro(&circ->hs_ident->identity_pk) :
  1347. rend_client_get_random_intro(circ->rend_data);
  1348. if (ei == NULL) {
  1349. log_warn(LD_REND, "No usable introduction points left. Closing.");
  1350. circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_INTERNAL);
  1351. goto end;
  1352. }
  1353. if (circ->remaining_relay_early_cells) {
  1354. log_info(LD_REND, "Re-extending circ %u, this time to %s.",
  1355. (unsigned int) TO_CIRCUIT(circ)->n_circ_id,
  1356. safe_str_client(extend_info_describe(ei)));
  1357. ret = circuit_extend_to_new_exit(circ, ei);
  1358. if (ret == 0) {
  1359. /* We were able to extend so update the timestamp so we avoid expiring
  1360. * this circuit too early. The intro circuit is short live so the
  1361. * linkability issue is minimized, we just need the circuit to hold a
  1362. * bit longer so we can introduce. */
  1363. TO_CIRCUIT(circ)->timestamp_dirty = time(NULL);
  1364. }
  1365. } else {
  1366. log_info(LD_REND, "Closing intro circ %u (out of RELAY_EARLY cells).",
  1367. (unsigned int) TO_CIRCUIT(circ)->n_circ_id);
  1368. circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_FINISHED);
  1369. /* connection_ap_handshake_attach_circuit will launch a new intro circ. */
  1370. ret = 0;
  1371. }
  1372. end:
  1373. extend_info_free(ei);
  1374. return ret;
  1375. }
  1376. /* Release all the storage held by the client subsystem. */
  1377. void
  1378. hs_client_free_all(void)
  1379. {
  1380. /* Purge the hidden service request cache. */
  1381. hs_purge_last_hid_serv_requests();
  1382. }
  1383. /* Purge all potentially remotely-detectable state held in the hidden
  1384. * service client code. Called on SIGNAL NEWNYM. */
  1385. void
  1386. hs_client_purge_state(void)
  1387. {
  1388. /* v2 subsystem. */
  1389. rend_client_purge_state();
  1390. /* Cancel all descriptor fetches. Do this first so once done we are sure
  1391. * that our descriptor cache won't modified. */
  1392. cancel_descriptor_fetches();
  1393. /* Purge the introduction point state cache. */
  1394. hs_cache_client_intro_state_purge();
  1395. /* Purge the descriptor cache. */
  1396. hs_cache_purge_as_client();
  1397. /* Purge the last hidden service request cache. */
  1398. hs_purge_last_hid_serv_requests();
  1399. log_info(LD_REND, "Hidden service client state has been purged.");
  1400. }
  1401. /* Called when our directory information has changed. */
  1402. void
  1403. hs_client_dir_info_changed(void)
  1404. {
  1405. /* We have possibly reached the minimum directory information or new
  1406. * consensus so retry all pending SOCKS connection in
  1407. * AP_CONN_STATE_RENDDESC_WAIT state in order to fetch the descriptor. */
  1408. retry_all_socks_conn_waiting_for_desc();
  1409. }