hs_ident.h 4.8 KB

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