onion.h 5.0 KB

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