onion.h 4.8 KB

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