tor  master
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-2017, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
6 
12 #ifndef TOR_RENDSERVICE_H
13 #define TOR_RENDSERVICE_H
14 
15 #include "or.h"
16 #include "hs_service.h"
17 
19 
20 /* This can be used for both INTRODUCE1 and INTRODUCE2 */
21 
23  /* Is this an INTRODUCE1 or INTRODUCE2? (set to 1 or 2) */
24  uint8_t type;
25  /* Public key digest */
26  uint8_t pk[DIGEST_LEN];
27  /* Optionally, store ciphertext here */
28  uint8_t *ciphertext;
29  ssize_t ciphertext_len;
30  /* Optionally, store plaintext */
31  uint8_t *plaintext;
32  ssize_t plaintext_len;
33  /* Have we parsed the plaintext? */
34  uint8_t parsed;
35  /* intro protocol version (0, 1, 2 or 3) */
36  uint8_t version;
37  /* Version-specific parts */
38  union {
39  struct {
40  /* Rendezvous point nickname or hex-encoded key digest */
41  uint8_t rp[42];
42  } v0_v1;
43  struct {
44  /* The extend_info_t struct has everything v2 uses */
45  extend_info_t *extend_info;
46  } v2;
47  struct {
48  /* Auth type used */
49  uint8_t auth_type;
50  /* Length of auth data */
51  uint16_t auth_len;
52  /* Auth data */
53  uint8_t *auth_data;
54  /* Rendezvous point's IP address/port, identity digest and onion key */
55  extend_info_t *extend_info;
56  } v3;
57  } u;
58  /* Rendezvous cookie */
59  uint8_t rc[REND_COOKIE_LEN];
60  /* Diffie-Hellman data */
61  uint8_t dh[DH_KEY_LEN];
62 };
63 
64 #ifdef RENDSERVICE_PRIVATE
65 
67 typedef struct rend_service_t {
68  /* Fields specified in config file */
69  char *directory;
71  int dir_group_readable;
73  smartlist_t *ports;
74  rend_auth_type_t auth_type;
76  smartlist_t *clients;
79  /* Other fields */
80  crypto_pk_t *private_key;
81  char service_id[REND_SERVICE_ID_LEN_BASE32+1];
83  char pk_digest[DIGEST_LEN];
84  smartlist_t *intro_nodes;
89  smartlist_t *expiring_nodes;
90  time_t intro_period_started;
92  int n_intro_circuits_launched;
94  unsigned int n_intro_points_wanted;
97  time_t desc_is_dirty;
100  time_t next_upload_time;
107  replaycache_t *accepted_intro_dh_parts;
110  int allow_unknown_ports;
114  int max_streams_per_circuit;
117  int max_streams_close_circuit;
118 } rend_service_t;
119 
120 STATIC void rend_service_free_(rend_service_t *service);
121 #define rend_service_free(s) \
122  FREE_AND_NULL(rend_service_t, rend_service_free_, (s))
123 STATIC char *rend_service_sos_poison_path(const rend_service_t *service);
125  const rend_service_t *s,
126  const or_options_t *options);
128  const rend_service_t *s,
129  const or_options_t* options);
130 #ifdef TOR_UNIT_TESTS
131 
132 STATIC void set_rend_service_list(smartlist_t *new_list);
133 STATIC void set_rend_rend_service_staging_list(smartlist_t *new_list);
134 STATIC void rend_service_prune_list_impl_(void);
135 
136 #endif /* defined(TOR_UNIT_TESTS) */
137 
138 #endif /* defined(RENDSERVICE_PRIVATE) */
139 
140 int rend_num_services(void);
141 int rend_config_service(const config_line_t *line_,
142  const or_options_t *options,
143  hs_service_config_t *config);
144 void rend_service_prune_list(void);
145 void rend_service_free_staging_list(void);
146 int rend_service_load_all_keys(const smartlist_t *service_list);
148  smartlist_t *stat_lst);
149 void rend_consider_services_intro_points(time_t now);
150 void rend_consider_services_upload(time_t now);
151 void rend_hsdir_routers_changed(void);
153 
156  const uint8_t *request,
157  size_t request_len);
160  const uint8_t *request,
161  size_t request_len);
163  crypto_pk_t *key,
164  char **err_msg_out);
166 #define rend_service_free_intro(req) do { \
167  rend_service_free_intro_(req); \
168  (req) = NULL; \
169  } while (0)
170 rend_intro_cell_t * rend_service_begin_parse_intro(const uint8_t *request,
171  size_t request_len,
172  uint8_t type,
173  char **err_msg_out);
175  char **err_msg_out);
176 ssize_t rend_service_encode_establish_intro_cell(char *cell_body_out,
177  size_t cell_body_out_len,
178  crypto_pk_t *intro_key,
179  const char *rend_circ_nonce);
181  char **err_msg_out);
184  origin_circuit_t *circ);
185 void rend_service_dump_stats(int severity);
186 void rend_service_free_all(void);
187 void rend_service_init(void);
188 
190  const char *sep,
191  char **err_msg_out);
193 #define rend_service_port_config_free(p) \
194  FREE_AND_NULL(rend_service_port_config_t, rend_service_port_config_free_, \
195  (p))
196 
198 #define rend_authorized_client_free(client) \
199  FREE_AND_NULL(rend_authorized_client_t, rend_authorized_client_free_, \
200  (client))
201 
203  smartlist_t *ports,
204  int max_streams_per_circuit,
205  int max_streams_close_circuit,
206  rend_auth_type_t auth_type,
207  smartlist_t *auth_clients,
208  char **service_id_out);
209 int rend_service_del_ephemeral(const char *service_id);
210 
212  smartlist_t *descs, smartlist_t *hs_dirs,
213  const char *service_id, int seconds_valid);
214 void rend_service_desc_has_uploaded(const rend_data_t *rend_data);
215 
216 int rend_service_allow_non_anonymous_connection(const or_options_t *options);
217 int rend_service_reveal_startup_time(const or_options_t *options);
218 int rend_service_non_anonymous_mode_enabled(const or_options_t *options);
219 
220 #endif /* !defined(TOR_RENDSERVICE_H) */
221 
Definition: or.h:842
int rend_num_services(void)
Definition: rendservice.c:153
Definition: rendservice.h:22
Definition: confline.h:23
Definition: or.h:3657
int rend_service_set_connection_addr_port(edge_connection_t *conn, origin_circuit_t *circ)
Definition: rendservice.c:4309
void rend_service_free_intro_(rend_intro_cell_t *request)
Definition: rendservice.c:2241
void rend_consider_services_upload(time_t now)
Definition: rendservice.c:4189
#define DIGEST_LEN
Definition: crypto_digest.h:22
Header file containing service data for the HS subsytem.
STATIC void rend_service_free_(rend_service_t *service)
Definition: rendservice.c:185
int rend_service_validate_intro_late(const rend_intro_cell_t *intro, char **err_msg_out)
Definition: rendservice.c:2915
void rend_service_rendezvous_has_opened(origin_circuit_t *circuit)
Definition: rendservice.c:3366
int rend_service_load_all_keys(const smartlist_t *service_list)
Definition: rendservice.c:1325
void rend_service_free_all(void)
Definition: rendservice.c:236
void rend_service_relaunch_rendezvous(origin_circuit_t *oldcirc)
Definition: rendservice.c:2950
Definition: container.h:18
void rend_service_intro_has_opened(origin_circuit_t *circuit)
Definition: rendservice.c:3173
rend_auth_type_t
Definition: or.h:826
int rend_service_del_ephemeral(const char *service_id)
Definition: rendservice.c:933
void rend_service_port_config_free_(rend_service_port_config_t *p)
Definition: rendservice.c:482
int rend_service_parse_intro_plaintext(rend_intro_cell_t *intro, char **err_msg_out)
Definition: rendservice.c:2809
void rend_consider_descriptor_republication(void)
Definition: rendservice.c:4248
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:3576
int rend_service_decrypt_intro(rend_intro_cell_t *request, crypto_pk_t *key, char **err_msg_out)
Definition: rendservice.c:2686
Definition: hs_common.h:146
void rend_hsdir_routers_changed(void)
Definition: rendservice.c:4239
Definition: or.h:5359
Master header file for Tor-specific functionality.
void rend_authorized_client_free_(rend_authorized_client_t *client)
Definition: rendservice.c:162
rend_service_port_config_t * rend_service_parse_port_config(const char *string, const char *sep, char **err_msg_out)
Definition: rendservice.c:388
hs_service_add_ephemeral_status_t
Definition: hs_common.h:135
STATIC int rend_service_verify_single_onion_poison(const rend_service_t *s, const or_options_t *options)
Definition: rendservice.c:1172
int rend_service_intro_established(origin_circuit_t *circuit, const uint8_t *request, size_t request_len)
Definition: rendservice.c:3305
void rend_service_dump_stats(int severity)
Definition: rendservice.c:4274
void rend_services_add_filenames_to_lists(smartlist_t *open_lst, smartlist_t *stat_lst)
Definition: rendservice.c:1363
#define REND_SERVICE_ID_LEN_BASE32
Definition: or.h:755
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:2310
int rend_service_receive_introduction(origin_circuit_t *circuit, const uint8_t *request, size_t request_len)
Definition: rendservice.c:1814
Definition: crypto_rsa.c:41
STATIC int rend_service_poison_new_single_onion_dir(const rend_service_t *s, const or_options_t *options)
Definition: rendservice.c:1287
#define REND_COOKIE_LEN
Definition: or.h:823
void rend_consider_services_intro_points(time_t now)
Definition: rendservice.c:4006
Definition: or.h:5249
Definition: or.h:2838
Definition: hs_service.h:150
Definition: or.h:1687
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:865
Definition: or.h:3256
void rend_service_desc_has_uploaded(const rend_data_t *rend_data)
Definition: rendservice.c:3953