tor  0.4.1.0-alpha-dev
hs_cell.h
Go to the documentation of this file.
1 /* Copyright (c) 2017-2019, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
3 
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 
15 /* An INTRODUCE1 cell requires at least this amount of bytes (see section
16  * 3.2.2 of the specification). Below this value, the cell must be padded. */
17 #define HS_CELL_INTRODUCE1_MIN_SIZE 246
18 
19 /* Status code of an INTRODUCE_ACK cell. */
20 typedef enum {
21  HS_CELL_INTRO_ACK_SUCCESS = 0x0000, /* Cell relayed to service. */
22  HS_CELL_INTRO_ACK_FAILURE = 0x0001, /* Service ID not recognized */
23  HS_CELL_INTRO_ACK_BADFMT = 0x0002, /* Bad message format */
24  HS_CELL_INTRO_ACK_NORELAY = 0x0003, /* Can't relay cell to service */
25 } hs_cell_introd_ack_status_t;
26 
27 /* Onion key type found in the INTRODUCE1 cell. */
28 typedef enum {
29  HS_CELL_ONION_KEY_TYPE_NTOR = 1,
30 } hs_cell_onion_key_type_t;
31 
32 /* This data structure contains data that we need to build an INTRODUCE1 cell
33  * used by the INTRODUCE1 build function. */
34 typedef struct hs_cell_introduce1_data_t {
35  /* Is this a legacy introduction point? */
36  unsigned int is_legacy : 1;
37  /* (Legacy only) The encryption key for a legacy intro point. Only set if
38  * is_legacy is true. */
39  const crypto_pk_t *legacy_key;
40  /* Introduction point authentication public key. */
41  const ed25519_public_key_t *auth_pk;
42  /* Introduction point encryption public key. */
43  const curve25519_public_key_t *enc_pk;
44  /* Subcredentials of the service. */
45  const uint8_t *subcredential;
46  /* Onion public key for the ntor handshake. */
47  const curve25519_public_key_t *onion_pk;
48  /* Rendezvous cookie. */
49  const uint8_t *rendezvous_cookie;
50  /* Public key put before the encrypted data (CLIENT_PK). */
51  const curve25519_keypair_t *client_kp;
52  /* Rendezvous point link specifiers. */
53  smartlist_t *link_specifiers;
55 
56 /* This data structure contains data that we need to parse an INTRODUCE2 cell
57  * which is used by the INTRODUCE2 cell parsing function. On a successful
58  * parsing, the onion_pk and rendezvous_cookie will be populated with the
59  * computed key material from the cell data. This structure is only used during
60  * INTRO2 parsing and discarded after that. */
61 typedef struct hs_cell_introduce2_data_t {
62  /*** Immutable Section: Set on structure init. ***/
63 
64  /* Introduction point authentication public key. Pointer owned by the
65  introduction point object through which we received the INTRO2 cell. */
66  const ed25519_public_key_t *auth_pk;
67  /* Introduction point encryption keypair for the ntor handshake. Pointer
68  owned by the introduction point object through which we received the
69  INTRO2 cell*/
70  const curve25519_keypair_t *enc_kp;
71  /* Subcredentials of the service. Pointer owned by the descriptor that owns
72  the introduction point through which we received the INTRO2 cell. */
73  const uint8_t *subcredential;
74  /* Payload of the received encoded cell. */
75  const uint8_t *payload;
76  /* Size of the payload of the received encoded cell. */
77  size_t payload_len;
78 
79  /*** Mutable Section: Set upon parsing INTRODUCE2 cell. ***/
80 
81  /* Onion public key computed using the INTRODUCE2 encrypted section. */
82  curve25519_public_key_t onion_pk;
83  /* Rendezvous cookie taken from the INTRODUCE2 encrypted section. */
84  uint8_t rendezvous_cookie[REND_COOKIE_LEN];
85  /* Client public key from the INTRODUCE2 encrypted section. */
86  curve25519_public_key_t client_pk;
87  /* Link specifiers of the rendezvous point. Contains link_specifier_t. */
88  smartlist_t *link_specifiers;
89  /* Replay cache of the introduction point. */
90  replaycache_t *replay_cache;
92 
93 /* Build cell API. */
94 ssize_t hs_cell_build_establish_intro(const char *circ_nonce,
95  const hs_service_intro_point_t *ip,
96  uint8_t *cell_out);
97 ssize_t hs_cell_build_rendezvous1(const uint8_t *rendezvous_cookie,
98  size_t rendezvous_cookie_len,
99  const uint8_t *rendezvous_handshake_info,
100  size_t rendezvous_handshake_info_len,
101  uint8_t *cell_out);
102 ssize_t hs_cell_build_introduce1(const hs_cell_introduce1_data_t *data,
103  uint8_t *cell_out);
104 ssize_t hs_cell_build_establish_rendezvous(const uint8_t *rendezvous_cookie,
105  uint8_t *cell_out);
106 
107 /* Parse cell API. */
108 ssize_t hs_cell_parse_intro_established(const uint8_t *payload,
109  size_t payload_len);
110 ssize_t hs_cell_parse_introduce2(hs_cell_introduce2_data_t *data,
111  const origin_circuit_t *circ,
112  const hs_service_t *service);
113 int hs_cell_parse_introduce_ack(const uint8_t *payload, size_t payload_len);
114 int hs_cell_parse_rendezvous2(const uint8_t *payload, size_t payload_len,
115  uint8_t *handshake_info,
116  size_t handshake_info_len);
117 
118 /* Util API. */
119 void hs_cell_introduce1_data_clear(hs_cell_introduce1_data_t *data);
120 
121 #endif /* !defined(TOR_HS_CELL_H) */
122 
Header file containing service data for the HS subsytem.
Master header file for Tor-specific functionality.
#define REND_COOKIE_LEN
Definition: or.h:399