rendservice.h 9.7 KB

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