connection_or.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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-2019, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. /**
  7. * \file connection_or.h
  8. * \brief Header file for connection_or.c.
  9. **/
  10. #ifndef TOR_CONNECTION_OR_H
  11. #define TOR_CONNECTION_OR_H
  12. struct ed25519_public_key_t;
  13. struct ed25519_keypair_t;
  14. or_connection_t *TO_OR_CONN(connection_t *);
  15. #define OR_CONN_STATE_MIN_ 1
  16. /** State for a connection to an OR: waiting for connect() to finish. */
  17. #define OR_CONN_STATE_CONNECTING 1
  18. /** State for a connection to an OR: waiting for proxy handshake to complete */
  19. #define OR_CONN_STATE_PROXY_HANDSHAKING 2
  20. /** State for an OR connection client: SSL is handshaking, not done
  21. * yet. */
  22. #define OR_CONN_STATE_TLS_HANDSHAKING 3
  23. /** State for a connection to an OR: We're doing a second SSL handshake for
  24. * renegotiation purposes. (V2 handshake only.) */
  25. #define OR_CONN_STATE_TLS_CLIENT_RENEGOTIATING 4
  26. /** State for a connection at an OR: We're waiting for the client to
  27. * renegotiate (to indicate a v2 handshake) or send a versions cell (to
  28. * indicate a v3 handshake) */
  29. #define OR_CONN_STATE_TLS_SERVER_RENEGOTIATING 5
  30. /** State for an OR connection: We're done with our SSL handshake, we've done
  31. * renegotiation, but we haven't yet negotiated link protocol versions and
  32. * sent a netinfo cell. */
  33. #define OR_CONN_STATE_OR_HANDSHAKING_V2 6
  34. /** State for an OR connection: We're done with our SSL handshake, but we
  35. * haven't yet negotiated link protocol versions, done a V3 handshake, and
  36. * sent a netinfo cell. */
  37. #define OR_CONN_STATE_OR_HANDSHAKING_V3 7
  38. /** State for an OR connection: Ready to send/receive cells. */
  39. #define OR_CONN_STATE_OPEN 8
  40. #define OR_CONN_STATE_MAX_ 8
  41. void connection_or_clear_identity(or_connection_t *conn);
  42. void connection_or_clear_identity_map(void);
  43. void clear_broken_connection_map(int disable);
  44. or_connection_t *connection_or_get_for_extend(const char *digest,
  45. const tor_addr_t *target_addr,
  46. const char **msg_out,
  47. int *launch_out);
  48. void connection_or_block_renegotiation(or_connection_t *conn);
  49. int connection_or_reached_eof(or_connection_t *conn);
  50. int connection_or_process_inbuf(or_connection_t *conn);
  51. ssize_t connection_or_num_cells_writeable(or_connection_t *conn);
  52. int connection_or_flushed_some(or_connection_t *conn);
  53. int connection_or_finished_flushing(or_connection_t *conn);
  54. int connection_or_finished_connecting(or_connection_t *conn);
  55. void connection_or_about_to_close(or_connection_t *conn);
  56. int connection_or_digest_is_known_relay(const char *id_digest);
  57. void connection_or_update_token_buckets(smartlist_t *conns,
  58. const or_options_t *options);
  59. void connection_or_connect_failed(or_connection_t *conn,
  60. int reason, const char *msg);
  61. void connection_or_notify_error(or_connection_t *conn,
  62. int reason, const char *msg);
  63. MOCK_DECL(or_connection_t *,
  64. connection_or_connect,
  65. (const tor_addr_t *addr, uint16_t port,
  66. const char *id_digest,
  67. const struct ed25519_public_key_t *ed_id,
  68. channel_tls_t *chan));
  69. void connection_or_close_normally(or_connection_t *orconn, int flush);
  70. MOCK_DECL(void,connection_or_close_for_error,
  71. (or_connection_t *orconn, int flush));
  72. void connection_or_report_broken_states(int severity, int domain);
  73. MOCK_DECL(int,connection_tls_start_handshake,(or_connection_t *conn,
  74. int receiving));
  75. int connection_tls_continue_handshake(or_connection_t *conn);
  76. void connection_or_set_canonical(or_connection_t *or_conn,
  77. int is_canonical);
  78. int connection_init_or_handshake_state(or_connection_t *conn,
  79. int started_here);
  80. void connection_or_init_conn_from_address(or_connection_t *conn,
  81. const tor_addr_t *addr,
  82. uint16_t port,
  83. const char *rsa_id_digest,
  84. const struct ed25519_public_key_t *ed_id,
  85. int started_here);
  86. int connection_or_client_learned_peer_id(or_connection_t *conn,
  87. const uint8_t *rsa_peer_id,
  88. const struct ed25519_public_key_t *ed_peer_id);
  89. time_t connection_or_client_used(or_connection_t *conn);
  90. MOCK_DECL(int, connection_or_get_num_circuits, (or_connection_t *conn));
  91. void or_handshake_state_free_(or_handshake_state_t *state);
  92. #define or_handshake_state_free(state) \
  93. FREE_AND_NULL(or_handshake_state_t, or_handshake_state_free_, (state))
  94. void or_handshake_state_record_cell(or_connection_t *conn,
  95. or_handshake_state_t *state,
  96. const cell_t *cell,
  97. int incoming);
  98. void or_handshake_state_record_var_cell(or_connection_t *conn,
  99. or_handshake_state_t *state,
  100. const var_cell_t *cell,
  101. int incoming);
  102. int connection_or_set_state_open(or_connection_t *conn);
  103. void connection_or_write_cell_to_buf(const cell_t *cell,
  104. or_connection_t *conn);
  105. MOCK_DECL(void,connection_or_write_var_cell_to_buf,(const var_cell_t *cell,
  106. or_connection_t *conn));
  107. int connection_or_send_versions(or_connection_t *conn, int v3_plus);
  108. MOCK_DECL(int,connection_or_send_netinfo,(or_connection_t *conn));
  109. int connection_or_send_certs_cell(or_connection_t *conn);
  110. int connection_or_send_auth_challenge_cell(or_connection_t *conn);
  111. int authchallenge_type_is_supported(uint16_t challenge_type);
  112. int authchallenge_type_is_better(uint16_t challenge_type_a,
  113. uint16_t challenge_type_b);
  114. var_cell_t *connection_or_compute_authenticate_cell_body(
  115. or_connection_t *conn,
  116. const int authtype,
  117. crypto_pk_t *signing_key,
  118. const struct ed25519_keypair_t *ed_signing_key,
  119. int server);
  120. MOCK_DECL(int,connection_or_send_authenticate_cell,
  121. (or_connection_t *conn, int type));
  122. int is_or_protocol_version_known(uint16_t version);
  123. void cell_pack(packed_cell_t *dest, const cell_t *src, int wide_circ_ids);
  124. int var_cell_pack_header(const var_cell_t *cell, char *hdr_out,
  125. int wide_circ_ids);
  126. var_cell_t *var_cell_new(uint16_t payload_len);
  127. var_cell_t *var_cell_copy(const var_cell_t *src);
  128. void var_cell_free_(var_cell_t *cell);
  129. #define var_cell_free(cell) FREE_AND_NULL(var_cell_t, var_cell_free_, (cell))
  130. /* DOCDOC */
  131. #define MIN_LINK_PROTO_FOR_WIDE_CIRC_IDS 4
  132. #define MIN_LINK_PROTO_FOR_CHANNEL_PADDING 5
  133. #define MAX_LINK_PROTO MIN_LINK_PROTO_FOR_CHANNEL_PADDING
  134. int connection_or_single_set_badness_(time_t now,
  135. or_connection_t *or_conn,
  136. int force);
  137. void connection_or_group_set_badness_(smartlist_t *group, int force);
  138. #ifdef CONNECTION_OR_PRIVATE
  139. STATIC int should_connect_to_relay(const or_connection_t *or_conn);
  140. STATIC void note_or_connect_failed(const or_connection_t *or_conn);
  141. #endif
  142. #ifdef TOR_UNIT_TESTS
  143. extern int certs_cell_ed25519_disabled_for_testing;
  144. extern int testing__connection_or_pretend_TLSSECRET_is_supported;
  145. #endif
  146. #endif /* !defined(TOR_CONNECTION_OR_H) */