onion.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* Copyright (c) 2001 Matej Pfajfar.
  2. * Copyright (c) 2001-2004, Roger Dingledine.
  3. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  4. * Copyright (c) 2007-2018, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. /**
  7. * \file onion.h
  8. * \brief Header file for onion.c.
  9. **/
  10. #ifndef TOR_ONION_H
  11. #define TOR_ONION_H
  12. struct create_cell_t;
  13. struct curve25519_keypair_t;
  14. struct curve25519_public_key_t;
  15. #include "lib/crypt_ops/crypto_ed25519.h"
  16. int onion_pending_add(or_circuit_t *circ, struct create_cell_t *onionskin);
  17. or_circuit_t *onion_next_task(struct create_cell_t **onionskin_out);
  18. int onion_num_pending(uint16_t handshake_type);
  19. void onion_pending_remove(or_circuit_t *circ);
  20. void clear_pending_onions(void);
  21. typedef struct server_onion_keys_t {
  22. uint8_t my_identity[DIGEST_LEN];
  23. crypto_pk_t *onion_key;
  24. crypto_pk_t *last_onion_key;
  25. struct di_digest256_map_t *curve25519_key_map;
  26. struct curve25519_keypair_t *junk_keypair;
  27. } server_onion_keys_t;
  28. #define MAX_ONIONSKIN_CHALLENGE_LEN 255
  29. #define MAX_ONIONSKIN_REPLY_LEN 255
  30. server_onion_keys_t *server_onion_keys_new(void);
  31. void server_onion_keys_free_(server_onion_keys_t *keys);
  32. #define server_onion_keys_free(keys) \
  33. FREE_AND_NULL(server_onion_keys_t, server_onion_keys_free_, (keys))
  34. void onion_handshake_state_release(onion_handshake_state_t *state);
  35. int onion_skin_create(int type,
  36. const extend_info_t *node,
  37. onion_handshake_state_t *state_out,
  38. uint8_t *onion_skin_out);
  39. int onion_skin_server_handshake(int type,
  40. const uint8_t *onion_skin, size_t onionskin_len,
  41. const server_onion_keys_t *keys,
  42. uint8_t *reply_out,
  43. uint8_t *keys_out, size_t key_out_len,
  44. uint8_t *rend_nonce_out);
  45. int onion_skin_client_handshake(int type,
  46. const onion_handshake_state_t *handshake_state,
  47. const uint8_t *reply, size_t reply_len,
  48. uint8_t *keys_out, size_t key_out_len,
  49. uint8_t *rend_authenticator_out,
  50. const char **msg_out);
  51. /** A parsed CREATE, CREATE_FAST, or CREATE2 cell. */
  52. typedef struct create_cell_t {
  53. /** The cell command. One of CREATE{,_FAST,2} */
  54. uint8_t cell_type;
  55. /** One of the ONION_HANDSHAKE_TYPE_* values */
  56. uint16_t handshake_type;
  57. /** The number of bytes used in <b>onionskin</b>. */
  58. uint16_t handshake_len;
  59. /** The client-side message for the circuit creation handshake. */
  60. uint8_t onionskin[CELL_PAYLOAD_SIZE - 4];
  61. } create_cell_t;
  62. /** A parsed CREATED, CREATED_FAST, or CREATED2 cell. */
  63. typedef struct created_cell_t {
  64. /** The cell command. One of CREATED{,_FAST,2} */
  65. uint8_t cell_type;
  66. /** The number of bytes used in <b>reply</b>. */
  67. uint16_t handshake_len;
  68. /** The server-side message for the circuit creation handshake. */
  69. uint8_t reply[CELL_PAYLOAD_SIZE - 2];
  70. } created_cell_t;
  71. /** A parsed RELAY_EXTEND or RELAY_EXTEND2 cell */
  72. typedef struct extend_cell_t {
  73. /** One of RELAY_EXTEND or RELAY_EXTEND2 */
  74. uint8_t cell_type;
  75. /** An IPv4 address and port for the node we're connecting to. */
  76. tor_addr_port_t orport_ipv4;
  77. /** An IPv6 address and port for the node we're connecting to. Not currently
  78. * used. */
  79. tor_addr_port_t orport_ipv6;
  80. /** Identity fingerprint of the node we're conecting to.*/
  81. uint8_t node_id[DIGEST_LEN];
  82. /** Ed25519 public identity key. Zero if not set. */
  83. struct ed25519_public_key_t ed_pubkey;
  84. /** The "create cell" embedded in this extend cell. Note that unlike the
  85. * create cells we generate ourself, this once can have a handshake type we
  86. * don't recognize. */
  87. create_cell_t create_cell;
  88. } extend_cell_t;
  89. /** A parsed RELAY_EXTEND or RELAY_EXTEND2 cell */
  90. typedef struct extended_cell_t {
  91. /** One of RELAY_EXTENDED or RELAY_EXTENDED2. */
  92. uint8_t cell_type;
  93. /** The "created cell" embedded in this extended cell. */
  94. created_cell_t created_cell;
  95. } extended_cell_t;
  96. void create_cell_init(create_cell_t *cell_out, uint8_t cell_type,
  97. uint16_t handshake_type, uint16_t handshake_len,
  98. const uint8_t *onionskin);
  99. int create_cell_parse(create_cell_t *cell_out, const cell_t *cell_in);
  100. int created_cell_parse(created_cell_t *cell_out, const cell_t *cell_in);
  101. int extend_cell_parse(extend_cell_t *cell_out, const uint8_t command,
  102. const uint8_t *payload_in, size_t payload_len);
  103. int extended_cell_parse(extended_cell_t *cell_out, const uint8_t command,
  104. const uint8_t *payload_in, size_t payload_len);
  105. int create_cell_format(cell_t *cell_out, const create_cell_t *cell_in);
  106. int create_cell_format_relayed(cell_t *cell_out, const create_cell_t *cell_in);
  107. int created_cell_format(cell_t *cell_out, const created_cell_t *cell_in);
  108. int extend_cell_format(uint8_t *command_out, uint16_t *len_out,
  109. uint8_t *payload_out, const extend_cell_t *cell_in);
  110. int extended_cell_format(uint8_t *command_out, uint16_t *len_out,
  111. uint8_t *payload_out, const extended_cell_t *cell_in);
  112. #endif /* !defined(TOR_ONION_H) */