rendservice.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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-2016, 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. typedef struct rend_intro_cell_s rend_intro_cell_t;
  14. typedef struct rend_service_port_config_s rend_service_port_config_t;
  15. #ifdef RENDSERVICE_PRIVATE
  16. /* This can be used for both INTRODUCE1 and INTRODUCE2 */
  17. struct rend_intro_cell_s {
  18. /* Is this an INTRODUCE1 or INTRODUCE2? (set to 1 or 2) */
  19. uint8_t type;
  20. /* Public key digest */
  21. uint8_t pk[DIGEST_LEN];
  22. /* Optionally, store ciphertext here */
  23. uint8_t *ciphertext;
  24. ssize_t ciphertext_len;
  25. /* Optionally, store plaintext */
  26. uint8_t *plaintext;
  27. ssize_t plaintext_len;
  28. /* Have we parsed the plaintext? */
  29. uint8_t parsed;
  30. /* intro protocol version (0, 1, 2 or 3) */
  31. uint8_t version;
  32. /* Version-specific parts */
  33. union {
  34. struct {
  35. /* Rendezvous point nickname or hex-encoded key digest */
  36. uint8_t rp[42];
  37. } v0_v1;
  38. struct {
  39. /* The extend_info_t struct has everything v2 uses */
  40. extend_info_t *extend_info;
  41. } v2;
  42. struct {
  43. /* Auth type used */
  44. uint8_t auth_type;
  45. /* Length of auth data */
  46. uint16_t auth_len;
  47. /* Auth data */
  48. uint8_t *auth_data;
  49. /* Rendezvous point's IP address/port, identity digest and onion key */
  50. extend_info_t *extend_info;
  51. } v3;
  52. } u;
  53. /* Rendezvous cookie */
  54. uint8_t rc[REND_COOKIE_LEN];
  55. /* Diffie-Hellman data */
  56. uint8_t dh[DH_KEY_LEN];
  57. };
  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 simultanious 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. STATIC char *rend_service_sos_poison_path(const rend_service_t *service);
  113. #endif
  114. int num_rend_services(void);
  115. int rend_config_services(const or_options_t *options, int validate_only);
  116. int rend_service_load_all_keys(const smartlist_t *service_list);
  117. void rend_services_add_filenames_to_lists(smartlist_t *open_lst,
  118. smartlist_t *stat_lst);
  119. void rend_consider_services_intro_points(void);
  120. void rend_consider_services_upload(time_t now);
  121. void rend_hsdir_routers_changed(void);
  122. void rend_consider_descriptor_republication(void);
  123. void rend_service_intro_has_opened(origin_circuit_t *circuit);
  124. int rend_service_intro_established(origin_circuit_t *circuit,
  125. const uint8_t *request,
  126. size_t request_len);
  127. void rend_service_rendezvous_has_opened(origin_circuit_t *circuit);
  128. int rend_service_receive_introduction(origin_circuit_t *circuit,
  129. const uint8_t *request,
  130. size_t request_len);
  131. int rend_service_decrypt_intro(rend_intro_cell_t *request,
  132. crypto_pk_t *key,
  133. char **err_msg_out);
  134. void rend_service_free_intro(rend_intro_cell_t *request);
  135. rend_intro_cell_t * rend_service_begin_parse_intro(const uint8_t *request,
  136. size_t request_len,
  137. uint8_t type,
  138. char **err_msg_out);
  139. int rend_service_parse_intro_plaintext(rend_intro_cell_t *intro,
  140. char **err_msg_out);
  141. int rend_service_validate_intro_late(const rend_intro_cell_t *intro,
  142. char **err_msg_out);
  143. void rend_service_relaunch_rendezvous(origin_circuit_t *oldcirc);
  144. int rend_service_set_connection_addr_port(edge_connection_t *conn,
  145. origin_circuit_t *circ);
  146. void rend_service_dump_stats(int severity);
  147. void rend_service_free_all(void);
  148. rend_service_port_config_t *rend_service_parse_port_config(const char *string,
  149. const char *sep,
  150. char **err_msg_out);
  151. void rend_service_port_config_free(rend_service_port_config_t *p);
  152. void rend_authorized_client_free(rend_authorized_client_t *client);
  153. int rend_service_list_verify_single_onion_poison(
  154. const smartlist_t *service_list,
  155. const or_options_t *options);
  156. int rend_service_poison_new_single_onion_dirs(const smartlist_t *service_list);
  157. /** Return value from rend_service_add_ephemeral. */
  158. typedef enum {
  159. RSAE_BADAUTH = -5, /**< Invalid auth_type/auth_clients */
  160. RSAE_BADVIRTPORT = -4, /**< Invalid VIRTPORT/TARGET(s) */
  161. RSAE_ADDREXISTS = -3, /**< Onion address collision */
  162. RSAE_BADPRIVKEY = -2, /**< Invalid public key */
  163. RSAE_INTERNAL = -1, /**< Internal error */
  164. RSAE_OKAY = 0 /**< Service added as expected */
  165. } rend_service_add_ephemeral_status_t;
  166. rend_service_add_ephemeral_status_t rend_service_add_ephemeral(crypto_pk_t *pk,
  167. smartlist_t *ports,
  168. int max_streams_per_circuit,
  169. int max_streams_close_circuit,
  170. rend_auth_type_t auth_type,
  171. smartlist_t *auth_clients,
  172. char **service_id_out);
  173. int rend_service_del_ephemeral(const char *service_id);
  174. void directory_post_to_hs_dir(rend_service_descriptor_t *renddesc,
  175. smartlist_t *descs, smartlist_t *hs_dirs,
  176. const char *service_id, int seconds_valid);
  177. void rend_service_desc_has_uploaded(const rend_data_t *rend_data);
  178. int rend_service_allow_non_anonymous_connection(const or_options_t *options);
  179. int rend_service_reveal_startup_time(const or_options_t *options);
  180. int rend_service_non_anonymous_mode_enabled(const or_options_t *options);
  181. #endif