9 #ifndef TOR_HS_COMMON_H
10 #define TOR_HS_COMMON_H
20 #include "trunnel/ed25519_cert.h"
23 #define HS_VERSION_THREE 3
25 #define HS_VERSION_MIN HS_VERSION_THREE
27 #define HS_VERSION_MAX HS_VERSION_THREE
30 #define NUM_INTRO_POINTS_DEFAULT 3
32 #define NUM_INTRO_POINTS_MAX 10
35 #define NUM_INTRO_POINTS_EXTRA 2
38 #define INTRO_CIRC_RETRY_PERIOD (60*5)
41 #define MAX_INTRO_CIRCS_PER_PERIOD 10
44 #define MAX_REND_FAILURES 1
47 #define MAX_REND_TIMEOUT 30
50 #define ESTABLISH_INTRO_SIG_PREFIX "Tor establish-intro cell v1"
53 #define HS_TIME_PERIOD_LENGTH_DEFAULT 1440
55 #define HS_TIME_PERIOD_LENGTH_MIN 30
57 #define HS_TIME_PERIOD_LENGTH_MAX (60 * 24 * 10)
60 #define HS_SERVICE_ADDR_CHECKSUM_PREFIX ".onion checksum"
62 #define HS_SERVICE_ADDR_CHECKSUM_PREFIX_LEN \
63 (sizeof(HS_SERVICE_ADDR_CHECKSUM_PREFIX) - 1)
68 #define HS_SERVICE_ADDR_CHECKSUM_INPUT_LEN \
69 (HS_SERVICE_ADDR_CHECKSUM_PREFIX_LEN + ED25519_PUBKEY_LEN + sizeof(uint8_t))
71 #define HS_SERVICE_ADDR_CHECKSUM_LEN_USED 2
76 #define HS_SERVICE_ADDR_LEN \
77 (ED25519_PUBKEY_LEN + HS_SERVICE_ADDR_CHECKSUM_LEN_USED + sizeof(uint8_t))
80 #define HS_SERVICE_ADDR_LEN_BASE32 \
81 (CEIL_DIV(HS_SERVICE_ADDR_LEN * 8, 5))
84 #define HS_TIME_PERIOD_LENGTH_DEFAULT 1440
86 #define HS_TIME_PERIOD_LENGTH_MIN 30
88 #define HS_TIME_PERIOD_LENGTH_MAX (60 * 24 * 10)
91 #define HS_TIME_PERIOD_ROTATION_OFFSET (12 * 60)
95 #define HS_KEYBLIND_NONCE_PREFIX "key-blind"
96 #define HS_KEYBLIND_NONCE_PREFIX_LEN (sizeof(HS_KEYBLIND_NONCE_PREFIX) - 1)
97 #define HS_KEYBLIND_NONCE_LEN \
98 (HS_KEYBLIND_NONCE_PREFIX_LEN + sizeof(uint64_t) + sizeof(uint64_t))
101 #define HS_CREDENTIAL_PREFIX "credential"
102 #define HS_CREDENTIAL_PREFIX_LEN (sizeof(HS_CREDENTIAL_PREFIX) - 1)
103 #define HS_SUBCREDENTIAL_PREFIX "subcredential"
104 #define HS_SUBCREDENTIAL_PREFIX_LEN (sizeof(HS_SUBCREDENTIAL_PREFIX) - 1)
107 #define HS_INDEX_PREFIX "store-at-idx"
108 #define HS_INDEX_PREFIX_LEN (sizeof(HS_INDEX_PREFIX) - 1)
111 #define HSDIR_INDEX_PREFIX "node-idx"
112 #define HSDIR_INDEX_PREFIX_LEN (sizeof(HSDIR_INDEX_PREFIX) - 1)
115 #define HS_SRV_DISASTER_PREFIX "shared-random-disaster"
116 #define HS_SRV_DISASTER_PREFIX_LEN (sizeof(HS_SRV_DISASTER_PREFIX) - 1)
119 #define HS_DEFAULT_HSDIR_N_REPLICAS 2
121 #define HS_DEFAULT_HSDIR_SPREAD_STORE 4
123 #define HS_DEFAULT_HSDIR_SPREAD_FETCH 3
128 #define HS_LEGACY_RENDEZVOUS_CELL_SIZE \
129 (REND_COOKIE_LEN + DH1024_KEY_LEN + DIGEST_LEN)
133 HS_AUTH_KEY_TYPE_LEGACY = 1,
134 HS_AUTH_KEY_TYPE_ED25519 = 2,
169 unsigned int dir_group_readable,
170 unsigned int create);
178 uint8_t *checksum_out, uint8_t *version_out);
181 uint8_t *checksum_out, uint8_t *version_out,
182 const char **errmsg);
185 const uint8_t *secret,
size_t secret_len,
186 uint64_t time_period_num,
189 const uint8_t *secret,
size_t secret_len,
190 uint64_t time_period_num,
194 routerstatus_t *pick_hsdir(
const char *desc_id,
const char *desc_id_base32);
215 const uint8_t *srv, uint64_t period_num,
216 uint8_t *hsdir_index_out);
219 uint64_t period_num, uint8_t *hs_index_out);
226 uint64_t time_period_num,
227 int use_second_hsdir_index,
230 const char *req_key_str,
231 bool *is_rate_limited_out);
235 const char *desc_id_base32,
236 time_t now,
int set);
245 #define hs_port_config_free(p) \
246 FREE_AND_NULL(hs_port_config_t, hs_port_config_free_, (p))
257 #ifdef HS_COMMON_PRIVATE
263 #define REND_HID_SERV_DIR_REQUERY_PERIOD (15 * 60)
266 #define REND_HID_SERV_DIR_REQUERY_PERIOD_TESTING (5)
268 #ifdef TOR_UNIT_TESTS
273 STATIC uint8_t *get_first_cached_disaster_srv(
void);
274 STATIC uint8_t *get_second_cached_disaster_srv(
void);
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)
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)
void hs_get_subcredential(const ed25519_public_key_t *identity_pk, const ed25519_public_key_t *blinded_pk, hs_subcredential_t *subcred_out)
void hs_build_hs_index(uint64_t replica, const ed25519_public_key_t *blinded_pk, uint64_t period_num, uint8_t *hs_index_out)
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)
void hs_build_address(const ed25519_public_key_t *key, uint8_t version, char *addr_out)
STATIC void get_disaster_srv(uint64_t time_period_num, uint8_t *srv_out)
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)
STATIC uint64_t get_time_period_length(void)
STATIC strmap_t * get_last_hid_serv_requests(void)
extend_info_t * hs_get_extend_info_from_lspecs(const smartlist_t *lspecs, const curve25519_public_key_t *onion_key, int direct_conn)
void hs_port_config_free_(hs_port_config_t *p)
int hs_parse_address_no_log(const char *address, struct ed25519_public_key_t *key_out, uint8_t *checksum_out, uint8_t *version_out, const char **errmsg)
uint64_t hs_get_time_period_num(time_t now)
void hs_purge_last_hid_serv_requests(void)
hs_service_add_ephemeral_status_t
time_t hs_get_start_time_of_next_time_period(time_t now)
uint64_t hs_get_next_time_period_num(time_t now)
int32_t hs_get_hsdir_n_replicas(void)
link_specifier_t * link_specifier_dup(const link_specifier_t *src)
void hs_dec_rdv_stream_counter(origin_circuit_t *circ)
uint64_t hs_get_previous_time_period_num(time_t now)
time_t hs_lookup_last_hid_serv_request(routerstatus_t *hs_dir, const char *desc_id_base32, time_t now, int set)
int hs_address_is_valid(const char *address)
uint8_t * hs_get_current_srv(uint64_t time_period_num, const networkstatus_t *ns)
char * hs_path_from_filename(const char *directory, const char *filename)
int hs_get_service_max_rend_failures(void)
int hs_parse_address(const char *address, struct ed25519_public_key_t *key_out, uint8_t *checksum_out, uint8_t *version_out)
void hs_purge_hid_serv_from_last_hid_serv_requests(const char *desc_id)
int32_t hs_get_hsdir_spread_fetch(void)
int hs_set_conn_addr_port(const smartlist_t *ports, edge_connection_t *conn)
time_t hs_hsdir_requery_period(const or_options_t *options)
routerstatus_t * hs_pick_hsdir(smartlist_t *responsible_dirs, const char *req_key_str, bool *is_rate_limited_out)
void hs_inc_rdv_stream_counter(origin_circuit_t *circ)
int hs_check_service_private_dir(const char *username, const char *path, unsigned int dir_group_readable, unsigned int create)
void hs_clean_last_hid_serv_requests(time_t now)
uint8_t * hs_get_previous_srv(uint64_t time_period_num, const networkstatus_t *ns)
hs_port_config_t * hs_parse_port_config(const char *string, const char *sep, char **err_msg_out)
int hs_service_requires_uptime_circ(const smartlist_t *ports)
int hs_in_period_between_tp_and_srv(const networkstatus_t *consensus, time_t now)
int32_t hs_get_hsdir_spread_store(void)
Master header file for Tor-specific functionality.
char unix_addr[FLEXIBLE_ARRAY_MEMBER]
unsigned int is_unix_addr
#define MOCK_DECL(rv, funcname, arglist)
Definitions for sizes of x25519 keys and elements.