hs_cell.h 5.2 KB

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