rendservice.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. /**
  7. * \file rendservice.h
  8. * \brief Header file for rendservice.c.
  9. **/
  10. #ifndef TOR_RENDSERVICE_H
  11. #define TOR_RENDSERVICE_H
  12. #include "or.h"
  13. #include "hs_service.h"
  14. typedef struct rend_intro_cell_s rend_intro_cell_t;
  15. /* This can be used for both INTRODUCE1 and INTRODUCE2 */
  16. struct rend_intro_cell_s {
  17. /* Is this an INTRODUCE1 or INTRODUCE2? (set to 1 or 2) */
  18. uint8_t type;
  19. /* Public key digest */
  20. uint8_t pk[DIGEST_LEN];
  21. /* Optionally, store ciphertext here */
  22. uint8_t *ciphertext;
  23. ssize_t ciphertext_len;
  24. /* Optionally, store plaintext */
  25. uint8_t *plaintext;
  26. ssize_t plaintext_len;
  27. /* Have we parsed the plaintext? */
  28. uint8_t parsed;
  29. /* intro protocol version (0, 1, 2 or 3) */
  30. uint8_t version;
  31. /* Version-specific parts */
  32. union {
  33. struct {
  34. /* Rendezvous point nickname or hex-encoded key digest */
  35. uint8_t rp[42];
  36. } v0_v1;
  37. struct {
  38. /* The extend_info_t struct has everything v2 uses */
  39. extend_info_t *extend_info;
  40. } v2;
  41. struct {
  42. /* Auth type used */
  43. uint8_t auth_type;
  44. /* Length of auth data */
  45. uint16_t auth_len;
  46. /* Auth data */
  47. uint8_t *auth_data;
  48. /* Rendezvous point's IP address/port, identity digest and onion key */
  49. extend_info_t *extend_info;
  50. } v3;
  51. } u;
  52. /* Rendezvous cookie */
  53. uint8_t rc[REND_COOKIE_LEN];
  54. /* Diffie-Hellman data */
  55. uint8_t dh[DH_KEY_LEN];
  56. };
  57. #ifdef RENDSERVICE_PRIVATE
  58. /** Represents a single hidden service running at this OP. */
  59. typedef struct rend_service_t {
  60. /* Fields specified in config file */
  61. char *directory; /**< where in the filesystem it stores it. Will be NULL if
  62. * this service is ephemeral. */
  63. int dir_group_readable; /**< if 1, allow group read
  64. permissions on directory */
  65. smartlist_t *ports; /**< List of rend_service_port_config_t */
  66. rend_auth_type_t auth_type; /**< Client authorization type or 0 if no client
  67. * authorization is performed. */
  68. smartlist_t *clients; /**< List of rend_authorized_client_t's of
  69. * clients that may access our service. Can be NULL
  70. * if no client authorization is performed. */
  71. /* Other fields */
  72. crypto_pk_t *private_key; /**< Permanent hidden-service key. */
  73. char service_id[REND_SERVICE_ID_LEN_BASE32+1]; /**< Onion address without
  74. * '.onion' */
  75. char pk_digest[DIGEST_LEN]; /**< Hash of permanent hidden-service key. */
  76. smartlist_t *intro_nodes; /**< List of rend_intro_point_t's we have,
  77. * or are trying to establish. */
  78. /** List of rend_intro_point_t that are expiring. They are removed once
  79. * the new descriptor is successfully uploaded. A node in this list CAN
  80. * NOT appear in the intro_nodes list. */
  81. smartlist_t *expiring_nodes;
  82. time_t intro_period_started; /**< Start of the current period to build
  83. * introduction points. */
  84. int n_intro_circuits_launched; /**< Count of intro circuits we have
  85. * established in this period. */
  86. unsigned int n_intro_points_wanted; /**< Number of intro points this
  87. * service wants to have open. */
  88. rend_service_descriptor_t *desc; /**< Current hidden service descriptor. */
  89. time_t desc_is_dirty; /**< Time at which changes to the hidden service
  90. * descriptor content occurred, or 0 if it's
  91. * up-to-date. */
  92. time_t next_upload_time; /**< Scheduled next hidden service descriptor
  93. * upload time. */
  94. /** Replay cache for Diffie-Hellman values of INTRODUCE2 cells, to
  95. * detect repeats. Clients may send INTRODUCE1 cells for the same
  96. * rendezvous point through two or more different introduction points;
  97. * when they do, this keeps us from launching multiple simultaneous attempts
  98. * to connect to the same rend point. */
  99. replaycache_t *accepted_intro_dh_parts;
  100. /** If true, we don't close circuits for making requests to unsupported
  101. * ports. */
  102. int allow_unknown_ports;
  103. /** The maximum number of simultaneous streams-per-circuit that are allowed
  104. * to be established, or 0 if no limit is set.
  105. */
  106. int max_streams_per_circuit;
  107. /** If true, we close circuits that exceed the max_streams_per_circuit
  108. * limit. */
  109. int max_streams_close_circuit;
  110. } rend_service_t;
  111. STATIC void rend_service_free_(rend_service_t *service);
  112. #define rend_service_free(s) \
  113. FREE_AND_NULL(rend_service_t, rend_service_free_, (s))
  114. STATIC char *rend_service_sos_poison_path(const rend_service_t *service);
  115. STATIC int rend_service_verify_single_onion_poison(
  116. const rend_service_t *s,
  117. const or_options_t *options);
  118. STATIC int rend_service_poison_new_single_onion_dir(
  119. const rend_service_t *s,
  120. const or_options_t* options);
  121. #ifdef TOR_UNIT_TESTS
  122. STATIC void set_rend_service_list(smartlist_t *new_list);
  123. STATIC void set_rend_rend_service_staging_list(smartlist_t *new_list);
  124. STATIC void rend_service_prune_list_impl_(void);
  125. #endif /* defined(TOR_UNIT_TESTS) */
  126. #endif /* defined(RENDSERVICE_PRIVATE) */
  127. int rend_num_services(void);
  128. int rend_config_service(const config_line_t *line_,
  129. const or_options_t *options,
  130. hs_service_config_t *config);
  131. void rend_service_prune_list(void);
  132. void rend_service_free_staging_list(void);
  133. int rend_service_load_all_keys(const smartlist_t *service_list);
  134. void rend_services_add_filenames_to_lists(smartlist_t *open_lst,
  135. smartlist_t *stat_lst);
  136. void rend_consider_services_intro_points(time_t now);
  137. void rend_consider_services_upload(time_t now);
  138. void rend_hsdir_routers_changed(void);
  139. void rend_consider_descriptor_republication(void);
  140. void rend_service_intro_has_opened(origin_circuit_t *circuit);
  141. int rend_service_intro_established(origin_circuit_t *circuit,
  142. const uint8_t *request,
  143. size_t request_len);
  144. void rend_service_rendezvous_has_opened(origin_circuit_t *circuit);
  145. int rend_service_receive_introduction(origin_circuit_t *circuit,
  146. const uint8_t *request,
  147. size_t request_len);
  148. int rend_service_decrypt_intro(rend_intro_cell_t *request,
  149. crypto_pk_t *key,
  150. char **err_msg_out);
  151. void rend_service_free_intro_(rend_intro_cell_t *request);
  152. #define rend_service_free_intro(req) do { \
  153. rend_service_free_intro_(req); \
  154. (req) = NULL; \
  155. } while (0)
  156. rend_intro_cell_t * rend_service_begin_parse_intro(const uint8_t *request,
  157. size_t request_len,
  158. uint8_t type,
  159. char **err_msg_out);
  160. int rend_service_parse_intro_plaintext(rend_intro_cell_t *intro,
  161. char **err_msg_out);
  162. ssize_t rend_service_encode_establish_intro_cell(char *cell_body_out,
  163. size_t cell_body_out_len,
  164. crypto_pk_t *intro_key,
  165. const char *rend_circ_nonce);
  166. int rend_service_validate_intro_late(const rend_intro_cell_t *intro,
  167. char **err_msg_out);
  168. void rend_service_relaunch_rendezvous(origin_circuit_t *oldcirc);
  169. int rend_service_set_connection_addr_port(edge_connection_t *conn,
  170. origin_circuit_t *circ);
  171. void rend_service_dump_stats(int severity);
  172. void rend_service_free_all(void);
  173. void rend_service_init(void);
  174. rend_service_port_config_t *rend_service_parse_port_config(const char *string,
  175. const char *sep,
  176. char **err_msg_out);
  177. void rend_service_port_config_free_(rend_service_port_config_t *p);
  178. #define rend_service_port_config_free(p) \
  179. FREE_AND_NULL(rend_service_port_config_t, rend_service_port_config_free_, \
  180. (p))
  181. void rend_authorized_client_free_(rend_authorized_client_t *client);
  182. #define rend_authorized_client_free(client) \
  183. FREE_AND_NULL(rend_authorized_client_t, rend_authorized_client_free_, \
  184. (client))
  185. hs_service_add_ephemeral_status_t rend_service_add_ephemeral(crypto_pk_t *pk,
  186. smartlist_t *ports,
  187. int max_streams_per_circuit,
  188. int max_streams_close_circuit,
  189. rend_auth_type_t auth_type,
  190. smartlist_t *auth_clients,
  191. char **service_id_out);
  192. int rend_service_del_ephemeral(const char *service_id);
  193. void directory_post_to_hs_dir(rend_service_descriptor_t *renddesc,
  194. smartlist_t *descs, smartlist_t *hs_dirs,
  195. const char *service_id, int seconds_valid);
  196. void rend_service_desc_has_uploaded(const rend_data_t *rend_data);
  197. int rend_service_allow_non_anonymous_connection(const or_options_t *options);
  198. int rend_service_reveal_startup_time(const or_options_t *options);
  199. int rend_service_non_anonymous_mode_enabled(const or_options_t *options);
  200. #endif /* !defined(TOR_RENDSERVICE_H) */