hs_cell.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* Copyright (c) 2017, 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 "or.h"
  10. #include "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. /* Onion key type found in the INTRODUCE1 cell. */
  15. typedef enum {
  16. HS_CELL_ONION_KEY_TYPE_NTOR = 1,
  17. } hs_cell_onion_key_type_t;
  18. /* This data structure contains data that we need to build an INTRODUCE1 cell
  19. * used by the INTRODUCE1 build function. */
  20. typedef struct hs_cell_introduce1_data_t {
  21. /* Is this a legacy introduction point? */
  22. unsigned int is_legacy : 1;
  23. /* (Legacy only) The encryption key for a legacy intro point. Only set if
  24. * is_legacy is true. */
  25. const crypto_pk_t *legacy_key;
  26. /* Introduction point authentication public key. */
  27. const ed25519_public_key_t *auth_pk;
  28. /* Introduction point encryption public key. */
  29. const curve25519_public_key_t *enc_pk;
  30. /* Subcredentials of the service. */
  31. const uint8_t *subcredential;
  32. /* Onion public key for the ntor handshake. */
  33. const curve25519_public_key_t *onion_pk;
  34. /* Rendezvous cookie. */
  35. const uint8_t *rendezvous_cookie;
  36. /* Public key put before the encrypted data (CLIENT_PK). */
  37. const curve25519_keypair_t *client_kp;
  38. /* Rendezvous point link specifiers. */
  39. smartlist_t *link_specifiers;
  40. } hs_cell_introduce1_data_t;
  41. /* This data structure contains data that we need to parse an INTRODUCE2 cell
  42. * which is used by the INTRODUCE2 cell parsing function. On a successful
  43. * parsing, the onion_pk and rendezvous_cookie will be populated with the
  44. * computed key material from the cell data. This structure is only used during
  45. * INTRO2 parsing and discarded after that. */
  46. typedef struct hs_cell_introduce2_data_t {
  47. /*** Immutable Section: Set on structure init. ***/
  48. /* Introduction point authentication public key. Pointer owned by the
  49. introduction point object through which we received the INTRO2 cell. */
  50. const ed25519_public_key_t *auth_pk;
  51. /* Introduction point encryption keypair for the ntor handshake. Pointer
  52. owned by the introduction point object through which we received the
  53. INTRO2 cell*/
  54. const curve25519_keypair_t *enc_kp;
  55. /* Subcredentials of the service. Pointer owned by the descriptor that owns
  56. the introduction point through which we received the INTRO2 cell. */
  57. const uint8_t *subcredential;
  58. /* Payload of the received encoded cell. */
  59. const uint8_t *payload;
  60. /* Size of the payload of the received encoded cell. */
  61. size_t payload_len;
  62. /*** Mutable Section: Set upon parsing INTRODUCE2 cell. ***/
  63. /* Onion public key computed using the INTRODUCE2 encrypted section. */
  64. curve25519_public_key_t onion_pk;
  65. /* Rendezvous cookie taken from the INTRODUCE2 encrypted section. */
  66. uint8_t rendezvous_cookie[REND_COOKIE_LEN];
  67. /* Client public key from the INTRODUCE2 encrypted section. */
  68. curve25519_public_key_t client_pk;
  69. /* Link specifiers of the rendezvous point. Contains link_specifier_t. */
  70. smartlist_t *link_specifiers;
  71. /* Replay cache of the introduction point. */
  72. replaycache_t *replay_cache;
  73. } hs_cell_introduce2_data_t;
  74. /* Build cell API. */
  75. ssize_t hs_cell_build_establish_intro(const char *circ_nonce,
  76. const hs_service_intro_point_t *ip,
  77. uint8_t *cell_out);
  78. ssize_t hs_cell_build_rendezvous1(const uint8_t *rendezvous_cookie,
  79. size_t rendezvous_cookie_len,
  80. const uint8_t *rendezvous_handshake_info,
  81. size_t rendezvous_handshake_info_len,
  82. uint8_t *cell_out);
  83. ssize_t hs_cell_build_introduce1(const hs_cell_introduce1_data_t *data,
  84. uint8_t *cell_out);
  85. ssize_t hs_cell_build_establish_rendezvous(const uint8_t *rendezvous_cookie,
  86. uint8_t *cell_out);
  87. /* Parse cell API. */
  88. ssize_t hs_cell_parse_intro_established(const uint8_t *payload,
  89. size_t payload_len);
  90. ssize_t hs_cell_parse_introduce2(hs_cell_introduce2_data_t *data,
  91. const origin_circuit_t *circ,
  92. const hs_service_t *service);
  93. #endif /* TOR_HS_CELL_H */