tor  0.4.2.0-alpha-dev
rendservice.h
Go to the documentation of this file.
1 /* Copyright (c) 2001 Matej Pfajfar.
2  * Copyright (c) 2001-2004, Roger Dingledine.
3  * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
4  * Copyright (c) 2007-2019, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
6 
12 #ifndef TOR_RENDSERVICE_H
13 #define TOR_RENDSERVICE_H
14 
15 #include "core/or/or.h"
16 #include "feature/hs/hs_service.h"
17 
19 struct config_line_t;
20 
21 /* This can be used for both INTRODUCE1 and INTRODUCE2 */
22 
24  /* Is this an INTRODUCE1 or INTRODUCE2? (set to 1 or 2) */
25  uint8_t type;
26  /* Public key digest */
27  uint8_t pk[DIGEST_LEN];
28  /* Optionally, store ciphertext here */
29  uint8_t *ciphertext;
30  ssize_t ciphertext_len;
31  /* Optionally, store plaintext */
32  uint8_t *plaintext;
33  ssize_t plaintext_len;
34  /* Have we parsed the plaintext? */
35  uint8_t parsed;
36  /* intro protocol version (0, 1, 2 or 3) */
37  uint8_t version;
38  /* Version-specific parts */
39  union {
40  struct {
41  /* Rendezvous point nickname or hex-encoded key digest */
42  uint8_t rp[42];
43  } v0_v1;
44  struct {
45  /* The extend_info_t struct has everything v2 uses */
46  extend_info_t *extend_info;
47  } v2;
48  struct {
49  /* Auth type used */
50  uint8_t auth_type;
51  /* Length of auth data */
52  uint16_t auth_len;
53  /* Auth data */
54  uint8_t *auth_data;
55  /* Rendezvous point's IP address/port, identity digest and onion key */
56  extend_info_t *extend_info;
57  } v3;
58  } u;
59  /* Rendezvous cookie */
60  uint8_t rc[REND_COOKIE_LEN];
61  /* Diffie-Hellman data */
62  uint8_t dh[DH1024_KEY_LEN];
63 };
64 
65 #ifdef RENDSERVICE_PRIVATE
66 
68 typedef struct rend_service_t {
69  /* Fields specified in config file */
70  char *directory;
72  int dir_group_readable;
74  smartlist_t *ports;
75  rend_auth_type_t auth_type;
77  smartlist_t *clients;
80  /* Other fields */
81  crypto_pk_t *private_key;
82  char service_id[REND_SERVICE_ID_LEN_BASE32+1];
84  char pk_digest[DIGEST_LEN];
85  smartlist_t *intro_nodes;
90  smartlist_t *expiring_nodes;
91  time_t intro_period_started;
93  int n_intro_circuits_launched;
95  unsigned int n_intro_points_wanted;
98  time_t desc_is_dirty;
101  time_t next_upload_time;
108  replaycache_t *accepted_intro_dh_parts;
111  int allow_unknown_ports;
115  int max_streams_per_circuit;
118  int max_streams_close_circuit;
119 } rend_service_t;
120 
121 STATIC void rend_service_free_(rend_service_t *service);
122 #define rend_service_free(s) \
123  FREE_AND_NULL(rend_service_t, rend_service_free_, (s))
124 STATIC char *rend_service_sos_poison_path(const rend_service_t *service);
126  const rend_service_t *s,
127  const or_options_t *options);
129  const rend_service_t *s,
130  const or_options_t* options);
131 #ifdef TOR_UNIT_TESTS
132 
133 STATIC void set_rend_service_list(smartlist_t *new_list);
134 STATIC void set_rend_rend_service_staging_list(smartlist_t *new_list);
135 STATIC void rend_service_prune_list_impl_(void);
136 
137 #endif /* defined(TOR_UNIT_TESTS) */
138 
139 #endif /* defined(RENDSERVICE_PRIVATE) */
140 
141 int rend_num_services(void);
142 int rend_config_service(const struct config_line_t *line_,
143  const or_options_t *options,
144  hs_service_config_t *config);
145 void rend_service_prune_list(void);
146 void rend_service_free_staging_list(void);
147 int rend_service_load_all_keys(const smartlist_t *service_list);
148 int rend_service_key_on_disk(const char *directory_path);
150  smartlist_t *stat_lst);
151 void rend_consider_services_intro_points(time_t now);
152 void rend_consider_services_upload(time_t now);
153 void rend_hsdir_routers_changed(void);
155 
158  const uint8_t *request,
159  size_t request_len);
162  const uint8_t *request,
163  size_t request_len);
165  crypto_pk_t *key,
166  char **err_msg_out);
168 #define rend_service_free_intro(req) do { \
169  rend_service_free_intro_(req); \
170  (req) = NULL; \
171  } while (0)
172 rend_intro_cell_t * rend_service_begin_parse_intro(const uint8_t *request,
173  size_t request_len,
174  uint8_t type,
175  char **err_msg_out);
177  char **err_msg_out);
178 ssize_t rend_service_encode_establish_intro_cell(char *cell_body_out,
179  size_t cell_body_out_len,
180  crypto_pk_t *intro_key,
181  const char *rend_circ_nonce);
183  char **err_msg_out);
186  origin_circuit_t *circ);
187 void rend_service_dump_stats(int severity);
188 void rend_service_free_all(void);
189 void rend_service_init(void);
190 
192  const char *sep,
193  char **err_msg_out);
195 #define rend_service_port_config_free(p) \
196  FREE_AND_NULL(rend_service_port_config_t, rend_service_port_config_free_, \
197  (p))
198 
200 #define rend_authorized_client_free(client) \
201  FREE_AND_NULL(rend_authorized_client_t, rend_authorized_client_free_, \
202  (client))
203 
205  smartlist_t *ports,
206  int max_streams_per_circuit,
207  int max_streams_close_circuit,
208  rend_auth_type_t auth_type,
209  smartlist_t *auth_clients,
210  char **service_id_out);
211 int rend_service_del_ephemeral(const char *service_id);
212 
214  smartlist_t *descs, smartlist_t *hs_dirs,
215  const char *service_id, int seconds_valid);
216 void rend_service_desc_has_uploaded(const rend_data_t *rend_data);
217 
218 int rend_service_allow_non_anonymous_connection(const or_options_t *options);
219 int rend_service_reveal_startup_time(const or_options_t *options);
220 int rend_service_non_anonymous_mode_enabled(const or_options_t *options);
221 
222 #endif /* !defined(TOR_RENDSERVICE_H) */
int rend_num_services(void)
Definition: rendservice.c:184
int rend_service_set_connection_addr_port(edge_connection_t *conn, origin_circuit_t *circ)
Definition: rendservice.c:4405
void rend_service_free_intro_(rend_intro_cell_t *request)
Definition: rendservice.c:2307
void rend_consider_services_upload(time_t now)
Definition: rendservice.c:4285
Header file containing service data for the HS subsytem.
STATIC void rend_service_free_(rend_service_t *service)
Definition: rendservice.c:216
int rend_service_validate_intro_late(const rend_intro_cell_t *intro, char **err_msg_out)
Definition: rendservice.c:2981
void rend_service_rendezvous_has_opened(origin_circuit_t *circuit)
Definition: rendservice.c:3461
int rend_service_load_all_keys(const smartlist_t *service_list)
Definition: rendservice.c:1387
void rend_service_free_all(void)
Definition: rendservice.c:267
void rend_service_relaunch_rendezvous(origin_circuit_t *oldcirc)
Definition: rendservice.c:3016
void rend_service_intro_has_opened(origin_circuit_t *circuit)
Definition: rendservice.c:3268
rend_auth_type_t
Definition: or.h:402
int rend_service_del_ephemeral(const char *service_id)
Definition: rendservice.c:972
void rend_service_port_config_free_(rend_service_port_config_t *p)
Definition: rendservice.c:521
int rend_service_parse_intro_plaintext(rend_intro_cell_t *intro, char **err_msg_out)
Definition: rendservice.c:2875
void rend_consider_descriptor_republication(void)
Definition: rendservice.c:4344
void directory_post_to_hs_dir(rend_service_descriptor_t *renddesc, smartlist_t *descs, smartlist_t *hs_dirs, const char *service_id, int seconds_valid)
Definition: rendservice.c:3671
int rend_service_decrypt_intro(rend_intro_cell_t *request, crypto_pk_t *key, char **err_msg_out)
Definition: rendservice.c:2752
void rend_hsdir_routers_changed(void)
Definition: rendservice.c:4335
#define DIGEST_LEN
Definition: digest_sizes.h:20
Master header file for Tor-specific functionality.
void rend_authorized_client_free_(rend_authorized_client_t *client)
Definition: rendservice.c:193
rend_service_port_config_t * rend_service_parse_port_config(const char *string, const char *sep, char **err_msg_out)
Definition: rendservice.c:419
hs_service_add_ephemeral_status_t
Definition: hs_common.h:140
STATIC int rend_service_verify_single_onion_poison(const rend_service_t *s, const or_options_t *options)
Definition: rendservice.c:1211
int rend_service_intro_established(origin_circuit_t *circuit, const uint8_t *request, size_t request_len)
Definition: rendservice.c:3400
void rend_service_dump_stats(int severity)
Definition: rendservice.c:4370
#define DH1024_KEY_LEN
Definition: dh_sizes.h:20
void rend_services_add_filenames_to_lists(smartlist_t *open_lst, smartlist_t *stat_lst)
Definition: rendservice.c:1425
#define REND_SERVICE_ID_LEN_BASE32
Definition: or.h:331
rend_intro_cell_t * rend_service_begin_parse_intro(const uint8_t *request, size_t request_len, uint8_t type, char **err_msg_out)
Definition: rendservice.c:2376
int rend_service_receive_introduction(origin_circuit_t *circuit, const uint8_t *request, size_t request_len)
Definition: rendservice.c:1876
STATIC int rend_service_poison_new_single_onion_dir(const rend_service_t *s, const or_options_t *options)
Definition: rendservice.c:1326
#define REND_COOKIE_LEN
Definition: or.h:399
void rend_consider_services_intro_points(time_t now)
Definition: rendservice.c:4101
hs_service_add_ephemeral_status_t rend_service_add_ephemeral(crypto_pk_t *pk, smartlist_t *ports, int max_streams_per_circuit, int max_streams_close_circuit, rend_auth_type_t auth_type, smartlist_t *auth_clients, char **service_id_out)
Definition: rendservice.c:904
void rend_service_desc_has_uploaded(const rend_data_t *rend_data)
Definition: rendservice.c:4048