hs_ident.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /* Copyright (c) 2017, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. /**
  4. * \file hs_ident.h
  5. * \brief Header file containing circuit and connection identifier data for
  6. * the whole HS subsytem.
  7. *
  8. * \details
  9. * This interface is used to uniquely identify a hidden service on a circuit
  10. * or connection using the service identity public key. Once the circuit or
  11. * connection subsystem calls in the hidden service one, we use those
  12. * identifiers to lookup the corresponding objects like service, intro point
  13. * and descriptor.
  14. *
  15. * Furthermore, the circuit identifier holds cryptographic material needed for
  16. * the e2e encryption on the rendezvous circuit which is set once the
  17. * rendezvous circuit has opened and ready to be used.
  18. **/
  19. #ifndef TOR_HS_IDENT_H
  20. #define TOR_HS_IDENT_H
  21. #include "crypto.h"
  22. #include "crypto_ed25519.h"
  23. #include "hs_common.h"
  24. /* Length of the rendezvous cookie that is used to connect circuits at the
  25. * rendezvous point. */
  26. #define HS_REND_COOKIE_LEN DIGEST_LEN
  27. /* Type of circuit an hs_ident_t object is associated with. */
  28. typedef enum {
  29. HS_IDENT_CIRCUIT_INTRO = 1,
  30. HS_IDENT_CIRCUIT_RENDEZVOUS = 2,
  31. } hs_ident_circuit_type_t;
  32. /* Client and service side circuit identifier that is used for hidden service
  33. * circuit establishment. Not all fields contain data, it depends on the
  34. * circuit purpose. This is attached to an origin_circuit_t. All fields are
  35. * used by both client and service. */
  36. typedef struct hs_ident_circuit_t {
  37. /* (All circuit) The public key used to uniquely identify the service. It is
  38. * the one found in the onion address. */
  39. ed25519_public_key_t identity_pk;
  40. /* (All circuit) The type of circuit this identifier is attached to.
  41. * Accessors of the fields in this object assert non fatal on this circuit
  42. * type. In other words, if a rendezvous field is being accessed, the
  43. * circuit type MUST BE of type HS_IDENT_CIRCUIT_RENDEZVOUS. This value is
  44. * set when an object is initialized in its constructor. */
  45. hs_ident_circuit_type_t circuit_type;
  46. /* (All circuit) Introduction point authentication key. It's also needed on
  47. * the rendezvous circuit for the ntor handshake. It's used as the unique key
  48. * of the introduction point so it should not be shared between multiple
  49. * intro points. */
  50. ed25519_public_key_t intro_auth_pk;
  51. /* (Only client rendezvous circuit) Introduction point encryption public
  52. * key. We keep it in the rendezvous identifier for the ntor handshake. */
  53. curve25519_public_key_t intro_enc_pk;
  54. /* (Only rendezvous circuit) Rendezvous cookie sent from the client to the
  55. * service with an INTRODUCE1 cell and used by the service in an
  56. * RENDEZVOUS1 cell. */
  57. uint8_t rendezvous_cookie[HS_REND_COOKIE_LEN];
  58. /* (Only service rendezvous circuit) The HANDSHAKE_INFO needed in the
  59. * RENDEZVOUS1 cell of the service. The construction is as follows:
  60. * SERVER_PK [32 bytes]
  61. * AUTH_MAC [32 bytes]
  62. */
  63. uint8_t rendezvous_handshake_info[CURVE25519_PUBKEY_LEN + DIGEST256_LEN];
  64. /* (Only client rendezvous circuit) Client ephemeral keypair needed for the
  65. * e2e encryption with the service. */
  66. curve25519_keypair_t rendezvous_client_kp;
  67. /* (Only rendezvous circuit) The NTOR_KEY_SEED needed for key derivation for
  68. * the e2e encryption with the client on the circuit. */
  69. uint8_t rendezvous_ntor_key_seed[DIGEST256_LEN];
  70. /* (Only rendezvous circuit) Number of streams associated with this
  71. * rendezvous circuit. We track this because there is a check on a maximum
  72. * value. */
  73. uint64_t num_rdv_streams;
  74. } hs_ident_circuit_t;
  75. /* Client and service side directory connection identifier used for a
  76. * directory connection to identify which service is being queried. This is
  77. * attached to a dir_connection_t. */
  78. typedef struct hs_ident_dir_conn_t {
  79. /* The public key used to uniquely identify the service. It is the one found
  80. * in the onion address. */
  81. ed25519_public_key_t identity_pk;
  82. /* The blinded public key used to uniquely identify the descriptor that this
  83. * directory connection identifier is for. Only used by the service-side code
  84. * to fine control descriptor uploads. */
  85. ed25519_public_key_t blinded_pk;
  86. /* XXX: Client authorization. */
  87. } hs_ident_dir_conn_t;
  88. /* Client and service side edge connection identifier used for an edge
  89. * connection to identify which service is being queried. This is attached to
  90. * a edge_connection_t. */
  91. typedef struct hs_ident_edge_conn_t {
  92. /* The public key used to uniquely identify the service. It is the one found
  93. * in the onion address. */
  94. ed25519_public_key_t identity_pk;
  95. /* XXX: Client authorization. */
  96. } hs_ident_edge_conn_t;
  97. /* Circuit identifier API. */
  98. hs_ident_circuit_t *hs_ident_circuit_new(
  99. const ed25519_public_key_t *identity_pk,
  100. hs_ident_circuit_type_t circuit_type);
  101. void hs_ident_circuit_free_(hs_ident_circuit_t *ident);
  102. #define hs_ident_circuit_free(id) \
  103. FREE_AND_NULL(hs_ident_circuit_t, hs_ident_circuit_free_, (id))
  104. hs_ident_circuit_t *hs_ident_circuit_dup(const hs_ident_circuit_t *src);
  105. /* Directory connection identifier API. */
  106. hs_ident_dir_conn_t *hs_ident_dir_conn_dup(const hs_ident_dir_conn_t *src);
  107. void hs_ident_dir_conn_free_(hs_ident_dir_conn_t *ident);
  108. #define hs_ident_dir_conn_free(id) \
  109. FREE_AND_NULL(hs_ident_dir_conn_t, hs_ident_dir_conn_free_, (id))
  110. void hs_ident_dir_conn_init(const ed25519_public_key_t *identity_pk,
  111. const ed25519_public_key_t *blinded_pk,
  112. hs_ident_dir_conn_t *ident);
  113. /* Edge connection identifier API. */
  114. hs_ident_edge_conn_t *hs_ident_edge_conn_new(
  115. const ed25519_public_key_t *identity_pk);
  116. void hs_ident_edge_conn_free_(hs_ident_edge_conn_t *ident);
  117. #define hs_ident_edge_conn_free(id) \
  118. FREE_AND_NULL(hs_ident_edge_conn_t, hs_ident_edge_conn_free_, (id))
  119. /* Validators */
  120. int hs_ident_intro_circ_is_valid(const hs_ident_circuit_t *ident);
  121. #endif /* !defined(TOR_HS_IDENT_H) */