tor  0.4.2.0-alpha-dev
Macros | Functions | Variables
hs_service.c File Reference
#include "core/or/or.h"
#include "app/config/config.h"
#include "app/config/statefile.h"
#include "core/mainloop/connection.h"
#include "core/mainloop/mainloop.h"
#include "core/or/circuitbuild.h"
#include "core/or/circuitlist.h"
#include "core/or/circuituse.h"
#include "core/or/relay.h"
#include "feature/client/circpathbias.h"
#include "feature/dirclient/dirclient.h"
#include "feature/dircommon/directory.h"
#include "feature/hs_common/shared_random_client.h"
#include "feature/keymgt/loadkey.h"
#include "feature/nodelist/describe.h"
#include "feature/nodelist/networkstatus.h"
#include "feature/nodelist/nickname.h"
#include "feature/nodelist/node_select.h"
#include "feature/nodelist/nodelist.h"
#include "feature/rend/rendservice.h"
#include "lib/crypt_ops/crypto_ope.h"
#include "lib/crypt_ops/crypto_rand.h"
#include "lib/crypt_ops/crypto_util.h"
#include "feature/hs/hs_circuit.h"
#include "feature/hs/hs_common.h"
#include "feature/hs/hs_config.h"
#include "feature/hs/hs_control.h"
#include "feature/hs/hs_descriptor.h"
#include "feature/hs/hs_ident.h"
#include "feature/hs/hs_intropoint.h"
#include "feature/hs/hs_service.h"
#include "feature/hs/hs_stats.h"
#include "feature/dircommon/dir_connection_st.h"
#include "core/or/edge_connection_st.h"
#include "core/or/extend_info_st.h"
#include "feature/nodelist/networkstatus_st.h"
#include "feature/nodelist/node_st.h"
#include "core/or/origin_circuit_st.h"
#include "app/config/or_state_st.h"
#include "feature/nodelist/routerstatus_st.h"
#include "lib/encoding/confline.h"
#include "lib/crypt_ops/crypto_format.h"
#include "trunnel/ed25519_cert.h"
#include "trunnel/hs/cell_common.h"
#include "trunnel/hs/cell_establish_intro.h"

Go to the source code of this file.

Macros

#define HS_SERVICE_PRIVATE
 
#define FOR_EACH_SERVICE_BEGIN(var)
 
#define FOR_EACH_SERVICE_END   } STMT_END ;
 
#define FOR_EACH_DESCRIPTOR_BEGIN(service, var)
 
#define FOR_EACH_DESCRIPTOR_END   } STMT_END ;
 
#define MIN_INTRO_POINT_LIFETIME_TESTING   10
 
#define MAX_INTRO_POINT_LIFETIME_TESTING   30
 
#define MAX_INTRO_POINT_CIRCUIT_RETRIES_TESTING   -1
 
#define MAX_STREAM_WARN_INTERVAL   600
 

Functions

static int load_client_keys (hs_service_t *service)
 
static void set_descriptor_revision_counter (hs_service_descriptor_t *hs_desc, time_t now, bool is_current)
 
static int build_service_desc_superencrypted (const hs_service_t *service, hs_service_descriptor_t *desc)
 
static void move_descriptors (hs_service_t *src, hs_service_t *dst)
 
static int service_encode_descriptor (const hs_service_t *service, const hs_service_descriptor_t *desc, const ed25519_keypair_t *signing_kp, char **encoded_out)
 
static int hs_service_ht_eq (const hs_service_t *first, const hs_service_t *second)
 
static unsigned int hs_service_ht_hash (const hs_service_t *service)
 
 HT_PROTOTYPE (HT_GENERATE2(hs_service_ht, HT_GENERATE2(hs_service_t, HT_GENERATE2(hs_service_node, HT_GENERATE2(hs_service_ht_hash, HT_GENERATE2(hs_service_ht_eq)
 
STATIC int register_service (hs_service_ht *map, hs_service_t *service)
 
STATIC void remove_service (hs_service_ht *map, hs_service_t *service)
 
static void set_service_default_config (hs_service_config_t *c, const or_options_t *options)
 
STATIC void service_clear_config (hs_service_config_t *config)
 
static const char * describe_intro_point (const hs_service_intro_point_t *ip)
 
static int32_t get_intro_point_min_introduce2 (void)
 
static int32_t get_intro_point_max_introduce2 (void)
 
static int32_t get_intro_point_min_lifetime (void)
 
static int32_t get_intro_point_max_lifetime (void)
 
static int32_t get_intro_point_num_extra (void)
 
static int ht_free_service_ (struct hs_service_t *service, void *data)
 
static void service_free_all (void)
 
STATIC void service_intro_point_free_ (hs_service_intro_point_t *ip)
 
static void service_intro_point_free_void (void *obj)
 
STATIC hs_service_intro_point_tservice_intro_point_new (const node_t *node)
 
STATIC void service_intro_point_add (digest256map_t *map, hs_service_intro_point_t *ip)
 
STATIC void service_intro_point_remove (const hs_service_t *service, const hs_service_intro_point_t *ip)
 
STATIC hs_service_intro_point_tservice_intro_point_find (const hs_service_t *service, const ed25519_public_key_t *auth_key)
 
STATIC hs_service_descriptor_tservice_desc_find_by_intro (const hs_service_t *service, const hs_service_intro_point_t *ip)
 
STATIC void get_objects_from_ident (const hs_ident_circuit_t *ident, hs_service_t **service, hs_service_intro_point_t **ip, hs_service_descriptor_t **desc)
 
static link_specifier_t * get_link_spec_by_type (const hs_service_intro_point_t *ip, uint8_t type)
 
STATIC const node_tget_node_from_intro_point (const hs_service_intro_point_t *ip)
 
static extend_info_tget_extend_info_from_intro_point (const hs_service_intro_point_t *ip, unsigned int direct_conn)
 
static unsigned int count_desc_circuit_established (const hs_service_descriptor_t *desc)
 
static void close_directory_connections (const hs_service_t *service, const hs_service_descriptor_t *desc)
 
static void close_service_rp_circuits (hs_service_t *service)
 
static void close_intro_circuits (hs_service_intropoints_t *intro_points)
 
static void close_service_intro_circuits (hs_service_t *service)
 
static void close_service_circuits (hs_service_t *service)
 
static void move_ephemeral_services (hs_service_ht *src, hs_service_ht *dst)
 
static const char * service_escaped_dir (const hs_service_t *s)
 
static void move_hs_state (hs_service_t *src_service, hs_service_t *dst_service)
 
static void register_all_services (void)
 
STATIC int write_address_to_file (const hs_service_t *service, const char *fname_)
 
static int load_service_keys (hs_service_t *service)
 
STATIC int client_filename_is_valid (const char *filename)
 
STATIC hs_service_authorized_client_tparse_authorized_client (const char *client_key_str)
 
STATIC void service_authorized_client_free_ (hs_service_authorized_client_t *client)
 
STATIC void service_descriptor_free_ (hs_service_descriptor_t *desc)
 
STATIC hs_service_descriptor_tservice_descriptor_new (void)
 
static hs_service_authorized_client_tservice_authorized_client_dup (const hs_service_authorized_client_t *client)
 
static int service_authorized_client_cmp (const hs_service_authorized_client_t *client1, const hs_service_authorized_client_t *client2)
 
static int compare_service_authorzized_client_ (const void **_a, const void **_b)
 
STATIC int service_authorized_client_config_equal (const hs_service_config_t *config1, const hs_service_config_t *config2)
 
static void remove_expired_failing_intro (hs_service_t *service, time_t now)
 
static void setup_intro_point_exclude_list (const hs_service_descriptor_t *desc, smartlist_t *node_list)
 
static void remember_failing_intro_point (const hs_service_intro_point_t *ip, hs_service_descriptor_t *desc, time_t now)
 
static int setup_desc_intro_point (const ed25519_keypair_t *signing_kp, const hs_service_intro_point_t *ip, time_t now, hs_desc_intro_point_t *desc_ip)
 
static void build_desc_intro_points (const hs_service_t *service, hs_service_descriptor_t *desc, time_t now)
 
static void build_desc_signing_key_cert (hs_service_descriptor_t *desc, time_t now)
 
static int build_service_desc_encrypted (const hs_service_t *service, hs_service_descriptor_t *desc)
 
static void build_service_desc_plaintext (const hs_service_t *service, hs_service_descriptor_t *desc)
 
static crypto_ope_tgenerate_ope_cipher_for_desc (const hs_service_descriptor_t *hs_desc)
 
static int build_service_desc_keys (const hs_service_t *service, hs_service_descriptor_t *desc)
 
static void build_service_descriptor (hs_service_t *service, uint64_t time_period_num, hs_service_descriptor_t **desc_out)
 
static void build_descriptors_for_new_service (hs_service_t *service, time_t now)
 
STATIC void build_all_descriptors (time_t now)
 
static hs_service_intro_point_tpick_intro_point (unsigned int direct_conn, smartlist_t *exclude_nodes)
 
static unsigned int pick_needed_intro_points (hs_service_t *service, hs_service_descriptor_t *desc)
 
static void service_desc_clear_previous_hsdirs (hs_service_descriptor_t *desc)
 
static void service_desc_note_upload (hs_service_descriptor_t *desc, const node_t *hsdir)
 
STATIC void service_desc_schedule_upload (hs_service_descriptor_t *desc, time_t now, int descriptor_changed)
 
static void update_service_descriptor_intro_points (hs_service_t *service, hs_service_descriptor_t *desc, time_t now)
 
STATIC void update_all_descriptors_intro_points (time_t now)
 
STATIC int intro_point_should_expire (const hs_service_intro_point_t *ip, time_t now)
 
static void cleanup_intro_points (hs_service_t *service, time_t now)
 
static void set_rotation_time (hs_service_t *service)
 
static unsigned int should_rotate_descriptors (hs_service_t *service, time_t now)
 
static void rotate_service_descriptors (hs_service_t *service)
 
STATIC void rotate_all_descriptors (time_t now)
 
STATIC void run_housekeeping_event (time_t now)
 
static void run_build_descriptor_event (time_t now)
 
static void launch_intro_point_circuits (hs_service_t *service)
 
static unsigned int get_max_intro_circ_per_period (const hs_service_t *service)
 
STATIC int can_service_launch_intro_circuit (hs_service_t *service, time_t now)
 
static void run_build_circuit_event (time_t now)
 
static void upload_descriptor_to_hsdir (const hs_service_t *service, hs_service_descriptor_t *desc, const node_t *hsdir)
 
STATIC void upload_descriptor_to_all (const hs_service_t *service, hs_service_descriptor_t *desc)
 
STATIC int service_desc_hsdirs_changed (const hs_service_t *service, const hs_service_descriptor_t *desc)
 
static int should_service_upload_descriptor (const hs_service_t *service, const hs_service_descriptor_t *desc, time_t now)
 
static void refresh_service_descriptor (const hs_service_t *service, hs_service_descriptor_t *desc, time_t now)
 
STATIC void run_upload_descriptor_event (time_t now)
 
static void service_intro_circ_has_opened (origin_circuit_t *circ)
 
static void service_rendezvous_circ_has_opened (origin_circuit_t *circ)
 
static int service_handle_intro_established (origin_circuit_t *circ, const uint8_t *payload, size_t payload_len)
 
static int service_handle_introduce2 (origin_circuit_t *circ, const uint8_t *payload, size_t payload_len)
 
static void service_add_fnames_to_list (const hs_service_t *service, smartlist_t *list)
 
static int service_key_on_disk (const char *directory_path)
 
void hs_service_map_has_changed (void)
 
void hs_service_upload_desc_to_dir (const char *encoded_desc, const uint8_t version, const ed25519_public_key_t *identity_pk, const ed25519_public_key_t *blinded_pk, const routerstatus_t *hsdir_rs)
 
hs_service_add_ephemeral_status_t hs_service_add_ephemeral (ed25519_secret_key_t *sk, smartlist_t *ports, int max_streams_per_rdv_circuit, int max_streams_close_circuit, char **address_out)
 
int hs_service_del_ephemeral (const char *address)
 
char * hs_service_lookup_current_desc (const ed25519_public_key_t *pk)
 
 MOCK_IMPL (unsigned int, hs_service_get_num_services,(void))
 
void hs_service_intro_circ_has_closed (origin_circuit_t *circ)
 
int hs_service_set_conn_addr_port (const origin_circuit_t *circ, edge_connection_t *conn)
 
hs_circuit_id_protocol_t hs_service_exports_circuit_id (const ed25519_public_key_t *pk)
 
void hs_service_lists_fnames_for_sandbox (smartlist_t *file_list, smartlist_t *dir_list)
 
void hs_service_dir_info_changed (void)
 
int hs_service_receive_introduce2 (origin_circuit_t *circ, const uint8_t *payload, size_t payload_len)
 
int hs_service_receive_intro_established (origin_circuit_t *circ, const uint8_t *payload, size_t payload_len)
 
void hs_service_circuit_has_opened (origin_circuit_t *circ)
 
int hs_service_get_version_from_key (const hs_service_t *service)
 
int hs_service_load_all_keys (void)
 
void hs_service_stage_services (const smartlist_t *service_list)
 
hs_service_ths_service_new (const or_options_t *options)
 
void hs_service_free_ (hs_service_t *service)
 
void hs_service_run_scheduled_events (time_t now)
 
void hs_service_init (void)
 
void hs_service_free_all (void)
 

Variables

static const char fname_keyfile_prefix [] = "hs_ed25519"
 
static const char dname_client_pubkeys [] = "authorized_clients"
 
static const char fname_hostname [] = "hostname"
 
static const char address_tld [] = "onion"
 
static smartlist_ths_service_staging_list
 
static int consider_republishing_hs_descriptors = 0
 
static struct hs_service_ht * hs_service_map
 

Detailed Description

Implement next generation hidden service functionality.

Definition in file hs_service.c.

Macro Definition Documentation

◆ FOR_EACH_DESCRIPTOR_BEGIN

#define FOR_EACH_DESCRIPTOR_BEGIN (   service,
  var 
)
Value:
STMT_BEGIN \
hs_service_descriptor_t *var; \
for (int var ## _loop_idx = 0; var ## _loop_idx < 2; \
++var ## _loop_idx) { \
(var ## _loop_idx == 0) ? (var = service->desc_current) : \
(var = service->desc_next); \
if (var == NULL) continue;

Definition at line 82 of file hs_service.c.

◆ FOR_EACH_SERVICE_BEGIN

#define FOR_EACH_SERVICE_BEGIN (   var)
Value:
STMT_BEGIN \
hs_service_t **var##_iter, *var; \
HT_FOREACH(var##_iter, hs_service_ht, hs_service_map) { \
var = *var##_iter;

Definition at line 72 of file hs_service.c.

Function Documentation

◆ generate_ope_cipher_for_desc()

static crypto_ope_t* generate_ope_cipher_for_desc ( const hs_service_descriptor_t hs_desc)
static

Compute the descriptor's OPE cipher for encrypting revision counters.

Definition at line 1846 of file hs_service.c.

References crypto_digest256_new(), and DIGEST256_LEN.

◆ hs_service_exports_circuit_id()

hs_circuit_id_protocol_t hs_service_exports_circuit_id ( const ed25519_public_key_t pk)

Does the service with identity pubkey pk export the circuit IDs of its clients?

Definition at line 3773 of file hs_service.c.

◆ move_hs_state()

static void move_hs_state ( hs_service_t src_service,
hs_service_t dst_service 
)
static

Move the hidden service state from src to dst. We do this when we receive a SIGHUP: dst is the post-HUP service

Definition at line 871 of file hs_service.c.

References tor_assert().

◆ service_desc_clear_previous_hsdirs()

static void service_desc_clear_previous_hsdirs ( hs_service_descriptor_t desc)
static

Clear previous cached HSDirs in desc.

Definition at line 2206 of file hs_service.c.

Referenced by service_desc_schedule_upload().

◆ service_desc_hsdirs_changed()

STATIC int service_desc_hsdirs_changed ( const hs_service_t service,
const hs_service_descriptor_t desc 
)

The set of HSDirs have changed: check if the change affects our descriptor HSDir placement, and if it does, reupload the desc.

Definition at line 2964 of file hs_service.c.

References hs_service_descriptor_t::previous_hsdirs.

◆ service_desc_note_upload()

static void service_desc_note_upload ( hs_service_descriptor_t desc,
const node_t hsdir 
)
static

Note that we attempted to upload desc to hsdir.

Definition at line 2218 of file hs_service.c.

References BASE64_DIGEST_LEN, digest_to_base64(), and node_t::identity.

◆ service_desc_schedule_upload()

STATIC void service_desc_schedule_upload ( hs_service_descriptor_t desc,
time_t  now,
int  descriptor_changed 
)

Schedule an upload of desc. If descriptor_changed is set, it means that this descriptor is dirty.

Definition at line 2235 of file hs_service.c.

References service_desc_clear_previous_hsdirs().

◆ set_descriptor_revision_counter()

static void set_descriptor_revision_counter ( hs_service_descriptor_t hs_desc,
time_t  now,
bool  is_current 
)
static

Set the revision counter in hs_desc. We do this by encrypting a timestamp using an OPE scheme and using the ciphertext as our revision counter.

If is_current is true, then this is the current HS descriptor, otherwise it's the next one.

Definition at line 2836 of file hs_service.c.

References sr_state_get_start_time_of_current_protocol_run(), and sr_state_get_start_time_of_previous_protocol_run().

◆ upload_descriptor_to_all()

STATIC void upload_descriptor_to_all ( const hs_service_t service,
hs_service_descriptor_t desc 
)

Clear list of previous hsdirs since we are about to upload to a new list. Let's keep it up to date.

Definition at line 2907 of file hs_service.c.

References tor_assert().

Variable Documentation

◆ consider_republishing_hs_descriptors

int consider_republishing_hs_descriptors = 0
static

True if the list of available router descriptors might have changed which might result in an altered hash ring. Check if the hash ring changed and reupload if needed

Definition at line 107 of file hs_service.c.