hs_cell.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* Copyright (c) 2017-2019, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. /**
  4. * \file hs_cell.h
  5. * \brief Header file containing cell data for the whole HS subsytem.
  6. **/
  7. #ifndef TOR_HS_CELL_H
  8. #define TOR_HS_CELL_H
  9. #include "core/or/or.h"
  10. #include "feature/hs/hs_service.h"
  11. /* An INTRODUCE1 cell requires at least this amount of bytes (see section
  12. * 3.2.2 of the specification). Below this value, the cell must be padded. */
  13. #define HS_CELL_INTRODUCE1_MIN_SIZE 246
  14. /* This data structure contains data that we need to build an INTRODUCE1 cell
  15. * used by the INTRODUCE1 build function. */
  16. typedef struct hs_cell_introduce1_data_t {
  17. /* Is this a legacy introduction point? */
  18. unsigned int is_legacy : 1;
  19. /* (Legacy only) The encryption key for a legacy intro point. Only set if
  20. * is_legacy is true. */
  21. const crypto_pk_t *legacy_key;
  22. /* Introduction point authentication public key. */
  23. const ed25519_public_key_t *auth_pk;
  24. /* Introduction point encryption public key. */
  25. const curve25519_public_key_t *enc_pk;
  26. /* Subcredentials of the service. */
  27. const uint8_t *subcredential;
  28. /* Onion public key for the ntor handshake. */
  29. const curve25519_public_key_t *onion_pk;
  30. /* Rendezvous cookie. */
  31. const uint8_t *rendezvous_cookie;
  32. /* Public key put before the encrypted data (CLIENT_PK). */
  33. const curve25519_keypair_t *client_kp;
  34. /* Rendezvous point link specifiers. */
  35. smartlist_t *link_specifiers;
  36. } hs_cell_introduce1_data_t;
  37. /* This data structure contains data that we need to parse an INTRODUCE2 cell
  38. * which is used by the INTRODUCE2 cell parsing function. On a successful
  39. * parsing, the onion_pk and rendezvous_cookie will be populated with the
  40. * computed key material from the cell data. This structure is only used during
  41. * INTRO2 parsing and discarded after that. */
  42. typedef struct hs_cell_introduce2_data_t {
  43. /*** Immutable Section: Set on structure init. ***/
  44. /* Introduction point authentication public key. Pointer owned by the
  45. introduction point object through which we received the INTRO2 cell. */
  46. const ed25519_public_key_t *auth_pk;
  47. /* Introduction point encryption keypair for the ntor handshake. Pointer
  48. owned by the introduction point object through which we received the
  49. INTRO2 cell*/
  50. const curve25519_keypair_t *enc_kp;
  51. /* Subcredentials of the service. Pointer owned by the descriptor that owns
  52. the introduction point through which we received the INTRO2 cell. */
  53. const uint8_t *subcredential;
  54. /* Payload of the received encoded cell. */
  55. const uint8_t *payload;
  56. /* Size of the payload of the received encoded cell. */
  57. size_t payload_len;
  58. /*** Mutable Section: Set upon parsing INTRODUCE2 cell. ***/
  59. /* Onion public key computed using the INTRODUCE2 encrypted section. */
  60. curve25519_public_key_t onion_pk;
  61. /* Rendezvous cookie taken from the INTRODUCE2 encrypted section. */
  62. uint8_t rendezvous_cookie[REND_COOKIE_LEN];
  63. /* Client public key from the INTRODUCE2 encrypted section. */
  64. curve25519_public_key_t client_pk;
  65. /* Link specifiers of the rendezvous point. Contains link_specifier_t. */
  66. smartlist_t *link_specifiers;
  67. /* Replay cache of the introduction point. */
  68. replaycache_t *replay_cache;
  69. } hs_cell_introduce2_data_t;
  70. /* Build cell API. */
  71. ssize_t hs_cell_build_establish_intro(const char *circ_nonce,
  72. const hs_service_config_t *config,
  73. const hs_service_intro_point_t *ip,
  74. uint8_t *cell_out);
  75. ssize_t hs_cell_build_rendezvous1(const uint8_t *rendezvous_cookie,
  76. size_t rendezvous_cookie_len,
  77. const uint8_t *rendezvous_handshake_info,
  78. size_t rendezvous_handshake_info_len,
  79. uint8_t *cell_out);
  80. ssize_t hs_cell_build_introduce1(const hs_cell_introduce1_data_t *data,
  81. uint8_t *cell_out);
  82. ssize_t hs_cell_build_establish_rendezvous(const uint8_t *rendezvous_cookie,
  83. uint8_t *cell_out);
  84. /* Parse cell API. */
  85. ssize_t hs_cell_parse_intro_established(const uint8_t *payload,
  86. size_t payload_len);
  87. ssize_t hs_cell_parse_introduce2(hs_cell_introduce2_data_t *data,
  88. const origin_circuit_t *circ,
  89. const hs_service_t *service);
  90. int hs_cell_parse_introduce_ack(const uint8_t *payload, size_t payload_len);
  91. int hs_cell_parse_rendezvous2(const uint8_t *payload, size_t payload_len,
  92. uint8_t *handshake_info,
  93. size_t handshake_info_len);
  94. /* Util API. */
  95. void hs_cell_introduce1_data_clear(hs_cell_introduce1_data_t *data);
  96. #ifdef TOR_UNIT_TESTS
  97. #include "trunnel/hs/cell_common.h"
  98. STATIC trn_cell_extension_t *
  99. build_establish_intro_extensions(const hs_service_config_t *service_config,
  100. const hs_service_intro_point_t *ip);
  101. #endif /* defined(TOR_UNIT_TESTS) */
  102. #endif /* !defined(TOR_HS_CELL_H) */