tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

hs_client.h (7092B)


      1 /* Copyright (c) 2017-2021, The Tor Project, Inc. */
      2 /* See LICENSE for licensing information */
      3 
      4 /**
      5 * \file hs_client.h
      6 * \brief Header file containing client data for the HS subsystem.
      7 **/
      8 
      9 #ifndef TOR_HS_CLIENT_H
     10 #define TOR_HS_CLIENT_H
     11 
     12 #include "lib/crypt_ops/crypto_ed25519.h"
     13 
     14 #include "feature/hs/hs_circuit.h"
     15 #include "feature/hs/hs_descriptor.h"
     16 #include "feature/hs/hs_ident.h"
     17 
     18 /** Status code of a descriptor fetch request. */
     19 typedef enum {
     20  /** Something internally went wrong. */
     21  HS_CLIENT_FETCH_ERROR        = -1,
     22  /** The fetch request has been launched successfully. */
     23  HS_CLIENT_FETCH_LAUNCHED     = 0,
     24  /** We already have a usable descriptor. No fetch. */
     25  HS_CLIENT_FETCH_HAVE_DESC    = 1,
     26  /** No more HSDir available to query. */
     27  HS_CLIENT_FETCH_NO_HSDIRS    = 2,
     28  /** The fetch request is not allowed. */
     29  HS_CLIENT_FETCH_NOT_ALLOWED  = 3,
     30  /** We are missing information to be able to launch a request. */
     31  HS_CLIENT_FETCH_MISSING_INFO = 4,
     32  /** There is a pending fetch for the requested service. */
     33  HS_CLIENT_FETCH_PENDING      = 5,
     34 } hs_client_fetch_status_t;
     35 
     36 /* Status code of client auth credential registration */
     37 typedef enum {
     38  /* We successfully registered these credentials */
     39  REGISTER_SUCCESS,
     40  /* We successfully registered these credentials, but had to replace some
     41   * existing ones. */
     42  REGISTER_SUCCESS_ALREADY_EXISTS,
     43  /* We successfully registered these credentials, and also decrypted a cached
     44   * descriptor. */
     45  REGISTER_SUCCESS_AND_DECRYPTED,
     46  /* We failed to register these credentials, because of a bad HS address. */
     47  REGISTER_FAIL_BAD_ADDRESS,
     48  /* We failed to store these credentials in a persistent file on disk. */
     49  REGISTER_FAIL_PERMANENT_STORAGE,
     50 } hs_client_register_auth_status_t;
     51 
     52 /* Status code of client auth credential removal */
     53 typedef enum {
     54  /* We successfully removed these credentials */
     55  REMOVAL_SUCCESS,
     56  /* No need to remove those credentials, because they were not there. */
     57  REMOVAL_SUCCESS_NOT_FOUND,
     58  /* We failed to register these credentials, because of a bad HS address. */
     59  REMOVAL_BAD_ADDRESS,
     60 } hs_client_removal_auth_status_t;
     61 
     62 /** Flag to set when a client auth is permanent (saved on disk). */
     63 #define CLIENT_AUTH_FLAG_IS_PERMANENT (1<<0)
     64 
     65 /** Client-side configuration of client authorization */
     66 typedef struct hs_client_service_authorization_t {
     67  /** An curve25519 secret key used to compute decryption keys that
     68   * allow the client to decrypt the hidden service descriptor. */
     69  curve25519_secret_key_t enc_seckey;
     70 
     71  /** An onion address that is used to connect to the onion service. */
     72  char onion_address[HS_SERVICE_ADDR_LEN_BASE32+1];
     73 
     74  /** An client name used to connect to the onion service. */
     75  char *client_name;
     76 
     77  /* Optional flags for this client. */
     78  int flags;
     79 } hs_client_service_authorization_t;
     80 
     81 const hs_desc_intro_point_t *
     82 find_desc_intro_point_by_ident(const hs_ident_circuit_t *ident,
     83                               const hs_descriptor_t *desc);
     84 
     85 hs_client_register_auth_status_t
     86 hs_client_register_auth_credentials(hs_client_service_authorization_t *creds);
     87 
     88 hs_client_removal_auth_status_t
     89 hs_client_remove_auth_credentials(const char *hsaddress);
     90 
     91 digest256map_t *get_hs_client_auths_map(void);
     92 
     93 #define client_service_authorization_free(auth)                      \
     94  FREE_AND_NULL(hs_client_service_authorization_t,                   \
     95                client_service_authorization_free_, (auth))
     96 
     97 void
     98 client_service_authorization_free_(hs_client_service_authorization_t *auth);
     99 
    100 void hs_client_note_connection_attempt_succeeded(
    101                                       const edge_connection_t *conn);
    102 
    103 void hs_client_launch_v3_desc_fetch(
    104                               const ed25519_public_key_t *onion_identity_pk,
    105                               const smartlist_t *hsdirs);
    106 
    107 int send_introduce1(origin_circuit_t *intro_circ,
    108                    origin_circuit_t *rend_circ,
    109                    const hs_descriptor_t *desc,
    110                    hs_pow_solution_t *pow_solution,
    111                    const hs_desc_intro_point_t *ip);
    112 
    113 hs_desc_decode_status_t hs_client_decode_descriptor(
    114                     const char *desc_str,
    115                     const ed25519_public_key_t *service_identity_pk,
    116                     hs_descriptor_t **desc);
    117 int hs_client_any_intro_points_usable(const ed25519_public_key_t *service_pk,
    118                                      const hs_descriptor_t *desc);
    119 int hs_client_refetch_hsdesc(const ed25519_public_key_t *identity_pk);
    120 void hs_client_dir_info_changed(void);
    121 
    122 int hs_client_setup_intro_circ_auth_key(origin_circuit_t *circ);
    123 
    124 int hs_client_send_introduce1(origin_circuit_t *intro_circ,
    125                              origin_circuit_t *rend_circ);
    126 
    127 void hs_client_circuit_has_opened(origin_circuit_t *circ);
    128 void hs_client_circuit_cleanup_on_close(const circuit_t *circ);
    129 void hs_client_circuit_cleanup_on_free(const circuit_t *circ);
    130 
    131 int hs_client_receive_rendezvous_acked(origin_circuit_t *circ,
    132                                       const uint8_t *payload,
    133                                       size_t payload_len);
    134 int hs_client_receive_introduce_ack(origin_circuit_t *circ,
    135                                    const uint8_t *payload,
    136                                    size_t payload_len);
    137 int hs_client_receive_rendezvous2(origin_circuit_t *circ,
    138                                  const uint8_t *payload,
    139                                  size_t payload_len);
    140 
    141 void hs_client_dir_fetch_done(dir_connection_t *dir_conn, const char *reason,
    142                              const char *body, const int status_code);
    143 
    144 extend_info_t *hs_client_get_random_intro_from_edge(
    145                                          const edge_connection_t *edge_conn);
    146 
    147 int hs_config_client_authorization(const or_options_t *options,
    148                                   int validate_only);
    149 
    150 int hs_client_reextend_intro_circuit(origin_circuit_t *circ);
    151 void hs_client_close_intro_circuits_from_desc(const hs_descriptor_t *desc);
    152 
    153 void hs_client_purge_state(void);
    154 
    155 void hs_client_free_all(void);
    156 
    157 #ifdef HS_CLIENT_PRIVATE
    158 
    159 STATIC int auth_key_filename_is_valid(const char *filename);
    160 
    161 STATIC hs_client_service_authorization_t *
    162 parse_auth_file_content(const char *client_key_str);
    163 
    164 STATIC routerstatus_t *
    165 pick_hsdir_v3(const ed25519_public_key_t *onion_identity_pk);
    166 
    167 STATIC extend_info_t *
    168 client_get_random_intro(const ed25519_public_key_t *service_pk);
    169 
    170 STATIC extend_info_t *
    171 desc_intro_point_to_extend_info(const hs_desc_intro_point_t *ip);
    172 
    173 STATIC int handle_rendezvous2(origin_circuit_t *circ, const uint8_t *payload,
    174                              size_t payload_len);
    175 
    176 MOCK_DECL(STATIC hs_client_fetch_status_t,
    177          fetch_v3_desc, (const ed25519_public_key_t *onion_identity_pk));
    178 
    179 STATIC void retry_all_socks_conn_waiting_for_desc(void);
    180 
    181 STATIC void purge_ephemeral_client_auth(void);
    182 
    183 #ifdef TOR_UNIT_TESTS
    184 
    185 STATIC void set_hs_client_auths_map(digest256map_t *map);
    186 
    187 #endif /* defined(TOR_UNIT_TESTS) */
    188 
    189 #endif /* defined(HS_CLIENT_PRIVATE) */
    190 
    191 #endif /* !defined(TOR_HS_CLIENT_H) */