hs_client.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* Copyright (c) 2017-2019, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. /**
  4. * \file hs_client.h
  5. * \brief Header file containing client data for the HS subsytem.
  6. **/
  7. #ifndef TOR_HS_CLIENT_H
  8. #define TOR_HS_CLIENT_H
  9. #include "lib/crypt_ops/crypto_ed25519.h"
  10. #include "feature/hs/hs_descriptor.h"
  11. #include "feature/hs/hs_ident.h"
  12. #include "feature/dirclient/dirclient.h"
  13. /* Status code of a descriptor fetch request. */
  14. typedef enum {
  15. /* Something internally went wrong. */
  16. HS_CLIENT_FETCH_ERROR = -1,
  17. /* The fetch request has been launched successfully. */
  18. HS_CLIENT_FETCH_LAUNCHED = 0,
  19. /* We already have a usable descriptor. No fetch. */
  20. HS_CLIENT_FETCH_HAVE_DESC = 1,
  21. /* No more HSDir available to query. */
  22. HS_CLIENT_FETCH_NO_HSDIRS = 2,
  23. /* The fetch request is not allowed. */
  24. HS_CLIENT_FETCH_NOT_ALLOWED = 3,
  25. /* We are missing information to be able to launch a request. */
  26. HS_CLIENT_FETCH_MISSING_INFO = 4,
  27. /* There is a pending fetch for the requested service. */
  28. HS_CLIENT_FETCH_PENDING = 5,
  29. } hs_client_fetch_status_t;
  30. /** Client-side configuration of authorization for a service. */
  31. typedef struct hs_client_service_authorization_t {
  32. /* An curve25519 secret key used to compute decryption keys that
  33. * allow the client to decrypt the hidden service descriptor. */
  34. curve25519_secret_key_t enc_seckey;
  35. /* An onion address that is used to connect to the onion service. */
  36. char onion_address[HS_SERVICE_ADDR_LEN_BASE32+1];
  37. } hs_client_service_authorization_t;
  38. void hs_client_note_connection_attempt_succeeded(
  39. const edge_connection_t *conn);
  40. int hs_client_decode_descriptor(
  41. const char *desc_str,
  42. const ed25519_public_key_t *service_identity_pk,
  43. hs_descriptor_t **desc);
  44. int hs_client_any_intro_points_usable(const ed25519_public_key_t *service_pk,
  45. const hs_descriptor_t *desc);
  46. int hs_client_refetch_hsdesc(const ed25519_public_key_t *identity_pk);
  47. void hs_client_dir_info_changed(void);
  48. int hs_client_send_introduce1(origin_circuit_t *intro_circ,
  49. origin_circuit_t *rend_circ);
  50. void hs_client_circuit_has_opened(origin_circuit_t *circ);
  51. int hs_client_receive_rendezvous_acked(origin_circuit_t *circ,
  52. const uint8_t *payload,
  53. size_t payload_len);
  54. int hs_client_receive_introduce_ack(origin_circuit_t *circ,
  55. const uint8_t *payload,
  56. size_t payload_len);
  57. int hs_client_receive_rendezvous2(origin_circuit_t *circ,
  58. const uint8_t *payload,
  59. size_t payload_len);
  60. void hs_client_desc_has_arrived(const hs_ident_dir_conn_t *ident);
  61. extend_info_t *hs_client_get_random_intro_from_edge(
  62. const edge_connection_t *edge_conn);
  63. int hs_config_client_authorization(const or_options_t *options,
  64. int validate_only);
  65. int hs_client_reextend_intro_circuit(origin_circuit_t *circ);
  66. void hs_client_close_intro_circuits_from_desc(const hs_descriptor_t *desc);
  67. void hs_client_purge_state(void);
  68. void hs_client_free_all(void);
  69. typedef struct {
  70. time_t timestamp;
  71. size_t size;
  72. char *params;
  73. } HSClientPIRParams;
  74. void hs_client_pir_init(void);
  75. void hs_client_pirparams_insert(const char *digest, size_t size,
  76. const char *params);
  77. HSClientPIRParams* hs_client_pirparams_lookup(const char *digest);
  78. void hs_client_pir_create(dir_connection_t *conn);
  79. void hs_client_pir_extract(connection_dir_client_conninfo_t conninfo,
  80. const char queryid[8], const char *body, size_t body_len);
  81. #ifdef HS_CLIENT_PRIVATE
  82. STATIC int auth_key_filename_is_valid(const char *filename);
  83. STATIC hs_client_service_authorization_t *
  84. parse_auth_file_content(const char *client_key_str);
  85. STATIC routerstatus_t *
  86. pick_hsdir_v3(const ed25519_public_key_t *onion_identity_pk);
  87. STATIC extend_info_t *
  88. client_get_random_intro(const ed25519_public_key_t *service_pk);
  89. STATIC extend_info_t *
  90. desc_intro_point_to_extend_info(const hs_desc_intro_point_t *ip);
  91. STATIC int handle_rendezvous2(origin_circuit_t *circ, const uint8_t *payload,
  92. size_t payload_len);
  93. MOCK_DECL(STATIC hs_client_fetch_status_t,
  94. fetch_v3_desc, (const ed25519_public_key_t *onion_identity_pk));
  95. STATIC void retry_all_socks_conn_waiting_for_desc(void);
  96. #ifdef TOR_UNIT_TESTS
  97. STATIC digest256map_t *get_hs_client_auths_map(void);
  98. #endif /* defined(TOR_UNIT_TESTS) */
  99. #endif /* defined(HS_CLIENT_PRIVATE) */
  100. #endif /* !defined(TOR_HS_CLIENT_H) */