mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-13 06:33:44 +01:00
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.
This commit is contained in:
parent
83249015c2
commit
0b2018a4d0
@ -42,6 +42,7 @@
|
|||||||
#include "control.h"
|
#include "control.h"
|
||||||
#include "entrynodes.h"
|
#include "entrynodes.h"
|
||||||
#include "hs_common.h"
|
#include "hs_common.h"
|
||||||
|
#include "hs_ident.h"
|
||||||
#include "nodelist.h"
|
#include "nodelist.h"
|
||||||
#include "networkstatus.h"
|
#include "networkstatus.h"
|
||||||
#include "policies.h"
|
#include "policies.h"
|
||||||
@ -55,6 +56,36 @@
|
|||||||
static void circuit_expire_old_circuits_clientside(void);
|
static void circuit_expire_old_circuits_clientside(void);
|
||||||
static void circuit_increment_failure_count(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().
|
/** Return 1 if <b>circ</b> could be returned by circuit_get_best().
|
||||||
* Else return 0.
|
* Else return 0.
|
||||||
*/
|
*/
|
||||||
@ -169,14 +200,9 @@ circuit_is_acceptable(const origin_circuit_t *origin_circ,
|
|||||||
/* can't exit from this router */
|
/* can't exit from this router */
|
||||||
return 0;
|
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);
|
const edge_connection_t *edge_conn = ENTRY_TO_EDGE_CONN(conn);
|
||||||
if ((edge_conn->rend_data && !origin_circ->rend_data) ||
|
if (!circuit_matches_with_rend_stream(edge_conn, origin_circ)) {
|
||||||
(!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;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3566,8 +3566,14 @@ int
|
|||||||
connection_edge_is_rendezvous_stream(const edge_connection_t *conn)
|
connection_edge_is_rendezvous_stream(const edge_connection_t *conn)
|
||||||
{
|
{
|
||||||
tor_assert(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 1;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user