commit 0b2018a4d078a6ea47678c296c634714ab7eee94 Author: George Kadianakis desnacked@riseup.net Date: Tue May 2 16:20:26 2017 +0300
Refactor legacy code to support hs_ident along with rend_data.
The legacy HS circuit code uses rend_data to match between circuits and streams. We refactor some of that code so that it understands hs_ident as well which is used for prop224. --- src/or/circuituse.c | 40 +++++++++++++++++++++++++++++++++------- src/or/connection_edge.c | 8 +++++++- 2 files changed, 40 insertions(+), 8 deletions(-)
diff --git a/src/or/circuituse.c b/src/or/circuituse.c index 9f9d3ab..288b49e 100644 --- a/src/or/circuituse.c +++ b/src/or/circuituse.c @@ -42,6 +42,7 @@ #include "control.h" #include "entrynodes.h" #include "hs_common.h" +#include "hs_ident.h" #include "nodelist.h" #include "networkstatus.h" #include "policies.h" @@ -55,6 +56,36 @@ static void circuit_expire_old_circuits_clientside(void); static void circuit_increment_failure_count(void);
+/** Check whether the hidden service destination of the stream at + * <b>edge_conn</b> is the same as the destination of the circuit at + * <b>origin_circ</b>. */ +static int +circuit_matches_with_rend_stream(const edge_connection_t *edge_conn, + const origin_circuit_t *origin_circ) +{ + /* Check if this is a v2 rendezvous circ/stream */ + if ((edge_conn->rend_data && !origin_circ->rend_data) || + (!edge_conn->rend_data && origin_circ->rend_data) || + (edge_conn->rend_data && origin_circ->rend_data && + rend_cmp_service_ids(rend_data_get_address(edge_conn->rend_data), + rend_data_get_address(origin_circ->rend_data)))) { + /* this circ is not for this conn */ + return 0; + } + + /* Check if this is a v3 rendezvous circ/stream */ + if ((edge_conn->hs_ident && !origin_circ->hs_ident) || + (!edge_conn->hs_ident && origin_circ->hs_ident) || + (edge_conn->hs_ident && origin_circ->hs_ident && + !ed25519_pubkey_eq(&edge_conn->hs_ident->identity_pk, + &origin_circ->hs_ident->identity_pk))) { + /* this circ is not for this conn */ + return 0; + } + + return 1; +} + /** Return 1 if <b>circ</b> could be returned by circuit_get_best(). * Else return 0. */ @@ -169,14 +200,9 @@ circuit_is_acceptable(const origin_circuit_t *origin_circ, /* can't exit from this router */ return 0; } - } else { /* not general */ + } else { /* not general: this might be a rend circuit */ const edge_connection_t *edge_conn = ENTRY_TO_EDGE_CONN(conn); - if ((edge_conn->rend_data && !origin_circ->rend_data) || - (!edge_conn->rend_data && origin_circ->rend_data) || - (edge_conn->rend_data && origin_circ->rend_data && - rend_cmp_service_ids(rend_data_get_address(edge_conn->rend_data), - rend_data_get_address(origin_circ->rend_data)))) { - /* this circ is not for this conn */ + if (!circuit_matches_with_rend_stream(edge_conn, origin_circ)) { return 0; } } diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c index 8480a35..9c98c56 100644 --- a/src/or/connection_edge.c +++ b/src/or/connection_edge.c @@ -3566,8 +3566,14 @@ int connection_edge_is_rendezvous_stream(const edge_connection_t *conn) { tor_assert(conn); - if (conn->rend_data) + + if (BUG(conn->rend_data && conn->hs_ident)) { + log_warn(LD_BUG, "Connection has both rend_data and hs_ident..."); + } + + if (conn->rend_data || conn->hs_ident) { return 1; + } return 0; }