Tor  0.4.6.0-alpha-dev
hs_client.c
Go to the documentation of this file.
1 /* Copyright (c) 2016-2020, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
3 
4 /**
5  * \file hs_client.c
6  * \brief Implement next generation hidden service client functionality
7  **/
8 
9 #define HS_CLIENT_PRIVATE
10 
11 #include "core/or/or.h"
12 #include "app/config/config.h"
13 #include "core/crypto/hs_ntor.h"
15 #include "core/or/circuitbuild.h"
16 #include "core/or/circuitlist.h"
17 #include "core/or/circuituse.h"
19 #include "core/or/extendinfo.h"
20 #include "core/or/reasons.h"
21 #include "feature/client/circpathbias.h"
24 #include "feature/hs/hs_cache.h"
25 #include "feature/hs/hs_cell.h"
26 #include "feature/hs/hs_circuit.h"
28 #include "feature/hs/hs_client.h"
29 #include "feature/hs/hs_control.h"
31 #include "feature/hs/hs_ident.h"
40 
44 #include "core/or/extend_info_st.h"
47 
48 /** Client-side authorizations for hidden services; map of service identity
49  * public key to hs_client_service_authorization_t *. */
50 static digest256map_t *client_auths = NULL;
51 
52 #include "trunnel/hs/cell_introduce1.h"
53 
54 /** Return a human-readable string for the client fetch status code. */
55 static const char *
57 {
58  switch (status) {
60  return "Internal error";
62  return "Descriptor fetch launched";
64  return "Already have descriptor";
66  return "No more HSDir available to query";
68  return "Fetching descriptors is not allowed";
70  return "Missing directory information";
72  return "Pending descriptor fetch";
73  default:
74  return "(Unknown client fetch status code)";
75  }
76 }
77 
78 /** Return true iff tor should close the SOCKS request(s) for the descriptor
79  * fetch that ended up with this given status code. */
80 static int
82 {
83  switch (status) {
85  /* No more HSDir to query, we can't complete the SOCKS request(s). */
87  /* The fetch triggered an internal error. */
89  /* Client is not allowed to fetch (FetchHidServDescriptors 0). */
90  goto close;
95  /* The rest doesn't require tor to close the SOCKS request(s). */
96  goto no_close;
97  }
98 
99  no_close:
100  return 0;
101  close:
102  return 1;
103 }
104 
105 /* Return a newly allocated list of all the entry connections that matches the
106  * given service identity pk. If service_identity_pk is NULL, all entry
107  * connections with an hs_ident are returned.
108  *
109  * Caller must free the returned list but does NOT have ownership of the
110  * object inside thus they have to remain untouched. */
111 static smartlist_t *
112 find_entry_conns(const ed25519_public_key_t *service_identity_pk)
113 {
114  time_t now = time(NULL);
115  smartlist_t *conns = NULL, *entry_conns = NULL;
116 
117  entry_conns = smartlist_new();
118 
119  conns = connection_list_by_type_state(CONN_TYPE_AP,
121  SMARTLIST_FOREACH_BEGIN(conns, connection_t *, base_conn) {
122  entry_connection_t *entry_conn = TO_ENTRY_CONN(base_conn);
123  const edge_connection_t *edge_conn = ENTRY_TO_EDGE_CONN(entry_conn);
124 
125  /* Only consider the entry connections that matches the service for which
126  * we just fetched its descriptor. */
127  if (!edge_conn->hs_ident ||
128  (service_identity_pk &&
129  !ed25519_pubkey_eq(service_identity_pk,
130  &edge_conn->hs_ident->identity_pk))) {
131  continue;
132  }
133  assert_connection_ok(base_conn, now);
134 
135  /* Validated! Add the entry connection to the list. */
136  smartlist_add(entry_conns, entry_conn);
137  } SMARTLIST_FOREACH_END(base_conn);
138 
139  /* We don't have ownership of the objects in this list. */
140  smartlist_free(conns);
141  return entry_conns;
142 }
143 
144 /* Cancel all descriptor fetches currently in progress. */
145 static void
146 cancel_descriptor_fetches(void)
147 {
148  smartlist_t *conns =
149  connection_list_by_type_purpose(CONN_TYPE_DIR, DIR_PURPOSE_FETCH_HSDESC);
150  SMARTLIST_FOREACH_BEGIN(conns, connection_t *, conn) {
151  const hs_ident_dir_conn_t *ident = TO_DIR_CONN(conn)->hs_ident;
152  if (BUG(ident == NULL)) {
153  /* A directory connection fetching a service descriptor can't have an
154  * empty hidden service identifier. */
155  continue;
156  }
157  log_debug(LD_REND, "Marking for close a directory connection fetching "
158  "a hidden service descriptor for service %s.",
159  safe_str_client(ed25519_fmt(&ident->identity_pk)));
160  connection_mark_for_close(conn);
161  } SMARTLIST_FOREACH_END(conn);
162 
163  /* No ownership of the objects in this list. */
164  smartlist_free(conns);
165  log_info(LD_REND, "Hidden service client descriptor fetches cancelled.");
166 }
167 
168 /** Get all connections that are waiting on a circuit and flag them back to
169  * waiting for a hidden service descriptor for the given service key
170  * service_identity_pk. */
171 static void
173 {
174  tor_assert(service_identity_pk);
175 
176  smartlist_t *conns =
177  connection_list_by_type_state(CONN_TYPE_AP, AP_CONN_STATE_CIRCUIT_WAIT);
178 
179  SMARTLIST_FOREACH_BEGIN(conns, connection_t *, conn) {
180  edge_connection_t *edge_conn;
181  if (BUG(!CONN_IS_EDGE(conn))) {
182  continue;
183  }
184  edge_conn = TO_EDGE_CONN(conn);
185  if (edge_conn->hs_ident &&
186  ed25519_pubkey_eq(&edge_conn->hs_ident->identity_pk,
187  service_identity_pk)) {
189  }
190  } SMARTLIST_FOREACH_END(conn);
191 
192  smartlist_free(conns);
193 }
194 
195 /** Remove tracked HSDir requests from our history for this hidden service
196  * identity public key. */
197 static void
199 {
200  char base64_blinded_pk[ED25519_BASE64_LEN + 1];
201  ed25519_public_key_t blinded_pk;
202 
203  tor_assert(identity_pk);
204 
205  /* Get blinded pubkey of hidden service. It is possible that we just moved
206  * to a new time period meaning that we won't be able to purge the request
207  * from the previous time period. That is fine because they will expire at
208  * some point and we don't care about those anymore. */
209  hs_build_blinded_pubkey(identity_pk, NULL, 0,
210  hs_get_time_period_num(0), &blinded_pk);
211  ed25519_public_to_base64(base64_blinded_pk, &blinded_pk);
212  /* Purge last hidden service request from cache for this blinded key. */
214 }
215 
216 /** Return true iff there is at least one pending directory descriptor request
217  * for the service identity_pk. */
218 static int
220 {
221  int ret = 0;
222  smartlist_t *conns =
223  connection_list_by_type_purpose(CONN_TYPE_DIR, DIR_PURPOSE_FETCH_HSDESC);
224 
225  SMARTLIST_FOREACH_BEGIN(conns, connection_t *, conn) {
226  const hs_ident_dir_conn_t *ident = TO_DIR_CONN(conn)->hs_ident;
227  if (BUG(ident == NULL)) {
228  /* A directory connection fetching a service descriptor can't have an
229  * empty hidden service identifier. */
230  continue;
231  }
232  if (!ed25519_pubkey_eq(identity_pk, &ident->identity_pk)) {
233  continue;
234  }
235  ret = 1;
236  break;
237  } SMARTLIST_FOREACH_END(conn);
238 
239  /* No ownership of the objects in this list. */
240  smartlist_free(conns);
241  return ret;
242 }
243 
244 /** Helper function that changes the state of an entry connection to waiting
245  * for a circuit. For this to work properly, the connection timestamps are set
246  * to now and the connection is then marked as pending for a circuit. */
247 static void
249 {
250  tor_assert(conn);
251 
252  /* Because the connection can now proceed to opening circuit and ultimately
253  * connect to the service, reset those timestamp so the connection is
254  * considered "fresh" and can continue without being closed too early. */
255  conn->timestamp_created = now;
256  conn->timestamp_last_read_allowed = now;
257  conn->timestamp_last_write_allowed = now;
258  /* Change connection's state into waiting for a circuit. */
260 
261  connection_ap_mark_as_pending_circuit(TO_ENTRY_CONN(conn));
262 }
263 
264 /** We failed to fetch a descriptor for the service with <b>identity_pk</b>
265  * because of <b>status</b>. Find all pending SOCKS connections for this
266  * service that are waiting on the descriptor and close them with
267  * <b>reason</b>. */
268 static void
271  int reason)
272 {
273  unsigned int count = 0;
274  smartlist_t *entry_conns = find_entry_conns(identity_pk);
275 
276  SMARTLIST_FOREACH_BEGIN(entry_conns, entry_connection_t *, entry_conn) {
277  /* Unattach the entry connection which will close for the reason. */
278  connection_mark_unattached_ap(entry_conn, reason);
279  count++;
280  } SMARTLIST_FOREACH_END(entry_conn);
281 
282  if (count > 0) {
283  char onion_address[HS_SERVICE_ADDR_LEN_BASE32 + 1];
284  hs_build_address(identity_pk, HS_VERSION_THREE, onion_address);
285  log_notice(LD_REND, "Closed %u streams for service %s.onion "
286  "for reason %s. Fetch status: %s.",
287  count, safe_str_client(onion_address),
289  fetch_status_to_string(status));
290  }
291 
292  /* No ownership of the object(s) in this list. */
293  smartlist_free(entry_conns);
294 }
295 
296 /** Find all pending SOCKS connection waiting for a descriptor and retry them
297  * all. This is called when the directory information changed. */
298 STATIC void
300 {
301  smartlist_t *entry_conns = find_entry_conns(NULL);
302 
303  SMARTLIST_FOREACH_BEGIN(entry_conns, entry_connection_t *, entry_conn) {
305  edge_connection_t *edge_conn = ENTRY_TO_EDGE_CONN(entry_conn);
306  connection_t *base_conn = &edge_conn->base_;
307 
308  /* Ignore non HS or non v3 connection. */
309  if (edge_conn->hs_ident == NULL) {
310  continue;
311  }
312 
313  /* In this loop, we will possibly try to fetch a descriptor for the
314  * pending connections because we just got more directory information.
315  * However, the refetch process can cleanup all SOCKS request to the same
316  * service if an internal error happens. Thus, we can end up with closed
317  * connections in our list. */
318  if (base_conn->marked_for_close) {
319  continue;
320  }
321 
322  /* XXX: There is an optimization we could do which is that for a service
323  * key, we could check if we can fetch and remember that decision. */
324 
325  /* Order a refetch in case it works this time. */
326  status = hs_client_refetch_hsdesc(&edge_conn->hs_ident->identity_pk);
327  if (status == HS_CLIENT_FETCH_HAVE_DESC) {
328  /* This is a rare case where a SOCKS connection is in state waiting for
329  * a descriptor but we do have it in the cache.
330  *
331  * This can happen is tor comes back from suspend where it previously
332  * had the descriptor but the intro points were not usable. Once it
333  * came back to life, the intro point failure cache was cleaned up and
334  * thus the descriptor became usable again leaving us in this code path.
335  *
336  * We'll mark the connection as waiting for a circuit so the descriptor
337  * can be retried. This is safe because a connection in state waiting
338  * for a descriptor can not be in the entry connection pending list. */
340  continue;
341  }
342  /* In the case of an error, either all SOCKS connections have been
343  * closed or we are still missing directory information. Leave the
344  * connection in renddesc wait state so when we get more info, we'll be
345  * able to try it again. */
346  } SMARTLIST_FOREACH_END(entry_conn);
347 
348  /* We don't have ownership of those objects. */
349  smartlist_free(entry_conns);
350 }
351 
352 /** A v3 HS circuit successfully connected to the hidden service. Update the
353  * stream state at <b>hs_conn_ident</b> appropriately. */
354 static void
356 {
357  tor_assert(hs_conn_ident);
358 
359  /* Remove from the hid serv cache all requests for that service so we can
360  * query the HSDir again later on for various reasons. */
361  purge_hid_serv_request(&hs_conn_ident->identity_pk);
362 
363  /* The v2 subsystem cleans up the intro point time out flag at this stage.
364  * We don't try to do it here because we still need to keep intact the intro
365  * point state for future connections. Even though we are able to connect to
366  * the service, doesn't mean we should reset the timed out intro points.
367  *
368  * It is not possible to have successfully connected to an intro point
369  * present in our cache that was on error or timed out. Every entry in that
370  * cache have a 2 minutes lifetime so ultimately the intro point(s) state
371  * will be reset and thus possible to be retried. */
372 }
373 
374 /** Given the pubkey of a hidden service in <b>onion_identity_pk</b>, fetch its
375  * descriptor by launching a dir connection to <b>hsdir</b>. Return a
376  * hs_client_fetch_status_t status code depending on how it went. */
379  const routerstatus_t *hsdir)
380 {
381  uint64_t current_time_period = hs_get_time_period_num(0);
382  ed25519_public_key_t blinded_pubkey;
383  char base64_blinded_pubkey[ED25519_BASE64_LEN + 1];
384  hs_ident_dir_conn_t hs_conn_dir_ident;
385 
386  tor_assert(hsdir);
387  tor_assert(onion_identity_pk);
388 
389  /* Get blinded pubkey */
390  hs_build_blinded_pubkey(onion_identity_pk, NULL, 0,
391  current_time_period, &blinded_pubkey);
392  /* ...and base64 it. */
393  ed25519_public_to_base64(base64_blinded_pubkey, &blinded_pubkey);
394 
395  /* Copy onion pk to a dir_ident so that we attach it to the dir conn */
396  hs_ident_dir_conn_init(onion_identity_pk, &blinded_pubkey,
397  &hs_conn_dir_ident);
398 
399  /* Setup directory request */
400  directory_request_t *req =
404  directory_request_set_resource(req, base64_blinded_pubkey);
405  directory_request_fetch_set_hs_ident(req, &hs_conn_dir_ident);
407  directory_request_free(req);
408 
409  log_info(LD_REND, "Descriptor fetch request for service %s with blinded "
410  "key %s to directory %s",
411  safe_str_client(ed25519_fmt(onion_identity_pk)),
412  safe_str_client(base64_blinded_pubkey),
413  safe_str_client(routerstatus_describe(hsdir)));
414 
415  /* Fire a REQUESTED event on the control port. */
416  hs_control_desc_event_requested(onion_identity_pk, base64_blinded_pubkey,
417  hsdir);
418 
419  /* Cleanup memory. */
420  memwipe(&blinded_pubkey, 0, sizeof(blinded_pubkey));
421  memwipe(base64_blinded_pubkey, 0, sizeof(base64_blinded_pubkey));
422  memwipe(&hs_conn_dir_ident, 0, sizeof(hs_conn_dir_ident));
423 
425 }
426 
427 /** Return the HSDir we should use to fetch the descriptor of the hidden
428  * service with identity key <b>onion_identity_pk</b>. */
430 pick_hsdir_v3(const ed25519_public_key_t *onion_identity_pk)
431 {
432  char base64_blinded_pubkey[ED25519_BASE64_LEN + 1];
433  uint64_t current_time_period = hs_get_time_period_num(0);
434  smartlist_t *responsible_hsdirs = NULL;
435  ed25519_public_key_t blinded_pubkey;
436  routerstatus_t *hsdir_rs = NULL;
437 
438  tor_assert(onion_identity_pk);
439 
440  /* Get blinded pubkey of hidden service */
441  hs_build_blinded_pubkey(onion_identity_pk, NULL, 0,
442  current_time_period, &blinded_pubkey);
443  /* ...and base64 it. */
444  ed25519_public_to_base64(base64_blinded_pubkey, &blinded_pubkey);
445 
446  /* Get responsible hsdirs of service for this time period */
447  responsible_hsdirs = smartlist_new();
448 
449  hs_get_responsible_hsdirs(&blinded_pubkey, current_time_period,
450  0, 1, responsible_hsdirs);
451 
452  log_debug(LD_REND, "Found %d responsible HSDirs and about to pick one.",
453  smartlist_len(responsible_hsdirs));
454 
455  /* Pick an HSDir from the responsible ones. The ownership of
456  * responsible_hsdirs is given to this function so no need to free it. */
457  hsdir_rs = hs_pick_hsdir(responsible_hsdirs, base64_blinded_pubkey, NULL);
458 
459  return hsdir_rs;
460 }
461 
462 /** Fetch a v3 descriptor using the given <b>onion_identity_pk</b>.
463  *
464  * On success, HS_CLIENT_FETCH_LAUNCHED is returned. Otherwise, an error from
465  * hs_client_fetch_status_t is returned. */
467 fetch_v3_desc, (const ed25519_public_key_t *onion_identity_pk))
468 {
469  routerstatus_t *hsdir_rs =NULL;
470 
471  tor_assert(onion_identity_pk);
472 
473  hsdir_rs = pick_hsdir_v3(onion_identity_pk);
474  if (!hsdir_rs) {
475  log_info(LD_REND, "Couldn't pick a v3 hsdir.");
477  }
478 
479  return directory_launch_v3_desc_fetch(onion_identity_pk, hsdir_rs);
480 }
481 
482 /** With a given <b>onion_identity_pk</b>, fetch its descriptor. If
483  * <b>hsdirs</b> is specified, use the directory servers specified in the list.
484  * Else, use a random server. */
485 void
487  const smartlist_t *hsdirs)
488 {
489  tor_assert(onion_identity_pk);
490 
491  if (hsdirs != NULL) {
492  SMARTLIST_FOREACH_BEGIN(hsdirs, const routerstatus_t *, hsdir) {
493  directory_launch_v3_desc_fetch(onion_identity_pk, hsdir);
494  } SMARTLIST_FOREACH_END(hsdir);
495  } else {
496  fetch_v3_desc(onion_identity_pk);
497  }
498 }
499 
500 /** Make sure that the given v3 origin circuit circ is a valid correct
501  * introduction circuit. This will BUG() on any problems and hard assert if
502  * the anonymity of the circuit is not ok. Return 0 on success else -1 where
503  * the circuit should be mark for closed immediately. */
504 static int
506 {
507  int ret = 0;
508 
509  tor_assert(circ);
510 
511  if (BUG(TO_CIRCUIT(circ)->purpose != CIRCUIT_PURPOSE_C_INTRODUCING &&
513  TO_CIRCUIT(circ)->purpose != CIRCUIT_PURPOSE_C_INTRODUCE_ACKED)) {
514  ret = -1;
515  }
516  if (BUG(circ->hs_ident == NULL)) {
517  ret = -1;
518  }
519  if (BUG(!hs_ident_intro_circ_is_valid(circ->hs_ident))) {
520  ret = -1;
521  }
522 
523  /* This can stop the tor daemon but we want that since if we don't have
524  * anonymity on this circuit, something went really wrong. */
525  assert_circ_anonymity_ok(circ, get_options());
526  return ret;
527 }
528 
529 /** Find a descriptor intro point object that matches the given ident in the
530  * given descriptor desc. Return NULL if not found. */
531 static const hs_desc_intro_point_t *
533  const hs_descriptor_t *desc)
534 {
535  const hs_desc_intro_point_t *intro_point = NULL;
536 
537  tor_assert(ident);
538  tor_assert(desc);
539 
541  const hs_desc_intro_point_t *, ip) {
542  if (ed25519_pubkey_eq(&ident->intro_auth_pk,
543  &ip->auth_key_cert->signed_key)) {
544  intro_point = ip;
545  break;
546  }
547  } SMARTLIST_FOREACH_END(ip);
548 
549  return intro_point;
550 }
551 
552 /** Find a descriptor intro point object from the descriptor object desc that
553  * matches the given legacy identity digest in legacy_id. Return NULL if not
554  * found. */
555 static hs_desc_intro_point_t *
557  const hs_descriptor_t *desc)
558 {
559  hs_desc_intro_point_t *ret_ip = NULL;
560 
561  tor_assert(legacy_id);
562  tor_assert(desc);
563 
564  /* We will go over every intro point and try to find which one is linked to
565  * that circuit. Those lists are small so it's not that expensive. */
567  hs_desc_intro_point_t *, ip) {
568  SMARTLIST_FOREACH_BEGIN(ip->link_specifiers,
569  const link_specifier_t *, lspec) {
570  /* Not all tor node have an ed25519 identity key so we still rely on the
571  * legacy identity digest. */
572  if (link_specifier_get_ls_type(lspec) != LS_LEGACY_ID) {
573  continue;
574  }
575  if (fast_memneq(legacy_id,
576  link_specifier_getconstarray_un_legacy_id(lspec),
577  DIGEST_LEN)) {
578  break;
579  }
580  /* Found it. */
581  ret_ip = ip;
582  goto end;
583  } SMARTLIST_FOREACH_END(lspec);
584  } SMARTLIST_FOREACH_END(ip);
585 
586  end:
587  return ret_ip;
588 }
589 
590 /** Send an INTRODUCE1 cell along the intro circuit and populate the rend
591  * circuit identifier with the needed key material for the e2e encryption.
592  * Return 0 on success, -1 if there is a transient error such that an action
593  * has been taken to recover and -2 if there is a permanent error indicating
594  * that both circuits were closed. */
595 static int
597  origin_circuit_t *rend_circ)
598 {
599  int status;
600  char onion_address[HS_SERVICE_ADDR_LEN_BASE32 + 1];
601  const ed25519_public_key_t *service_identity_pk = NULL;
602  const hs_desc_intro_point_t *ip;
603 
604  tor_assert(rend_circ);
605  if (intro_circ_is_ok(intro_circ) < 0) {
606  goto perm_err;
607  }
608 
609  service_identity_pk = &intro_circ->hs_ident->identity_pk;
610  /* For logging purposes. There will be a time where the hs_ident will have a
611  * version number but for now there is none because it's all v3. */
612  hs_build_address(service_identity_pk, HS_VERSION_THREE, onion_address);
613 
614  log_info(LD_REND, "Sending INTRODUCE1 cell to service %s on circuit %u",
615  safe_str_client(onion_address), TO_CIRCUIT(intro_circ)->n_circ_id);
616 
617  /* 1) Get descriptor from our cache. */
618  const hs_descriptor_t *desc =
619  hs_cache_lookup_as_client(service_identity_pk);
620  if (desc == NULL || !hs_client_any_intro_points_usable(service_identity_pk,
621  desc)) {
622  log_info(LD_REND, "Request to %s %s. Trying to fetch a new descriptor.",
623  safe_str_client(onion_address),
624  (desc) ? "didn't have usable intro points" :
625  "didn't have a descriptor");
626  hs_client_refetch_hsdesc(service_identity_pk);
627  /* We just triggered a refetch, make sure every connections are back
628  * waiting for that descriptor. */
629  flag_all_conn_wait_desc(service_identity_pk);
630  /* We just asked for a refetch so this is a transient error. */
631  goto tran_err;
632  }
633 
634  /* We need to find which intro point in the descriptor we are connected to
635  * on intro_circ. */
636  ip = find_desc_intro_point_by_ident(intro_circ->hs_ident, desc);
637  if (ip == NULL) {
638  /* The following is possible if the descriptor was changed while we had
639  * this introduction circuit open and waiting for the rendezvous circuit to
640  * be ready. Which results in this situation where we can't find the
641  * corresponding intro point within the descriptor of the service. */
642  log_info(LD_REND, "Unable to find introduction point for service %s "
643  "while trying to send an INTRODUCE1 cell.",
644  safe_str_client(onion_address));
645  goto perm_err;
646  }
647 
648  /* Send the INTRODUCE1 cell. */
649  if (hs_circ_send_introduce1(intro_circ, rend_circ, ip,
650  &desc->subcredential) < 0) {
651  if (TO_CIRCUIT(intro_circ)->marked_for_close) {
652  /* If the introduction circuit was closed, we were unable to send the
653  * cell for some reasons. In any case, the intro circuit has to be
654  * closed by the above function. We'll return a transient error so tor
655  * can recover and pick a new intro point. To avoid picking that same
656  * intro point, we'll note down the intro point failure so it doesn't
657  * get reused. */
658  hs_cache_client_intro_state_note(service_identity_pk,
659  &intro_circ->hs_ident->intro_auth_pk,
660  INTRO_POINT_FAILURE_GENERIC);
661  }
662  /* It is also possible that the rendezvous circuit was closed due to being
663  * unable to use the rendezvous point node_t so in that case, we also want
664  * to recover and let tor pick a new one. */
665  goto tran_err;
666  }
667 
668  /* Cell has been sent successfully. Copy the introduction point
669  * authentication and encryption key in the rendezvous circuit identifier so
670  * we can compute the ntor keys when we receive the RENDEZVOUS2 cell. */
671  memcpy(&rend_circ->hs_ident->intro_enc_pk, &ip->enc_key,
672  sizeof(rend_circ->hs_ident->intro_enc_pk));
674  &intro_circ->hs_ident->intro_auth_pk);
675 
676  /* Now, we wait for an ACK or NAK on this circuit. */
679  /* Set timestamp_dirty, because circuit_expire_building expects it to
680  * specify when a circuit entered the _C_INTRODUCE_ACK_WAIT state. */
681  TO_CIRCUIT(intro_circ)->timestamp_dirty = time(NULL);
682  pathbias_count_use_attempt(intro_circ);
683 
684  /* Success. */
685  status = 0;
686  goto end;
687 
688  perm_err:
689  /* Permanent error: it is possible that the intro circuit was closed prior
690  * because we weren't able to send the cell. Make sure we don't double close
691  * it which would result in a warning. */
692  if (!TO_CIRCUIT(intro_circ)->marked_for_close) {
693  circuit_mark_for_close(TO_CIRCUIT(intro_circ), END_CIRC_REASON_INTERNAL);
694  }
695  circuit_mark_for_close(TO_CIRCUIT(rend_circ), END_CIRC_REASON_INTERNAL);
696  status = -2;
697  goto end;
698 
699  tran_err:
700  status = -1;
701 
702  end:
703  memwipe(onion_address, 0, sizeof(onion_address));
704  return status;
705 }
706 
707 /** Using the introduction circuit circ, setup the authentication key of the
708  * intro point this circuit has extended to.
709  *
710  * Return 0 if everything went well, otherwise return -1 in the case of errors.
711  */
712 static int
714 {
715  const hs_descriptor_t *desc;
716  const hs_desc_intro_point_t *ip;
717 
718  tor_assert(circ);
719 
721  if (desc == NULL) {
722  /* There is a very small race window between the opening of this circuit
723  * and the client descriptor cache that gets purged (NEWNYM) or the
724  * cleaned up because it expired. Mark the circuit for close so a new
725  * descriptor fetch can occur. */
726  goto err;
727  }
728 
729  /* We will go over every intro point and try to find which one is linked to
730  * that circuit. Those lists are small so it's not that expensive. */
732  circ->build_state->chosen_exit->identity_digest, desc);
733  if (!ip) {
734  /* Reaching this point means we didn't find any intro point for this
735  * circuit which is not supposed to happen. */
736  log_info(LD_REND,"Could not match opened intro circuit with intro point.");
737  goto err;
738  }
739 
740  /* We got it, copy its authentication key to the identifier. */
742  &ip->auth_key_cert->signed_key);
743  return 0;
744 
745  err:
746  circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_INTERNAL);
747  return -1;
748 }
749 
750 /** Called when an introduction circuit has opened. */
751 static void
753 {
754  tor_assert(circ);
756  log_info(LD_REND, "Introduction circuit %u has opened. Attaching streams.",
757  (unsigned int) TO_CIRCUIT(circ)->n_circ_id);
758 
759  /* This is an introduction circuit so we'll attach the correct
760  * authentication key to the circuit identifier so it can be identified
761  * properly later on. */
762  if (setup_intro_circ_auth_key(circ) < 0) {
763  return;
764  }
765 
767 }
768 
769 /** Called when a rendezvous circuit has opened. */
770 static void
772 {
773  tor_assert(circ);
775 
776  const extend_info_t *rp_ei = circ->build_state->chosen_exit;
777 
778  /* Check that we didn't accidentally choose a node that does not understand
779  * the v3 rendezvous protocol */
780  if (rp_ei) {
781  const node_t *rp_node = node_get_by_id(rp_ei->identity_digest);
782  if (rp_node && !node_supports_v3_rendezvous_point(rp_node)) {
783  /* Even tho we checked that this node supported v3 when we created the
784  rendezvous circuit, there is a chance that we might think it does
785  not support v3 anymore. This might happen if we got a new consensus
786  in the meanwhile, where the relay is still listed but its listed
787  descriptor digest has changed and hence we can't access its 'ri' or
788  'md'. */
789  log_info(LD_REND, "Rendezvous node %s did not support v3 after circuit "
790  "has opened.", safe_str_client(extend_info_describe(rp_ei)));
791  return;
792  }
793  }
794 
795  log_info(LD_REND, "Rendezvous circuit has opened to %s.",
796  safe_str_client(extend_info_describe(rp_ei)));
797 
798  /* Ignore returned value, nothing we can really do. On failure, the circuit
799  * will be marked for close. */
801 
802  /* Register rend circuit in circuitmap if it's still alive. */
803  if (!TO_CIRCUIT(circ)->marked_for_close) {
805  circ->hs_ident->rendezvous_cookie);
806  }
807 }
808 
809 /** This is an helper function that convert a descriptor intro point object ip
810  * to a newly allocated extend_info_t object fully initialized. Return NULL if
811  * we can't convert it for which chances are that we are missing or malformed
812  * link specifiers. */
815 {
816  extend_info_t *ei;
817 
818  tor_assert(ip);
819 
820  /* Explicitly put the direct connection option to 0 because this is client
821  * side and there is no such thing as a non anonymous client. */
823 
824  return ei;
825 }
826 
827 /** Return true iff the intro point ip for the service service_pk is usable.
828  * This function checks if the intro point is in the client intro state cache
829  * and checks at the failures. It is considered usable if:
830  * - No error happened (INTRO_POINT_FAILURE_GENERIC)
831  * - It is not flagged as timed out (INTRO_POINT_FAILURE_TIMEOUT)
832  * - The unreachable count is lower than
833  * MAX_INTRO_POINT_REACHABILITY_FAILURES (INTRO_POINT_FAILURE_UNREACHABLE)
834  */
835 static int
837  const hs_desc_intro_point_t *ip)
838 {
839  const hs_cache_intro_state_t *state;
840 
841  tor_assert(service_pk);
842  tor_assert(ip);
843 
844  state = hs_cache_client_intro_state_find(service_pk,
845  &ip->auth_key_cert->signed_key);
846  if (state == NULL) {
847  /* This means we've never encountered any problem thus usable. */
848  goto usable;
849  }
850  if (state->error) {
851  log_info(LD_REND, "Intro point with auth key %s had an error. Not usable",
852  safe_str_client(ed25519_fmt(&ip->auth_key_cert->signed_key)));
853  goto not_usable;
854  }
855  if (state->timed_out) {
856  log_info(LD_REND, "Intro point with auth key %s timed out. Not usable",
857  safe_str_client(ed25519_fmt(&ip->auth_key_cert->signed_key)));
858  goto not_usable;
859  }
861  log_info(LD_REND, "Intro point with auth key %s unreachable. Not usable",
862  safe_str_client(ed25519_fmt(&ip->auth_key_cert->signed_key)));
863  goto not_usable;
864  }
865 
866  usable:
867  return 1;
868  not_usable:
869  return 0;
870 }
871 
872 /** Using a descriptor desc, return a newly allocated extend_info_t object of a
873  * randomly picked introduction point from its list. Return NULL if none are
874  * usable. */
877 {
878  extend_info_t *ei = NULL, *ei_excluded = NULL;
879  smartlist_t *usable_ips = NULL;
880  const hs_descriptor_t *desc;
881  const hs_desc_encrypted_data_t *enc_data;
882  const or_options_t *options = get_options();
883  /* Calculate the onion address for logging purposes */
884  char onion_address[HS_SERVICE_ADDR_LEN_BASE32 + 1];
885 
886  tor_assert(service_pk);
887 
888  desc = hs_cache_lookup_as_client(service_pk);
889  /* Assume the service is v3 if the descriptor is missing. This is ok,
890  * because we only use the address in log messages */
891  hs_build_address(service_pk,
892  desc ? desc->plaintext_data.version : HS_VERSION_THREE,
893  onion_address);
894  if (desc == NULL || !hs_client_any_intro_points_usable(service_pk,
895  desc)) {
896  log_info(LD_REND, "Unable to randomly select an introduction point "
897  "for service %s because descriptor %s. We can't connect.",
898  safe_str_client(onion_address),
899  (desc) ? "doesn't have any usable intro points"
900  : "is missing (assuming v3 onion address)");
901  goto end;
902  }
903 
904  enc_data = &desc->encrypted_data;
905  usable_ips = smartlist_new();
906  smartlist_add_all(usable_ips, enc_data->intro_points);
907  while (smartlist_len(usable_ips) != 0) {
908  int idx;
909  const hs_desc_intro_point_t *ip;
910 
911  /* Pick a random intro point and immediately remove it from the usable
912  * list so we don't pick it again if we have to iterate more. */
913  idx = crypto_rand_int(smartlist_len(usable_ips));
914  ip = smartlist_get(usable_ips, idx);
915  smartlist_del(usable_ips, idx);
916 
917  /* We need to make sure we have a usable intro points which is in a good
918  * state in our cache. */
919  if (!intro_point_is_usable(service_pk, ip)) {
920  continue;
921  }
922 
923  /* Generate an extend info object from the intro point object. */
925  if (ei == NULL) {
926  /* We can get here for instance if the intro point is a private address
927  * and we aren't allowed to extend to those. */
928  log_info(LD_REND, "Unable to select introduction point with auth key %s "
929  "for service %s, because we could not extend to it.",
930  safe_str_client(ed25519_fmt(&ip->auth_key_cert->signed_key)),
931  safe_str_client(onion_address));
932  continue;
933  }
934 
935  /* Test the pick against ExcludeNodes. */
936  if (routerset_contains_extendinfo(options->ExcludeNodes, ei)) {
937  /* If this pick is in the ExcludeNodes list, we keep its reference so if
938  * we ever end up not being able to pick anything else and StrictNodes is
939  * unset, we'll use it. */
940  if (ei_excluded) {
941  /* If something was already here free it. After the loop is gone we
942  * will examine the last excluded intro point, and that's fine since
943  * that's random anyway */
944  extend_info_free(ei_excluded);
945  }
946  ei_excluded = ei;
947  continue;
948  }
949 
950  /* Good pick! Let's go with this. */
951  goto end;
952  }
953 
954  /* Reaching this point means a couple of things. Either we can't use any of
955  * the intro point listed because the IP address can't be extended to or it
956  * is listed in the ExcludeNodes list. In the later case, if StrictNodes is
957  * set, we are forced to not use anything. */
958  ei = ei_excluded;
959  if (options->StrictNodes) {
960  log_warn(LD_REND, "Every introduction point for service %s is in the "
961  "ExcludeNodes set and StrictNodes is set. We can't connect.",
962  safe_str_client(onion_address));
963  extend_info_free(ei);
964  ei = NULL;
965  } else {
966  log_fn(LOG_PROTOCOL_WARN, LD_REND, "Every introduction point for service "
967  "%s is unusable or we can't extend to it. We can't connect.",
968  safe_str_client(onion_address));
969  }
970 
971  end:
972  smartlist_free(usable_ips);
973  memwipe(onion_address, 0, sizeof(onion_address));
974  return ei;
975 }
976 
977 /** Return true iff all intro points for the given service have timed out. */
978 static bool
980 {
981  bool ret = false;
982 
983  tor_assert(service_pk);
984 
985  const hs_descriptor_t *desc = hs_cache_lookup_as_client(service_pk);
986  if (BUG(!desc)) {
987  /* We can't introduce without a descriptor so ending up here means somehow
988  * between the introduction failure and this, the cache entry was removed
989  * which shouldn't be possible in theory. */
990  goto end;
991  }
992 
994  const hs_desc_intro_point_t *, ip) {
995  const hs_cache_intro_state_t *state =
997  &ip->auth_key_cert->signed_key);
998  if (!state || !state->timed_out) {
999  /* No state or if this intro point has not timed out, we are done since
1000  * clearly not all of them have timed out. */
1001  goto end;
1002  }
1003  } SMARTLIST_FOREACH_END(ip);
1004 
1005  /* Exiting the loop here means that all intro points we've looked at have
1006  * timed out. Note that we can _not_ have a descriptor without intro points
1007  * in the client cache. */
1008  ret = true;
1009 
1010  end:
1011  return ret;
1012 }
1013 
1014 /** Called when a rendezvous circuit has timed out. Every stream attached to
1015  * the circuit will get set with the SOCKS5_HS_REND_FAILED (0xF3) extended
1016  * error code so if the connection to the rendezvous point ends up not
1017  * working, this code could be sent back as a reason. */
1018 static void
1020 {
1021  tor_assert(rend_circ);
1022 
1023  /* For each entry connection attached to this rendezvous circuit, report
1024  * the error. */
1025  for (edge_connection_t *edge = rend_circ->p_streams; edge;
1026  edge = edge->next_stream) {
1027  entry_connection_t *entry = EDGE_TO_ENTRY_CONN(edge);
1028  if (entry->socks_request) {
1030  SOCKS5_HS_REND_FAILED;
1031  }
1032  }
1033 }
1034 
1035 /** Called when introduction has failed meaning there is no more usable
1036  * introduction points to be used (either NACKed or failed) for the given
1037  * entry connection.
1038  *
1039  * This function only reports back the SOCKS5_HS_INTRO_FAILED (0xF2) code or
1040  * SOCKS5_HS_INTRO_TIMEDOUT (0xF7) if all intros have timed out. The caller
1041  * has to make sure to close the entry connections. */
1042 static void
1044  const ed25519_public_key_t *identity_pk)
1045 {
1046  socks5_reply_status_t code = SOCKS5_HS_INTRO_FAILED;
1047 
1048  tor_assert(conn);
1049  tor_assert(conn->socks_request);
1050  tor_assert(identity_pk);
1051 
1052  if (intro_points_all_timed_out(identity_pk)) {
1053  code = SOCKS5_HS_INTRO_TIMEDOUT;
1054  }
1056 }
1057 
1058 /** For this introduction circuit, we'll look at if we have any usable
1059  * introduction point left for this service. If so, we'll use the circuit to
1060  * re-extend to a new intro point. Else, we'll close the circuit and its
1061  * corresponding rendezvous circuit. Return 0 if we are re-extending else -1
1062  * if we are closing the circuits.
1063  *
1064  * This is called when getting an INTRODUCE_ACK cell with a NACK. */
1065 static int
1067 {
1068  int ret = -1;
1069  const hs_descriptor_t *desc;
1070  origin_circuit_t *rend_circ;
1071 
1072  tor_assert(intro_circ);
1073 
1074  desc = hs_cache_lookup_as_client(&intro_circ->hs_ident->identity_pk);
1075  if (desc == NULL) {
1076  /* We can't continue without a descriptor. This is possible if the cache
1077  * was cleaned up between the intro point established and the reception of
1078  * the introduce ack. */
1079  goto close;
1080  }
1081  /* We still have the descriptor, great! Let's try to see if we can
1082  * re-extend by looking up if there are any usable intro points. */
1084  desc)) {
1085  goto close;
1086  }
1087  /* Try to re-extend now. */
1088  if (hs_client_reextend_intro_circuit(intro_circ) < 0) {
1089  goto close;
1090  }
1091  /* Success on re-extending. Don't return an error. */
1092  ret = 0;
1093  goto end;
1094 
1095  close:
1096  /* Change the intro circuit purpose before so we don't report an intro point
1097  * failure again triggering an extra descriptor fetch. The circuit can
1098  * already be closed on failure to re-extend. */
1099  if (!TO_CIRCUIT(intro_circ)->marked_for_close) {
1100  circuit_change_purpose(TO_CIRCUIT(intro_circ),
1102  circuit_mark_for_close(TO_CIRCUIT(intro_circ), END_CIRC_REASON_FINISHED);
1103  }
1104  /* Close the related rendezvous circuit. */
1106  intro_circ->hs_ident->rendezvous_cookie);
1107  /* The rendezvous circuit might have collapsed while the INTRODUCE_ACK was
1108  * inflight so we can't expect one every time. */
1109  if (rend_circ) {
1110  circuit_mark_for_close(TO_CIRCUIT(rend_circ), END_CIRC_REASON_FINISHED);
1111  }
1112 
1113  end:
1114  return ret;
1115 }
1116 
1117 /** Called when we get an INTRODUCE_ACK success status code. Do the appropriate
1118  * actions for the rendezvous point and finally close intro_circ. */
1119 static void
1121 {
1122  origin_circuit_t *rend_circ = NULL;
1123 
1124  tor_assert(intro_circ);
1125 
1126  log_info(LD_REND, "Received INTRODUCE_ACK ack! Informing rendezvous");
1127 
1128  /* Get the rendezvous circuit for this rendezvous cookie. */
1129  uint8_t *rendezvous_cookie = intro_circ->hs_ident->rendezvous_cookie;
1130  rend_circ =
1132  if (rend_circ == NULL) {
1133  log_warn(LD_REND, "Can't find any rendezvous circuit. Stopping");
1134  goto end;
1135  }
1136 
1137  assert_circ_anonymity_ok(rend_circ, get_options());
1138 
1139  /* It is possible to get a RENDEZVOUS2 cell before the INTRODUCE_ACK which
1140  * means that the circuit will be joined and already transmitting data. In
1141  * that case, simply skip the purpose change and close the intro circuit
1142  * like it should be. */
1143  if (TO_CIRCUIT(rend_circ)->purpose == CIRCUIT_PURPOSE_C_REND_JOINED) {
1144  goto end;
1145  }
1148  /* Set timestamp_dirty, because circuit_expire_building expects it to
1149  * specify when a circuit entered the
1150  * CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED state. */
1151  TO_CIRCUIT(rend_circ)->timestamp_dirty = time(NULL);
1152 
1153  end:
1154  /* We don't need the intro circuit anymore. It did what it had to do! */
1155  circuit_change_purpose(TO_CIRCUIT(intro_circ),
1157  circuit_mark_for_close(TO_CIRCUIT(intro_circ), END_CIRC_REASON_FINISHED);
1158 
1159  /* XXX: Close pending intro circuits we might have in parallel. */
1160  return;
1161 }
1162 
1163 /** Called when we get an INTRODUCE_ACK failure status code. Depending on our
1164  * failure cache status, either close the circuit or re-extend to a new
1165  * introduction point. */
1166 static void
1168 {
1169  tor_assert(circ);
1170 
1171  log_info(LD_REND, "Received INTRODUCE_ACK nack by %s. Reason: %u",
1172  safe_str_client(extend_info_describe(circ->build_state->chosen_exit)),
1173  status);
1174 
1175  /* It's a NAK. The introduction point didn't relay our request. */
1177 
1178  /* Note down this failure in the intro point failure cache. Depending on how
1179  * many times we've tried this intro point, close it or reextend. */
1181  &circ->hs_ident->intro_auth_pk,
1182  INTRO_POINT_FAILURE_GENERIC);
1183 }
1184 
1185 /** Called when we get an INTRODUCE_ACK on the intro circuit circ. The encoded
1186  * cell is in payload of length payload_len. Return 0 on success else a
1187  * negative value. The circuit is either close or reuse to re-extend to a new
1188  * introduction point. */
1189 static int
1190 handle_introduce_ack(origin_circuit_t *circ, const uint8_t *payload,
1191  size_t payload_len)
1192 {
1193  int status, ret = -1;
1194 
1195  tor_assert(circ);
1196  tor_assert(circ->build_state);
1198  assert_circ_anonymity_ok(circ, get_options());
1199  tor_assert(payload);
1200 
1201  status = hs_cell_parse_introduce_ack(payload, payload_len);
1202  switch (status) {
1203  case TRUNNEL_HS_INTRO_ACK_STATUS_SUCCESS:
1204  ret = 0;
1206  goto end;
1207  case TRUNNEL_HS_INTRO_ACK_STATUS_UNKNOWN_ID:
1208  case TRUNNEL_HS_INTRO_ACK_STATUS_BAD_FORMAT:
1209  /* It is possible that the intro point can send us an unknown status code
1210  * for the NACK that we do not know about like a new code for instance.
1211  * Just fallthrough so we can note down the NACK and re-extend. */
1212  default:
1213  handle_introduce_ack_bad(circ, status);
1214  /* We are going to see if we have to close the circuits (IP and RP) or we
1215  * can re-extend to a new intro point. */
1216  ret = close_or_reextend_intro_circ(circ);
1217  break;
1218  }
1219 
1220  end:
1221  return ret;
1222 }
1223 
1224 /** Called when we get a RENDEZVOUS2 cell on the rendezvous circuit circ. The
1225  * encoded cell is in payload of length payload_len. Return 0 on success or a
1226  * negative value on error. On error, the circuit is marked for close. */
1227 STATIC int
1228 handle_rendezvous2(origin_circuit_t *circ, const uint8_t *payload,
1229  size_t payload_len)
1230 {
1231  int ret = -1;
1232  curve25519_public_key_t server_pk;
1233  uint8_t auth_mac[DIGEST256_LEN] = {0};
1234  uint8_t handshake_info[CURVE25519_PUBKEY_LEN + sizeof(auth_mac)] = {0};
1236  const hs_ident_circuit_t *ident;
1237 
1238  tor_assert(circ);
1239  tor_assert(payload);
1240 
1241  /* Make things easier. */
1242  ident = circ->hs_ident;
1243  tor_assert(ident);
1244 
1245  if (hs_cell_parse_rendezvous2(payload, payload_len, handshake_info,
1246  sizeof(handshake_info)) < 0) {
1247  goto err;
1248  }
1249  /* Get from the handshake info the SERVER_PK and AUTH_MAC. */
1250  memcpy(&server_pk, handshake_info, CURVE25519_PUBKEY_LEN);
1251  memcpy(auth_mac, handshake_info + CURVE25519_PUBKEY_LEN, sizeof(auth_mac));
1252 
1253  /* Generate the handshake info. */
1254  if (hs_ntor_client_get_rendezvous1_keys(&ident->intro_auth_pk,
1255  &ident->rendezvous_client_kp,
1256  &ident->intro_enc_pk, &server_pk,
1257  &keys) < 0) {
1258  log_info(LD_REND, "Unable to compute the rendezvous keys.");
1259  goto err;
1260  }
1261 
1262  /* Critical check, make sure that the MAC matches what we got with what we
1263  * computed just above. */
1264  if (!hs_ntor_client_rendezvous2_mac_is_good(&keys, auth_mac)) {
1265  log_info(LD_REND, "Invalid MAC in RENDEZVOUS2. Rejecting cell.");
1266  goto err;
1267  }
1268 
1269  /* Setup the e2e encryption on the circuit and finalize its state. */
1270  if (hs_circuit_setup_e2e_rend_circ(circ, keys.ntor_key_seed,
1271  sizeof(keys.ntor_key_seed), 0) < 0) {
1272  log_info(LD_REND, "Unable to setup the e2e encryption.");
1273  goto err;
1274  }
1275  /* Success. Hidden service connection finalized! */
1276  ret = 0;
1277  goto end;
1278 
1279  err:
1280  circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_TORPROTOCOL);
1281  end:
1282  memwipe(&keys, 0, sizeof(keys));
1283  return ret;
1284 }
1285 
1286 /** Return true iff the client can fetch a descriptor for this service public
1287  * identity key and status_out if not NULL is untouched. If the client can
1288  * _not_ fetch the descriptor and if status_out is not NULL, it is set with
1289  * the fetch status code. */
1290 static unsigned int
1292  hs_client_fetch_status_t *status_out)
1293 {
1294  hs_client_fetch_status_t status;
1295 
1296  tor_assert(identity_pk);
1297 
1298  /* Are we configured to fetch descriptors? */
1299  if (!get_options()->FetchHidServDescriptors) {
1300  log_warn(LD_REND, "We received an onion address for a hidden service "
1301  "descriptor but we are configured to not fetch.");
1302  status = HS_CLIENT_FETCH_NOT_ALLOWED;
1303  goto cannot;
1304  }
1305 
1306  /* Without a live consensus we can't do any client actions. It is needed to
1307  * compute the hashring for a service. */
1309  log_info(LD_REND, "Can't fetch descriptor for service %s because we "
1310  "are missing a live consensus. Stalling connection.",
1311  safe_str_client(ed25519_fmt(identity_pk)));
1313  goto cannot;
1314  }
1315 
1317  log_info(LD_REND, "Can't fetch descriptor for service %s because we "
1318  "dont have enough descriptors. Stalling connection.",
1319  safe_str_client(ed25519_fmt(identity_pk)));
1321  goto cannot;
1322  }
1323 
1324  /* Check if fetching a desc for this HS is useful to us right now */
1325  {
1326  const hs_descriptor_t *cached_desc = NULL;
1327  cached_desc = hs_cache_lookup_as_client(identity_pk);
1328  if (cached_desc && hs_client_any_intro_points_usable(identity_pk,
1329  cached_desc)) {
1330  log_info(LD_GENERAL, "We would fetch a v3 hidden service descriptor "
1331  "but we already have a usable descriptor.");
1332  status = HS_CLIENT_FETCH_HAVE_DESC;
1333  goto cannot;
1334  }
1335  }
1336 
1337  /* Don't try to refetch while we have a pending request for it. */
1338  if (directory_request_is_pending(identity_pk)) {
1339  log_info(LD_REND, "Already a pending directory request. Waiting on it.");
1340  status = HS_CLIENT_FETCH_PENDING;
1341  goto cannot;
1342  }
1343 
1344  /* Yes, client can fetch! */
1345  return 1;
1346  cannot:
1347  if (status_out) {
1348  *status_out = status;
1349  }
1350  return 0;
1351 }
1352 
1353 /** Purge the client authorization cache of all ephemeral entries that is the
1354  * entries that are not flagged with CLIENT_AUTH_FLAG_IS_PERMANENT.
1355  *
1356  * This is called from the hs_client_purge_state() used by a SIGNEWNYM. */
1357 STATIC void
1359 {
1360  DIGEST256MAP_FOREACH_MODIFY(client_auths, key,
1362  /* Cleanup every entry that are _NOT_ permanent that is ephemeral. */
1363  if (!(auth->flags & CLIENT_AUTH_FLAG_IS_PERMANENT)) {
1364  MAP_DEL_CURRENT(key);
1365  client_service_authorization_free(auth);
1366  }
1368 
1369  log_info(LD_REND, "Client onion service ephemeral authorization "
1370  "cache has been purged.");
1371 }
1372 
1373 /** Return the client auth in the map using the service identity public key.
1374  * Return NULL if it does not exist in the map. */
1376 find_client_auth(const ed25519_public_key_t *service_identity_pk)
1377 {
1378  /* If the map is not allocated, we can assume that we do not have any client
1379  * auth information. */
1380  if (!client_auths) {
1381  return NULL;
1382  }
1383  return digest256map_get(client_auths, service_identity_pk->pubkey);
1384 }
1385 
1386 /** This is called when a descriptor has arrived following a fetch request and
1387  * has been stored in the client cache. The given entry connections, matching
1388  * the service identity key, will get attached to the service circuit. */
1389 static void
1391 {
1392  time_t now = time(NULL);
1393 
1394  tor_assert(entry_conns);
1395 
1396  SMARTLIST_FOREACH_BEGIN(entry_conns, entry_connection_t *, entry_conn) {
1397  const hs_descriptor_t *desc;
1398  edge_connection_t *edge_conn = ENTRY_TO_EDGE_CONN(entry_conn);
1399  const ed25519_public_key_t *identity_pk =
1400  &edge_conn->hs_ident->identity_pk;
1401 
1402  /* We were just called because we stored the descriptor for this service
1403  * so not finding a descriptor means we have a bigger problem. */
1404  desc = hs_cache_lookup_as_client(identity_pk);
1405  if (BUG(desc == NULL)) {
1406  goto end;
1407  }
1408 
1409  if (!hs_client_any_intro_points_usable(identity_pk, desc)) {
1410  log_info(LD_REND, "Hidden service descriptor is unusable. "
1411  "Closing streams.");
1412  /* Report the extended socks error code that we were unable to introduce
1413  * to the service. */
1414  socks_mark_introduction_failed(entry_conn, identity_pk);
1415 
1416  connection_mark_unattached_ap(entry_conn,
1417  END_STREAM_REASON_RESOLVEFAILED);
1418  /* We are unable to use the descriptor so remove the directory request
1419  * from the cache so the next connection can try again. */
1420  note_connection_attempt_succeeded(edge_conn->hs_ident);
1421  continue;
1422  }
1423 
1424  log_info(LD_REND, "Descriptor has arrived. Launching circuits.");
1425 
1426  /* Mark connection as waiting for a circuit since we do have a usable
1427  * descriptor now. */
1428  mark_conn_as_waiting_for_circuit(&edge_conn->base_, now);
1429  } SMARTLIST_FOREACH_END(entry_conn);
1430 
1431  end:
1432  return;
1433 }
1434 
1435 /** This is called when a descriptor fetch was successful but the descriptor
1436  * couldn't be decrypted due to missing or bad client authorization. */
1437 static void
1439  hs_desc_decode_status_t status)
1440 {
1441  tor_assert(entry_conns);
1442 
1443  SMARTLIST_FOREACH_BEGIN(entry_conns, entry_connection_t *, entry_conn) {
1444  socks5_reply_status_t code;
1445  if (status == HS_DESC_DECODE_BAD_CLIENT_AUTH) {
1446  code = SOCKS5_HS_BAD_CLIENT_AUTH;
1447  } else if (status == HS_DESC_DECODE_NEED_CLIENT_AUTH) {
1448  code = SOCKS5_HS_MISSING_CLIENT_AUTH;
1449  } else {
1450  /* We should not be called with another type of status. Recover by
1451  * sending a generic error. */
1453  code = SOCKS5_GENERAL_ERROR;
1454  }
1455  entry_conn->socks_request->socks_extended_error_code = code;
1456  connection_mark_unattached_ap(entry_conn, END_STREAM_REASON_MISC);
1457  } SMARTLIST_FOREACH_END(entry_conn);
1458 }
1459 
1460 /** Called when we get a 200 directory fetch status code. */
1461 static void
1463  const smartlist_t *entry_conns, const char *body)
1464 {
1465  hs_desc_decode_status_t decode_status;
1466 
1467  tor_assert(dir_conn);
1468  tor_assert(entry_conns);
1469  tor_assert(body);
1470 
1471  /* We got something: Try storing it in the cache. */
1472  decode_status = hs_cache_store_as_client(body,
1473  &dir_conn->hs_ident->identity_pk);
1474  switch (decode_status) {
1475  case HS_DESC_DECODE_OK:
1476  case HS_DESC_DECODE_NEED_CLIENT_AUTH:
1477  case HS_DESC_DECODE_BAD_CLIENT_AUTH:
1478  log_info(LD_REND, "Stored hidden service descriptor successfully.");
1479  TO_CONN(dir_conn)->purpose = DIR_PURPOSE_HAS_FETCHED_HSDESC;
1480  if (decode_status == HS_DESC_DECODE_OK) {
1481  client_desc_has_arrived(entry_conns);
1482  } else {
1483  /* This handles both client auth decode status. */
1484  client_desc_missing_bad_client_auth(entry_conns, decode_status);
1485  log_info(LD_REND, "Stored hidden service descriptor requires "
1486  "%s client authorization.",
1487  decode_status == HS_DESC_DECODE_NEED_CLIENT_AUTH ? "missing"
1488  : "new");
1489  }
1490  /* Fire control port RECEIVED event. */
1491  hs_control_desc_event_received(dir_conn->hs_ident,
1492  dir_conn->identity_digest);
1493  hs_control_desc_event_content(dir_conn->hs_ident,
1494  dir_conn->identity_digest, body);
1495  break;
1496  case HS_DESC_DECODE_ENCRYPTED_ERROR:
1497  case HS_DESC_DECODE_SUPERENC_ERROR:
1498  case HS_DESC_DECODE_PLAINTEXT_ERROR:
1499  case HS_DESC_DECODE_GENERIC_ERROR:
1500  default:
1501  log_info(LD_REND, "Failed to store hidden service descriptor. "
1502  "Descriptor decoding status: %d", decode_status);
1503  /* Fire control port FAILED event. */
1504  hs_control_desc_event_failed(dir_conn->hs_ident,
1505  dir_conn->identity_digest, "BAD_DESC");
1506  hs_control_desc_event_content(dir_conn->hs_ident,
1507  dir_conn->identity_digest, NULL);
1508  break;
1509  }
1510 }
1511 
1512 /** Called when we get a 404 directory fetch status code. */
1513 static void
1515  const smartlist_t *entry_conns)
1516 {
1517  tor_assert(entry_conns);
1518 
1519  /* Not there. We'll retry when connection_about_to_close_connection() tries
1520  * to clean this conn up. */
1521  log_info(LD_REND, "Fetching hidden service v3 descriptor not found: "
1522  "Retrying at another directory.");
1523  /* Fire control port FAILED event. */
1524  hs_control_desc_event_failed(dir_conn->hs_ident, dir_conn->identity_digest,
1525  "NOT_FOUND");
1526  hs_control_desc_event_content(dir_conn->hs_ident, dir_conn->identity_digest,
1527  NULL);
1528 
1529  /* Flag every entry connections that the descriptor was not found. */
1530  SMARTLIST_FOREACH_BEGIN(entry_conns, entry_connection_t *, entry_conn) {
1532  SOCKS5_HS_NOT_FOUND;
1533  } SMARTLIST_FOREACH_END(entry_conn);
1534 }
1535 
1536 /** Called when we get a 400 directory fetch status code. */
1537 static void
1538 client_dir_fetch_400(dir_connection_t *dir_conn, const char *reason)
1539 {
1540  tor_assert(dir_conn);
1541 
1542  log_warn(LD_REND, "Fetching v3 hidden service descriptor failed: "
1543  "http status 400 (%s). Dirserver didn't like our "
1544  "query? Retrying at another directory.",
1545  escaped(reason));
1546 
1547  /* Fire control port FAILED event. */
1548  hs_control_desc_event_failed(dir_conn->hs_ident, dir_conn->identity_digest,
1549  "QUERY_REJECTED");
1550  hs_control_desc_event_content(dir_conn->hs_ident, dir_conn->identity_digest,
1551  NULL);
1552 }
1553 
1554 /** Called when we get an unexpected directory fetch status code. */
1555 static void
1556 client_dir_fetch_unexpected(dir_connection_t *dir_conn, const char *reason,
1557  const int status_code)
1558 {
1559  tor_assert(dir_conn);
1560 
1561  log_warn(LD_REND, "Fetching v3 hidden service descriptor failed: "
1562  "http status %d (%s) response unexpected from HSDir "
1563  "server %s'. Retrying at another directory.",
1564  status_code, escaped(reason),
1565  connection_describe_peer(TO_CONN(dir_conn)));
1566  /* Fire control port FAILED event. */
1567  hs_control_desc_event_failed(dir_conn->hs_ident, dir_conn->identity_digest,
1568  "UNEXPECTED");
1569  hs_control_desc_event_content(dir_conn->hs_ident, dir_conn->identity_digest,
1570  NULL);
1571 }
1572 
1573 /** Get the full filename for storing the client auth credentials for the
1574  * service in <b>onion_address</b>. The base directory is <b>dir</b>.
1575  * This function never returns NULL. */
1576 static char *
1577 get_client_auth_creds_filename(const char *onion_address,
1578  const char *dir)
1579 {
1580  char *full_fname = NULL;
1581  char *fname;
1582 
1583  tor_asprintf(&fname, "%s.auth_private", onion_address);
1584  full_fname = hs_path_from_filename(dir, fname);
1585  tor_free(fname);
1586 
1587  return full_fname;
1588 }
1589 
1590 /** Permanently store the credentials in <b>creds</b> to disk.
1591  *
1592  * Return -1 if there was an error while storing the credentials, otherwise
1593  * return 0.
1594  */
1595 static int
1597  const hs_client_service_authorization_t *creds)
1598 {
1599  const or_options_t *options = get_options();
1600  char *full_fname = NULL;
1601  char *file_contents = NULL;
1602  char priv_key_b32[BASE32_NOPAD_LEN(CURVE25519_PUBKEY_LEN)+1];
1603  int retval = -1;
1604 
1605  tor_assert(creds->flags & CLIENT_AUTH_FLAG_IS_PERMANENT);
1606 
1607  /* We need ClientOnionAuthDir to be set, otherwise we can't proceed */
1608  if (!options->ClientOnionAuthDir) {
1609  log_warn(LD_GENERAL, "Can't register permanent client auth credentials "
1610  "for %s without ClientOnionAuthDir option. Discarding.",
1611  creds->onion_address);
1612  goto err;
1613  }
1614 
1615  /* Make sure the directory exists and is private enough. */
1616  if (check_private_dir(options->ClientOnionAuthDir, 0, options->User) < 0) {
1617  goto err;
1618  }
1619 
1620  /* Get filename that we should store the credentials */
1621  full_fname = get_client_auth_creds_filename(creds->onion_address,
1622  options->ClientOnionAuthDir);
1623 
1624  /* Encode client private key */
1625  base32_encode(priv_key_b32, sizeof(priv_key_b32),
1626  (char*)creds->enc_seckey.secret_key,
1627  sizeof(creds->enc_seckey.secret_key));
1628 
1629  /* Get the full file contents and write it to disk! */
1630  tor_asprintf(&file_contents, "%s:descriptor:x25519:%s",
1631  creds->onion_address, priv_key_b32);
1632  if (write_str_to_file(full_fname, file_contents, 0) < 0) {
1633  log_warn(LD_GENERAL, "Failed to write client auth creds file for %s!",
1634  creds->onion_address);
1635  goto err;
1636  }
1637 
1638  retval = 0;
1639 
1640  err:
1641  tor_free(file_contents);
1642  tor_free(full_fname);
1643 
1644  return retval;
1645 }
1646 
1647 /** Register the credential <b>creds</b> as part of the client auth subsystem.
1648  *
1649  * Takes ownership of <b>creds</b>.
1650  **/
1651 hs_client_register_auth_status_t
1653 {
1654  ed25519_public_key_t service_identity_pk;
1655  hs_client_service_authorization_t *old_creds = NULL;
1656  hs_client_register_auth_status_t retval = REGISTER_SUCCESS;
1657 
1658  tor_assert(creds);
1659 
1660  if (!client_auths) {
1661  client_auths = digest256map_new();
1662  }
1663 
1664  if (hs_parse_address(creds->onion_address, &service_identity_pk,
1665  NULL, NULL) < 0) {
1666  client_service_authorization_free(creds);
1667  return REGISTER_FAIL_BAD_ADDRESS;
1668  }
1669 
1670  /* If we reach this point, the credentials will be stored one way or another:
1671  * Make them permanent if the user asked us to. */
1672  if (creds->flags & CLIENT_AUTH_FLAG_IS_PERMANENT) {
1673  if (store_permanent_client_auth_credentials(creds) < 0) {
1674  client_service_authorization_free(creds);
1675  return REGISTER_FAIL_PERMANENT_STORAGE;
1676  }
1677  }
1678 
1679  old_creds = digest256map_get(client_auths, service_identity_pk.pubkey);
1680  if (old_creds) {
1681  digest256map_remove(client_auths, service_identity_pk.pubkey);
1682  client_service_authorization_free(old_creds);
1683  retval = REGISTER_SUCCESS_ALREADY_EXISTS;
1684  }
1685 
1686  digest256map_set(client_auths, service_identity_pk.pubkey, creds);
1687 
1688  /** Now that we set the new credentials, also try to decrypt any cached
1689  * descriptors. */
1690  if (hs_cache_client_new_auth_parse(&service_identity_pk)) {
1691  retval = REGISTER_SUCCESS_AND_DECRYPTED;
1692  }
1693 
1694  return retval;
1695 }
1696 
1697 /** Load a client authorization file with <b>filename</b> that is stored under
1698  * the global client auth directory, and return a newly-allocated credentials
1699  * object if it parsed well. Otherwise, return NULL.
1700  */
1703  const or_options_t *options)
1704 {
1705  hs_client_service_authorization_t *auth = NULL;
1706  char *client_key_file_path = NULL;
1707  char *client_key_str = NULL;
1708 
1709  log_info(LD_REND, "Loading a client authorization key file %s...",
1710  filename);
1711 
1712  if (!auth_key_filename_is_valid(filename)) {
1713  log_notice(LD_REND, "Client authorization unrecognized filename %s. "
1714  "File must end in .auth_private. Ignoring.",
1715  filename);
1716  goto err;
1717  }
1718 
1719  /* Create a full path for a file. */
1720  client_key_file_path = hs_path_from_filename(options->ClientOnionAuthDir,
1721  filename);
1722 
1723  client_key_str = read_file_to_str(client_key_file_path, 0, NULL);
1724  if (!client_key_str) {
1725  log_warn(LD_REND, "The file %s cannot be read.", filename);
1726  goto err;
1727  }
1728 
1729  auth = parse_auth_file_content(client_key_str);
1730  if (!auth) {
1731  goto err;
1732  }
1733 
1734  err:
1735  tor_free(client_key_str);
1736  tor_free(client_key_file_path);
1737 
1738  return auth;
1739 }
1740 
1741 /*
1742  * Remove the file in <b>filename</b> under the global client auth credential
1743  * storage.
1744  */
1745 static void
1746 remove_client_auth_creds_file(const char *filename)
1747 {
1748  char *creds_file_path = NULL;
1749  const or_options_t *options = get_options();
1750 
1751  creds_file_path = hs_path_from_filename(options->ClientOnionAuthDir,
1752  filename);
1753  if (tor_unlink(creds_file_path) != 0) {
1754  log_warn(LD_REND, "Failed to remove client auth file (%s).",
1755  creds_file_path);
1756  goto end;
1757  }
1758 
1759  log_warn(LD_REND, "Successfully removed client auth file (%s).",
1760  creds_file_path);
1761 
1762  end:
1763  tor_free(creds_file_path);
1764 }
1765 
1766 /**
1767  * Find the filesystem file corresponding to the permanent client auth
1768  * credentials in <b>cred</b> and remove it.
1769  */
1770 static void
1773 {
1774  smartlist_t *file_list = NULL;
1775  const or_options_t *options = get_options();
1776 
1778 
1779  if (!options->ClientOnionAuthDir) {
1780  log_warn(LD_REND, "Found permanent credential but no ClientOnionAuthDir "
1781  "configured. There is no file to be removed.");
1782  goto end;
1783  }
1784 
1785  file_list = tor_listdir(options->ClientOnionAuthDir);
1786  if (file_list == NULL) {
1787  log_warn(LD_REND, "Client authorization key directory %s can't be listed.",
1788  options->ClientOnionAuthDir);
1789  goto end;
1790  }
1791 
1792  SMARTLIST_FOREACH_BEGIN(file_list, const char *, filename) {
1793  hs_client_service_authorization_t *tmp_cred = NULL;
1794 
1795  tmp_cred = get_creds_from_client_auth_filename(filename, options);
1796  if (!tmp_cred) {
1797  continue;
1798  }
1799 
1800  /* Find the right file for this credential */
1801  if (!strcmp(tmp_cred->onion_address, cred->onion_address)) {
1802  /* Found it! Remove the file! */
1803  remove_client_auth_creds_file(filename);
1804  /* cleanup and get out of here */
1805  client_service_authorization_free(tmp_cred);
1806  break;
1807  }
1808 
1809  client_service_authorization_free(tmp_cred);
1810  } SMARTLIST_FOREACH_END(filename);
1811 
1812  end:
1813  if (file_list) {
1814  SMARTLIST_FOREACH(file_list, char *, s, tor_free(s));
1815  smartlist_free(file_list);
1816  }
1817 }
1818 
1819 /** Remove client auth credentials for the service <b>hs_address</b>. */
1820 hs_client_removal_auth_status_t
1822 {
1823  ed25519_public_key_t service_identity_pk;
1824 
1825  if (!client_auths) {
1826  return REMOVAL_SUCCESS_NOT_FOUND;
1827  }
1828 
1829  if (hs_parse_address(hsaddress, &service_identity_pk, NULL, NULL) < 0) {
1830  return REMOVAL_BAD_ADDRESS;
1831  }
1832 
1833  hs_client_service_authorization_t *cred = NULL;
1834  cred = digest256map_remove(client_auths, service_identity_pk.pubkey);
1835 
1836  /* digestmap_remove() returns the previously stored data if there were any */
1837  if (cred) {
1838  if (cred->flags & CLIENT_AUTH_FLAG_IS_PERMANENT) {
1839  /* These creds are stored on disk: remove the corresponding file. */
1841  }
1842 
1843  /* Remove associated descriptor if any. */
1844  hs_cache_remove_as_client(&service_identity_pk);
1845 
1846  client_service_authorization_free(cred);
1847  return REMOVAL_SUCCESS;
1848  }
1849 
1850  return REMOVAL_SUCCESS_NOT_FOUND;
1851 }
1852 
1853 /** Get the HS client auth map. */
1854 digest256map_t *
1856 {
1857  return client_auths;
1858 }
1859 
1860 /* ========== */
1861 /* Public API */
1862 /* ========== */
1863 
1864 /** Called when a circuit was just cleaned up. This is done right before the
1865  * circuit is marked for close. */
1866 void
1868 {
1869  bool has_timed_out;
1870 
1871  tor_assert(circ);
1873 
1874  has_timed_out =
1875  (circ->marked_for_close_orig_reason == END_CIRC_REASON_TIMEOUT);
1876 
1877  switch (circ->purpose) {
1882  /* Report extended SOCKS error code when a rendezvous circuit times out.
1883  * This MUST be done on_close() because it is possible the entry
1884  * connection would get closed before the circuit is freed and thus
1885  * would fail to report the error code. */
1886  if (has_timed_out) {
1887  socks_mark_rend_circuit_timed_out(CONST_TO_ORIGIN_CIRCUIT(circ));
1888  }
1889  break;
1890  default:
1891  break;
1892  }
1893 }
1894 
1895 /** Called when a circuit was just cleaned up. This is done right before the
1896  * circuit is freed. */
1897 void
1899 {
1900  bool has_timed_out;
1901  rend_intro_point_failure_t failure = INTRO_POINT_FAILURE_GENERIC;
1902  const origin_circuit_t *orig_circ = NULL;
1903 
1904  tor_assert(circ);
1906 
1907  orig_circ = CONST_TO_ORIGIN_CIRCUIT(circ);
1908  tor_assert(orig_circ->hs_ident);
1909 
1910  has_timed_out =
1911  (circ->marked_for_close_orig_reason == END_CIRC_REASON_TIMEOUT);
1912  if (has_timed_out) {
1913  failure = INTRO_POINT_FAILURE_TIMEOUT;
1914  }
1915 
1916  switch (circ->purpose) {
1918  log_info(LD_REND, "Failed v3 intro circ for service %s to intro point %s "
1919  "(awaiting ACK). Failure code: %d",
1920  safe_str_client(ed25519_fmt(&orig_circ->hs_ident->identity_pk)),
1921  safe_str_client(build_state_get_exit_nickname(orig_circ->build_state)),
1922  failure);
1924  &orig_circ->hs_ident->intro_auth_pk,
1925  failure);
1926  break;
1928  if (has_timed_out || !orig_circ->build_state) {
1929  break;
1930  }
1931  failure = INTRO_POINT_FAILURE_UNREACHABLE;
1932  log_info(LD_REND, "Failed v3 intro circ for service %s to intro point %s "
1933  "(while building circuit). Marking as unreachable.",
1934  safe_str_client(ed25519_fmt(&orig_circ->hs_ident->identity_pk)),
1935  safe_str_client(build_state_get_exit_nickname(orig_circ->build_state)));
1937  &orig_circ->hs_ident->intro_auth_pk,
1938  failure);
1939  break;
1940  default:
1941  break;
1942  }
1943 }
1944 
1945 /** A circuit just finished connecting to a hidden service that the stream
1946  * <b>conn</b> has been waiting for. Let the HS subsystem know about this. */
1947 void
1949 {
1951 
1952  if (BUG(conn->rend_data && conn->hs_ident)) {
1953  log_warn(LD_BUG, "Stream had both rend_data and hs_ident..."
1954  "Prioritizing hs_ident");
1955  }
1956 
1957  if (conn->hs_ident) { /* It's v3: pass it to the prop224 handler */
1958  note_connection_attempt_succeeded(conn->hs_ident);
1959  return;
1960  } else if (conn->rend_data) { /* It's v2: pass it to the legacy handler */
1962  return;
1963  }
1964 }
1965 
1966 /** With the given encoded descriptor in desc_str and the service key in
1967  * service_identity_pk, decode the descriptor and set the desc pointer with a
1968  * newly allocated descriptor object.
1969  *
1970  * On success, HS_DESC_DECODE_OK is returned and desc is set to the decoded
1971  * descriptor. On error, desc is set to NULL and a decoding error status is
1972  * returned depending on what was the issue. */
1974 hs_client_decode_descriptor(const char *desc_str,
1975  const ed25519_public_key_t *service_identity_pk,
1976  hs_descriptor_t **desc)
1977 {
1979  hs_subcredential_t subcredential;
1980  ed25519_public_key_t blinded_pubkey;
1981  hs_client_service_authorization_t *client_auth = NULL;
1982  curve25519_secret_key_t *client_auth_sk = NULL;
1983 
1984  tor_assert(desc_str);
1985  tor_assert(service_identity_pk);
1986  tor_assert(desc);
1987 
1988  /* Check if we have a client authorization for this service in the map. */
1989  client_auth = find_client_auth(service_identity_pk);
1990  if (client_auth) {
1991  client_auth_sk = &client_auth->enc_seckey;
1992  }
1993 
1994  /* Create subcredential for this HS so that we can decrypt */
1995  {
1996  uint64_t current_time_period = hs_get_time_period_num(0);
1997  hs_build_blinded_pubkey(service_identity_pk, NULL, 0, current_time_period,
1998  &blinded_pubkey);
1999  hs_get_subcredential(service_identity_pk, &blinded_pubkey, &subcredential);
2000  }
2001 
2002  /* Parse descriptor */
2003  ret = hs_desc_decode_descriptor(desc_str, &subcredential,
2004  client_auth_sk, desc);
2005  memwipe(&subcredential, 0, sizeof(subcredential));
2006  if (ret != HS_DESC_DECODE_OK) {
2007  goto err;
2008  }
2009 
2010  /* Make sure the descriptor signing key cross certifies with the computed
2011  * blinded key. Without this validation, anyone knowing the subcredential
2012  * and onion address can forge a descriptor. */
2013  tor_cert_t *cert = (*desc)->plaintext_data.signing_key_cert;
2014  if (tor_cert_checksig(cert,
2015  &blinded_pubkey, approx_time()) < 0) {
2016  log_warn(LD_GENERAL, "Descriptor signing key certificate signature "
2017  "doesn't validate with computed blinded key: %s",
2019  ret = HS_DESC_DECODE_GENERIC_ERROR;
2020  goto err;
2021  }
2022 
2023  return HS_DESC_DECODE_OK;
2024  err:
2025  return ret;
2026 }
2027 
2028 /** Return true iff there are at least one usable intro point in the service
2029  * descriptor desc. */
2030 int
2032  const hs_descriptor_t *desc)
2033 {
2034  tor_assert(service_pk);
2035  tor_assert(desc);
2036 
2038  const hs_desc_intro_point_t *, ip) {
2039  if (intro_point_is_usable(service_pk, ip)) {
2040  goto usable;
2041  }
2042  } SMARTLIST_FOREACH_END(ip);
2043 
2044  return 0;
2045  usable:
2046  return 1;
2047 }
2048 
2049 /** Launch a connection to a hidden service directory to fetch a hidden
2050  * service descriptor using <b>identity_pk</b> to get the necessary keys.
2051  *
2052  * A hs_client_fetch_status_t code is returned. */
2053 int
2055 {
2056  hs_client_fetch_status_t status;
2057 
2058  tor_assert(identity_pk);
2059 
2060  if (!can_client_refetch_desc(identity_pk, &status)) {
2061  return status;
2062  }
2063 
2064  /* Try to fetch the desc and if we encounter an unrecoverable error, mark
2065  * the desc as unavailable for now. */
2066  status = fetch_v3_desc(identity_pk);
2067  if (fetch_status_should_close_socks(status)) {
2068  close_all_socks_conns_waiting_for_desc(identity_pk, status,
2069  END_STREAM_REASON_RESOLVEFAILED);
2070  /* Remove HSDir fetch attempts so that we can retry later if the user
2071  * wants us to regardless of if we closed any connections. */
2072  purge_hid_serv_request(identity_pk);
2073  }
2074  return status;
2075 }
2076 
2077 /** This is called when we are trying to attach an AP connection to these
2078  * hidden service circuits from connection_ap_handshake_attach_circuit().
2079  * Return 0 on success, -1 for a transient error that is actions were
2080  * triggered to recover or -2 for a permenent error where both circuits will
2081  * marked for close.
2082  *
2083  * The following supports every hidden service version. */
2084 int
2086  origin_circuit_t *rend_circ)
2087 {
2088  return (intro_circ->hs_ident) ? send_introduce1(intro_circ, rend_circ) :
2089  rend_client_send_introduction(intro_circ,
2090  rend_circ);
2091 }
2092 
2093 /** Called when the client circuit circ has been established. It can be either
2094  * an introduction or rendezvous circuit. This function handles all hidden
2095  * service versions. */
2096 void
2098 {
2099  tor_assert(circ);
2100 
2101  /* Handle both version. v2 uses rend_data and v3 uses the hs circuit
2102  * identifier hs_ident. Can't be both. */
2103  switch (TO_CIRCUIT(circ)->purpose) {
2105  if (circ->hs_ident) {
2107  } else {
2109  }
2110  break;
2112  if (circ->hs_ident) {
2114  } else {
2116  }
2117  break;
2118  default:
2120  }
2121 }
2122 
2123 /** Called when we receive a RENDEZVOUS_ESTABLISHED cell. Change the state of
2124  * the circuit to CIRCUIT_PURPOSE_C_REND_READY. Return 0 on success else a
2125  * negative value and the circuit marked for close. */
2126 int
2128  const uint8_t *payload, size_t payload_len)
2129 {
2130  tor_assert(circ);
2131  tor_assert(payload);
2132 
2133  (void) payload_len;
2134 
2135  if (TO_CIRCUIT(circ)->purpose != CIRCUIT_PURPOSE_C_ESTABLISH_REND) {
2136  log_warn(LD_PROTOCOL, "Got a RENDEZVOUS_ESTABLISHED but we were not "
2137  "expecting one. Closing circuit.");
2138  goto err;
2139  }
2140 
2141  log_info(LD_REND, "Received an RENDEZVOUS_ESTABLISHED. This circuit is "
2142  "now ready for rendezvous.");
2144 
2145  /* Set timestamp_dirty, because circuit_expire_building expects it to
2146  * specify when a circuit entered the _C_REND_READY state. */
2147  TO_CIRCUIT(circ)->timestamp_dirty = time(NULL);
2148 
2149  /* From a path bias point of view, this circuit is now successfully used.
2150  * Waiting any longer opens us up to attacks from malicious hidden services.
2151  * They could induce the client to attempt to connect to their hidden
2152  * service and never reply to the client's rend requests */
2154 
2155  /* If we already have the introduction circuit built, make sure we send
2156  * the INTRODUCE cell _now_ */
2158 
2159  return 0;
2160  err:
2161  circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_TORPROTOCOL);
2162  return -1;
2163 }
2164 
2165 void
2166 client_service_authorization_free_(hs_client_service_authorization_t *auth)
2167 {
2168  if (!auth) {
2169  return;
2170  }
2171 
2172  tor_free(auth->client_name);
2173 
2174  memwipe(auth, 0, sizeof(*auth));
2175  tor_free(auth);
2176 }
2177 
2178 /** Helper for digest256map_free. */
2179 static void
2181 {
2182  client_service_authorization_free_(auth);
2183 }
2184 
2185 static void
2186 client_service_authorization_free_all(void)
2187 {
2188  if (!client_auths) {
2189  return;
2190  }
2192 }
2193 
2194 /** Check if the auth key file name is valid or not. Return 1 if valid,
2195  * otherwise return 0. */
2196 STATIC int
2197 auth_key_filename_is_valid(const char *filename)
2198 {
2199  int ret = 1;
2200  const char *valid_extension = ".auth_private";
2201 
2202  tor_assert(filename);
2203 
2204  /* The length of the filename must be greater than the length of the
2205  * extension and the valid extension must be at the end of filename. */
2206  if (!strcmpend(filename, valid_extension) &&
2207  strlen(filename) != strlen(valid_extension)) {
2208  ret = 1;
2209  } else {
2210  ret = 0;
2211  }
2212 
2213  return ret;
2214 }
2215 
2216 /** Parse the client auth credentials off a string in <b>client_key_str</b>
2217  * based on the file format documented in the "Client side configuration"
2218  * section of rend-spec-v3.txt.
2219  *
2220  * Return NULL if there was an error, otherwise return a newly allocated
2221  * hs_client_service_authorization_t structure.
2222  */
2224 parse_auth_file_content(const char *client_key_str)
2225 {
2226  char *onion_address = NULL;
2227  char *auth_type = NULL;
2228  char *key_type = NULL;
2229  char *seckey_b32 = NULL;
2230  hs_client_service_authorization_t *auth = NULL;
2231  smartlist_t *fields = smartlist_new();
2232 
2233  tor_assert(client_key_str);
2234 
2235  smartlist_split_string(fields, client_key_str, ":",
2236  SPLIT_SKIP_SPACE, 0);
2237  /* Wrong number of fields. */
2238  if (smartlist_len(fields) != 4) {
2239  goto err;
2240  }
2241 
2242  onion_address = smartlist_get(fields, 0);
2243  auth_type = smartlist_get(fields, 1);
2244  key_type = smartlist_get(fields, 2);
2245  seckey_b32 = smartlist_get(fields, 3);
2246 
2247  /* Currently, the only supported auth type is "descriptor" and the only
2248  * supported key type is "x25519". */
2249  if (strcmp(auth_type, "descriptor") || strcmp(key_type, "x25519")) {
2250  goto err;
2251  }
2252 
2253  if (strlen(seckey_b32) != BASE32_NOPAD_LEN(CURVE25519_SECKEY_LEN)) {
2254  log_warn(LD_REND, "Client authorization encoded base32 private key "
2255  "length is invalid: %s", seckey_b32);
2256  goto err;
2257  }
2258 
2259  auth = tor_malloc_zero(sizeof(hs_client_service_authorization_t));
2260  if (base32_decode((char *) auth->enc_seckey.secret_key,
2261  sizeof(auth->enc_seckey.secret_key),
2262  seckey_b32, strlen(seckey_b32)) !=
2263  sizeof(auth->enc_seckey.secret_key)) {
2264  log_warn(LD_REND, "Client authorization encoded base32 private key "
2265  "can't be decoded: %s", seckey_b32);
2266  goto err;
2267  }
2268 
2269  if (fast_mem_is_zero((const char*)auth->enc_seckey.secret_key,
2270  sizeof(auth->enc_seckey.secret_key))) {
2271  log_warn(LD_REND, "Client authorization private key can't be all-zeroes");
2272  goto err;
2273  }
2274 
2275  strncpy(auth->onion_address, onion_address, HS_SERVICE_ADDR_LEN_BASE32);
2276 
2277  /* We are reading this from the disk, so set the permanent flag anyway. */
2278  auth->flags |= CLIENT_AUTH_FLAG_IS_PERMANENT;
2279 
2280  /* Success. */
2281  goto done;
2282 
2283  err:
2284  client_service_authorization_free(auth);
2285  done:
2286  /* It is also a good idea to wipe the private key. */
2287  if (seckey_b32) {
2288  memwipe(seckey_b32, 0, strlen(seckey_b32));
2289  }
2290  tor_assert(fields);
2291  SMARTLIST_FOREACH(fields, char *, s, tor_free(s));
2292  smartlist_free(fields);
2293  return auth;
2294 }
2295 
2296 /** From a set of <b>options</b>, setup every client authorization detail
2297  * found. Return 0 on success or -1 on failure. If <b>validate_only</b>
2298  * is set, parse, warn and return as normal, but don't actually change
2299  * the configuration. */
2300 int
2302  int validate_only)
2303 {
2304  int ret = -1;
2305  digest256map_t *auths = digest256map_new();
2306  smartlist_t *file_list = NULL;
2307 
2308  tor_assert(options);
2309 
2310  /* There is no client auth configured. We can just silently ignore this
2311  * function. */
2312  if (!options->ClientOnionAuthDir) {
2313  ret = 0;
2314  goto end;
2315  }
2316 
2317  /* Make sure the directory exists and is private enough. */
2318  if (check_private_dir(options->ClientOnionAuthDir, 0, options->User) < 0) {
2319  goto end;
2320  }
2321 
2322  file_list = tor_listdir(options->ClientOnionAuthDir);
2323  if (file_list == NULL) {
2324  log_warn(LD_REND, "Client authorization key directory %s can't be listed.",
2325  options->ClientOnionAuthDir);
2326  goto end;
2327  }
2328 
2329  SMARTLIST_FOREACH_BEGIN(file_list, const char *, filename) {
2330  hs_client_service_authorization_t *auth = NULL;
2331  ed25519_public_key_t identity_pk;
2332 
2333  auth = get_creds_from_client_auth_filename(filename, options);
2334  if (!auth) {
2335  continue;
2336  }
2337 
2338  /* Parse the onion address to get an identity public key and use it
2339  * as a key of global map in the future. */
2340  if (hs_parse_address(auth->onion_address, &identity_pk,
2341  NULL, NULL) < 0) {
2342  log_warn(LD_REND, "The onion address \"%s\" is invalid in "
2343  "file %s", filename, auth->onion_address);
2344  client_service_authorization_free(auth);
2345  continue;
2346  }
2347 
2348  if (digest256map_get(auths, identity_pk.pubkey)) {
2349  log_warn(LD_REND, "Duplicate authorization for the same hidden "
2350  "service address %s.",
2351  safe_str_client_opts(options, auth->onion_address));
2352  client_service_authorization_free(auth);
2353  goto end;
2354  }
2355 
2356  digest256map_set(auths, identity_pk.pubkey, auth);
2357  log_info(LD_REND, "Loaded a client authorization key file %s.",
2358  filename);
2359  } SMARTLIST_FOREACH_END(filename);
2360 
2361  /* Success. */
2362  ret = 0;
2363 
2364  end:
2365  if (file_list) {
2366  SMARTLIST_FOREACH(file_list, char *, s, tor_free(s));
2367  smartlist_free(file_list);
2368  }
2369 
2370  if (!validate_only && ret == 0) {
2371  client_service_authorization_free_all();
2372  client_auths = auths;
2373  } else {
2374  digest256map_free(auths, client_service_authorization_free_void);
2375  }
2376 
2377  return ret;
2378 }
2379 
2380 /** Called when a descriptor directory fetch is done.
2381  *
2382  * Act accordingly on all entry connections depending on the HTTP status code
2383  * we got. In case of an error, the SOCKS error is set (if ExtendedErrors is
2384  * set).
2385  *
2386  * The reason is a human readable string returned by the directory server
2387  * which can describe the status of the request. The body is the response
2388  * content, on 200 code it is the descriptor itself. Finally, the status_code
2389  * is the HTTP code returned by the directory server. */
2390 void
2391 hs_client_dir_fetch_done(dir_connection_t *dir_conn, const char *reason,
2392  const char *body, const int status_code)
2393 {
2394  smartlist_t *entry_conns;
2395 
2396  tor_assert(dir_conn);
2397  tor_assert(body);
2398 
2399  /* Get all related entry connections. */
2400  entry_conns = find_entry_conns(&dir_conn->hs_ident->identity_pk);
2401 
2402  switch (status_code) {
2403  case 200:
2404  client_dir_fetch_200(dir_conn, entry_conns, body);
2405  break;
2406  case 404:
2407  client_dir_fetch_404(dir_conn, entry_conns);
2408  break;
2409  case 400:
2410  client_dir_fetch_400(dir_conn, reason);
2411  break;
2412  default:
2413  client_dir_fetch_unexpected(dir_conn, reason, status_code);
2414  break;
2415  }
2416 
2417  /* We don't have ownership of the objects in this list. */
2418  smartlist_free(entry_conns);
2419 }
2420 
2421 /** Return a newly allocated extend_info_t for a randomly chosen introduction
2422  * point for the given edge connection identifier ident. Return NULL if we
2423  * can't pick any usable introduction points. */
2424 extend_info_t *
2426 {
2427  tor_assert(edge_conn);
2428 
2429  return (edge_conn->hs_ident) ?
2430  client_get_random_intro(&edge_conn->hs_ident->identity_pk) :
2432 }
2433 
2434 /** Called when get an INTRODUCE_ACK cell on the introduction circuit circ.
2435  * Return 0 on success else a negative value is returned. The circuit will be
2436  * closed or reuse to extend again to another intro point. */
2437 int
2439  const uint8_t *payload, size_t payload_len)
2440 {
2441  int ret = -1;
2442 
2443  tor_assert(circ);
2444  tor_assert(payload);
2445 
2446  if (TO_CIRCUIT(circ)->purpose != CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT) {
2447  log_warn(LD_PROTOCOL, "Unexpected INTRODUCE_ACK on circuit %u.",
2448  (unsigned int) TO_CIRCUIT(circ)->n_circ_id);
2449  circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_TORPROTOCOL);
2450  goto end;
2451  }
2452 
2453  ret = (circ->hs_ident) ? handle_introduce_ack(circ, payload, payload_len) :
2454  rend_client_introduction_acked(circ, payload,
2455  payload_len);
2456  /* For path bias: This circuit was used successfully. NACK or ACK counts. */
2458 
2459  end:
2460  return ret;
2461 }
2462 
2463 /** Called when get a RENDEZVOUS2 cell on the rendezvous circuit circ. Return
2464  * 0 on success else a negative value is returned. The circuit will be closed
2465  * on error. */
2466 int
2468  const uint8_t *payload, size_t payload_len)
2469 {
2470  int ret = -1;
2471 
2472  tor_assert(circ);
2473  tor_assert(payload);
2474 
2475  /* Circuit can possibly be in both state because we could receive a
2476  * RENDEZVOUS2 cell before the INTRODUCE_ACK has been received. */
2477  if (TO_CIRCUIT(circ)->purpose != CIRCUIT_PURPOSE_C_REND_READY &&
2479  log_warn(LD_PROTOCOL, "Unexpected RENDEZVOUS2 cell on circuit %u. "
2480  "Closing circuit.",
2481  (unsigned int) TO_CIRCUIT(circ)->n_circ_id);
2482  circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_TORPROTOCOL);
2483  goto end;
2484  }
2485 
2486  log_info(LD_REND, "Got RENDEZVOUS2 cell from hidden service on circuit %u.",
2487  TO_CIRCUIT(circ)->n_circ_id);
2488 
2489  ret = (circ->hs_ident) ? handle_rendezvous2(circ, payload, payload_len) :
2490  rend_client_receive_rendezvous(circ, payload,
2491  payload_len);
2492  end:
2493  return ret;
2494 }
2495 
2496 /** Extend the introduction circuit circ to another valid introduction point
2497  * for the hidden service it is trying to connect to, or mark it and launch a
2498  * new circuit if we can't extend it. Return 0 on success or possible
2499  * success. Return -1 and mark the introduction circuit for close on permanent
2500  * failure.
2501  *
2502  * On failure, the caller is responsible for marking the associated rendezvous
2503  * circuit for close. */
2504 int
2506 {
2507  int ret = -1;
2508  extend_info_t *ei;
2509 
2510  tor_assert(circ);
2511 
2512  ei = (circ->hs_ident) ?
2515  if (ei == NULL) {
2516  log_warn(LD_REND, "No usable introduction points left. Closing.");
2517  circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_INTERNAL);
2518  goto end;
2519  }
2520 
2521  if (circ->remaining_relay_early_cells) {
2522  log_info(LD_REND, "Re-extending circ %u, this time to %s.",
2523  (unsigned int) TO_CIRCUIT(circ)->n_circ_id,
2524  safe_str_client(extend_info_describe(ei)));
2525  ret = circuit_extend_to_new_exit(circ, ei);
2526  if (ret == 0) {
2527  /* We were able to extend so update the timestamp so we avoid expiring
2528  * this circuit too early. The intro circuit is short live so the
2529  * linkability issue is minimized, we just need the circuit to hold a
2530  * bit longer so we can introduce. */
2531  TO_CIRCUIT(circ)->timestamp_dirty = time(NULL);
2532  }
2533  } else {
2534  log_info(LD_REND, "Closing intro circ %u (out of RELAY_EARLY cells).",
2535  (unsigned int) TO_CIRCUIT(circ)->n_circ_id);
2536  circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_FINISHED);
2537  /* connection_ap_handshake_attach_circuit will launch a new intro circ. */
2538  ret = 0;
2539  }
2540 
2541  end:
2542  extend_info_free(ei);
2543  return ret;
2544 }
2545 
2546 /** Close all client introduction circuits related to the given descriptor.
2547  * This is called with a descriptor that is about to get replaced in the
2548  * client cache.
2549  *
2550  * Even though the introduction point might be exactly the same, we'll rebuild
2551  * them if needed but the odds are very low that an existing matching
2552  * introduction circuit exists at that stage. */
2553 void
2555 {
2556  origin_circuit_t *ocirc = NULL;
2557 
2558  tor_assert(desc);
2559 
2560  /* We iterate over all client intro circuits because they aren't kept in the
2561  * HS circuitmap. That is probably something we want to do one day. */
2562  while ((ocirc = circuit_get_next_intro_circ(ocirc, true))) {
2563  if (ocirc->hs_ident == NULL) {
2564  /* Not a v3 circuit, ignore it. */
2565  continue;
2566  }
2567 
2568  /* Does it match any IP in the given descriptor? If not, ignore. */
2569  if (find_desc_intro_point_by_ident(ocirc->hs_ident, desc) == NULL) {
2570  continue;
2571  }
2572 
2573  /* We have a match. Close the circuit as consider it expired. */
2574  circuit_mark_for_close(TO_CIRCUIT(ocirc), END_CIRC_REASON_FINISHED);
2575  }
2576 }
2577 
2578 /** Release all the storage held by the client subsystem. */
2579 void
2581 {
2582  /* Purge the hidden service request cache. */
2584  client_service_authorization_free_all();
2585 }
2586 
2587 /** Purge all potentially remotely-detectable state held in the hidden
2588  * service client code. Called on SIGNAL NEWNYM. */
2589 void
2591 {
2592  /* v2 subsystem. */
2594 
2595  /* Cancel all descriptor fetches. Do this first so once done we are sure
2596  * that our descriptor cache won't modified. */
2597  cancel_descriptor_fetches();
2598  /* Purge the introduction point state cache. */
2600  /* Purge the descriptor cache. */
2602  /* Purge the last hidden service request cache. */
2604  /* Purge ephemeral client authorization. */
2606 
2607  log_info(LD_REND, "Hidden service client state has been purged.");
2608 }
2609 
2610 /** Called when our directory information has changed. */
2611 void
2613 {
2614  /* We have possibly reached the minimum directory information or new
2615  * consensus so retry all pending SOCKS connection in
2616  * AP_CONN_STATE_RENDDESC_WAIT state in order to fetch the descriptor. */
2618 }
2619 
2620 #ifdef TOR_UNIT_TESTS
2621 
2622 STATIC void
2623 set_hs_client_auths_map(digest256map_t *map)
2624 {
2625  client_auths = map;
2626 }
2627 
2628 #endif /* defined(TOR_UNIT_TESTS) */
close_or_reextend_intro_circ
static int close_or_reextend_intro_circ(origin_circuit_t *intro_circ)
Definition: hs_client.c:1066
edge_connection_t::rend_data
rend_data_t * rend_data
Definition: edge_connection_st.h:38
log_fn
#define log_fn(severity, domain, args,...)
Definition: log.h:283
hs_circuit_setup_e2e_rend_circ
int hs_circuit_setup_e2e_rend_circ(origin_circuit_t *circ, const uint8_t *ntor_key_seed, size_t seed_len, int is_service_side)
Definition: hs_circuit.c:1096
HS_CLIENT_FETCH_HAVE_DESC
@ HS_CLIENT_FETCH_HAVE_DESC
Definition: hs_client.h:25
tor_free
#define tor_free(p)
Definition: malloc.h:52
connection_edge.h
Header file for connection_edge.c.
CURVE25519_PUBKEY_LEN
#define CURVE25519_PUBKEY_LEN
Definition: x25519_sizes.h:20
get_client_auth_creds_filename
static char * get_client_auth_creds_filename(const char *onion_address, const char *dir)
Definition: hs_client.c:1577
smartlist_split_string
int smartlist_split_string(smartlist_t *sl, const char *str, const char *sep, int flags, int max)
Definition: smartlist_split.c:37
rend_client_get_random_intro
extend_info_t * rend_client_get_random_intro(const rend_data_t *rend_query)
Definition: rendclient.c:1016
hs_cache_store_as_client
hs_desc_decode_status_t hs_cache_store_as_client(const char *desc_str, const ed25519_public_key_t *identity_pk)
Definition: hs_cache.c:864
circuit_t::purpose
uint8_t purpose
Definition: circuit_st.h:111
hs_config_client_authorization
int hs_config_client_authorization(const or_options_t *options, int validate_only)
Definition: hs_client.c:2301
hs_cache_client_intro_state_note
void hs_cache_client_intro_state_note(const ed25519_public_key_t *service_pk, const ed25519_public_key_t *auth_key, rend_intro_point_failure_t failure)
Definition: hs_cache.c:961
hs_client_circuit_has_opened
void hs_client_circuit_has_opened(origin_circuit_t *circ)
Definition: hs_client.c:2097
routerstatus_describe
const char * routerstatus_describe(const routerstatus_t *rs)
Definition: describe.c:203
hs_ntor_client_rendezvous2_mac_is_good
int hs_ntor_client_rendezvous2_mac_is_good(const hs_ntor_rend_cell_keys_t *hs_ntor_rend_cell_keys, const uint8_t *rcvd_mac)
Definition: hs_ntor.c:594
hs_desc_decode_status_t
hs_desc_decode_status_t
Definition: hs_descriptor.h:74
entry_connection_st.h
Entry connection structure.
tor_cert_t
Definition: torcert.h:30
hs_ident.h
Header file containing circuit and connection identifier data for the whole HS subsystem.
memwipe
void memwipe(void *mem, uint8_t byte, size_t sz)
Definition: crypto_util.c:55
ED25519_BASE64_LEN
#define ED25519_BASE64_LEN
Definition: x25519_sizes.h:43
circuit_get_next_intro_circ
origin_circuit_t * circuit_get_next_intro_circ(const origin_circuit_t *start, bool want_client_circ)
Definition: circuitlist.c:1734
note_connection_attempt_succeeded
static void note_connection_attempt_succeeded(const hs_ident_edge_conn_t *hs_conn_ident)
Definition: hs_client.c:355
directory_initiate_request
void directory_initiate_request(directory_request_t *request)
Definition: dirclient.c:1235
approx_time
time_t approx_time(void)
Definition: approx_time.c:32
MOCK_IMPL
#define MOCK_IMPL(rv, funcname, arglist)
Definition: testsupport.h:133
intro_circ_is_ok
static int intro_circ_is_ok(const origin_circuit_t *circ)
Definition: hs_client.c:505
hs_client_fetch_status_t
hs_client_fetch_status_t
Definition: hs_client.h:19
hs_client_receive_introduce_ack
int hs_client_receive_introduce_ack(origin_circuit_t *circ, const uint8_t *payload, size_t payload_len)
Definition: hs_client.c:2438
desc_intro_point_to_extend_info
STATIC extend_info_t * desc_intro_point_to_extend_info(const hs_desc_intro_point_t *ip)
Definition: hs_client.c:814
circuit_extend_to_new_exit
int circuit_extend_to_new_exit(origin_circuit_t *circ, extend_info_t *exit_ei)
Definition: circuitbuild.c:2097
dir_connection_t::identity_digest
char identity_digest[DIGEST_LEN]
Definition: dir_connection_st.h:57
HS_CLIENT_FETCH_ERROR
@ HS_CLIENT_FETCH_ERROR
Definition: hs_client.h:21
HS_CLIENT_FETCH_NO_HSDIRS
@ HS_CLIENT_FETCH_NO_HSDIRS
Definition: hs_client.h:27
or_options_t::User
char * User
Definition: or_options_st.h:162
parse_auth_file_content
STATIC hs_client_service_authorization_t * parse_auth_file_content(const char *client_key_str)
Definition: hs_client.c:2224
socks5_reply_status_t
socks5_reply_status_t
Definition: socks5_status.h:20
hs_ident_intro_circ_is_valid
int hs_ident_intro_circ_is_valid(const hs_ident_circuit_t *ident)
Definition: hs_ident.c:104
hs_desc_encrypted_data_t
Definition: hs_descriptor.h:158
routerset_contains_extendinfo
int routerset_contains_extendinfo(const routerset_t *set, const extend_info_t *ei)
Definition: routerset.c:308
AP_CONN_STATE_CIRCUIT_WAIT
#define AP_CONN_STATE_CIRCUIT_WAIT
Definition: connection_edge.h:49
hs_client_circuit_cleanup_on_free
void hs_client_circuit_cleanup_on_free(const circuit_t *circ)
Definition: hs_client.c:1898
tor_assert
#define tor_assert(expr)
Definition: util_bug.h:102
hs_desc_intro_point_t::link_specifiers
smartlist_t * link_specifiers
Definition: hs_descriptor.h:102
CONN_TYPE_DIR
#define CONN_TYPE_DIR
Definition: connection.h:55
LD_BUG
#define LD_BUG
Definition: log.h:86
ed25519_pubkey_eq
int ed25519_pubkey_eq(const ed25519_public_key_t *key1, const ed25519_public_key_t *key2)
Definition: crypto_ed25519.c:642
hs_circ_send_establish_rendezvous
int hs_circ_send_establish_rendezvous(origin_circuit_t *circ)
Definition: hs_circuit.c:1231
cpath_build_state_st.h
Circuit-build-stse structure.
hs_cache_intro_state_t
Definition: hs_cache.h:26
hs_ident_circuit_t::identity_pk
ed25519_public_key_t identity_pk
Definition: hs_ident.h:45
fast_mem_is_zero
int fast_mem_is_zero(const char *mem, size_t len)
Definition: util_string.c:74
circuituse.h
Header file for circuituse.c.
LD_GENERAL
#define LD_GENERAL
Definition: log.h:62
DIGESTMAP_FOREACH_END
#define DIGESTMAP_FOREACH_END
Definition: map.h:168
describe.h
Header file for describe.c.
smartlist_add_all
void smartlist_add_all(smartlist_t *s1, const smartlist_t *s2)
Definition: smartlist_core.c:125
purge_hid_serv_request
static void purge_hid_serv_request(const ed25519_public_key_t *identity_pk)
Definition: hs_client.c:198
pathbias_count_use_attempt
void pathbias_count_use_attempt(origin_circuit_t *circ)
Definition: circpathbias.c:604
store_permanent_client_auth_credentials
static int store_permanent_client_auth_credentials(const hs_client_service_authorization_t *creds)
Definition: hs_client.c:1596
hs_client_note_connection_attempt_succeeded
void hs_client_note_connection_attempt_succeeded(const edge_connection_t *conn)
Definition: hs_client.c:1948
node_get_by_id
const node_t * node_get_by_id(const char *identity_digest)
Definition: nodelist.c:223
networkstatus_get_live_consensus
networkstatus_t * networkstatus_get_live_consensus(time_t now)
Definition: networkstatus.c:1416
handle_introduce_ack_success
static void handle_introduce_ack_success(origin_circuit_t *intro_circ)
Definition: hs_client.c:1120
smartlist_add
void smartlist_add(smartlist_t *sl, void *element)
Definition: smartlist_core.c:117
HS_CLIENT_FETCH_MISSING_INFO
@ HS_CLIENT_FETCH_MISSING_INFO
Definition: hs_client.h:31
hs_descriptor_t::plaintext_data
hs_desc_plaintext_data_t plaintext_data
Definition: hs_descriptor.h:228
hs_desc_plaintext_data_t::version
uint32_t version
Definition: hs_descriptor.h:196
CIRCUIT_PURPOSE_C_REND_JOINED
#define CIRCUIT_PURPOSE_C_REND_JOINED
Definition: circuitlist.h:90
routerstatus_t
Definition: routerstatus_st.h:19
ed25519_pubkey_copy
void ed25519_pubkey_copy(ed25519_public_key_t *dest, const ed25519_public_key_t *src)
Definition: crypto_ed25519.c:654
setup_intro_circ_auth_key
static int setup_intro_circ_auth_key(origin_circuit_t *circ)
Definition: hs_client.c:713
client_dir_fetch_unexpected
static void client_dir_fetch_unexpected(dir_connection_t *dir_conn, const char *reason, const int status_code)
Definition: hs_client.c:1556
hs_build_address
void hs_build_address(const ed25519_public_key_t *key, uint8_t version, char *addr_out)
Definition: hs_common.c:1021
client_service_authorization_free_void
static void client_service_authorization_free_void(void *auth)
Definition: hs_client.c:2180
hs_control_desc_event_failed
void hs_control_desc_event_failed(const hs_ident_dir_conn_t *ident, const char *hsdir_id_digest, const char *reason)
Definition: hs_control.c:65
hs_client_any_intro_points_usable
int hs_client_any_intro_points_usable(const ed25519_public_key_t *service_pk, const hs_descriptor_t *desc)
Definition: hs_client.c:2031
CLIENT_AUTH_FLAG_IS_PERMANENT
#define CLIENT_AUTH_FLAG_IS_PERMANENT
Definition: hs_client.h:63
tor_cert_checksig
int tor_cert_checksig(tor_cert_t *cert, const ed25519_public_key_t *pubkey, time_t now)
Definition: torcert.c:244
smartlist_new
smartlist_t * smartlist_new(void)
Definition: smartlist_core.c:26
reasons.h
Header file for reasons.c.
hs_desc_intro_point_t::auth_key_cert
tor_cert_t * auth_key_cert
Definition: hs_descriptor.h:111
hs_client_launch_v3_desc_fetch
void hs_client_launch_v3_desc_fetch(const ed25519_public_key_t *onion_identity_pk, const smartlist_t *hsdirs)
Definition: hs_client.c:486
socks_request_st.h
Client request structure.
CIRCUIT_IS_ORIGIN
#define CIRCUIT_IS_ORIGIN(c)
Definition: circuitlist.h:148
HS_CLIENT_FETCH_NOT_ALLOWED
@ HS_CLIENT_FETCH_NOT_ALLOWED
Definition: hs_client.h:29
CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT
#define CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT
Definition: circuitlist.h:78
rend_client_receive_rendezvous
int rend_client_receive_rendezvous(origin_circuit_t *circ, const uint8_t *request, size_t request_len)
Definition: rendclient.c:898
ed25519_public_to_base64
void ed25519_public_to_base64(char *output, const ed25519_public_key_t *pkey)
Definition: crypto_format.c:227
hs_client_dir_fetch_done
void hs_client_dir_fetch_done(dir_connection_t *dir_conn, const char *reason, const char *body, const int status_code)
Definition: hs_client.c:2391
strcmpend
int strcmpend(const char *s1, const char *s2)
Definition: util_string.c:251
intro_points_all_timed_out
static bool intro_points_all_timed_out(const ed25519_public_key_t *service_pk)
Definition: hs_client.c:979
hs_control_desc_event_content
void hs_control_desc_event_content(const hs_ident_dir_conn_t *ident, const char *hsdir_id_digest, const char *body)
Definition: hs_control.c:178
SMARTLIST_FOREACH
#define SMARTLIST_FOREACH(sl, type, var, cmd)
Definition: smartlist_foreach.h:112
hs_client_receive_rendezvous2
int hs_client_receive_rendezvous2(origin_circuit_t *circ, const uint8_t *payload, size_t payload_len)
Definition: hs_client.c:2467
crypto_rand_int
int crypto_rand_int(unsigned int max)
Definition: crypto_rand_numeric.c:52
extend_info_describe
const char * extend_info_describe(const extend_info_t *ei)
Definition: describe.c:224
hs_cell.h
Header file containing cell data for the whole HS subsystem.
base32_decode
int base32_decode(char *dest, size_t destlen, const char *src, size_t srclen)
Definition: binascii.c:90
build_state_get_exit_nickname
const char * build_state_get_exit_nickname(cpath_build_state_t *state)
Definition: circuitbuild.c:2506
hs_circ_send_introduce1
int hs_circ_send_introduce1(origin_circuit_t *intro_circ, origin_circuit_t *rend_circ, const hs_desc_intro_point_t *ip, const hs_subcredential_t *subcredential)
Definition: hs_circuit.c:1152
networkstatus.h
Header file for networkstatus.c.
hs_control_desc_event_requested
void hs_control_desc_event_requested(const ed25519_public_key_t *onion_pk, const char *base64_blinded_pk, const routerstatus_t *hsdir_rs)
Definition: hs_control.c:29
rend_client_send_introduction
int rend_client_send_introduction(origin_circuit_t *introcirc, origin_circuit_t *rendcirc)
Definition: rendclient.c:113
CIRCUIT_PURPOSE_C_ESTABLISH_REND
#define CIRCUIT_PURPOSE_C_ESTABLISH_REND
Definition: circuitlist.h:83
hs_client_purge_state
void hs_client_purge_state(void)
Definition: hs_client.c:2590
hs_client.h
Header file containing client data for the HS subsystem.
base32_encode
void base32_encode(char *dest, size_t destlen, const char *src, size_t srclen)
Definition: binascii.c:60
ed25519_fmt
const char * ed25519_fmt(const ed25519_public_key_t *pkey)
Definition: crypto_format.c:193
hs_client_get_random_intro_from_edge
extend_info_t * hs_client_get_random_intro_from_edge(const edge_connection_t *edge_conn)
Definition: hs_client.c:2425
crypto_util.h
Common functions for cryptographic routines.
hs_purge_last_hid_serv_requests
void hs_purge_last_hid_serv_requests(void)
Definition: hs_common.c:1601
hs_client_receive_rendezvous_acked
int hs_client_receive_rendezvous_acked(origin_circuit_t *circ, const uint8_t *payload, size_t payload_len)
Definition: hs_client.c:2127
hs_cache.h
Header file for hs_cache.c.
mark_conn_as_waiting_for_circuit
static void mark_conn_as_waiting_for_circuit(connection_t *conn, time_t now)
Definition: hs_client.c:248
socks_request_t::socks_extended_error_code
socks5_reply_status_t socks_extended_error_code
Definition: socks_request_st.h:72
ENTRY_TO_EDGE_CONN
#define ENTRY_TO_EDGE_CONN(c)
Definition: entry_connection_st.h:102
hs_cache_purge_as_client
void hs_cache_purge_as_client(void)
Definition: hs_cache.c:943
hs_circuitmap_get_established_rend_circ_client_side
origin_circuit_t * hs_circuitmap_get_established_rend_circ_client_side(const uint8_t *cookie)
Definition: hs_circuitmap.c:492
rend_client_note_connection_attempt_ended
void rend_client_note_connection_attempt_ended(const rend_data_t *rend_data)
Definition: rendclient.c:974
circuitlist.h
Header file for circuitlist.c.
hs_desc_intro_point_t::enc_key
curve25519_public_key_t enc_key
Definition: hs_descriptor.h:114
write_str_to_file
int write_str_to_file(const char *fname, const char *str, int bin)
Definition: files.c:274
DIGEST_LEN
#define DIGEST_LEN
Definition: digest_sizes.h:20
hs_pick_hsdir
routerstatus_t * hs_pick_hsdir(smartlist_t *responsible_dirs, const char *req_key_str, bool *is_rate_limited_out)
Definition: hs_common.c:1629
circuit_t::marked_for_close_orig_reason
int marked_for_close_orig_reason
Definition: circuit_st.h:201
pick_hsdir_v3
STATIC routerstatus_t * pick_hsdir_v3(const ed25519_public_key_t *onion_identity_pk)
Definition: hs_client.c:430
rend_client_introduction_acked
int rend_client_introduction_acked(origin_circuit_t *circ, const uint8_t *request, size_t request_len)
Definition: rendclient.c:383
CONN_TYPE_AP
#define CONN_TYPE_AP
Definition: connection.h:51
crypto_format.h
Header for crypto_format.c.
cpath_build_state_t::chosen_exit
extend_info_t * chosen_exit
Definition: cpath_build_state_st.h:20
DIR_PURPOSE_FETCH_HSDESC
#define DIR_PURPOSE_FETCH_HSDESC
Definition: directory.h:75
find_desc_intro_point_by_legacy_id
static hs_desc_intro_point_t * find_desc_intro_point_by_legacy_id(const char *legacy_id, const hs_descriptor_t *desc)
Definition: hs_client.c:556
handle_rendezvous2
STATIC int handle_rendezvous2(origin_circuit_t *circ, const uint8_t *payload, size_t payload_len)
Definition: hs_client.c:1228
TO_ENTRY_CONN
entry_connection_t * TO_ENTRY_CONN(connection_t *c)
Definition: connection_edge.c:202
intro_point_is_usable
static int intro_point_is_usable(const ed25519_public_key_t *service_pk, const hs_desc_intro_point_t *ip)
Definition: hs_client.c:836
hs_ident_circuit_t::intro_auth_pk
ed25519_public_key_t intro_auth_pk
Definition: hs_ident.h:51
connection_ap_mark_as_waiting_for_renddesc
void connection_ap_mark_as_waiting_for_renddesc(entry_connection_t *entry_conn)
Definition: connection_edge.c:1446
hs_path_from_filename
char * hs_path_from_filename(const char *directory, const char *filename)
Definition: hs_common.c:179
tor_assert_nonfatal_unreached
#define tor_assert_nonfatal_unreached()
Definition: util_bug.h:176
get_hs_client_auths_map
digest256map_t * get_hs_client_auths_map(void)
Definition: hs_client.c:1855
hs_cache_client_intro_state_purge
void hs_cache_client_intro_state_purge(void)
Definition: hs_cache.c:1013
node_t
Definition: node_st.h:34
origin_circuit_t
Definition: origin_circuit_st.h:79
directory_request_set_routerstatus
void directory_request_set_routerstatus(directory_request_t *req, const routerstatus_t *status)
Definition: dirclient.c:1162
hs_ident_dir_conn_init
void hs_ident_dir_conn_init(const ed25519_public_key_t *identity_pk, const ed25519_public_key_t *blinded_pk, hs_ident_dir_conn_t *ident)
Definition: hs_ident.c:69
client_auths
static digest256map_t * client_auths
Definition: hs_client.c:50
connection_describe_peer
const char * connection_describe_peer(const connection_t *conn)
Definition: connection.c:529
hs_circuitmap_get_rend_circ_client_side
origin_circuit_t * hs_circuitmap_get_rend_circ_client_side(const uint8_t *cookie)
Definition: hs_circuitmap.c:461
directory.h
Header file for directory.c.
hs_desc_decode_descriptor
hs_desc_decode_status_t hs_desc_decode_descriptor(const char *encoded, const hs_subcredential_t *subcredential, const curve25519_secret_key_t *client_auth_sk, hs_descriptor_t **desc_out)
Definition: hs_descriptor.c:2571
ed25519_public_key_t
Definition: crypto_ed25519.h:23
or_options_t::ExcludeNodes
struct routerset_t * ExcludeNodes
Definition: or_options_st.h:120
hs_client_send_introduce1
int hs_client_send_introduce1(origin_circuit_t *intro_circ, origin_circuit_t *rend_circ)
Definition: hs_client.c:2085
hs_cache_lookup_as_client
const hs_descriptor_t * hs_cache_lookup_as_client(const ed25519_public_key_t *key)
Definition: hs_cache.c:833
client_dir_fetch_404
static void client_dir_fetch_404(dir_connection_t *dir_conn, const smartlist_t *entry_conns)
Definition: hs_client.c:1514
MAX_INTRO_POINT_REACHABILITY_FAILURES
#define MAX_INTRO_POINT_REACHABILITY_FAILURES
Definition: or.h:1077
LD_REND
#define LD_REND
Definition: log.h:84
escaped
const char * escaped(const char *s)
Definition: escape.c:126
tor_unlink
int tor_unlink(const char *pathname)
Definition: files.c:154
or_options_t::StrictNodes
int StrictNodes
Definition: or_options_st.h:117
hs_cache_remove_as_client
void hs_cache_remove_as_client(const ed25519_public_key_t *key)
Definition: hs_cache.c:900
circuit_change_purpose
void circuit_change_purpose(circuit_t *circ, uint8_t new_purpose)
Definition: circuituse.c:3101
smartlist_del
void smartlist_del(smartlist_t *sl, int idx)
Definition: smartlist_core.c:214
connection_ap_attach_pending
void connection_ap_attach_pending(int retry)
Definition: connection_edge.c:1305
AP_CONN_STATE_RENDDESC_WAIT
#define AP_CONN_STATE_RENDDESC_WAIT
Definition: connection_edge.h:44
connection_t::marked_for_close
uint16_t marked_for_close
Definition: connection_st.h:149
circuit_t
Definition: circuit_st.h:61
nodelist.h
Header file for nodelist.c.
hs_control.h
Header file containing control port event related code.
hs_ident_dir_conn_t
Definition: hs_ident.h:87
hs_descriptor_t
Definition: hs_descriptor.h:226
hs_client_close_intro_circuits_from_desc
void hs_client_close_intro_circuits_from_desc(const hs_descriptor_t *desc)
Definition: hs_client.c:2554
flag_all_conn_wait_desc
static void flag_all_conn_wait_desc(const ed25519_public_key_t *service_identity_pk)
Definition: hs_client.c:172
routerset.h
Header file for routerset.c.
hs_purge_hid_serv_from_last_hid_serv_requests
void hs_purge_hid_serv_from_last_hid_serv_requests(const char *req_key_str)
Definition: hs_common.c:1560
close_all_socks_conns_waiting_for_desc
static void close_all_socks_conns_waiting_for_desc(const ed25519_public_key_t *identity_pk, hs_client_fetch_status_t status, int reason)
Definition: hs_client.c:269
assert_connection_ok
void assert_connection_ok(connection_t *conn, time_t now)
Definition: connection.c:5560
directory_request_is_pending
static int directory_request_is_pending(const ed25519_public_key_t *identity_pk)
Definition: hs_client.c:219
find_client_auth
static hs_client_service_authorization_t * find_client_auth(const ed25519_public_key_t *service_identity_pk)
Definition: hs_client.c:1376
client_desc_missing_bad_client_auth
static void client_desc_missing_bad_client_auth(const smartlist_t *entry_conns, hs_desc_decode_status_t status)
Definition: hs_client.c:1438
rend_client_purge_state
void rend_client_purge_state(void)
Definition: rendclient.c:57
hs_cache_intro_state_t::timed_out
unsigned int timed_out
Definition: hs_cache.h:34
DIGEST256_LEN
#define DIGEST256_LEN
Definition: digest_sizes.h:23
rend_client_rendcirc_has_opened
void rend_client_rendcirc_has_opened(origin_circuit_t *circ)
Definition: rendclient.c:344
hs_cell_parse_rendezvous2
int hs_cell_parse_rendezvous2(const uint8_t *payload, size_t payload_len, uint8_t *handshake_info, size_t handshake_info_len)
Definition: hs_cell.c:1098
extendinfo.h
Header for core/or/extendinfo.c.
hs_cache_intro_state_t::error
unsigned int error
Definition: hs_cache.h:31
tor_cert_describe_signature_status
const char * tor_cert_describe_signature_status(const tor_cert_t *cert)
Definition: torcert.c:279
hs_desc_intro_point_t::onion_key
curve25519_public_key_t onion_key
Definition: hs_descriptor.h:106
fetch_v3_desc
STATIC hs_client_fetch_status_t fetch_v3_desc(const ed25519_public_key_t *onion_identity_pk)
Definition: hs_client.c:467
fetch_status_should_close_socks
static int fetch_status_should_close_socks(hs_client_fetch_status_t status)
Definition: hs_client.c:81
fast_memneq
#define fast_memneq(a, b, c)
Definition: di_ops.h:42
connection_t
Definition: connection_st.h:45
pathbias_mark_use_success
void pathbias_mark_use_success(origin_circuit_t *circ)
Definition: circpathbias.c:661
hs_client_refetch_hsdesc
int hs_client_refetch_hsdesc(const ed25519_public_key_t *identity_pk)
Definition: hs_client.c:2054
hs_ident_dir_conn_t::identity_pk
ed25519_public_key_t identity_pk
Definition: hs_ident.h:90
hs_client_service_authorization_t
Definition: hs_client.h:66
crypto_rand.h
Common functions for using (pseudo-)random number generators.
HS_CLIENT_FETCH_LAUNCHED
@ HS_CLIENT_FETCH_LAUNCHED
Definition: hs_client.h:23
entry_connection_t::socks_request
socks_request_t * socks_request
Definition: entry_connection_st.h:27
get_options
const or_options_t * get_options(void)
Definition: config.c:932
hs_circuitmap_register_rend_circ_client_side
void hs_circuitmap_register_rend_circ_client_side(origin_circuit_t *or_circ, const uint8_t *cookie)
Definition: hs_circuitmap.c:554
origin_circuit_t::build_state
cpath_build_state_t * build_state
Definition: origin_circuit_st.h:123
get_creds_from_client_auth_filename
static hs_client_service_authorization_t * get_creds_from_client_auth_filename(const char *filename, const or_options_t *options)
Definition: hs_client.c:1702
circuitbuild.h
Header file for circuitbuild.c.
TO_EDGE_CONN
edge_connection_t * TO_EDGE_CONN(connection_t *c)
Definition: connection_edge.c:176
hs_get_responsible_hsdirs
void hs_get_responsible_hsdirs(const ed25519_public_key_t *blinded_pk, uint64_t time_period_num, int use_second_hsdir_index, int for_fetching, smartlist_t *responsible_dirs)
Definition: hs_common.c:1343
client_dir_fetch_400
static void client_dir_fetch_400(dir_connection_t *dir_conn, const char *reason)
Definition: hs_client.c:1538
connection_edge_is_rendezvous_stream
int connection_edge_is_rendezvous_stream(const edge_connection_t *conn)
Definition: connection_edge.c:4414
origin_circuit_t::remaining_relay_early_cells
unsigned int remaining_relay_early_cells
Definition: origin_circuit_st.h:149
directory_request_set_resource
void directory_request_set_resource(directory_request_t *req, const char *resource)
Definition: dirclient.c:1045
fetch_status_to_string
static const char * fetch_status_to_string(hs_client_fetch_status_t status)
Definition: hs_client.c:56
hs_client_dir_info_changed
void hs_client_dir_info_changed(void)
Definition: hs_client.c:2612
extend_info_st.h
Extend-info structure.
CIRCUIT_PURPOSE_C_INTRODUCE_ACKED
#define CIRCUIT_PURPOSE_C_INTRODUCE_ACKED
Definition: circuitlist.h:81
curve25519_public_key_t
Definition: crypto_curve25519.h:24
socks_mark_rend_circuit_timed_out
static void socks_mark_rend_circuit_timed_out(const origin_circuit_t *rend_circ)
Definition: hs_client.c:1019
DIR_PURPOSE_HAS_FETCHED_HSDESC
#define DIR_PURPOSE_HAS_FETCHED_HSDESC
Definition: directory.h:78
hs_client_service_authorization_t::client_name
char * client_name
Definition: hs_client.h:75
purge_ephemeral_client_auth
STATIC void purge_ephemeral_client_auth(void)
Definition: hs_client.c:1358
hs_control_desc_event_received
void hs_control_desc_event_received(const hs_ident_dir_conn_t *ident, const char *hsdir_id_digest)
Definition: hs_control.c:89
CIRCUIT_PURPOSE_C_REND_READY
#define CIRCUIT_PURPOSE_C_REND_READY
Definition: circuitlist.h:85
connection.h
Header file for connection.c.
extend_info_t::identity_digest
char identity_digest[DIGEST_LEN]
Definition: extend_info_st.h:31
directory_request_new
directory_request_t * directory_request_new(uint8_t dir_purpose)
Definition: dirclient.c:948
hs_client_service_authorization_t::enc_seckey
curve25519_secret_key_t enc_seckey
Definition: hs_client.h:69
hs_get_extend_info_from_lspecs
extend_info_t * hs_get_extend_info_from_lspecs(const smartlist_t *lspecs, const curve25519_public_key_t *onion_key, int direct_conn)
Definition: hs_common.c:1716
hs_subcredential_t
Definition: hs_ntor.h:43
stream_end_reason_to_string
const char * stream_end_reason_to_string(int reason)
Definition: reasons.c:64
hs_client_decode_descriptor
hs_desc_decode_status_t hs_client_decode_descriptor(const char *desc_str, const ed25519_public_key_t *service_identity_pk, hs_descriptor_t **desc)
Definition: hs_client.c:1974
hs_ident_circuit_t
Definition: hs_ident.h:42
curve25519_secret_key_t
Definition: crypto_curve25519.h:33
dirclient.h
Header file for dirclient.c.
node_supports_v3_rendezvous_point
bool node_supports_v3_rendezvous_point(const node_t *node)
Definition: nodelist.c:1190
CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED
#define CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED
Definition: circuitlist.h:88
hs_cell_parse_introduce_ack
int hs_cell_parse_introduce_ack(const uint8_t *payload, size_t payload_len)
Definition: hs_cell.c:1063
safe_str_client_opts
const char * safe_str_client_opts(const or_options_t *options, const char *address)
Definition: config.c:1085
tor_asprintf
int tor_asprintf(char **strp, const char *fmt,...)
Definition: printf.c:75
hs_client_free_all
void hs_client_free_all(void)
Definition: hs_client.c:2580
origin_circuit_t::rend_data
rend_data_t * rend_data
Definition: origin_circuit_st.h:132
hs_get_time_period_num
uint64_t hs_get_time_period_num(time_t now)
Definition: hs_common.c:270
SMARTLIST_FOREACH_BEGIN
#define SMARTLIST_FOREACH_BEGIN(sl, type, var)
Definition: smartlist_foreach.h:78
socks_mark_introduction_failed
static void socks_mark_introduction_failed(entry_connection_t *conn, const ed25519_public_key_t *identity_pk)
Definition: hs_client.c:1043
hs_client_circuit_cleanup_on_close
void hs_client_circuit_cleanup_on_close(const circuit_t *circ)
Definition: hs_client.c:1867
hs_ident_circuit_t::rendezvous_cookie
uint8_t rendezvous_cookie[HS_REND_COOKIE_LEN]
Definition: hs_ident.h:60
hs_cache_client_intro_state_find
const hs_cache_intro_state_t * hs_cache_client_intro_state_find(const ed25519_public_key_t *service_pk, const ed25519_public_key_t *auth_key)
Definition: hs_cache.c:983
client_intro_circ_has_opened
static void client_intro_circ_has_opened(origin_circuit_t *circ)
Definition: hs_client.c:752
HS_VERSION_THREE
#define HS_VERSION_THREE
Definition: hs_common.h:26
connection_t::timestamp_last_write_allowed
time_t timestamp_last_write_allowed
Definition: connection_st.h:106
dir_connection_st.h
Client/server directory connection structure.
directory_request_fetch_set_hs_ident
void directory_request_fetch_set_hs_ident(directory_request_t *req, const hs_ident_dir_conn_t *ident)
Definition: dirclient.c:1125
MAP_DEL_CURRENT
#define MAP_DEL_CURRENT(keyvar)
Definition: map.h:140
client_rendezvous_circ_has_opened
static void client_rendezvous_circ_has_opened(origin_circuit_t *circ)
Definition: hs_client.c:771
hs_ntor_rend_cell_keys_t
Definition: hs_ntor.h:30
hs_desc_encrypted_data_t::intro_points
smartlist_t * intro_points
Definition: hs_descriptor.h:171
hs_descriptor_t::encrypted_data
hs_desc_encrypted_data_t encrypted_data
Definition: hs_descriptor.h:238
edge_connection_t
Definition: edge_connection_st.h:21
client_get_random_intro
STATIC extend_info_t * client_get_random_intro(const ed25519_public_key_t *service_pk)
Definition: hs_client.c:876
client_dir_fetch_200
static void client_dir_fetch_200(dir_connection_t *dir_conn, const smartlist_t *entry_conns, const char *body)
Definition: hs_client.c:1462
hs_cache_intro_state_t::unreachable_count
uint32_t unreachable_count
Definition: hs_cache.h:37
hs_build_blinded_pubkey
void hs_build_blinded_pubkey(const ed25519_public_key_t *pk, const uint8_t *secret, size_t secret_len, uint64_t time_period_num, ed25519_public_key_t *blinded_pk_out)
Definition: hs_common.c:1047
TO_DIR_CONN
dir_connection_t * TO_DIR_CONN(connection_t *c)
Definition: directory.c:89
hs_ntor.h
Header for hs_ntor.c.
hs_circuitmap.h
Header file for hs_circuitmap.c.
hs_client_register_auth_credentials
hs_client_register_auth_status_t hs_client_register_auth_credentials(hs_client_service_authorization_t *creds)
Definition: hs_client.c:1652
client_desc_has_arrived
static void client_desc_has_arrived(const smartlist_t *entry_conns)
Definition: hs_client.c:1390
or_options_t::ClientOnionAuthDir
char * ClientOnionAuthDir
Definition: or_options_st.h:434
find_desc_intro_point_by_ident
static const hs_desc_intro_point_t * find_desc_intro_point_by_ident(const hs_ident_circuit_t *ident, const hs_descriptor_t *desc)
Definition: hs_client.c:532
handle_introduce_ack_bad
static void handle_introduce_ack_bad(origin_circuit_t *circ, int status)
Definition: hs_client.c:1167
config.h
Header file for config.c.
rend_client_introcirc_has_opened
void rend_client_introcirc_has_opened(origin_circuit_t *circ)
Definition: rendclient.c:68
retry_all_socks_conn_waiting_for_desc
STATIC void retry_all_socks_conn_waiting_for_desc(void)
Definition: hs_client.c:299
hs_ident_edge_conn_t
Definition: hs_ident.h:103
can_client_refetch_desc
static unsigned int can_client_refetch_desc(const ed25519_public_key_t *identity_pk, hs_client_fetch_status_t *status_out)
Definition: hs_client.c:1291
hs_descriptor_t::subcredential
hs_subcredential_t subcredential
Definition: hs_descriptor.h:242
send_introduce1
static int send_introduce1(origin_circuit_t *intro_circ, origin_circuit_t *rend_circ)
Definition: hs_client.c:596
connection_t::timestamp_created
time_t timestamp_created
Definition: connection_st.h:109
hs_parse_address
int hs_parse_address(const char *address, ed25519_public_key_t *key_out, uint8_t *checksum_out, uint8_t *version_out)
Definition: hs_common.c:960
connection_t::state
uint8_t state
Definition: connection_st.h:49
origin_circuit_t::hs_ident
struct hs_ident_circuit_t * hs_ident
Definition: origin_circuit_st.h:136
origin_circuit_t::p_streams
edge_connection_t * p_streams
Definition: origin_circuit_st.h:84
TO_CIRCUIT
#define TO_CIRCUIT(x)
Definition: or.h:965
edge_connection_t::next_stream
struct edge_connection_t * next_stream
Definition: edge_connection_st.h:24
or_options_t
Definition: or_options_st.h:64
tor_cert_t::signed_key
ed25519_public_key_t signed_key
Definition: torcert.h:32
TO_CONN
#define TO_CONN(c)
Definition: or.h:736
STATIC
#define STATIC
Definition: testsupport.h:32
hs_ident_edge_conn_t::identity_pk
ed25519_public_key_t identity_pk
Definition: hs_ident.h:106
find_and_remove_client_auth_creds_file
static void find_and_remove_client_auth_creds_file(const hs_client_service_authorization_t *cred)
Definition: hs_client.c:1771
dir_connection_t
Definition: dir_connection_st.h:21
router_have_minimum_dir_info
int router_have_minimum_dir_info(void)
Definition: nodelist.c:2346
hs_client_reextend_intro_circuit
int hs_client_reextend_intro_circuit(origin_circuit_t *circ)
Definition: hs_client.c:2505
hs_circuit.h
Header file containing circuit data for the whole HS subsystem.
entry_connection_t
Definition: entry_connection_st.h:19
CURVE25519_SECKEY_LEN
#define CURVE25519_SECKEY_LEN
Definition: x25519_sizes.h:22
DIRIND_ANONYMOUS
@ DIRIND_ANONYMOUS
Definition: dirclient.h:39
directory_request_t
struct directory_request_t directory_request_t
Definition: dirclient.h:52
hs_get_subcredential
void hs_get_subcredential(const ed25519_public_key_t *identity_pk, const ed25519_public_key_t *blinded_pk, hs_subcredential_t *subcred_out)
Definition: hs_common.c:816
origin_circuit_st.h
Origin circuit structure.
connection_t::timestamp_last_read_allowed
time_t timestamp_last_read_allowed
Definition: connection_st.h:104
CONN_IS_EDGE
#define CONN_IS_EDGE(x)
Definition: connection_st.h:183
hs_desc_intro_point_t
Definition: hs_descriptor.h:99
HS_CLIENT_FETCH_PENDING
@ HS_CLIENT_FETCH_PENDING
Definition: hs_client.h:33
hs_descriptor.h
Header file for hs_descriptor.c.
smartlist_t
Definition: smartlist_core.h:26
HS_SERVICE_ADDR_LEN_BASE32
#define HS_SERVICE_ADDR_LEN_BASE32
Definition: hs_common.h:83
rendclient.h
Header file for rendclient.c.
hs_ident_circuit_t::intro_enc_pk
curve25519_public_key_t intro_enc_pk
Definition: hs_ident.h:55
directory_request_set_indirection
void directory_request_set_indirection(directory_request_t *req, dir_indirection_t indirection)
Definition: dirclient.c:1032
CIRCUIT_PURPOSE_C_INTRODUCING
#define CIRCUIT_PURPOSE_C_INTRODUCING
Definition: circuitlist.h:75
EDGE_TO_ENTRY_CONN
entry_connection_t * EDGE_TO_ENTRY_CONN(edge_connection_t *c)
Definition: connection_edge.c:227
hs_ident_circuit_t::rendezvous_client_kp
curve25519_keypair_t rendezvous_client_kp
Definition: hs_ident.h:72
check_private_dir
int check_private_dir(const char *dirname, cpd_check_t check, const char *effective_user)
Definition: dir.c:71
extend_info_t
Definition: extend_info_st.h:27
tor_listdir
smartlist_t * tor_listdir(const char *dirname)
Definition: dir.c:307
directory_launch_v3_desc_fetch
static hs_client_fetch_status_t directory_launch_v3_desc_fetch(const ed25519_public_key_t *onion_identity_pk, const routerstatus_t *hsdir)
Definition: hs_client.c:378
hs_client_remove_auth_credentials
hs_client_removal_auth_status_t hs_client_remove_auth_credentials(const char *hsaddress)
Definition: hs_client.c:1821
or.h
Master header file for Tor-specific functionality.
LD_PROTOCOL
#define LD_PROTOCOL
Definition: log.h:72
handle_introduce_ack
static int handle_introduce_ack(origin_circuit_t *circ, const uint8_t *payload, size_t payload_len)
Definition: hs_client.c:1190
hs_client_service_authorization_t::onion_address
char onion_address[HS_SERVICE_ADDR_LEN_BASE32+1]
Definition: hs_client.h:72
auth_key_filename_is_valid
STATIC int auth_key_filename_is_valid(const char *filename)
Definition: hs_client.c:2197