hs_common.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* Copyright (c) 2016-2017, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. /**
  4. * \file hs_common.h
  5. * \brief Header file containing common data for the whole HS subsytem.
  6. **/
  7. #ifndef TOR_HS_COMMON_H
  8. #define TOR_HS_COMMON_H
  9. #include "or.h"
  10. /* Protocol version 2. Use this instead of hardcoding "2" in the code base,
  11. * this adds a clearer semantic to the value when used. */
  12. #define HS_VERSION_TWO 2
  13. /* Version 3 of the protocol (prop224). */
  14. #define HS_VERSION_THREE 3
  15. /* Earliest and latest version we support. */
  16. #define HS_VERSION_MIN HS_VERSION_TWO
  17. #define HS_VERSION_MAX HS_VERSION_THREE
  18. /** Try to maintain this many intro points per service by default. */
  19. #define NUM_INTRO_POINTS_DEFAULT 3
  20. /** Maximum number of intro points per generic and version 2 service. */
  21. #define NUM_INTRO_POINTS_MAX 10
  22. /** Number of extra intro points we launch if our set of intro nodes is empty.
  23. * See proposal 155, section 4. */
  24. #define NUM_INTRO_POINTS_EXTRA 2
  25. /** If we can't build our intro circuits, don't retry for this long. */
  26. #define INTRO_CIRC_RETRY_PERIOD (60*5)
  27. /** Don't try to build more than this many circuits before giving up for a
  28. * while.*/
  29. #define MAX_INTRO_CIRCS_PER_PERIOD 10
  30. /** How many times will a hidden service operator attempt to connect to a
  31. * requested rendezvous point before giving up? */
  32. #define MAX_REND_FAILURES 1
  33. /** How many seconds should we spend trying to connect to a requested
  34. * rendezvous point before giving up? */
  35. #define MAX_REND_TIMEOUT 30
  36. /* String prefix for the signature of ESTABLISH_INTRO */
  37. #define ESTABLISH_INTRO_SIG_PREFIX "Tor establish-intro cell v1"
  38. /* The default HS time period length */
  39. #define HS_TIME_PERIOD_LENGTH_DEFAULT 1440 /* 1440 minutes == one day */
  40. /* The minimum time period length as seen in prop224 section [TIME-PERIODS] */
  41. #define HS_TIME_PERIOD_LENGTH_MIN 30 /* minutes */
  42. /* The minimum time period length as seen in prop224 section [TIME-PERIODS] */
  43. #define HS_TIME_PERIOD_LENGTH_MAX (60 * 24 * 10) /* 10 days or 14400 minutes */
  44. /* The time period rotation offset as seen in prop224 section [TIME-PERIODS] */
  45. #define HS_TIME_PERIOD_ROTATION_OFFSET (12 * 60) /* minutes */
  46. /* Prefix of the onion address checksum. */
  47. #define HS_SERVICE_ADDR_CHECKSUM_PREFIX ".onion checksum"
  48. /* Length of the checksum prefix minus the NUL terminated byte. */
  49. #define HS_SERVICE_ADDR_CHECKSUM_PREFIX_LEN \
  50. (sizeof(HS_SERVICE_ADDR_CHECKSUM_PREFIX) - 1)
  51. /* Length of the resulting checksum of the address. The construction of this
  52. * checksum looks like:
  53. * CHECKSUM = ".onion checksum" || PUBKEY || VERSION
  54. * where VERSION is 1 byte. This is pre-hashing. */
  55. #define HS_SERVICE_ADDR_CHECKSUM_INPUT_LEN \
  56. (HS_SERVICE_ADDR_CHECKSUM_PREFIX_LEN + ED25519_PUBKEY_LEN + sizeof(uint8_t))
  57. /* The amount of bytes we use from the address checksum. */
  58. #define HS_SERVICE_ADDR_CHECKSUM_LEN_USED 2
  59. /* Length of the binary encoded service address which is of course before the
  60. * base32 encoding. Construction is:
  61. * PUBKEY || CHECKSUM || VERSION
  62. * with 1 byte VERSION and 2 bytes CHECKSUM. The following is 35 bytes. */
  63. #define HS_SERVICE_ADDR_LEN \
  64. (ED25519_PUBKEY_LEN + HS_SERVICE_ADDR_CHECKSUM_LEN_USED + sizeof(uint8_t))
  65. /* Length of 'y' portion of 'y.onion' URL. This is base32 encoded and the
  66. * length ends up to 56 bytes (not counting the terminated NUL byte.) */
  67. #define HS_SERVICE_ADDR_LEN_BASE32 \
  68. (CEIL_DIV(HS_SERVICE_ADDR_LEN * 8, 5))
  69. /* Type of authentication key used by an introduction point. */
  70. typedef enum {
  71. HS_AUTH_KEY_TYPE_LEGACY = 1,
  72. HS_AUTH_KEY_TYPE_ED25519 = 2,
  73. } hs_auth_key_type_t;
  74. void hs_init(void);
  75. void hs_free_all(void);
  76. int hs_check_service_private_dir(const char *username, const char *path,
  77. unsigned int dir_group_readable,
  78. unsigned int create);
  79. char *hs_path_from_filename(const char *directory, const char *filename);
  80. void hs_build_address(const ed25519_public_key_t *key, uint8_t version,
  81. char *addr_out);
  82. int hs_address_is_valid(const char *address);
  83. int hs_parse_address(const char *address, ed25519_public_key_t *key_out,
  84. uint8_t *checksum_out, uint8_t *version_out);
  85. void rend_data_free(rend_data_t *data);
  86. rend_data_t *rend_data_dup(const rend_data_t *data);
  87. rend_data_t *rend_data_client_create(const char *onion_address,
  88. const char *desc_id,
  89. const char *cookie,
  90. rend_auth_type_t auth_type);
  91. rend_data_t *rend_data_service_create(const char *onion_address,
  92. const char *pk_digest,
  93. const uint8_t *cookie,
  94. rend_auth_type_t auth_type);
  95. const char *rend_data_get_address(const rend_data_t *rend_data);
  96. const char *rend_data_get_desc_id(const rend_data_t *rend_data,
  97. uint8_t replica, size_t *len_out);
  98. const uint8_t *rend_data_get_pk_digest(const rend_data_t *rend_data,
  99. size_t *len_out);
  100. uint64_t hs_get_next_time_period_num(time_t now);
  101. #ifdef HS_COMMON_PRIVATE
  102. #ifdef TOR_UNIT_TESTS
  103. STATIC uint64_t get_time_period_length(void);
  104. STATIC uint64_t get_time_period_num(time_t now);
  105. #endif /* TOR_UNIT_TESTS */
  106. #endif /* HS_COMMON_PRIVATE */
  107. #endif /* TOR_HS_COMMON_H */