tor

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

hs_cell.h (6111B)


      1 /* Copyright (c) 2017-2021, The Tor Project, Inc. */
      2 /* See LICENSE for licensing information */
      3 
      4 /**
      5 * \file hs_cell.h
      6 * \brief Header file containing cell data for the whole HS subsystem.
      7 **/
      8 
      9 #ifndef TOR_HS_CELL_H
     10 #define TOR_HS_CELL_H
     11 
     12 #include "core/or/or.h"
     13 #include "feature/hs/hs_service.h"
     14 #include "feature/hs/hs_pow.h"
     15 
     16 /** An INTRODUCE1 cell requires at least this amount of bytes (see section
     17 * 3.2.2 of the specification). Below this value, the cell must be padded. */
     18 #define HS_CELL_INTRODUCE1_MIN_SIZE 246
     19 
     20 struct hs_subcredential_t;
     21 
     22 /** This data structure contains data that we need to build an INTRODUCE1 cell
     23 * used by the INTRODUCE1 build function. */
     24 typedef struct hs_cell_introduce1_data_t {
     25  /** Is this a legacy introduction point? */
     26  unsigned int is_legacy : 1;
     27  /** (Legacy only) The encryption key for a legacy intro point. Only set if
     28   * is_legacy is true. */
     29  const crypto_pk_t *legacy_key;
     30  /** Introduction point authentication public key. */
     31  const ed25519_public_key_t *auth_pk;
     32  /** Introduction point encryption public key. */
     33  const curve25519_public_key_t *enc_pk;
     34  /** Subcredentials of the service. */
     35  const struct hs_subcredential_t *subcredential;
     36  /** Onion public key for the ntor handshake. */
     37  const curve25519_public_key_t *onion_pk;
     38  /** Rendezvous cookie. */
     39  const uint8_t *rendezvous_cookie;
     40  /** Public key put before the encrypted data (CLIENT_PK). */
     41  const curve25519_keypair_t *client_kp;
     42  /** Rendezvous point link specifiers. */
     43  smartlist_t *link_specifiers;
     44  /** Congestion control parameters. */
     45  unsigned int cc_enabled : 1;
     46  /** PoW solution (Can be NULL if disabled). */
     47  const hs_pow_solution_t *pow_solution;
     48 } hs_cell_introduce1_data_t;
     49 
     50 /** Introduction data needed to launch a rendezvous circuit. This is set after
     51 * receiving an INTRODUCE2 valid cell. */
     52 typedef struct hs_cell_intro_rdv_data_t {
     53  /** Onion public key computed using the INTRODUCE2 encrypted section. */
     54  curve25519_public_key_t onion_pk;
     55  /** Rendezvous cookie taken from the INTRODUCE2 encrypted section. */
     56  uint8_t rendezvous_cookie[REND_COOKIE_LEN];
     57  /** Client public key from the INTRODUCE2 encrypted section. */
     58  curve25519_public_key_t client_pk;
     59  /** Link specifiers of the rendezvous point. Contains link_specifier_t. */
     60  smartlist_t *link_specifiers;
     61  /** Congestion control parameters. */
     62  unsigned int cc_enabled : 1;
     63  /** PoW effort. */
     64  uint32_t pow_effort;
     65 } hs_cell_intro_rdv_data_t;
     66 
     67 /** This data structure contains data that we need to parse an INTRODUCE2 cell
     68 * which is used by the INTRODUCE2 cell parsing function. On a successful
     69 * parsing, the onion_pk and rendezvous_cookie will be populated with the
     70 * computed key material from the cell data. This structure is only used during
     71 * INTRO2 parsing and discarded after that. */
     72 typedef struct hs_cell_introduce2_data_t {
     73  /*** Immutable Section: Set on structure init. ***/
     74 
     75  /** Introduction point authentication public key. Pointer owned by the
     76     introduction point object through which we received the INTRO2 cell. */
     77  const ed25519_public_key_t *auth_pk;
     78  /** Introduction point encryption keypair for the ntor handshake. Pointer
     79     owned by the introduction point object through which we received the
     80     INTRO2 cell*/
     81  const curve25519_keypair_t *enc_kp;
     82  /**
     83   * Length of the subcredentials array below.
     84   **/
     85  size_t n_subcredentials;
     86  /** Array of <b>n_subcredentials</b> subcredentials for the service. Pointer
     87   * owned by the descriptor that owns the introduction point through which we
     88   * received the INTRO2 cell. */
     89  const struct hs_subcredential_t *subcredentials;
     90  /** Payload of the received encoded cell. */
     91  const uint8_t *payload;
     92  /** Size of the payload of the received encoded cell. */
     93  size_t payload_len;
     94 
     95  /*** Mutable Section: Set upon parsing INTRODUCE2 cell. ***/
     96 
     97  /** Data needed to launch a rendezvous circuit. */
     98  hs_cell_intro_rdv_data_t rdv_data;
     99  /** Replay cache of the introduction point. */
    100  replaycache_t *replay_cache;
    101  /** Flow control negotiation parameters. */
    102  protover_summary_flags_t pv;
    103 } hs_cell_introduce2_data_t;
    104 
    105 /* Build cell API. */
    106 ssize_t hs_cell_build_establish_intro(const char *circ_nonce,
    107                                      const hs_service_config_t *config,
    108                                      const hs_service_intro_point_t *ip,
    109                                      uint8_t *cell_out);
    110 ssize_t hs_cell_build_rendezvous1(const uint8_t *rendezvous_cookie,
    111                                  size_t rendezvous_cookie_len,
    112                                  const uint8_t *rendezvous_handshake_info,
    113                                  size_t rendezvous_handshake_info_len,
    114                                  uint8_t *cell_out);
    115 ssize_t hs_cell_build_introduce1(const hs_cell_introduce1_data_t *data,
    116                                 uint8_t *cell_out);
    117 ssize_t hs_cell_build_establish_rendezvous(const uint8_t *rendezvous_cookie,
    118                                           uint8_t *cell_out);
    119 
    120 /* Parse cell API. */
    121 ssize_t hs_cell_parse_intro_established(const uint8_t *payload,
    122                                        size_t payload_len);
    123 ssize_t hs_cell_parse_introduce2(hs_cell_introduce2_data_t *data,
    124                                 const origin_circuit_t *circ,
    125                                 const hs_service_t *service,
    126                                 const hs_service_intro_point_t *ip);
    127 int hs_cell_parse_introduce_ack(const uint8_t *payload, size_t payload_len);
    128 int hs_cell_parse_rendezvous2(const uint8_t *payload, size_t payload_len,
    129                              uint8_t *handshake_info,
    130                              size_t handshake_info_len);
    131 
    132 /* Util API. */
    133 void hs_cell_introduce1_data_clear(hs_cell_introduce1_data_t *data);
    134 
    135 #ifdef TOR_UNIT_TESTS
    136 
    137 #include "trunnel/extension.h"
    138 
    139 STATIC trn_extension_t *
    140 build_establish_intro_extensions(const hs_service_config_t *service_config,
    141                                 const hs_service_intro_point_t *ip);
    142 
    143 #endif /* defined(TOR_UNIT_TESTS) */
    144 
    145 #endif /* !defined(TOR_HS_CELL_H) */