Tor  0.4.6.0-alpha-dev
hs_common.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_common.c
6  * \brief Contains code shared between different HS protocol version as well
7  * as useful data structures and accessors used by other subsystems.
8  * The rendcommon.c should only contains code relating to the v2
9  * protocol.
10  **/
11 
12 #define HS_COMMON_PRIVATE
13 
14 #include "core/or/or.h"
15 
16 #include "app/config/config.h"
17 #include "core/or/circuitbuild.h"
18 #include "core/or/policies.h"
19 #include "core/or/extendinfo.h"
21 #include "feature/hs/hs_cache.h"
23 #include "feature/hs/hs_client.h"
24 #include "feature/hs/hs_common.h"
25 #include "feature/hs/hs_dos.h"
26 #include "feature/hs/hs_ob.h"
27 #include "feature/hs/hs_ident.h"
28 #include "feature/hs/hs_service.h"
40 
46 
47 /* Trunnel */
48 #include "trunnel/ed25519_cert.h"
49 
50 /** Ed25519 Basepoint value. Taken from section 5 of
51  * https://tools.ietf.org/html/draft-josefsson-eddsa-ed25519-03 */
52 static const char *str_ed25519_basepoint =
53  "(15112221349535400772501151409588531511"
54  "454012693041857206046113283949847762202, "
55  "463168356949264781694283940034751631413"
56  "07993866256225615783033603165251855960)";
57 
58 #ifdef HAVE_SYS_UN_H
59 
60 /** Given <b>ports</b>, a smarlist containing rend_service_port_config_t,
61  * add the given <b>p</b>, a AF_UNIX port to the list. Return 0 on success
62  * else return -ENOSYS if AF_UNIX is not supported (see function in the
63  * #else statement below). */
64 static int
65 add_unix_port(smartlist_t *ports, rend_service_port_config_t *p)
66 {
67  tor_assert(ports);
68  tor_assert(p);
70 
71  smartlist_add(ports, p);
72  return 0;
73 }
74 
75 /** Given <b>conn</b> set it to use the given port <b>p</b> values. Return 0
76  * on success else return -ENOSYS if AF_UNIX is not supported (see function
77  * in the #else statement below). */
78 static int
79 set_unix_port(edge_connection_t *conn, rend_service_port_config_t *p)
80 {
81  tor_assert(conn);
82  tor_assert(p);
84 
85  conn->base_.socket_family = AF_UNIX;
86  tor_addr_make_unspec(&conn->base_.addr);
87  conn->base_.port = 1;
88  conn->base_.address = tor_strdup(p->unix_addr);
89  return 0;
90 }
91 
92 #else /* !defined(HAVE_SYS_UN_H) */
93 
94 static int
95 set_unix_port(edge_connection_t *conn, rend_service_port_config_t *p)
96 {
97  (void) conn;
98  (void) p;
99  return -ENOSYS;
100 }
101 
102 static int
103 add_unix_port(smartlist_t *ports, rend_service_port_config_t *p)
104 {
105  (void) ports;
106  (void) p;
107  return -ENOSYS;
108 }
109 
110 #endif /* defined(HAVE_SYS_UN_H) */
111 
112 /** Helper function: The key is a digest that we compare to a node_t object
113  * current hsdir_index. */
114 static int
115 compare_digest_to_fetch_hsdir_index(const void *_key, const void **_member)
116 {
117  const char *key = _key;
118  const node_t *node = *_member;
119  return tor_memcmp(key, node->hsdir_index.fetch, DIGEST256_LEN);
120 }
121 
122 /** Helper function: The key is a digest that we compare to a node_t object
123  * next hsdir_index. */
124 static int
126  const void **_member)
127 {
128  const char *key = _key;
129  const node_t *node = *_member;
130  return tor_memcmp(key, node->hsdir_index.store_first, DIGEST256_LEN);
131 }
132 
133 /** Helper function: The key is a digest that we compare to a node_t object
134  * next hsdir_index. */
135 static int
137  const void **_member)
138 {
139  const char *key = _key;
140  const node_t *node = *_member;
141  return tor_memcmp(key, node->hsdir_index.store_second, DIGEST256_LEN);
142 }
143 
144 /** Helper function: Compare two node_t objects current hsdir_index. */
145 static int
146 compare_node_fetch_hsdir_index(const void **a, const void **b)
147 {
148  const node_t *node1= *a;
149  const node_t *node2 = *b;
150  return tor_memcmp(node1->hsdir_index.fetch,
151  node2->hsdir_index.fetch,
152  DIGEST256_LEN);
153 }
154 
155 /** Helper function: Compare two node_t objects next hsdir_index. */
156 static int
157 compare_node_store_first_hsdir_index(const void **a, const void **b)
158 {
159  const node_t *node1= *a;
160  const node_t *node2 = *b;
161  return tor_memcmp(node1->hsdir_index.store_first,
162  node2->hsdir_index.store_first,
163  DIGEST256_LEN);
164 }
165 
166 /** Helper function: Compare two node_t objects next hsdir_index. */
167 static int
168 compare_node_store_second_hsdir_index(const void **a, const void **b)
169 {
170  const node_t *node1= *a;
171  const node_t *node2 = *b;
172  return tor_memcmp(node1->hsdir_index.store_second,
173  node2->hsdir_index.store_second,
174  DIGEST256_LEN);
175 }
176 
177 /** Allocate and return a string containing the path to filename in directory.
178  * This function will never return NULL. The caller must free this path. */
179 char *
180 hs_path_from_filename(const char *directory, const char *filename)
181 {
182  char *file_path = NULL;
183 
184  tor_assert(directory);
185  tor_assert(filename);
186 
187  tor_asprintf(&file_path, "%s%s%s", directory, PATH_SEPARATOR, filename);
188  return file_path;
189 }
190 
191 /** Make sure that the directory for <b>service</b> is private, using the
192  * config <b>username</b>.
193  *
194  * If <b>create</b> is true:
195  * - if the directory exists, change permissions if needed,
196  * - if the directory does not exist, create it with the correct permissions.
197  * If <b>create</b> is false:
198  * - if the directory exists, check permissions,
199  * - if the directory does not exist, check if we think we can create it.
200  * Return 0 on success, -1 on failure. */
201 int
202 hs_check_service_private_dir(const char *username, const char *path,
203  unsigned int dir_group_readable,
204  unsigned int create)
205 {
206  cpd_check_t check_opts = CPD_NONE;
207 
208  tor_assert(path);
209 
210  if (create) {
211  check_opts |= CPD_CREATE;
212  } else {
213  check_opts |= CPD_CHECK_MODE_ONLY;
214  check_opts |= CPD_CHECK;
215  }
216  if (dir_group_readable) {
217  check_opts |= CPD_GROUP_READ;
218  }
219  /* Check/create directory */
220  if (check_private_dir(path, check_opts, username) < 0) {
221  return -1;
222  }
223  return 0;
224 }
225 
226 /* Default, minimum, and maximum values for the maximum rendezvous failures
227  * consensus parameter. */
228 #define MAX_REND_FAILURES_DEFAULT 2
229 #define MAX_REND_FAILURES_MIN 1
230 #define MAX_REND_FAILURES_MAX 10
231 
232 /** How many times will a hidden service operator attempt to connect to
233  * a requested rendezvous point before giving up? */
234 int
236 {
237  return networkstatus_get_param(NULL, "hs_service_max_rdv_failures",
238  MAX_REND_FAILURES_DEFAULT,
239  MAX_REND_FAILURES_MIN,
240  MAX_REND_FAILURES_MAX);
241 }
242 
243 /** Get the default HS time period length in minutes from the consensus. */
244 STATIC uint64_t
246 {
247  /* If we are on a test network, make the time period smaller than normal so
248  that we actually see it rotate. Specifically, make it the same length as
249  an SRV protocol run. */
250  if (get_options()->TestingTorNetwork) {
251  unsigned run_duration = sr_state_get_protocol_run_duration();
252  /* An SRV run should take more than a minute (it's 24 rounds) */
253  tor_assert_nonfatal(run_duration > 60);
254  /* Turn it from seconds to minutes before returning: */
256  }
257 
258  int32_t time_period_length = networkstatus_get_param(NULL, "hsdir_interval",
262  /* Make sure it's a positive value. */
263  tor_assert(time_period_length > 0);
264  /* uint64_t will always be able to contain a positive int32_t */
265  return (uint64_t) time_period_length;
266 }
267 
268 /** Get the HS time period number at time <b>now</b>. If <b>now</b> is not set,
269  * we try to get the time ourselves from a live consensus. */
270 uint64_t
272 {
273  uint64_t time_period_num;
274  time_t current_time;
275 
276  /* If no time is specified, set current time based on consensus time, and
277  * only fall back to system time if that fails. */
278  if (now != 0) {
279  current_time = now;
280  } else {
281  networkstatus_t *ns =
284  current_time = ns ? ns->valid_after : approx_time();
285  }
286 
287  /* Start by calculating minutes since the epoch */
288  uint64_t time_period_length = get_time_period_length();
289  uint64_t minutes_since_epoch = current_time / 60;
290 
291  /* Apply the rotation offset as specified by prop224 (section
292  * [TIME-PERIODS]), so that new time periods synchronize nicely with SRV
293  * publication */
294  unsigned int time_period_rotation_offset = sr_state_get_phase_duration();
295  time_period_rotation_offset /= 60; /* go from seconds to minutes */
296  tor_assert(minutes_since_epoch > time_period_rotation_offset);
297  minutes_since_epoch -= time_period_rotation_offset;
298 
299  /* Calculate the time period */
300  time_period_num = minutes_since_epoch / time_period_length;
301  return time_period_num;
302 }
303 
304 /** Get the number of the _upcoming_ HS time period, given that the current
305  * time is <b>now</b>. If <b>now</b> is not set, we try to get the time from a
306  * live consensus. */
307 uint64_t
309 {
310  return hs_get_time_period_num(now) + 1;
311 }
312 
313 /** Get the number of the _previous_ HS time period, given that the current
314  * time is <b>now</b>. If <b>now</b> is not set, we try to get the time from a
315  * live consensus. */
316 uint64_t
318 {
319  return hs_get_time_period_num(now) - 1;
320 }
321 
322 /** Return the start time of the upcoming time period based on <b>now</b>. If
323  * <b>now</b> is not set, we try to get the time ourselves from a live
324  * consensus. */
325 time_t
327 {
328  uint64_t time_period_length = get_time_period_length();
329 
330  /* Get start time of next time period */
331  uint64_t next_time_period_num = hs_get_next_time_period_num(now);
332  uint64_t start_of_next_tp_in_mins = next_time_period_num *time_period_length;
333 
334  /* Apply rotation offset as specified by prop224 section [TIME-PERIODS] */
335  unsigned int time_period_rotation_offset = sr_state_get_phase_duration();
336  return (time_t)(start_of_next_tp_in_mins * 60 + time_period_rotation_offset);
337 }
338 
339 /** Create a new rend_data_t for a specific given <b>version</b>.
340  * Return a pointer to the newly allocated data structure. */
341 static rend_data_t *
342 rend_data_alloc(uint32_t version)
343 {
344  rend_data_t *rend_data = NULL;
345 
346  switch (version) {
347  case HS_VERSION_TWO:
348  {
349  rend_data_v2_t *v2 = tor_malloc_zero(sizeof(*v2));
350  v2->base_.version = HS_VERSION_TWO;
351  v2->base_.hsdirs_fp = smartlist_new();
352  rend_data = &v2->base_;
353  break;
354  }
355  default:
356  tor_assert(0);
357  break;
358  }
359 
360  return rend_data;
361 }
362 
363 /** Free all storage associated with <b>data</b> */
364 void
366 {
367  if (!data) {
368  return;
369  }
370  /* By using our allocation function, this should always be set. */
371  tor_assert(data->hsdirs_fp);
372  /* Cleanup the HSDir identity digest. */
373  SMARTLIST_FOREACH(data->hsdirs_fp, char *, d, tor_free(d));
374  smartlist_free(data->hsdirs_fp);
375  /* Depending on the version, cleanup. */
376  switch (data->version) {
377  case HS_VERSION_TWO:
378  {
379  rend_data_v2_t *v2_data = TO_REND_DATA_V2(data);
380  tor_free(v2_data);
381  break;
382  }
383  default:
384  tor_assert(0);
385  }
386 }
387 
388 /** Allocate and return a deep copy of <b>data</b>. */
389 rend_data_t *
391 {
392  rend_data_t *data_dup = NULL;
393  smartlist_t *hsdirs_fp = smartlist_new();
394 
395  tor_assert(data);
396  tor_assert(data->hsdirs_fp);
397 
398  SMARTLIST_FOREACH(data->hsdirs_fp, char *, fp,
399  smartlist_add(hsdirs_fp, tor_memdup(fp, DIGEST_LEN)));
400 
401  switch (data->version) {
402  case HS_VERSION_TWO:
403  {
404  rend_data_v2_t *v2_data = tor_memdup(TO_REND_DATA_V2(data),
405  sizeof(*v2_data));
406  data_dup = &v2_data->base_;
407  data_dup->hsdirs_fp = hsdirs_fp;
408  break;
409  }
410  default:
411  tor_assert(0);
412  break;
413  }
414 
415  return data_dup;
416 }
417 
418 /** Compute the descriptor ID for each HS descriptor replica and save them. A
419  * valid onion address must be present in the <b>rend_data</b>.
420  *
421  * Return 0 on success else -1. */
422 static int
424 {
425  int ret = 0;
426  unsigned replica;
427  time_t now = time(NULL);
428 
429  tor_assert(rend_data);
430 
431  switch (rend_data->version) {
432  case HS_VERSION_TWO:
433  {
434  rend_data_v2_t *v2_data = TO_REND_DATA_V2(rend_data);
435  /* Compute descriptor ID for each replicas. */
436  for (replica = 0; replica < ARRAY_LENGTH(v2_data->descriptor_id);
437  replica++) {
438  ret = rend_compute_v2_desc_id(v2_data->descriptor_id[replica],
439  v2_data->onion_address,
440  v2_data->descriptor_cookie,
441  now, replica);
442  if (ret < 0) {
443  goto end;
444  }
445  }
446  break;
447  }
448  default:
449  tor_assert(0);
450  }
451 
452  end:
453  return ret;
454 }
455 
456 /** Allocate and initialize a rend_data_t object for a service using the
457  * provided arguments. All arguments are optional (can be NULL), except from
458  * <b>onion_address</b> which MUST be set. The <b>pk_digest</b> is the hash of
459  * the service private key. The <b>cookie</b> is the rendezvous cookie and
460  * <b>auth_type</b> is which authentiation this service is configured with.
461  *
462  * Return a valid rend_data_t pointer. This only returns a version 2 object of
463  * rend_data_t. */
464 rend_data_t *
465 rend_data_service_create(const char *onion_address, const char *pk_digest,
466  const uint8_t *cookie, rend_auth_type_t auth_type)
467 {
468  /* Create a rend_data_t object for version 2. */
470  rend_data_v2_t *v2= TO_REND_DATA_V2(rend_data);
471 
472  /* We need at least one else the call is wrong. */
473  tor_assert(onion_address != NULL);
474 
475  if (pk_digest) {
476  memcpy(v2->rend_pk_digest, pk_digest, sizeof(v2->rend_pk_digest));
477  }
478  if (cookie) {
479  memcpy(rend_data->rend_cookie, cookie, sizeof(rend_data->rend_cookie));
480  }
481 
482  strlcpy(v2->onion_address, onion_address, sizeof(v2->onion_address));
483  v2->auth_type = auth_type;
484 
485  return rend_data;
486 }
487 
488 /** Allocate and initialize a rend_data_t object for a client request using the
489  * given arguments. Either an onion address or a descriptor ID is needed. Both
490  * can be given but in this case only the onion address will be used to make
491  * the descriptor fetch. The <b>cookie</b> is the rendezvous cookie and
492  * <b>auth_type</b> is which authentiation the service is configured with.
493  *
494  * Return a valid rend_data_t pointer or NULL on error meaning the
495  * descriptor IDs couldn't be computed from the given data. */
496 rend_data_t *
497 rend_data_client_create(const char *onion_address, const char *desc_id,
498  const char *cookie, rend_auth_type_t auth_type)
499 {
500  /* Create a rend_data_t object for version 2. */
502  rend_data_v2_t *v2= TO_REND_DATA_V2(rend_data);
503 
504  /* We need at least one else the call is wrong. */
505  tor_assert(onion_address != NULL || desc_id != NULL);
506 
507  if (cookie) {
508  memcpy(v2->descriptor_cookie, cookie, sizeof(v2->descriptor_cookie));
509  }
510  if (desc_id) {
511  memcpy(v2->desc_id_fetch, desc_id, sizeof(v2->desc_id_fetch));
512  }
513  if (onion_address) {
514  strlcpy(v2->onion_address, onion_address, sizeof(v2->onion_address));
515  if (compute_desc_id(rend_data) < 0) {
516  goto error;
517  }
518  }
519 
520  v2->auth_type = auth_type;
521 
522  return rend_data;
523 
524  error:
525  rend_data_free(rend_data);
526  return NULL;
527 }
528 
529 /** Return the onion address from the rend data. Depending on the version,
530  * the size of the address can vary but it's always NUL terminated. */
531 const char *
533 {
534  tor_assert(rend_data);
535 
536  switch (rend_data->version) {
537  case HS_VERSION_TWO:
538  return TO_REND_DATA_V2(rend_data)->onion_address;
539  default:
540  /* We should always have a supported version. */
541  tor_assert_unreached();
542  }
543 }
544 
545 /** Return the descriptor ID for a specific replica number from the rend
546  * data. The returned data is a binary digest and depending on the version its
547  * size can vary. The size of the descriptor ID is put in <b>len_out</b> if
548  * non NULL. */
549 const char *
550 rend_data_get_desc_id(const rend_data_t *rend_data, uint8_t replica,
551  size_t *len_out)
552 {
553  tor_assert(rend_data);
554 
555  switch (rend_data->version) {
556  case HS_VERSION_TWO:
558  if (len_out) {
559  *len_out = DIGEST_LEN;
560  }
561  return TO_REND_DATA_V2(rend_data)->descriptor_id[replica];
562  default:
563  /* We should always have a supported version. */
564  tor_assert_unreached();
565  }
566 }
567 
568 /** Return the public key digest using the given <b>rend_data</b>. The size of
569  * the digest is put in <b>len_out</b> (if set) which can differ depending on
570  * the version. */
571 const uint8_t *
572 rend_data_get_pk_digest(const rend_data_t *rend_data, size_t *len_out)
573 {
574  tor_assert(rend_data);
575 
576  switch (rend_data->version) {
577  case HS_VERSION_TWO:
578  {
579  const rend_data_v2_t *v2_data = TO_REND_DATA_V2(rend_data);
580  if (len_out) {
581  *len_out = sizeof(v2_data->rend_pk_digest);
582  }
583  return (const uint8_t *) v2_data->rend_pk_digest;
584  }
585  default:
586  /* We should always have a supported version. */
587  tor_assert_unreached();
588  }
589 }
590 
591 /** Using the given time period number, compute the disaster shared random
592  * value and put it in srv_out. It MUST be at least DIGEST256_LEN bytes. */
593 static void
594 compute_disaster_srv(uint64_t time_period_num, uint8_t *srv_out)
595 {
596  crypto_digest_t *digest;
597 
598  tor_assert(srv_out);
599 
600  digest = crypto_digest256_new(DIGEST_SHA3_256);
601 
602  /* Start setting up payload:
603  * H("shared-random-disaster" | INT_8(period_length) | INT_8(period_num)) */
605  HS_SRV_DISASTER_PREFIX_LEN);
606 
607  /* Setup INT_8(period_length) | INT_8(period_num) */
608  {
609  uint64_t time_period_length = get_time_period_length();
610  char period_stuff[sizeof(uint64_t)*2];
611  size_t offset = 0;
612  set_uint64(period_stuff, tor_htonll(time_period_length));
613  offset += sizeof(uint64_t);
614  set_uint64(period_stuff+offset, tor_htonll(time_period_num));
615  offset += sizeof(uint64_t);
616  tor_assert(offset == sizeof(period_stuff));
617 
618  crypto_digest_add_bytes(digest, period_stuff, sizeof(period_stuff));
619  }
620 
621  crypto_digest_get_digest(digest, (char *) srv_out, DIGEST256_LEN);
622  crypto_digest_free(digest);
623 }
624 
625 /** Due to the high cost of computing the disaster SRV and that potentially we
626  * would have to do it thousands of times in a row, we always cache the
627  * computer disaster SRV (and its corresponding time period num) in case we
628  * want to reuse it soon after. We need to cache two SRVs, one for each active
629  * time period.
630  */
632 static uint64_t cached_time_period_nums[2] = {0};
633 
634 /** Compute the disaster SRV value for this <b>time_period_num</b> and put it
635  * in <b>srv_out</b> (of size at least DIGEST256_LEN). First check our caches
636  * to see if we have already computed it. */
637 STATIC void
638 get_disaster_srv(uint64_t time_period_num, uint8_t *srv_out)
639 {
640  if (time_period_num == cached_time_period_nums[0]) {
641  memcpy(srv_out, cached_disaster_srv[0], DIGEST256_LEN);
642  return;
643  } else if (time_period_num == cached_time_period_nums[1]) {
644  memcpy(srv_out, cached_disaster_srv[1], DIGEST256_LEN);
645  return;
646  } else {
647  int replace_idx;
648  // Replace the lower period number.
649  if (cached_time_period_nums[0] <= cached_time_period_nums[1]) {
650  replace_idx = 0;
651  } else {
652  replace_idx = 1;
653  }
654  cached_time_period_nums[replace_idx] = time_period_num;
655  compute_disaster_srv(time_period_num, cached_disaster_srv[replace_idx]);
656  memcpy(srv_out, cached_disaster_srv[replace_idx], DIGEST256_LEN);
657  return;
658  }
659 }
660 
661 #ifdef TOR_UNIT_TESTS
662 
663 /** Get the first cached disaster SRV. Only used by unittests. */
664 STATIC uint8_t *
665 get_first_cached_disaster_srv(void)
666 {
667  return cached_disaster_srv[0];
668 }
669 
670 /** Get the second cached disaster SRV. Only used by unittests. */
671 STATIC uint8_t *
672 get_second_cached_disaster_srv(void)
673 {
674  return cached_disaster_srv[1];
675 }
676 
677 #endif /* defined(TOR_UNIT_TESTS) */
678 
679 /** When creating a blinded key, we need a parameter which construction is as
680  * follow: H(pubkey | [secret] | ed25519-basepoint | nonce).
681  *
682  * The nonce has a pre-defined format which uses the time period number
683  * period_num and the start of the period in second start_time_period.
684  *
685  * The secret of size secret_len is optional meaning that it can be NULL and
686  * thus will be ignored for the param construction.
687  *
688  * The result is put in param_out. */
689 static void
691  const uint8_t *secret, size_t secret_len,
692  uint64_t period_num, uint64_t period_length,
693  uint8_t *param_out)
694 {
695  size_t offset = 0;
696  const char blind_str[] = "Derive temporary signing key";
697  uint8_t nonce[HS_KEYBLIND_NONCE_LEN];
698  crypto_digest_t *digest;
699 
700  tor_assert(pubkey);
701  tor_assert(param_out);
702 
703  /* Create the nonce N. The construction is as follow:
704  * N = "key-blind" || INT_8(period_num) || INT_8(period_length) */
705  memcpy(nonce, HS_KEYBLIND_NONCE_PREFIX, HS_KEYBLIND_NONCE_PREFIX_LEN);
706  offset += HS_KEYBLIND_NONCE_PREFIX_LEN;
707  set_uint64(nonce + offset, tor_htonll(period_num));
708  offset += sizeof(uint64_t);
709  set_uint64(nonce + offset, tor_htonll(period_length));
710  offset += sizeof(uint64_t);
711  tor_assert(offset == HS_KEYBLIND_NONCE_LEN);
712 
713  /* Generate the parameter h and the construction is as follow:
714  * h = H(BLIND_STRING | pubkey | [secret] | ed25519-basepoint | N) */
715  digest = crypto_digest256_new(DIGEST_SHA3_256);
716  crypto_digest_add_bytes(digest, blind_str, sizeof(blind_str));
717  crypto_digest_add_bytes(digest, (char *) pubkey, ED25519_PUBKEY_LEN);
718  /* Optional secret. */
719  if (secret) {
720  crypto_digest_add_bytes(digest, (char *) secret, secret_len);
721  }
723  strlen(str_ed25519_basepoint));
724  crypto_digest_add_bytes(digest, (char *) nonce, sizeof(nonce));
725 
726  /* Extract digest and put it in the param. */
727  crypto_digest_get_digest(digest, (char *) param_out, DIGEST256_LEN);
728  crypto_digest_free(digest);
729 
730  memwipe(nonce, 0, sizeof(nonce));
731 }
732 
733 /** Using an ed25519 public key and version to build the checksum of an
734  * address. Put in checksum_out. Format is:
735  * SHA3-256(".onion checksum" || PUBKEY || VERSION)
736  *
737  * checksum_out must be large enough to receive 32 bytes (DIGEST256_LEN). */
738 static void
739 build_hs_checksum(const ed25519_public_key_t *key, uint8_t version,
740  uint8_t *checksum_out)
741 {
742  size_t offset = 0;
744 
745  /* Build checksum data. */
746  memcpy(data, HS_SERVICE_ADDR_CHECKSUM_PREFIX,
749  memcpy(data + offset, key->pubkey, ED25519_PUBKEY_LEN);
750  offset += ED25519_PUBKEY_LEN;
751  set_uint8(data + offset, version);
752  offset += sizeof(version);
754 
755  /* Hash the data payload to create the checksum. */
756  crypto_digest256((char *) checksum_out, data, sizeof(data),
757  DIGEST_SHA3_256);
758 }
759 
760 /** Using an ed25519 public key, checksum and version to build the binary
761  * representation of a service address. Put in addr_out. Format is:
762  * addr_out = PUBKEY || CHECKSUM || VERSION
763  *
764  * addr_out must be large enough to receive HS_SERVICE_ADDR_LEN bytes. */
765 static void
766 build_hs_address(const ed25519_public_key_t *key, const uint8_t *checksum,
767  uint8_t version, char *addr_out)
768 {
769  size_t offset = 0;
770 
771  tor_assert(key);
772  tor_assert(checksum);
773 
774  memcpy(addr_out, key->pubkey, ED25519_PUBKEY_LEN);
775  offset += ED25519_PUBKEY_LEN;
776  memcpy(addr_out + offset, checksum, HS_SERVICE_ADDR_CHECKSUM_LEN_USED);
778  set_uint8(addr_out + offset, version);
779  offset += sizeof(uint8_t);
780  tor_assert(offset == HS_SERVICE_ADDR_LEN);
781 }
782 
783 /** Helper for hs_parse_address(): Using a binary representation of a service
784  * address, parse its content into the key_out, checksum_out and version_out.
785  * Any out variable can be NULL in case the caller would want only one field.
786  * checksum_out MUST at least be 2 bytes long. address must be at least
787  * HS_SERVICE_ADDR_LEN bytes but doesn't need to be NUL terminated. */
788 static void
789 hs_parse_address_impl(const char *address, ed25519_public_key_t *key_out,
790  uint8_t *checksum_out, uint8_t *version_out)
791 {
792  size_t offset = 0;
793 
794  tor_assert(address);
795 
796  if (key_out) {
797  /* First is the key. */
798  memcpy(key_out->pubkey, address, ED25519_PUBKEY_LEN);
799  }
800  offset += ED25519_PUBKEY_LEN;
801  if (checksum_out) {
802  /* Followed by a 2 bytes checksum. */
803  memcpy(checksum_out, address + offset, HS_SERVICE_ADDR_CHECKSUM_LEN_USED);
804  }
806  if (version_out) {
807  /* Finally, version value is 1 byte. */
808  *version_out = get_uint8(address + offset);
809  }
810  offset += sizeof(uint8_t);
811  /* Extra safety. */
812  tor_assert(offset == HS_SERVICE_ADDR_LEN);
813 }
814 
815 /** Using the given identity public key and a blinded public key, compute the
816  * subcredential and put it in subcred_out.
817  * This can't fail. */
818 void
820  const ed25519_public_key_t *blinded_pk,
821  hs_subcredential_t *subcred_out)
822 {
823  uint8_t credential[DIGEST256_LEN];
824  crypto_digest_t *digest;
825 
826  tor_assert(identity_pk);
827  tor_assert(blinded_pk);
828  tor_assert(subcred_out);
829 
830  /* First, build the credential. Construction is as follow:
831  * credential = H("credential" | public-identity-key) */
832  digest = crypto_digest256_new(DIGEST_SHA3_256);
834  HS_CREDENTIAL_PREFIX_LEN);
835  crypto_digest_add_bytes(digest, (const char *) identity_pk->pubkey,
837  crypto_digest_get_digest(digest, (char *) credential, DIGEST256_LEN);
838  crypto_digest_free(digest);
839 
840  /* Now, compute the subcredential. Construction is as follow:
841  * subcredential = H("subcredential" | credential | blinded-public-key). */
842  digest = crypto_digest256_new(DIGEST_SHA3_256);
843  crypto_digest_add_bytes(digest, HS_SUBCREDENTIAL_PREFIX,
844  HS_SUBCREDENTIAL_PREFIX_LEN);
845  crypto_digest_add_bytes(digest, (const char *) credential,
846  sizeof(credential));
847  crypto_digest_add_bytes(digest, (const char *) blinded_pk->pubkey,
849  crypto_digest_get_digest(digest, (char *) subcred_out->subcred,
850  SUBCRED_LEN);
851  crypto_digest_free(digest);
852 
853  memwipe(credential, 0, sizeof(credential));
854 }
855 
856 /** From the given list of hidden service ports, find the ones that match the
857  * given edge connection conn, pick one at random and use it to set the
858  * connection address. Return 0 on success or -1 if none. */
859 int
861 {
862  rend_service_port_config_t *chosen_port;
863  unsigned int warn_once = 0;
864  smartlist_t *matching_ports;
865 
866  tor_assert(ports);
867  tor_assert(conn);
868 
869  matching_ports = smartlist_new();
871  if (TO_CONN(conn)->port != p->virtual_port) {
872  continue;
873  }
874  if (!(p->is_unix_addr)) {
875  smartlist_add(matching_ports, p);
876  } else {
877  if (add_unix_port(matching_ports, p)) {
878  if (!warn_once) {
879  /* Unix port not supported so warn only once. */
880  log_warn(LD_REND, "Saw AF_UNIX virtual port mapping for port %d "
881  "which is unsupported on this platform. "
882  "Ignoring it.",
883  TO_CONN(conn)->port);
884  }
885  warn_once++;
886  }
887  }
888  } SMARTLIST_FOREACH_END(p);
889 
890  chosen_port = smartlist_choose(matching_ports);
891  smartlist_free(matching_ports);
892  if (chosen_port) {
893  /* Remember, v2 doesn't use an hs_ident. */
894  if (conn->hs_ident) {
895  /* There is always a connection identifier at this point. Regardless of a
896  * Unix or TCP port, note the virtual port. */
897  conn->hs_ident->orig_virtual_port = chosen_port->virtual_port;
898  }
899 
900  if (!(chosen_port->is_unix_addr)) {
901  /* Get a non-AF_UNIX connection ready for connection_exit_connect() */
902  tor_addr_copy(&TO_CONN(conn)->addr, &chosen_port->real_addr);
903  TO_CONN(conn)->port = chosen_port->real_port;
904  } else {
905  if (set_unix_port(conn, chosen_port)) {
906  /* Simply impossible to end up here else we were able to add a Unix
907  * port without AF_UNIX support... ? */
908  tor_assert(0);
909  }
910  }
911  }
912  return (chosen_port) ? 0 : -1;
913 }
914 
915 /** Using a base32 representation of a service address, parse its content into
916  * the key_out, checksum_out and version_out. Any out variable can be NULL in
917  * case the caller would want only one field. checksum_out MUST at least be 2
918  * bytes long.
919  *
920  * Return 0 if parsing went well; return -1 in case of error and if errmsg is
921  * non NULL, a human readable string message is set. */
922 int
923 hs_parse_address_no_log(const char *address, ed25519_public_key_t *key_out,
924  uint8_t *checksum_out, uint8_t *version_out,
925  const char **errmsg)
926 {
927  char decoded[HS_SERVICE_ADDR_LEN];
928 
929  tor_assert(address);
930 
931  if (errmsg) {
932  *errmsg = NULL;
933  }
934 
935  /* Obvious length check. */
936  if (strlen(address) != HS_SERVICE_ADDR_LEN_BASE32) {
937  if (errmsg) {
938  *errmsg = "Invalid length";
939  }
940  goto invalid;
941  }
942 
943  /* Decode address so we can extract needed fields. */
944  if (base32_decode(decoded, sizeof(decoded), address, strlen(address))
945  != sizeof(decoded)) {
946  if (errmsg) {
947  *errmsg = "Unable to base32 decode";
948  }
949  goto invalid;
950  }
951 
952  /* Parse the decoded address into the fields we need. */
953  hs_parse_address_impl(decoded, key_out, checksum_out, version_out);
954 
955  return 0;
956  invalid:
957  return -1;
958 }
959 
960 /** Same has hs_parse_address_no_log() but emits a log warning on parsing
961  * failure. */
962 int
963 hs_parse_address(const char *address, ed25519_public_key_t *key_out,
964  uint8_t *checksum_out, uint8_t *version_out)
965 {
966  const char *errmsg = NULL;
967  int ret = hs_parse_address_no_log(address, key_out, checksum_out,
968  version_out, &errmsg);
969  if (ret < 0) {
970  log_warn(LD_REND, "Service address %s failed to be parsed: %s",
971  escaped_safe_str(address), errmsg);
972  }
973  return ret;
974 }
975 
976 /** Validate a given onion address. The length, the base32 decoding, and
977  * checksum are validated. Return 1 if valid else 0. */
978 int
979 hs_address_is_valid(const char *address)
980 {
981  uint8_t version;
982  uint8_t checksum[HS_SERVICE_ADDR_CHECKSUM_LEN_USED];
983  uint8_t target_checksum[DIGEST256_LEN];
984  ed25519_public_key_t service_pubkey;
985 
986  /* Parse the decoded address into the fields we need. */
987  if (hs_parse_address(address, &service_pubkey, checksum, &version) < 0) {
988  goto invalid;
989  }
990 
991  /* Get the checksum it's supposed to be and compare it with what we have
992  * encoded in the address. */
993  build_hs_checksum(&service_pubkey, version, target_checksum);
994  if (tor_memcmp(checksum, target_checksum, sizeof(checksum))) {
995  log_warn(LD_REND, "Service address %s invalid checksum.",
996  escaped_safe_str(address));
997  goto invalid;
998  }
999 
1000  /* Validate that this pubkey does not have a torsion component. We need to do
1001  * this on the prop224 client-side so that attackers can't give equivalent
1002  * forms of an onion address to users. */
1003  if (ed25519_validate_pubkey(&service_pubkey) < 0) {
1004  log_warn(LD_REND, "Service address %s has bad pubkey .",
1005  escaped_safe_str(address));
1006  goto invalid;
1007  }
1008 
1009  /* Valid address. */
1010  return 1;
1011  invalid:
1012  return 0;
1013 }
1014 
1015 /** Build a service address using an ed25519 public key and a given version.
1016  * The returned address is base32 encoded and put in addr_out. The caller MUST
1017  * make sure the addr_out is at least HS_SERVICE_ADDR_LEN_BASE32 + 1 long.
1018  *
1019  * Format is as follows:
1020  * base32(PUBKEY || CHECKSUM || VERSION)
1021  * CHECKSUM = H(".onion checksum" || PUBKEY || VERSION)
1022  * */
1023 void
1024 hs_build_address(const ed25519_public_key_t *key, uint8_t version,
1025  char *addr_out)
1026 {
1027  uint8_t checksum[DIGEST256_LEN];
1028  char address[HS_SERVICE_ADDR_LEN];
1029 
1030  tor_assert(key);
1031  tor_assert(addr_out);
1032 
1033  /* Get the checksum of the address. */
1034  build_hs_checksum(key, version, checksum);
1035  /* Get the binary address representation. */
1036  build_hs_address(key, checksum, version, address);
1037 
1038  /* Encode the address. addr_out will be NUL terminated after this. */
1039  base32_encode(addr_out, HS_SERVICE_ADDR_LEN_BASE32 + 1, address,
1040  sizeof(address));
1041  /* Validate what we just built. */
1042  tor_assert(hs_address_is_valid(addr_out));
1043 }
1044 
1045 /** From a given ed25519 public key pk and an optional secret, compute a
1046  * blinded public key and put it in blinded_pk_out. This is only useful to
1047  * the client side because the client only has access to the identity public
1048  * key of the service. */
1049 void
1051  const uint8_t *secret, size_t secret_len,
1052  uint64_t time_period_num,
1053  ed25519_public_key_t *blinded_pk_out)
1054 {
1055  /* Our blinding key API requires a 32 bytes parameter. */
1056  uint8_t param[DIGEST256_LEN];
1057 
1058  tor_assert(pk);
1059  tor_assert(blinded_pk_out);
1061 
1062  build_blinded_key_param(pk, secret, secret_len,
1063  time_period_num, get_time_period_length(), param);
1064  ed25519_public_blind(blinded_pk_out, pk, param);
1065 
1066  memwipe(param, 0, sizeof(param));
1067 }
1068 
1069 /** From a given ed25519 keypair kp and an optional secret, compute a blinded
1070  * keypair for the current time period and put it in blinded_kp_out. This is
1071  * only useful by the service side because the client doesn't have access to
1072  * the identity secret key. */
1073 void
1075  const uint8_t *secret, size_t secret_len,
1076  uint64_t time_period_num,
1077  ed25519_keypair_t *blinded_kp_out)
1078 {
1079  /* Our blinding key API requires a 32 bytes parameter. */
1080  uint8_t param[DIGEST256_LEN];
1081 
1082  tor_assert(kp);
1083  tor_assert(blinded_kp_out);
1084  /* Extra safety. A zeroed key is bad. */
1085  tor_assert(!fast_mem_is_zero((char *) &kp->pubkey, ED25519_PUBKEY_LEN));
1086  tor_assert(!fast_mem_is_zero((char *) &kp->seckey, ED25519_SECKEY_LEN));
1087 
1088  build_blinded_key_param(&kp->pubkey, secret, secret_len,
1089  time_period_num, get_time_period_length(), param);
1090  ed25519_keypair_blind(blinded_kp_out, kp, param);
1091 
1092  memwipe(param, 0, sizeof(param));
1093 }
1094 
1095 /** Return true if we are currently in the time segment between a new time
1096  * period and a new SRV (in the real network that happens between 12:00 and
1097  * 00:00 UTC). Here is a diagram showing exactly when this returns true:
1098  *
1099  * +------------------------------------------------------------------+
1100  * | |
1101  * | 00:00 12:00 00:00 12:00 00:00 12:00 |
1102  * | SRV#1 TP#1 SRV#2 TP#2 SRV#3 TP#3 |
1103  * | |
1104  * | $==========|-----------$===========|-----------$===========| |
1105  * | ^^^^^^^^^^^^ ^^^^^^^^^^^^ |
1106  * | |
1107  * +------------------------------------------------------------------+
1108  */
1109 MOCK_IMPL(int,
1110 hs_in_period_between_tp_and_srv,(const networkstatus_t *consensus, time_t now))
1111 {
1112  time_t valid_after;
1113  time_t srv_start_time, tp_start_time;
1114 
1115  if (!consensus) {
1118  if (!consensus) {
1119  return 0;
1120  }
1121  }
1122 
1123  /* Get start time of next TP and of current SRV protocol run, and check if we
1124  * are between them. */
1125  valid_after = consensus->valid_after;
1127  tp_start_time = hs_get_start_time_of_next_time_period(srv_start_time);
1128 
1129  if (valid_after >= srv_start_time && valid_after < tp_start_time) {
1130  return 0;
1131  }
1132 
1133  return 1;
1134 }
1135 
1136 /** Return 1 if any virtual port in ports needs a circuit with good uptime.
1137  * Else return 0. */
1138 int
1140 {
1141  tor_assert(ports);
1142 
1144  if (smartlist_contains_int_as_string(get_options()->LongLivedPorts,
1145  p->virtual_port)) {
1146  return 1;
1147  }
1148  } SMARTLIST_FOREACH_END(p);
1149  return 0;
1150 }
1151 
1152 /** Build hs_index which is used to find the responsible hsdirs. This index
1153  * value is used to select the responsible HSDir where their hsdir_index is
1154  * closest to this value.
1155  * SHA3-256("store-at-idx" | blinded_public_key |
1156  * INT_8(replicanum) | INT_8(period_length) | INT_8(period_num) )
1157  *
1158  * hs_index_out must be large enough to receive DIGEST256_LEN bytes. */
1159 void
1160 hs_build_hs_index(uint64_t replica, const ed25519_public_key_t *blinded_pk,
1161  uint64_t period_num, uint8_t *hs_index_out)
1162 {
1163  crypto_digest_t *digest;
1164 
1165  tor_assert(blinded_pk);
1166  tor_assert(hs_index_out);
1167 
1168  /* Build hs_index. See construction at top of function comment. */
1169  digest = crypto_digest256_new(DIGEST_SHA3_256);
1170  crypto_digest_add_bytes(digest, HS_INDEX_PREFIX, HS_INDEX_PREFIX_LEN);
1171  crypto_digest_add_bytes(digest, (const char *) blinded_pk->pubkey,
1173 
1174  /* Now setup INT_8(replicanum) | INT_8(period_length) | INT_8(period_num) */
1175  {
1176  uint64_t period_length = get_time_period_length();
1177  char buf[sizeof(uint64_t)*3];
1178  size_t offset = 0;
1179  set_uint64(buf, tor_htonll(replica));
1180  offset += sizeof(uint64_t);
1181  set_uint64(buf+offset, tor_htonll(period_length));
1182  offset += sizeof(uint64_t);
1183  set_uint64(buf+offset, tor_htonll(period_num));
1184  offset += sizeof(uint64_t);
1185  tor_assert(offset == sizeof(buf));
1186 
1187  crypto_digest_add_bytes(digest, buf, sizeof(buf));
1188  }
1189 
1190  crypto_digest_get_digest(digest, (char *) hs_index_out, DIGEST256_LEN);
1191  crypto_digest_free(digest);
1192 }
1193 
1194 /** Build hsdir_index which is used to find the responsible hsdirs. This is the
1195  * index value that is compare to the hs_index when selecting an HSDir.
1196  * SHA3-256("node-idx" | node_identity |
1197  * shared_random_value | INT_8(period_length) | INT_8(period_num) )
1198  *
1199  * hsdir_index_out must be large enough to receive DIGEST256_LEN bytes. */
1200 void
1202  const uint8_t *srv_value, uint64_t period_num,
1203  uint8_t *hsdir_index_out)
1204 {
1205  crypto_digest_t *digest;
1206 
1207  tor_assert(identity_pk);
1208  tor_assert(srv_value);
1209  tor_assert(hsdir_index_out);
1210 
1211  /* Build hsdir_index. See construction at top of function comment. */
1212  digest = crypto_digest256_new(DIGEST_SHA3_256);
1213  crypto_digest_add_bytes(digest, HSDIR_INDEX_PREFIX, HSDIR_INDEX_PREFIX_LEN);
1214  crypto_digest_add_bytes(digest, (const char *) identity_pk->pubkey,
1216  crypto_digest_add_bytes(digest, (const char *) srv_value, DIGEST256_LEN);
1217 
1218  {
1219  uint64_t time_period_length = get_time_period_length();
1220  char period_stuff[sizeof(uint64_t)*2];
1221  size_t offset = 0;
1222  set_uint64(period_stuff, tor_htonll(period_num));
1223  offset += sizeof(uint64_t);
1224  set_uint64(period_stuff+offset, tor_htonll(time_period_length));
1225  offset += sizeof(uint64_t);
1226  tor_assert(offset == sizeof(period_stuff));
1227 
1228  crypto_digest_add_bytes(digest, period_stuff, sizeof(period_stuff));
1229  }
1230 
1231  crypto_digest_get_digest(digest, (char *) hsdir_index_out, DIGEST256_LEN);
1232  crypto_digest_free(digest);
1233 }
1234 
1235 /** Return a newly allocated buffer containing the current shared random value
1236  * or if not present, a disaster value is computed using the given time period
1237  * number. If a consensus is provided in <b>ns</b>, use it to get the SRV
1238  * value. This function can't fail. */
1239 uint8_t *
1240 hs_get_current_srv(uint64_t time_period_num, const networkstatus_t *ns)
1241 {
1242  uint8_t *sr_value = tor_malloc_zero(DIGEST256_LEN);
1243  const sr_srv_t *current_srv = sr_get_current(ns);
1244 
1245  if (current_srv) {
1246  memcpy(sr_value, current_srv->value, sizeof(current_srv->value));
1247  } else {
1248  /* Disaster mode. */
1249  get_disaster_srv(time_period_num, sr_value);
1250  }
1251  return sr_value;
1252 }
1253 
1254 /** Return a newly allocated buffer containing the previous shared random
1255  * value or if not present, a disaster value is computed using the given time
1256  * period number. This function can't fail. */
1257 uint8_t *
1258 hs_get_previous_srv(uint64_t time_period_num, const networkstatus_t *ns)
1259 {
1260  uint8_t *sr_value = tor_malloc_zero(DIGEST256_LEN);
1261  const sr_srv_t *previous_srv = sr_get_previous(ns);
1262 
1263  if (previous_srv) {
1264  memcpy(sr_value, previous_srv->value, sizeof(previous_srv->value));
1265  } else {
1266  /* Disaster mode. */
1267  get_disaster_srv(time_period_num, sr_value);
1268  }
1269  return sr_value;
1270 }
1271 
1272 /** Return the number of replicas defined by a consensus parameter or the
1273  * default value. */
1274 int32_t
1276 {
1277  /* The [1,16] range is a specification requirement. */
1278  return networkstatus_get_param(NULL, "hsdir_n_replicas",
1280 }
1281 
1282 /** Return the spread fetch value defined by a consensus parameter or the
1283  * default value. */
1284 int32_t
1286 {
1287  /* The [1,128] range is a specification requirement. */
1288  return networkstatus_get_param(NULL, "hsdir_spread_fetch",
1290 }
1291 
1292 /** Return the spread store value defined by a consensus parameter or the
1293  * default value. */
1294 int32_t
1296 {
1297  /* The [1,128] range is a specification requirement. */
1298  return networkstatus_get_param(NULL, "hsdir_spread_store",
1300 }
1301 
1302 /** <b>node</b> is an HSDir so make sure that we have assigned an hsdir index.
1303  * Return 0 if everything is as expected, else return -1. */
1304 static int
1306 {
1308 
1309  /* A node can't have an HSDir index without a descriptor since we need desc
1310  * to get its ed25519 key. for_direct_connect should be zero, since we
1311  * always use the consensus-indexed node's keys to build the hash ring, even
1312  * if some of the consensus-indexed nodes are also bridges. */
1313  if (!node_has_preferred_descriptor(node, 0)) {
1314  return 0;
1315  }
1316 
1317  /* At this point, since the node has a desc, this node must also have an
1318  * hsdir index. If not, something went wrong, so BUG out. */
1319  if (BUG(fast_mem_is_zero((const char*)node->hsdir_index.fetch,
1320  DIGEST256_LEN))) {
1321  return 0;
1322  }
1323  if (BUG(fast_mem_is_zero((const char*)node->hsdir_index.store_first,
1324  DIGEST256_LEN))) {
1325  return 0;
1326  }
1327  if (BUG(fast_mem_is_zero((const char*)node->hsdir_index.store_second,
1328  DIGEST256_LEN))) {
1329  return 0;
1330  }
1331 
1332  return 1;
1333 }
1334 
1335 /** For a given blinded key and time period number, get the responsible HSDir
1336  * and put their routerstatus_t object in the responsible_dirs list. If
1337  * 'use_second_hsdir_index' is true, use the second hsdir_index of the node_t
1338  * is used. If 'for_fetching' is true, the spread fetch consensus parameter is
1339  * used else the spread store is used which is only for upload. This function
1340  * can't fail but it is possible that the responsible_dirs list contains fewer
1341  * nodes than expected.
1342  *
1343  * This function goes over the latest consensus routerstatus list and sorts it
1344  * by their node_t hsdir_index then does a binary search to find the closest
1345  * node. All of this makes it a bit CPU intensive so use it wisely. */
1346 void
1348  uint64_t time_period_num, int use_second_hsdir_index,
1349  int for_fetching, smartlist_t *responsible_dirs)
1350 {
1351  smartlist_t *sorted_nodes;
1352  /* The compare function used for the smartlist bsearch. We have two
1353  * different depending on is_next_period. */
1354  int (*cmp_fct)(const void *, const void **);
1355 
1356  tor_assert(blinded_pk);
1357  tor_assert(responsible_dirs);
1358 
1359  sorted_nodes = smartlist_new();
1360 
1361  /* Make sure we actually have a live consensus */
1362  networkstatus_t *c =
1365  if (!c || smartlist_len(c->routerstatus_list) == 0) {
1366  log_warn(LD_REND, "No live consensus so we can't get the responsible "
1367  "hidden service directories.");
1368  goto done;
1369  }
1370 
1371  /* Ensure the nodelist is fresh, since it contains the HSDir indices. */
1373 
1374  /* Add every node_t that support HSDir v3 for which we do have a valid
1375  * hsdir_index already computed for them for this consensus. */
1376  {
1378  /* Even though this node_t object won't be modified and should be const,
1379  * we can't add const object in a smartlist_t. */
1380  node_t *n = node_get_mutable_by_id(rs->identity_digest);
1381  tor_assert(n);
1382  if (node_supports_v3_hsdir(n) && rs->is_hs_dir) {
1383  if (!node_has_hsdir_index(n)) {
1384  log_info(LD_GENERAL, "Node %s was found without hsdir index.",
1385  node_describe(n));
1386  continue;
1387  }
1388  smartlist_add(sorted_nodes, n);
1389  }
1390  } SMARTLIST_FOREACH_END(rs);
1391  }
1392  if (smartlist_len(sorted_nodes) == 0) {
1393  log_warn(LD_REND, "No nodes found to be HSDir or supporting v3.");
1394  goto done;
1395  }
1396 
1397  /* First thing we have to do is sort all node_t by hsdir_index. The
1398  * is_next_period tells us if we want the current or the next one. Set the
1399  * bsearch compare function also while we are at it. */
1400  if (for_fetching) {
1403  } else if (use_second_hsdir_index) {
1406  } else {
1409  }
1410 
1411  /* For all replicas, we'll select a set of HSDirs using the consensus
1412  * parameters and the sorted list. The replica starting at value 1 is
1413  * defined by the specification. */
1414  for (int replica = 1; replica <= hs_get_hsdir_n_replicas(); replica++) {
1415  int idx, start, found, n_added = 0;
1416  uint8_t hs_index[DIGEST256_LEN] = {0};
1417  /* Number of node to add to the responsible dirs list depends on if we are
1418  * trying to fetch or store. A client always fetches. */
1419  int n_to_add = (for_fetching) ? hs_get_hsdir_spread_fetch() :
1421 
1422  /* Get the index that we should use to select the node. */
1423  hs_build_hs_index(replica, blinded_pk, time_period_num, hs_index);
1424  /* The compare function pointer has been set correctly earlier. */
1425  start = idx = smartlist_bsearch_idx(sorted_nodes, hs_index, cmp_fct,
1426  &found);
1427  /* Getting the length of the list if no member is greater than the key we
1428  * are looking for so start at the first element. */
1429  if (idx == smartlist_len(sorted_nodes)) {
1430  start = idx = 0;
1431  }
1432  while (n_added < n_to_add) {
1433  const node_t *node = smartlist_get(sorted_nodes, idx);
1434  /* If the node has already been selected which is possible between
1435  * replicas, the specification says to skip over. */
1436  if (!smartlist_contains(responsible_dirs, node->rs)) {
1437  smartlist_add(responsible_dirs, node->rs);
1438  ++n_added;
1439  }
1440  if (++idx == smartlist_len(sorted_nodes)) {
1441  /* Wrap if we've reached the end of the list. */
1442  idx = 0;
1443  }
1444  if (idx == start) {
1445  /* We've gone over the whole list, stop and avoid infinite loop. */
1446  break;
1447  }
1448  }
1449  }
1450 
1451  done:
1452  smartlist_free(sorted_nodes);
1453 }
1454 
1455 /*********************** HSDir request tracking ***************************/
1456 
1457 /** Return the period for which a hidden service directory cannot be queried
1458  * for the same descriptor ID again, taking TestingTorNetwork into account. */
1459 time_t
1461 {
1462  tor_assert(options);
1463 
1464  if (options->TestingTorNetwork) {
1465  return REND_HID_SERV_DIR_REQUERY_PERIOD_TESTING;
1466  } else {
1467  return REND_HID_SERV_DIR_REQUERY_PERIOD;
1468  }
1469 }
1470 
1471 /** Tracks requests for fetching hidden service descriptors. It's used by
1472  * hidden service clients, to avoid querying HSDirs that have already failed
1473  * giving back a descriptor. The same data structure is used to track both v2
1474  * and v3 HS descriptor requests.
1475  *
1476  * The string map is a key/value store that contains the last request times to
1477  * hidden service directories for certain queries. Specifically:
1478  *
1479  * key = base32(hsdir_identity) + base32(hs_identity)
1480  * value = time_t of last request for that hs_identity to that HSDir
1481  *
1482  * where 'hsdir_identity' is the identity digest of the HSDir node, and
1483  * 'hs_identity' is the descriptor ID of the HS in the v2 case, or the ed25519
1484  * blinded public key of the HS in the v3 case. */
1485 static strmap_t *last_hid_serv_requests_ = NULL;
1486 
1487 /** Returns last_hid_serv_requests_, initializing it to a new strmap if
1488  * necessary. */
1489 STATIC strmap_t *
1491 {
1493  last_hid_serv_requests_ = strmap_new();
1494  return last_hid_serv_requests_;
1495 }
1496 
1497 /** Look up the last request time to hidden service directory <b>hs_dir</b>
1498  * for descriptor request key <b>req_key_str</b> which is the descriptor ID
1499  * for a v2 service or the blinded key for v3. If <b>set</b> is non-zero,
1500  * assign the current time <b>now</b> and return that. Otherwise, return the
1501  * most recent request time, or 0 if no such request has been sent before. */
1502 time_t
1504  const char *req_key_str,
1505  time_t now, int set)
1506 {
1507  char hsdir_id_base32[BASE32_DIGEST_LEN + 1];
1508  char *hsdir_desc_comb_id = NULL;
1509  time_t *last_request_ptr;
1510  strmap_t *last_hid_serv_requests = get_last_hid_serv_requests();
1511 
1512  /* Create the key */
1513  base32_encode(hsdir_id_base32, sizeof(hsdir_id_base32),
1514  hs_dir->identity_digest, DIGEST_LEN);
1515  tor_asprintf(&hsdir_desc_comb_id, "%s%s", hsdir_id_base32, req_key_str);
1516 
1517  if (set) {
1518  time_t *oldptr;
1519  last_request_ptr = tor_malloc_zero(sizeof(time_t));
1520  *last_request_ptr = now;
1521  oldptr = strmap_set(last_hid_serv_requests, hsdir_desc_comb_id,
1522  last_request_ptr);
1523  tor_free(oldptr);
1524  } else {
1525  last_request_ptr = strmap_get(last_hid_serv_requests,
1526  hsdir_desc_comb_id);
1527  }
1528 
1529  tor_free(hsdir_desc_comb_id);
1530  return (last_request_ptr) ? *last_request_ptr : 0;
1531 }
1532 
1533 /** Clean the history of request times to hidden service directories, so that
1534  * it does not contain requests older than REND_HID_SERV_DIR_REQUERY_PERIOD
1535  * seconds any more. */
1536 void
1538 {
1539  strmap_iter_t *iter;
1540  time_t cutoff = now - hs_hsdir_requery_period(get_options());
1541  strmap_t *last_hid_serv_requests = get_last_hid_serv_requests();
1542  for (iter = strmap_iter_init(last_hid_serv_requests);
1543  !strmap_iter_done(iter); ) {
1544  const char *key;
1545  void *val;
1546  time_t *ent;
1547  strmap_iter_get(iter, &key, &val);
1548  ent = (time_t *) val;
1549  if (*ent < cutoff) {
1550  iter = strmap_iter_next_rmv(last_hid_serv_requests, iter);
1551  tor_free(ent);
1552  } else {
1553  iter = strmap_iter_next(last_hid_serv_requests, iter);
1554  }
1555  }
1556 }
1557 
1558 /** Remove all requests related to the descriptor request key string
1559  * <b>req_key_str</b> from the history of times of requests to hidden service
1560  * directories.
1561  *
1562  * This is called from rend_client_note_connection_attempt_ended(), which
1563  * must be idempotent, so any future changes to this function must leave it
1564  * idempotent too. */
1565 void
1567 {
1568  strmap_iter_t *iter;
1569  strmap_t *last_hid_serv_requests = get_last_hid_serv_requests();
1570 
1571  for (iter = strmap_iter_init(last_hid_serv_requests);
1572  !strmap_iter_done(iter); ) {
1573  const char *key;
1574  void *val;
1575  strmap_iter_get(iter, &key, &val);
1576 
1577  /* XXX: The use of REND_DESC_ID_V2_LEN_BASE32 is very wrong in terms of
1578  * semantic, see #23305. */
1579 
1580  /* This strmap contains variable-sized elements so this is a basic length
1581  * check on the strings we are about to compare. The key is variable sized
1582  * since it's composed as follows:
1583  * key = base32(hsdir_identity) + base32(req_key_str)
1584  * where 'req_key_str' is the descriptor ID of the HS in the v2 case, or
1585  * the ed25519 blinded public key of the HS in the v3 case. */
1586  if (strlen(key) < REND_DESC_ID_V2_LEN_BASE32 + strlen(req_key_str)) {
1587  iter = strmap_iter_next(last_hid_serv_requests, iter);
1588  continue;
1589  }
1590 
1591  /* Check if the tracked request matches our request key */
1592  if (tor_memeq(key + REND_DESC_ID_V2_LEN_BASE32, req_key_str,
1593  strlen(req_key_str))) {
1594  iter = strmap_iter_next_rmv(last_hid_serv_requests, iter);
1595  tor_free(val);
1596  } else {
1597  iter = strmap_iter_next(last_hid_serv_requests, iter);
1598  }
1599  }
1600 }
1601 
1602 /** Purge the history of request times to hidden service directories,
1603  * so that future lookups of an HS descriptor will not fail because we
1604  * accessed all of the HSDir relays responsible for the descriptor
1605  * recently. */
1606 void
1608 {
1609  /* Don't create the table if it doesn't exist yet (and it may very
1610  * well not exist if the user hasn't accessed any HSes)... */
1611  strmap_t *old_last_hid_serv_requests = last_hid_serv_requests_;
1612  /* ... and let get_last_hid_serv_requests re-create it for us if
1613  * necessary. */
1614  last_hid_serv_requests_ = NULL;
1615 
1616  if (old_last_hid_serv_requests != NULL) {
1617  log_info(LD_REND, "Purging client last-HS-desc-request-time table");
1618  strmap_free(old_last_hid_serv_requests, tor_free_);
1619  }
1620 }
1621 
1622 /***********************************************************************/
1623 
1624 /** Given the list of responsible HSDirs in <b>responsible_dirs</b>, pick the
1625  * one that we should use to fetch a descriptor right now. Take into account
1626  * previous failed attempts at fetching this descriptor from HSDirs using the
1627  * string identifier <b>req_key_str</b>. We return whether we are rate limited
1628  * into *<b>is_rate_limited_out</b> if it is not NULL.
1629  *
1630  * Steals ownership of <b>responsible_dirs</b>.
1631  *
1632  * Return the routerstatus of the chosen HSDir if successful, otherwise return
1633  * NULL if no HSDirs are worth trying right now. */
1635 hs_pick_hsdir(smartlist_t *responsible_dirs, const char *req_key_str,
1636  bool *is_rate_limited_out)
1637 {
1638  smartlist_t *usable_responsible_dirs = smartlist_new();
1639  const or_options_t *options = get_options();
1640  routerstatus_t *hs_dir;
1641  time_t now = time(NULL);
1642  int excluded_some;
1643  bool rate_limited = false;
1644  int rate_limited_count = 0;
1645  int responsible_dirs_count = smartlist_len(responsible_dirs);
1646 
1647  tor_assert(req_key_str);
1648 
1649  /* Clean outdated request history first. */
1651 
1652  /* Only select those hidden service directories to which we did not send a
1653  * request recently and for which we have a router descriptor here.
1654  *
1655  * Use for_direct_connect==0 even if we will be connecting to the node
1656  * directly, since we always use the key information in the
1657  * consensus-indexed node descriptors for building the index.
1658  **/
1659  SMARTLIST_FOREACH_BEGIN(responsible_dirs, routerstatus_t *, dir) {
1660  time_t last = hs_lookup_last_hid_serv_request(dir, req_key_str, 0, 0);
1661  const node_t *node = node_get_by_id(dir->identity_digest);
1662  if (last + hs_hsdir_requery_period(options) >= now ||
1663  !node || !node_has_preferred_descriptor(node, 0)) {
1664  SMARTLIST_DEL_CURRENT(responsible_dirs, dir);
1665  rate_limited_count++;
1666  continue;
1667  }
1668  if (!routerset_contains_node(options->ExcludeNodes, node)) {
1669  smartlist_add(usable_responsible_dirs, dir);
1670  }
1671  } SMARTLIST_FOREACH_END(dir);
1672 
1673  if (rate_limited_count > 0 || responsible_dirs_count > 0) {
1674  rate_limited = rate_limited_count == responsible_dirs_count;
1675  }
1676 
1677  excluded_some =
1678  smartlist_len(usable_responsible_dirs) < smartlist_len(responsible_dirs);
1679 
1680  hs_dir = smartlist_choose(usable_responsible_dirs);
1681  if (!hs_dir && !options->StrictNodes) {
1682  hs_dir = smartlist_choose(responsible_dirs);
1683  }
1684 
1685  smartlist_free(responsible_dirs);
1686  smartlist_free(usable_responsible_dirs);
1687  if (!hs_dir) {
1688  const char *warn_str = (rate_limited) ? "we are rate limited." :
1689  "we requested them all recently without success";
1690  log_info(LD_REND, "Could not pick one of the responsible hidden "
1691  "service directories, because %s.", warn_str);
1692  if (options->StrictNodes && excluded_some) {
1693  log_warn(LD_REND, "Could not pick a hidden service directory for the "
1694  "requested hidden service: they are all either down or "
1695  "excluded, and StrictNodes is set.");
1696  }
1697  } else {
1698  /* Remember that we are requesting a descriptor from this hidden service
1699  * directory now. */
1700  hs_lookup_last_hid_serv_request(hs_dir, req_key_str, now, 1);
1701  }
1702 
1703  if (is_rate_limited_out != NULL) {
1704  *is_rate_limited_out = rate_limited;
1705  }
1706 
1707  return hs_dir;
1708 }
1709 
1710 /** Given a list of link specifiers lspecs, a curve 25519 onion_key, and
1711  * a direct connection boolean direct_conn (true for single onion services),
1712  * return a newly allocated extend_info_t object.
1713  *
1714  * This function always returns an extend info with a valid IP address and
1715  * ORPort, or NULL. If direct_conn is false, the IP address is always IPv4.
1716  *
1717  * It performs the following checks:
1718  * if there is no usable IP address, or legacy ID is missing, return NULL.
1719  * if direct_conn, and we can't reach any IP address, return NULL.
1720  */
1721 extend_info_t *
1723  const curve25519_public_key_t *onion_key,
1724  int direct_conn)
1725 {
1726  int have_v4 = 0, have_legacy_id = 0, have_ed25519_id = 0;
1727  char legacy_id[DIGEST_LEN] = {0};
1728  ed25519_public_key_t ed25519_pk;
1729  extend_info_t *info = NULL;
1730  tor_addr_port_t ap;
1731 
1732  tor_addr_make_null(&ap.addr, AF_UNSPEC);
1733  ap.port = 0;
1734 
1735  if (lspecs == NULL) {
1736  log_warn(LD_BUG, "Specified link specifiers is null");
1737  goto done;
1738  }
1739 
1740  if (onion_key == NULL) {
1741  log_warn(LD_BUG, "Specified onion key is null");
1742  goto done;
1743  }
1744 
1745  if (smartlist_len(lspecs) == 0) {
1746  log_fn(LOG_PROTOCOL_WARN, LD_REND, "Empty link specifier list.");
1747  /* Return NULL. */
1748  goto done;
1749  }
1750 
1751  SMARTLIST_FOREACH_BEGIN(lspecs, const link_specifier_t *, ls) {
1752  switch (link_specifier_get_ls_type(ls)) {
1753  case LS_IPV4:
1754  /* Skip if we already seen a v4. If direct_conn is true, we skip this
1755  * block because reachable_addr_choose_from_ls() will set ap. If
1756  * direct_conn is false, set ap to the first IPv4 address and port in
1757  * the link specifiers.*/
1758  if (have_v4 || direct_conn) continue;
1759  tor_addr_from_ipv4h(&ap.addr,
1760  link_specifier_get_un_ipv4_addr(ls));
1761  ap.port = link_specifier_get_un_ipv4_port(ls);
1762  have_v4 = 1;
1763  break;
1764  case LS_LEGACY_ID:
1765  /* Make sure we do have enough bytes for the legacy ID. */
1766  if (link_specifier_getlen_un_legacy_id(ls) < sizeof(legacy_id)) {
1767  break;
1768  }
1769  memcpy(legacy_id, link_specifier_getconstarray_un_legacy_id(ls),
1770  sizeof(legacy_id));
1771  have_legacy_id = 1;
1772  break;
1773  case LS_ED25519_ID:
1774  memcpy(ed25519_pk.pubkey,
1775  link_specifier_getconstarray_un_ed25519_id(ls),
1777  have_ed25519_id = 1;
1778  break;
1779  default:
1780  /* Ignore unknown. */
1781  break;
1782  }
1783  } SMARTLIST_FOREACH_END(ls);
1784 
1785  /* Choose a preferred address first, but fall back to an allowed address. */
1786  if (direct_conn)
1787  reachable_addr_choose_from_ls(lspecs, 0, &ap);
1788 
1789  /* Legacy ID is mandatory, and we require an IP address. */
1790  if (!tor_addr_port_is_valid_ap(&ap, 0)) {
1791  /* If we're missing the IP address, log a warning and return NULL. */
1792  log_info(LD_NET, "Unreachable or invalid IP address in link state");
1793  goto done;
1794  }
1795  if (!have_legacy_id) {
1796  /* If we're missing the legacy ID, log a warning and return NULL. */
1797  log_warn(LD_PROTOCOL, "Missing Legacy ID in link state");
1798  goto done;
1799  }
1800 
1801  /* We will add support for falling back to a 3-hop path in a later
1802  * release. */
1803 
1804  /* We'll validate now that the address we've picked isn't a private one. If
1805  * it is, are we allowed to extend to private addresses? */
1806  if (!extend_info_addr_is_allowed(&ap.addr)) {
1807  log_fn(LOG_PROTOCOL_WARN, LD_REND,
1808  "Requested address is private and we are not allowed to extend to "
1809  "it: %s:%u", fmt_addr(&ap.addr), ap.port);
1810  goto done;
1811  }
1812 
1813  /* We do have everything for which we think we can connect successfully. */
1814  info = extend_info_new(NULL, legacy_id,
1815  (have_ed25519_id) ? &ed25519_pk : NULL, NULL,
1816  onion_key, &ap.addr, ap.port);
1817  done:
1818  return info;
1819 }
1820 
1821 /***********************************************************************/
1822 
1823 /** Initialize the entire HS subsystem. This is called in tor_init() before any
1824  * torrc options are loaded. Only for >= v3. */
1825 void
1826 hs_init(void)
1827 {
1829  hs_service_init();
1830  hs_cache_init();
1831 }
1832 
1833 /** Release and cleanup all memory of the HS subsystem (all version). This is
1834  * called by tor_free_all(). */
1835 void
1837 {
1842  hs_ob_free_all();
1843 }
1844 
1845 /** For the given origin circuit circ, decrement the number of rendezvous
1846  * stream counter. This handles every hidden service version. */
1847 void
1849 {
1850  tor_assert(circ);
1851 
1852  if (circ->rend_data) {
1853  circ->rend_data->nr_streams--;
1854  } else if (circ->hs_ident) {
1855  circ->hs_ident->num_rdv_streams--;
1856  } else {
1857  /* Should not be called if this circuit is not for hidden service. */
1859  }
1860 }
1861 
1862 /** For the given origin circuit circ, increment the number of rendezvous
1863  * stream counter. This handles every hidden service version. */
1864 void
1866 {
1867  tor_assert(circ);
1868 
1869  if (circ->rend_data) {
1870  circ->rend_data->nr_streams++;
1871  } else if (circ->hs_ident) {
1872  circ->hs_ident->num_rdv_streams++;
1873  } else {
1874  /* Should not be called if this circuit is not for hidden service. */
1876  }
1877 }
1878 
1879 /** Return a newly allocated link specifier object that is a copy of dst. */
1880 link_specifier_t *
1881 link_specifier_dup(const link_specifier_t *src)
1882 {
1883  link_specifier_t *dup = NULL;
1884  uint8_t *buf = NULL;
1885 
1886  if (BUG(!src)) {
1887  goto err;
1888  }
1889 
1890  ssize_t encoded_len_alloc = link_specifier_encoded_len(src);
1891  if (BUG(encoded_len_alloc < 0)) {
1892  goto err;
1893  }
1894 
1895  buf = tor_malloc_zero(encoded_len_alloc);
1896  ssize_t encoded_len_data = link_specifier_encode(buf,
1897  encoded_len_alloc,
1898  src);
1899  if (BUG(encoded_len_data < 0)) {
1900  goto err;
1901  }
1902 
1903  ssize_t parsed_len = link_specifier_parse(&dup, buf, encoded_len_alloc);
1904  if (BUG(parsed_len < 0)) {
1905  goto err;
1906  }
1907 
1908  goto done;
1909 
1910  err:
1911  dup = NULL;
1912 
1913  done:
1914  tor_free(buf);
1915  return dup;
1916 }
log_fn
#define log_fn(severity, domain, args,...)
Definition: log.h:283
routermode.h
Header file for routermode.c.
hs_cache_init
void hs_cache_init(void)
Definition: hs_cache.c:1127
tor_free
#define tor_free(p)
Definition: malloc.h:52
hs_service.h
Header file containing service data for the HS subsystem.
tor_free_
void tor_free_(void *mem)
Definition: malloc.c:227
rend_service_port_config_t::is_unix_addr
unsigned int is_unix_addr
Definition: hs_common.h:157
HS_TIME_PERIOD_LENGTH_MAX
#define HS_TIME_PERIOD_LENGTH_MAX
Definition: hs_common.h:91
tor_addr_make_null
void tor_addr_make_null(tor_addr_t *a, sa_family_t family)
Definition: address.c:235
HS_VERSION_TWO
#define HS_VERSION_TWO
Definition: hs_common.h:24
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
build_hs_address
static void build_hs_address(const ed25519_public_key_t *key, const uint8_t *checksum, uint8_t version, char *addr_out)
Definition: hs_common.c:766
cpd_check_t
unsigned int cpd_check_t
Definition: dir.h:20
smartlist_contains_int_as_string
int smartlist_contains_int_as_string(const smartlist_t *sl, int num)
Definition: smartlist.c:147
rend_data_v2_t::desc_id_fetch
char desc_id_fetch[DIGEST_LEN]
Definition: or.h:455
approx_time
time_t approx_time(void)
Definition: approx_time.c:32
ed25519_validate_pubkey
int ed25519_validate_pubkey(const ed25519_public_key_t *pubkey)
Definition: crypto_ed25519.c:796
connection_t::address
char * address
Definition: connection_st.h:166
MOCK_IMPL
#define MOCK_IMPL(rv, funcname, arglist)
Definition: testsupport.h:133
REND_NUMBER_OF_NON_CONSECUTIVE_REPLICAS
#define REND_NUMBER_OF_NON_CONSECUTIVE_REPLICAS
Definition: or.h:349
hs_service_init
void hs_service_init(void)
Definition: hs_service.c:4326
rend_data_v2_t::auth_type
rend_auth_type_t auth_type
Definition: or.h:450
hs_set_conn_addr_port
int hs_set_conn_addr_port(const smartlist_t *ports, edge_connection_t *conn)
Definition: hs_common.c:860
hs_hsdir_requery_period
time_t hs_hsdir_requery_period(const or_options_t *options)
Definition: hs_common.c:1460
tor_assert
#define tor_assert(expr)
Definition: util_bug.h:102
microdesc.h
Header file for microdesc.c.
LD_BUG
#define LD_BUG
Definition: log.h:86
hs_get_next_time_period_num
uint64_t hs_get_next_time_period_num(time_t now)
Definition: hs_common.c:308
rend_service_port_config_t
Definition: hs_common.h:153
fast_mem_is_zero
int fast_mem_is_zero(const char *mem, size_t len)
Definition: util_string.c:74
HS_DEFAULT_HSDIR_SPREAD_FETCH
#define HS_DEFAULT_HSDIR_SPREAD_FETCH
Definition: hs_common.h:126
LD_GENERAL
#define LD_GENERAL
Definition: log.h:62
rend_service_port_config_t::virtual_port
uint16_t virtual_port
Definition: hs_common.h:155
hs_in_period_between_tp_and_srv
int hs_in_period_between_tp_and_srv(const networkstatus_t *consensus, time_t now)
Definition: hs_common.c:1110
routerset_contains_node
int routerset_contains_node(const routerset_t *set, const node_t *node)
Definition: routerset.c:353
smartlist_choose
void * smartlist_choose(const smartlist_t *sl)
Definition: crypto_rand.c:590
rend_auth_type_t
rend_auth_type_t
Definition: or.h:403
set_uint8
static void set_uint8(void *cp, uint8_t v)
Definition: bytes.h:31
describe.h
Header file for describe.c.
node_get_by_id
const node_t * node_get_by_id(const char *identity_digest)
Definition: nodelist.c:223
smartlist_add
void smartlist_add(smartlist_t *sl, void *element)
Definition: smartlist_core.c:117
sr_srv_t
Definition: shared_random.h:62
routerstatus_t
Definition: routerstatus_st.h:19
compute_desc_id
static int compute_desc_id(rend_data_t *rend_data)
Definition: hs_common.c:423
hsdir_index_t::fetch
uint8_t fetch[DIGEST256_LEN]
Definition: hsdir_index_st.h:19
hs_build_blinded_keypair
void hs_build_blinded_keypair(const ed25519_keypair_t *kp, const uint8_t *secret, size_t secret_len, uint64_t time_period_num, ed25519_keypair_t *blinded_kp_out)
Definition: hs_common.c:1074
hs_build_address
void hs_build_address(const ed25519_public_key_t *key, uint8_t version, char *addr_out)
Definition: hs_common.c:1024
hs_build_hs_index
void hs_build_hs_index(uint64_t replica, const ed25519_public_key_t *blinded_pk, uint64_t period_num, uint8_t *hs_index_out)
Definition: hs_common.c:1160
hs_get_hsdir_spread_fetch
int32_t hs_get_hsdir_spread_fetch(void)
Definition: hs_common.c:1285
HS_SERVICE_ADDR_CHECKSUM_LEN_USED
#define HS_SERVICE_ADDR_CHECKSUM_LEN_USED
Definition: hs_common.h:74
ED25519_PUBKEY_LEN
#define ED25519_PUBKEY_LEN
Definition: x25519_sizes.h:27
crypto_digest_add_bytes
void crypto_digest_add_bytes(crypto_digest_t *digest, const char *data, size_t len)
Definition: crypto_digest_nss.c:308
smartlist_new
smartlist_t * smartlist_new(void)
Definition: smartlist_core.c:26
rend_data_t::nr_streams
int nr_streams
Definition: or.h:431
tor_addr_make_unspec
void tor_addr_make_unspec(tor_addr_t *a)
Definition: address.c:225
nodelist_ensure_freshness
void nodelist_ensure_freshness(const networkstatus_t *ns)
Definition: nodelist.c:946
crypto_digest_t
Definition: crypto_digest_nss.c:166
build_hs_checksum
static void build_hs_checksum(const ed25519_public_key_t *key, uint8_t version, uint8_t *checksum_out)
Definition: hs_common.c:739
last_hid_serv_requests_
static strmap_t * last_hid_serv_requests_
Definition: hs_common.c:1485
connection_t::port
uint16_t port
Definition: connection_st.h:146
hs_address_is_valid
int hs_address_is_valid(const char *address)
Definition: hs_common.c:979
hs_init
void hs_init(void)
Definition: hs_common.c:1826
SMARTLIST_FOREACH
#define SMARTLIST_FOREACH(sl, type, var, cmd)
Definition: smartlist_foreach.h:112
rend_data_dup
rend_data_t * rend_data_dup(const rend_data_t *data)
Definition: hs_common.c:390
base32_decode
int base32_decode(char *dest, size_t destlen, const char *src, size_t srclen)
Definition: binascii.c:90
hs_dos.h
Header file containing denial of service defenses for the HS subsystem for all versions.
networkstatus.h
Header file for networkstatus.c.
hsdir_index_t::store_first
uint8_t store_first[DIGEST256_LEN]
Definition: hsdir_index_st.h:24
hs_client.h
Header file containing client data for the HS subsystem.
tor_memeq
int tor_memeq(const void *a, const void *b, size_t sz)
Definition: di_ops.c:107
base32_encode
void base32_encode(char *dest, size_t destlen, const char *src, size_t srclen)
Definition: binascii.c:60
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:1607
hs_cache.h
Header file for hs_cache.c.
REND_DESC_ID_V2_LEN_BASE32
#define REND_DESC_ID_V2_LEN_BASE32
Definition: or.h:355
extend_info_new
extend_info_t * extend_info_new(const char *nickname, const char *rsa_id_digest, const ed25519_public_key_t *ed_id, crypto_pk_t *onion_key, const curve25519_public_key_t *ntor_key, const tor_addr_t *addr, uint16_t port)
Definition: extendinfo.c:33
hs_parse_address_impl
static void hs_parse_address_impl(const char *address, ed25519_public_key_t *key_out, uint8_t *checksum_out, uint8_t *version_out)
Definition: hs_common.c:789
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:1635
hs_lookup_last_hid_serv_request
time_t hs_lookup_last_hid_serv_request(routerstatus_t *hs_dir, const char *req_key_str, time_t now, int set)
Definition: hs_common.c:1503
hs_get_hsdir_spread_store
int32_t hs_get_hsdir_spread_store(void)
Definition: hs_common.c:1295
node_get_mutable_by_id
node_t * node_get_mutable_by_id(const char *identity_digest)
Definition: nodelist.c:194
hs_circuitmap_init
void hs_circuitmap_init(void)
Definition: hs_circuitmap.c:597
hs_get_previous_srv
uint8_t * hs_get_previous_srv(uint64_t time_period_num, const networkstatus_t *ns)
Definition: hs_common.c:1258
shared_random_state.h
Header for shared_random_state.c.
rend_service_port_config_t::real_port
uint16_t real_port
Definition: hs_common.h:159
tor_addr_from_ipv4h
#define tor_addr_from_ipv4h(dest, v4addr)
Definition: address.h:327
sr_get_current
const sr_srv_t * sr_get_current(const networkstatus_t *ns)
Definition: shared_random_client.c:146
hs_service_free_all
void hs_service_free_all(void)
Definition: hs_service.c:4343
node_supports_v3_hsdir
bool node_supports_v3_hsdir(const node_t *node)
Definition: nodelist.c:1171
hs_get_previous_time_period_num
uint64_t hs_get_previous_time_period_num(time_t now)
Definition: hs_common.c:317
tor_addr_port_t
Definition: address.h:81
HS_SERVICE_ADDR_CHECKSUM_INPUT_LEN
#define HS_SERVICE_ADDR_CHECKSUM_INPUT_LEN
Definition: hs_common.h:71
hs_path_from_filename
char * hs_path_from_filename(const char *directory, const char *filename)
Definition: hs_common.c:180
HS_DEFAULT_HSDIR_N_REPLICAS
#define HS_DEFAULT_HSDIR_N_REPLICAS
Definition: hs_common.h:122
tor_assert_nonfatal_unreached
#define tor_assert_nonfatal_unreached()
Definition: util_bug.h:176
node_t
Definition: node_st.h:34
origin_circuit_t
Definition: origin_circuit_st.h:79
HS_SERVICE_ADDR_CHECKSUM_PREFIX_LEN
#define HS_SERVICE_ADDR_CHECKSUM_PREFIX_LEN
Definition: hs_common.h:65
HS_SERVICE_ADDR_LEN
#define HS_SERVICE_ADDR_LEN
Definition: hs_common.h:79
rend_data_v2_t::descriptor_cookie
char descriptor_cookie[REND_DESC_COOKIE_LEN]
Definition: or.h:447
rend_service_port_config_t::real_addr
tor_addr_t real_addr
Definition: hs_common.h:161
ed25519_public_key_t
Definition: crypto_ed25519.h:23
or_options_t::ExcludeNodes
struct routerset_t * ExcludeNodes
Definition: or_options_st.h:120
rend_data_free_
void rend_data_free_(rend_data_t *data)
Definition: hs_common.c:365
networkstatus_get_reasonably_live_consensus
networkstatus_t * networkstatus_get_reasonably_live_consensus(time_t now, int flavor)
Definition: networkstatus.c:1477
hs_check_service_private_dir
int hs_check_service_private_dir(const char *username, const char *path, unsigned int dir_group_readable, unsigned int create)
Definition: hs_common.c:202
LD_REND
#define LD_REND
Definition: log.h:84
usable_consensus_flavor
int usable_consensus_flavor(void)
Definition: microdesc.c:1086
or_options_t::StrictNodes
int StrictNodes
Definition: or_options_st.h:117
HS_TIME_PERIOD_LENGTH_DEFAULT
#define HS_TIME_PERIOD_LENGTH_DEFAULT
Definition: hs_common.h:87
compare_digest_to_fetch_hsdir_index
static int compare_digest_to_fetch_hsdir_index(const void *_key, const void **_member)
Definition: hs_common.c:115
nodelist.h
Header file for nodelist.c.
build_blinded_key_param
static void build_blinded_key_param(const ed25519_public_key_t *pubkey, const uint8_t *secret, size_t secret_len, uint64_t period_num, uint64_t period_length, uint8_t *param_out)
Definition: hs_common.c:690
ED25519_SECKEY_LEN
#define ED25519_SECKEY_LEN
Definition: x25519_sizes.h:29
rend_data_service_create
rend_data_t * rend_data_service_create(const char *onion_address, const char *pk_digest, const uint8_t *cookie, rend_auth_type_t auth_type)
Definition: hs_common.c:465
compare_node_fetch_hsdir_index
static int compare_node_fetch_hsdir_index(const void **a, const void **b)
Definition: hs_common.c:146
ed25519_keypair_blind
int ed25519_keypair_blind(ed25519_keypair_t *out, const ed25519_keypair_t *inp, const uint8_t *param)
Definition: crypto_ed25519.c:514
routerset.h
Header file for routerset.c.
compare_node_store_first_hsdir_index
static int compare_node_store_first_hsdir_index(const void **a, const void **b)
Definition: hs_common.c:157
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:1566
rend_data_get_desc_id
const char * rend_data_get_desc_id(const rend_data_t *rend_data, uint8_t replica, size_t *len_out)
Definition: hs_common.c:550
extend_info_addr_is_allowed
int extend_info_addr_is_allowed(const tor_addr_t *addr)
Definition: extendinfo.c:224
connection_t::addr
tor_addr_t addr
Definition: connection_st.h:145
rendservice.h
Header file for rendservice.c.
hs_ob_free_all
void hs_ob_free_all(void)
Definition: hs_ob.c:406
DIGEST256_LEN
#define DIGEST256_LEN
Definition: digest_sizes.h:23
extendinfo.h
Header for core/or/extendinfo.c.
hsdir_index_t::store_second
uint8_t store_second[DIGEST256_LEN]
Definition: hsdir_index_st.h:26
networkstatus_t::routerstatus_list
smartlist_t * routerstatus_list
Definition: networkstatus_st.h:96
compute_disaster_srv
static void compute_disaster_srv(uint64_t time_period_num, uint8_t *srv_out)
Definition: hs_common.c:594
node_has_hsdir_index
static int node_has_hsdir_index(const node_t *node)
Definition: hs_common.c:1305
rend_data_t::rend_cookie
char rend_cookie[REND_COOKIE_LEN]
Definition: or.h:428
HS_INDEX_PREFIX
#define HS_INDEX_PREFIX
Definition: hs_common.h:110
crypto_digest256_new
crypto_digest_t * crypto_digest256_new(digest_algorithm_t algorithm)
Definition: crypto_digest_nss.c:272
ARRAY_LENGTH
#define ARRAY_LENGTH(x)
Definition: compat_compiler.h:222
hs_get_hsdir_n_replicas
int32_t hs_get_hsdir_n_replicas(void)
Definition: hs_common.c:1275
fmt_addr
#define fmt_addr(a)
Definition: address.h:239
crypto_rand.h
Common functions for using (pseudo-)random number generators.
hs_get_service_max_rend_failures
int hs_get_service_max_rend_failures(void)
Definition: hs_common.c:235
hs_build_hsdir_index
void hs_build_hsdir_index(const ed25519_public_key_t *identity_pk, const uint8_t *srv_value, uint64_t period_num, uint8_t *hsdir_index_out)
Definition: hs_common.c:1201
get_options
const or_options_t * get_options(void)
Definition: config.c:932
tor_memcmp
int tor_memcmp(const void *a, const void *b, size_t len)
Definition: di_ops.c:31
link_specifier_dup
link_specifier_t * link_specifier_dup(const link_specifier_t *src)
Definition: hs_common.c:1881
circuitbuild.h
Header file for circuitbuild.c.
HS_KEYBLIND_NONCE_PREFIX
#define HS_KEYBLIND_NONCE_PREFIX
Definition: hs_common.h:98
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:1347
hs_ident_edge_conn_t::orig_virtual_port
uint16_t orig_virtual_port
Definition: hs_ident.h:111
HS_SERVICE_ADDR_CHECKSUM_PREFIX
#define HS_SERVICE_ADDR_CHECKSUM_PREFIX
Definition: hs_common.h:63
crypto_digest_free
#define crypto_digest_free(d)
Definition: crypto_digest.h:130
routerstatus_st.h
Routerstatus (consensus entry) structure.
sr_srv_t::value
uint8_t value[DIGEST256_LEN]
Definition: shared_random.h:66
node_describe
const char * node_describe(const node_t *node)
Definition: describe.c:160
hs_common.h
Header file containing common data for the whole HS subsystem.
hs_circuitmap_free_all
void hs_circuitmap_free_all(void)
Definition: hs_circuitmap.c:607
curve25519_public_key_t
Definition: crypto_curve25519.h:24
edge_connection_st.h
Edge-connection structure.
HSDIR_INDEX_PREFIX
#define HSDIR_INDEX_PREFIX
Definition: hs_common.h:114
cached_disaster_srv
static uint8_t cached_disaster_srv[2][DIGEST256_LEN]
Definition: hs_common.c:631
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:1722
HS_SRV_DISASTER_PREFIX
#define HS_SRV_DISASTER_PREFIX
Definition: hs_common.h:118
hs_subcredential_t
Definition: hs_ntor.h:43
get_time_period_length
STATIC uint64_t get_time_period_length(void)
Definition: hs_common.c:245
networkstatus_t::valid_after
time_t valid_after
Definition: networkstatus_st.h:33
tor_htonll
static uint64_t tor_htonll(uint64_t a)
Definition: bytes.h:184
hs_service_requires_uptime_circ
int hs_service_requires_uptime_circ(const smartlist_t *ports)
Definition: hs_common.c:1139
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:2582
rend_data_v2_t::descriptor_id
char descriptor_id[REND_NUMBER_OF_NON_CONSECUTIVE_REPLICAS][DIGEST_LEN]
Definition: or.h:444
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:271
SMARTLIST_FOREACH_BEGIN
#define SMARTLIST_FOREACH_BEGIN(sl, type, var)
Definition: smartlist_foreach.h:78
rend_data_v2_t::onion_address
char onion_address[REND_SERVICE_ID_LEN_BASE32+1]
Definition: or.h:439
or_options_t::TestingTorNetwork
int TestingTorNetwork
Definition: or_options_st.h:814
SMARTLIST_DEL_CURRENT
#define SMARTLIST_DEL_CURRENT(sl, var)
Definition: smartlist_foreach.h:120
compare_digest_to_store_second_hsdir_index
static int compare_digest_to_store_second_hsdir_index(const void *_key, const void **_member)
Definition: hs_common.c:136
rend_data_client_create
rend_data_t * rend_data_client_create(const char *onion_address, const char *desc_id, const char *cookie, rend_auth_type_t auth_type)
Definition: hs_common.c:497
sr_state_get_start_time_of_current_protocol_run
time_t sr_state_get_start_time_of_current_protocol_run(void)
Definition: shared_random_client.c:245
node_st.h
Node information structure.
sr_get_previous
const sr_srv_t * sr_get_previous(const networkstatus_t *ns)
Definition: shared_random_client.c:170
reachable_addr_choose_from_ls
void reachable_addr_choose_from_ls(const smartlist_t *lspecs, int pref_only, tor_addr_port_t *ap)
Definition: policies.c:910
edge_connection_t
Definition: edge_connection_st.h:21
hs_ident_circuit_t::num_rdv_streams
uint64_t num_rdv_streams
Definition: hs_ident.h:81
hs_ob.h
Header file for the specific code for onion balance.
hs_clean_last_hid_serv_requests
void hs_clean_last_hid_serv_requests(time_t now)
Definition: hs_common.c:1537
get_uint8
static uint8_t get_uint8(const void *cp)
Definition: bytes.h:23
rend_data_t
Definition: or.h:419
hs_inc_rdv_stream_counter
void hs_inc_rdv_stream_counter(origin_circuit_t *circ)
Definition: hs_common.c:1865
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:1050
policies.h
Header file for policies.c.
rend_service_port_config_t::unix_addr
char unix_addr[FLEXIBLE_ARRAY_MEMBER]
Definition: hs_common.h:163
sr_state_get_protocol_run_duration
unsigned int sr_state_get_protocol_run_duration(void)
Definition: shared_random_client.c:310
hs_circuitmap.h
Header file for hs_circuitmap.c.
connection_t::socket_family
int socket_family
Definition: connection_st.h:111
rend_data_get_address
const char * rend_data_get_address(const rend_data_t *rend_data)
Definition: hs_common.c:532
shared_random_client.h
Header file for shared_random_client.c.
compare_digest_to_store_first_hsdir_index
static int compare_digest_to_store_first_hsdir_index(const void *_key, const void **_member)
Definition: hs_common.c:125
config.h
Header file for config.c.
crypto_digest256
int crypto_digest256(char *digest, const char *m, size_t len, digest_algorithm_t algorithm)
Definition: crypto_digest_nss.c:121
escaped_safe_str
const char * escaped_safe_str(const char *address)
Definition: config.c:1135
HS_DEFAULT_HSDIR_SPREAD_STORE
#define HS_DEFAULT_HSDIR_SPREAD_STORE
Definition: hs_common.h:124
smartlist_contains
int smartlist_contains(const smartlist_t *sl, const void *element)
Definition: smartlist_core.c:201
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:963
str_ed25519_basepoint
static const char * str_ed25519_basepoint
Definition: hs_common.c:52
LD_NET
#define LD_NET
Definition: log.h:66
hs_parse_address_no_log
int hs_parse_address_no_log(const char *address, ed25519_public_key_t *key_out, uint8_t *checksum_out, uint8_t *version_out, const char **errmsg)
Definition: hs_common.c:923
origin_circuit_t::hs_ident
struct hs_ident_circuit_t * hs_ident
Definition: origin_circuit_st.h:136
or_options_t
Definition: or_options_st.h:64
ed25519_public_blind
int ed25519_public_blind(ed25519_public_key_t *out, const ed25519_public_key_t *inp, const uint8_t *param)
Definition: crypto_ed25519.c:541
TO_CONN
#define TO_CONN(c)
Definition: or.h:736
STATIC
#define STATIC
Definition: testsupport.h:32
HS_TIME_PERIOD_LENGTH_MIN
#define HS_TIME_PERIOD_LENGTH_MIN
Definition: hs_common.h:89
rend_data_v2_t::rend_pk_digest
char rend_pk_digest[DIGEST_LEN]
Definition: or.h:458
hs_dec_rdv_stream_counter
void hs_dec_rdv_stream_counter(origin_circuit_t *circ)
Definition: hs_common.c:1848
set_uint64
static void set_uint64(void *cp, uint64_t v)
Definition: bytes.h:96
networkstatus_get_param
int32_t networkstatus_get_param(const networkstatus_t *ns, const char *param_name, int32_t default_val, int32_t min_val, int32_t max_val)
Definition: networkstatus.c:2500
networkstatus_st.h
Networkstatus consensus/vote structure.
rend_data_v2_t
Definition: or.h:434
HS_CREDENTIAL_PREFIX
#define HS_CREDENTIAL_PREFIX
Definition: hs_common.h:104
BASE32_DIGEST_LEN
#define BASE32_DIGEST_LEN
Definition: crypto_digest.h:23
smartlist_sort
void smartlist_sort(smartlist_t *sl, int(*compare)(const void **a, const void **b))
Definition: smartlist.c:334
routerstatus_t::identity_digest
char identity_digest[DIGEST_LEN]
Definition: routerstatus_st.h:27
networkstatus_t
Definition: networkstatus_st.h:26
hs_cache_free_all
void hs_cache_free_all(void)
Definition: hs_cache.c:1142
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:819
rend_data_t::hsdirs_fp
smartlist_t * hsdirs_fp
Definition: or.h:425
origin_circuit_st.h
Origin circuit structure.
compare_node_store_second_hsdir_index
static int compare_node_store_second_hsdir_index(const void **a, const void **b)
Definition: hs_common.c:168
rend_data_alloc
static rend_data_t * rend_data_alloc(uint32_t version)
Definition: hs_common.c:342
node_has_preferred_descriptor
int node_has_preferred_descriptor(const node_t *node, int for_direct_connect)
Definition: nodelist.c:1420
smartlist_t
Definition: smartlist_core.h:26
hs_get_start_time_of_next_time_period
time_t hs_get_start_time_of_next_time_period(time_t now)
Definition: hs_common.c:326
HS_SERVICE_ADDR_LEN_BASE32
#define HS_SERVICE_ADDR_LEN_BASE32
Definition: hs_common.h:83
sr_state_get_phase_duration
unsigned int sr_state_get_phase_duration(void)
Definition: shared_random_client.c:303
crypto_digest_get_digest
void crypto_digest_get_digest(crypto_digest_t *digest, char *out, size_t out_len)
Definition: crypto_digest_nss.c:348
smartlist_bsearch_idx
int smartlist_bsearch_idx(const smartlist_t *sl, const void *key, int(*compare)(const void *key, const void **member), int *found_out)
Definition: smartlist.c:428
rendcommon.h
Header file for rendcommon.c.
rend_data_get_pk_digest
const uint8_t * rend_data_get_pk_digest(const rend_data_t *rend_data, size_t *len_out)
Definition: hs_common.c:572
check_private_dir
int check_private_dir(const char *dirname, cpd_check_t check, const char *effective_user)
Definition: dir.c:71
tor_addr_copy
void tor_addr_copy(tor_addr_t *dest, const tor_addr_t *src)
Definition: address.c:933
extend_info_t
Definition: extend_info_st.h:27
get_last_hid_serv_requests
STATIC strmap_t * get_last_hid_serv_requests(void)
Definition: hs_common.c:1490
hs_free_all
void hs_free_all(void)
Definition: hs_common.c:1836
or.h
Master header file for Tor-specific functionality.
get_disaster_srv
STATIC void get_disaster_srv(uint64_t time_period_num, uint8_t *srv_out)
Definition: hs_common.c:638
ed25519_keypair_t
Definition: crypto_ed25519.h:39
rend_compute_v2_desc_id
int rend_compute_v2_desc_id(char *desc_id_out, const char *service_id, const char *descriptor_cookie, time_t now, uint8_t replica)
Definition: rendcommon.c:154
hs_get_current_srv
uint8_t * hs_get_current_srv(uint64_t time_period_num, const networkstatus_t *ns)
Definition: hs_common.c:1240
LD_PROTOCOL
#define LD_PROTOCOL
Definition: log.h:72