hs_ident.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. */
  48. ed25519_public_key_t intro_auth_pk;
  49. /* (Only client rendezvous circuit) Introduction point encryption public
  50. * key. We keep it in the rendezvous identifier for the ntor handshake. */
  51. curve25519_public_key_t intro_enc_pk;
  52. /* (Only rendezvous circuit) Rendezvous cookie sent from the client to the
  53. * service with an INTRODUCE1 cell and used by the service in an
  54. * RENDEZVOUS1 cell. */
  55. uint8_t rendezvous_cookie[HS_REND_COOKIE_LEN];
  56. /* (Only service rendezvous circuit) The HANDSHAKE_INFO needed in the
  57. * RENDEZVOUS1 cell of the service. The construction is as follows:
  58. * SERVER_PK [32 bytes]
  59. * AUTH_MAC [32 bytes]
  60. */
  61. uint8_t rendezvous_handshake_info[CURVE25519_PUBKEY_LEN + DIGEST256_LEN];
  62. /* (Only client rendezvous circuit) Client ephemeral keypair needed for the
  63. * e2e encryption with the service. */
  64. curve25519_keypair_t rendezvous_client_kp;
  65. /* (Only rendezvous circuit) The NTOR_KEY_SEED needed for key derivation for
  66. * the e2e encryption with the client on the circuit. */
  67. uint8_t rendezvous_ntor_key_seed[DIGEST256_LEN];
  68. /* (Only rendezvous circuit) Number of streams associated with this
  69. * rendezvous circuit. We track this because there is a check on a maximum
  70. * value. */
  71. uint64_t num_rdv_streams;
  72. } hs_ident_circuit_t;
  73. /* Client and service side directory connection identifier used for a
  74. * directory connection to identify which service is being queried. This is
  75. * attached to a dir_connection_t. */
  76. typedef struct hs_ident_dir_conn_t {
  77. /* The public key used to uniquely identify the service. It is the one found
  78. * in the onion address. */
  79. ed25519_public_key_t identity_pk;
  80. /* XXX: Client authorization. */
  81. } hs_ident_dir_conn_t;
  82. /* Client and service side edge connection identifier used for an edge
  83. * connection to identify which service is being queried. This is attached to
  84. * a edge_connection_t. */
  85. typedef struct hs_ident_edge_conn_t {
  86. /* The public key used to uniquely identify the service. It is the one found
  87. * in the onion address. */
  88. ed25519_public_key_t identity_pk;
  89. /* XXX: Client authorization. */
  90. } hs_ident_edge_conn_t;
  91. /* Circuit identifier API. */
  92. hs_ident_circuit_t *hs_ident_circuit_new(
  93. const ed25519_public_key_t *identity_pk,
  94. hs_ident_circuit_type_t circuit_type);
  95. void hs_ident_circuit_free(hs_ident_circuit_t *ident);
  96. /* Directory connection identifier API. */
  97. hs_ident_dir_conn_t *hs_ident_dir_conn_dup(const hs_ident_dir_conn_t *src);
  98. void hs_ident_dir_conn_free(hs_ident_dir_conn_t *ident);
  99. /* Edge connection identifier API. */
  100. hs_ident_edge_conn_t *hs_ident_edge_conn_new(
  101. const ed25519_public_key_t *identity_pk);
  102. void hs_ident_edge_conn_free(hs_ident_edge_conn_t *ident);
  103. #endif /* TOR_HS_IDENT_H */