2010-07-21 16:17:10 +02:00
|
|
|
/* Copyright (c) 2001 Matej Pfajfar.
|
|
|
|
* Copyright (c) 2001-2004, Roger Dingledine.
|
|
|
|
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
|
2020-01-08 18:39:17 -05:00
|
|
|
* Copyright (c) 2007-2020, The Tor Project, Inc. */
|
2010-07-21 16:17:10 +02:00
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file router.h
|
2010-07-28 17:42:33 +02:00
|
|
|
* \brief Header file for router.c.
|
2010-07-21 16:17:10 +02:00
|
|
|
**/
|
|
|
|
|
2012-10-12 12:13:10 -04:00
|
|
|
#ifndef TOR_ROUTER_H
|
|
|
|
#define TOR_ROUTER_H
|
2010-07-21 16:17:10 +02:00
|
|
|
|
2018-06-21 13:12:23 -04:00
|
|
|
#include "lib/testsupport/testsupport.h"
|
2013-06-06 17:58:28 -04:00
|
|
|
|
2018-07-01 13:04:21 -04:00
|
|
|
struct curve25519_keypair_t;
|
|
|
|
struct ed25519_keypair_t;
|
|
|
|
|
2018-05-03 17:07:29 +02:00
|
|
|
#define TOR_ROUTERINFO_ERROR_NO_EXT_ADDR (-1)
|
|
|
|
#define TOR_ROUTERINFO_ERROR_CANNOT_PARSE (-2)
|
|
|
|
#define TOR_ROUTERINFO_ERROR_NOT_A_SERVER (-3)
|
|
|
|
#define TOR_ROUTERINFO_ERROR_DIGEST_FAILED (-4)
|
|
|
|
#define TOR_ROUTERINFO_ERROR_CANNOT_GENERATE (-5)
|
2018-05-10 16:45:57 +03:00
|
|
|
#define TOR_ROUTERINFO_ERROR_DESC_REBUILDING (-6)
|
2019-01-10 19:47:24 +10:00
|
|
|
#define TOR_ROUTERINFO_ERROR_INTERNAL_BUG (-7)
|
2018-05-03 17:07:29 +02:00
|
|
|
|
2019-02-18 15:24:26 +10:00
|
|
|
MOCK_DECL(crypto_pk_t *,get_onion_key,(void));
|
2010-07-21 16:17:10 +02:00
|
|
|
time_t get_onion_key_set_at(void);
|
2012-01-18 15:53:30 -05:00
|
|
|
void set_server_identity_key(crypto_pk_t *k);
|
2019-10-18 14:16:24 +10:00
|
|
|
/* Some compilers are clever enough to know that when relay mode is disabled,
|
|
|
|
* this function never returns. */
|
|
|
|
#ifdef HAVE_MODULE_RELAY
|
2019-02-18 15:24:26 +10:00
|
|
|
MOCK_DECL(crypto_pk_t *,get_server_identity_key,(void));
|
2019-10-18 14:16:24 +10:00
|
|
|
#else
|
|
|
|
#define get_server_identity_key() (tor_abort_(),NULL)
|
|
|
|
#endif
|
2010-10-03 22:38:53 -07:00
|
|
|
int server_identity_key_is_set(void);
|
2012-01-18 15:53:30 -05:00
|
|
|
void set_client_identity_key(crypto_pk_t *k);
|
|
|
|
crypto_pk_t *get_tlsclient_identity_key(void);
|
2010-10-03 22:38:53 -07:00
|
|
|
int client_identity_key_is_set(void);
|
2015-09-07 12:22:33 -05:00
|
|
|
MOCK_DECL(authority_cert_t *, get_my_v3_authority_cert, (void));
|
2012-01-18 15:53:30 -05:00
|
|
|
crypto_pk_t *get_my_v3_authority_signing_key(void);
|
2010-07-21 16:17:10 +02:00
|
|
|
authority_cert_t *get_my_v3_legacy_cert(void);
|
2012-01-18 15:53:30 -05:00
|
|
|
crypto_pk_t *get_my_v3_legacy_signing_key(void);
|
|
|
|
void dup_onion_keys(crypto_pk_t **key, crypto_pk_t **last);
|
2017-03-10 13:00:20 +01:00
|
|
|
void expire_old_onion_keys(void);
|
2010-07-21 16:17:10 +02:00
|
|
|
void rotate_onion_key(void);
|
|
|
|
void v3_authority_check_key_expiry(void);
|
2017-03-10 12:18:52 +01:00
|
|
|
int get_onion_key_lifetime(void);
|
2017-03-10 12:56:36 +01:00
|
|
|
int get_onion_key_grace_period(void);
|
2010-07-21 16:17:10 +02:00
|
|
|
|
2018-08-23 14:05:42 -04:00
|
|
|
crypto_pk_t *router_get_rsa_onion_pkey(const char *pkey, size_t pkey_len);
|
|
|
|
void router_set_rsa_onion_pkey(const crypto_pk_t *pk, char **onion_pkey_out,
|
|
|
|
size_t *onion_pkey_len);
|
|
|
|
|
2012-12-04 15:58:18 -05:00
|
|
|
di_digest256_map_t *construct_ntor_key_map(void);
|
2017-11-21 09:37:47 -05:00
|
|
|
void ntor_key_map_free_(di_digest256_map_t *map);
|
2017-12-04 15:09:18 -05:00
|
|
|
#define ntor_key_map_free(map) \
|
2017-12-07 10:44:04 -05:00
|
|
|
FREE_AND_NULL(di_digest256_map_t, ntor_key_map_free_, (map))
|
2012-12-04 15:58:18 -05:00
|
|
|
|
2011-11-24 06:40:02 +01:00
|
|
|
int router_initialize_tls_context(void);
|
2010-07-21 16:17:10 +02:00
|
|
|
int init_keys(void);
|
2015-08-11 10:35:10 -04:00
|
|
|
int init_keys_client(void);
|
2010-07-21 16:17:10 +02:00
|
|
|
|
2013-03-11 17:20:43 -04:00
|
|
|
uint16_t router_get_active_listener_port_by_type_af(int listener_type,
|
|
|
|
sa_family_t family);
|
2020-07-21 12:59:03 -04:00
|
|
|
void routerconf_find_ipv6_or_ap(const or_options_t *options,
|
2019-12-20 14:30:51 +10:00
|
|
|
tor_addr_port_t *ipv6_ap_out);
|
2020-07-21 12:59:03 -04:00
|
|
|
bool routerconf_has_ipv6_orport(const or_options_t *options);
|
2020-04-30 06:47:46 +10:00
|
|
|
MOCK_DECL(bool, router_can_extend_over_ipv6,(const or_options_t *options));
|
2020-07-21 12:59:03 -04:00
|
|
|
uint16_t routerconf_find_or_port(const or_options_t *options,
|
2020-07-21 12:34:56 -04:00
|
|
|
sa_family_t family);
|
2020-07-21 12:59:03 -04:00
|
|
|
uint16_t routerconf_find_dir_port(const or_options_t *options,
|
2011-06-02 13:30:32 +02:00
|
|
|
uint16_t dirport);
|
2011-05-02 15:51:30 -04:00
|
|
|
|
2018-09-25 15:10:11 -04:00
|
|
|
int router_should_advertise_dirport(const or_options_t *options,
|
|
|
|
uint16_t dir_port);
|
|
|
|
|
2010-07-21 16:17:10 +02:00
|
|
|
void consider_publishable_server(int force);
|
2011-06-14 13:01:38 -04:00
|
|
|
int should_refuse_unknown_exits(const or_options_t *options);
|
2010-07-21 16:17:10 +02:00
|
|
|
|
2020-06-24 14:52:44 -04:00
|
|
|
void router_new_consensus_params(const networkstatus_t *);
|
2010-07-21 16:17:10 +02:00
|
|
|
void router_upload_dir_desc_to_dirservers(int force);
|
2011-06-22 12:27:27 -04:00
|
|
|
void mark_my_descriptor_dirty_if_too_old(time_t now);
|
2011-05-19 23:36:20 -04:00
|
|
|
void mark_my_descriptor_dirty(const char *reason);
|
2020-07-24 09:11:16 -04:00
|
|
|
void mark_my_descriptor_if_omit_ipv6_changes(const char *reason,
|
|
|
|
bool omit_ipv6);
|
2010-07-21 16:17:10 +02:00
|
|
|
void check_descriptor_bandwidth_changed(time_t now);
|
|
|
|
void check_descriptor_ipaddress_changed(time_t now);
|
2018-09-25 16:00:50 -04:00
|
|
|
int router_has_bandwidth_to_be_dirserver(const or_options_t *options);
|
2012-11-05 13:11:53 -05:00
|
|
|
int router_compare_to_my_exit_policy(const tor_addr_t *addr, uint16_t port);
|
2015-10-08 21:47:52 +03:00
|
|
|
MOCK_DECL(int, router_my_exit_policy_is_reject_star,(void));
|
2014-04-15 22:20:34 +10:00
|
|
|
MOCK_DECL(const routerinfo_t *, router_get_my_routerinfo, (void));
|
2018-05-10 16:13:16 +03:00
|
|
|
MOCK_DECL(const routerinfo_t *, router_get_my_routerinfo_with_err,(int *err));
|
2010-07-21 16:17:10 +02:00
|
|
|
extrainfo_t *router_get_my_extrainfo(void);
|
|
|
|
const char *router_get_my_descriptor(void);
|
2011-06-24 16:43:08 -04:00
|
|
|
const char *router_get_descriptor_gen_reason(void);
|
2010-07-21 16:17:10 +02:00
|
|
|
int router_digest_is_me(const char *digest);
|
2012-12-04 21:27:07 -05:00
|
|
|
const uint8_t *router_get_my_id_digest(void);
|
2010-07-21 16:17:10 +02:00
|
|
|
int router_extrainfo_digest_is_me(const char *digest);
|
2010-09-29 00:38:32 -04:00
|
|
|
int router_is_me(const routerinfo_t *router);
|
2020-08-06 11:21:00 -04:00
|
|
|
bool router_addr_is_my_published_addr(const tor_addr_t *addr);
|
2015-02-07 13:29:26 +01:00
|
|
|
int router_build_fresh_descriptor(routerinfo_t **r, extrainfo_t **e);
|
2010-07-21 16:17:10 +02:00
|
|
|
int router_rebuild_descriptor(int force);
|
2013-02-22 12:17:23 -05:00
|
|
|
char *router_dump_router_to_string(routerinfo_t *router,
|
2018-07-01 13:04:21 -04:00
|
|
|
const crypto_pk_t *ident_key,
|
|
|
|
const crypto_pk_t *tap_key,
|
|
|
|
const struct curve25519_keypair_t *ntor_keypair,
|
|
|
|
const struct ed25519_keypair_t *signing_keypair);
|
2013-08-23 21:06:42 +03:00
|
|
|
char *router_dump_exit_policy_to_string(const routerinfo_t *router,
|
|
|
|
int include_ipv4,
|
|
|
|
int include_ipv6);
|
2012-08-01 02:38:43 -07:00
|
|
|
int extrainfo_dump_to_string(char **s, extrainfo_t *extrainfo,
|
2015-05-28 10:42:22 -04:00
|
|
|
crypto_pk_t *ident_key,
|
2018-07-01 13:04:21 -04:00
|
|
|
const struct ed25519_keypair_t *signing_keypair);
|
2011-05-15 21:58:46 -04:00
|
|
|
|
2018-05-10 16:33:08 +03:00
|
|
|
const char *routerinfo_err_to_string(int err);
|
2018-05-03 17:07:29 +02:00
|
|
|
int routerinfo_err_is_transient(int err);
|
|
|
|
|
2020-05-05 13:24:03 -04:00
|
|
|
void log_addr_has_changed(int severity, const tor_addr_t *prev,
|
|
|
|
const tor_addr_t *cur, const char *source);
|
|
|
|
|
2010-07-21 16:17:10 +02:00
|
|
|
void router_reset_warnings(void);
|
|
|
|
void router_free_all(void);
|
|
|
|
|
|
|
|
#ifdef ROUTER_PRIVATE
|
2019-01-10 20:47:37 +10:00
|
|
|
/* Used only by router.c and the unit tests */
|
2013-06-06 17:58:28 -04:00
|
|
|
STATIC void get_platform_str(char *platform, size_t len);
|
2020-01-10 20:58:21 -08:00
|
|
|
STATIC int router_write_fingerprint(int hashed, int ed25519_identity);
|
2018-11-24 16:35:58 -05:00
|
|
|
STATIC smartlist_t *get_my_declared_family(const or_options_t *options);
|
2020-12-15 11:41:42 -05:00
|
|
|
STATIC int load_stats_file(const char *filename, const char *ts_tag,
|
|
|
|
time_t now, char **out);
|
2018-12-05 09:43:03 -05:00
|
|
|
|
2018-12-03 14:06:53 -05:00
|
|
|
#ifdef TOR_UNIT_TESTS
|
|
|
|
extern time_t desc_clean_since;
|
|
|
|
extern const char *desc_dirty_reason;
|
2018-11-24 16:35:58 -05:00
|
|
|
void set_server_identity_key_digest_testing(const uint8_t *digest);
|
2019-02-18 17:37:47 +10:00
|
|
|
MOCK_DECL(STATIC const struct curve25519_keypair_t *,
|
|
|
|
get_current_curve25519_keypair,(void));
|
2019-02-18 15:24:26 +10:00
|
|
|
|
|
|
|
MOCK_DECL(STATIC int,
|
|
|
|
router_build_fresh_unsigned_routerinfo,(routerinfo_t **ri_out));
|
|
|
|
STATIC extrainfo_t *router_build_fresh_signed_extrainfo(
|
|
|
|
const routerinfo_t *ri);
|
|
|
|
STATIC void router_update_routerinfo_from_extrainfo(routerinfo_t *ri,
|
|
|
|
const extrainfo_t *ei);
|
|
|
|
STATIC int router_dump_and_sign_routerinfo_descriptor_body(routerinfo_t *ri);
|
2019-02-19 21:23:27 +10:00
|
|
|
#endif /* defined(TOR_UNIT_TESTS) */
|
2018-12-05 09:43:03 -05:00
|
|
|
|
2019-02-19 21:23:27 +10:00
|
|
|
#endif /* defined(ROUTER_PRIVATE) */
|
2010-07-21 16:17:10 +02:00
|
|
|
|
2017-09-15 16:24:44 -04:00
|
|
|
#endif /* !defined(TOR_ROUTER_H) */
|