Ticket #24509: 0001-Restricts-TAP-usage-to-only-v2-onion-services.patch

File 0001-Restricts-TAP-usage-to-only-v2-onion-services.patch, 7.0 KB (added by irl, 2 years ago)
  • src/or/circuitbuild.c

    From 859853d0ea48432e9143871aa9e16544c2cbc82e Mon Sep 17 00:00:00 2001
    From: "Iain R. Learmonth" <irl@fsfe.org>
    Date: Sun, 10 Dec 2017 23:20:25 +0000
    Subject: [PATCH] Restricts TAP usage to only v2 onion services
    
    This adds a new circuit launch flag (CIRCLAUNCH_IS_V2_RP) for use when
    building v2 onion service related circuits. This state is added to
    circ->build_state->is_v2 when initialising the new circuit, and then used
    to determine whether or not the circuit is able to use TAP in
    circuit_can_use_tap().
    
    As circ->rend_data and circ->hs_ident are not available at the time that
    circuits are launched, this provides a reliable method of determining whether
    or not a circuit is related to a v2 onion service.
    
    Fixes: #24509
    ---
     src/or/circuitbuild.c | 5 ++++-
     src/or/circuituse.c   | 9 +++++++++
     src/or/circuituse.h   | 3 +++
     src/or/hs_ident.h     | 3 ++-
     src/or/or.h           | 5 ++++-
     src/or/rendservice.c  | 8 +++++---
     6 files changed, 27 insertions(+), 6 deletions(-)
    
    diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c
    index a350f6c14..0c1c764fa 100644
    a b origin_circuit_init(uint8_t purpose, int flags) 
    485485    ((flags & CIRCLAUNCH_NEED_CAPACITY) ? 1 : 0);
    486486  circ->build_state->is_internal =
    487487    ((flags & CIRCLAUNCH_IS_INTERNAL) ? 1 : 0);
     488  circ->build_state->is_v2 =
     489    ((flags & CIRCLAUNCH_IS_V2_RP) ? 1 : 0);
    488490  circ->base_.purpose = purpose;
    489491  return circ;
    490492}
    circuit_can_use_tap(const origin_circuit_t *circ) 
    28272829  tor_assert(circ->cpath);
    28282830  tor_assert(circ->cpath->extend_info);
    28292831  return (circuit_purpose_can_use_tap_impl(circ->base_.purpose) &&
    2830           extend_info_supports_tap(circ->cpath->extend_info));
     2832          extend_info_supports_tap(circ->cpath->extend_info) &&
     2833          circ->build_state->is_v2);
    28312834}
    28322835
    28332836/* Does circ have an onion key which it's allowed to use? */
  • src/or/circuituse.c

    diff --git a/src/or/circuituse.c b/src/or/circuituse.c
    index 825535739..0a5b69c31 100644
    a b circuit_get_open_circ_or_launch(entry_connection_t *conn, 
    22932293      if (need_uptime) flags |= CIRCLAUNCH_NEED_UPTIME;
    22942294      if (need_internal) flags |= CIRCLAUNCH_IS_INTERNAL;
    22952295
     2296      /* If we are about to pick a v2 RP right now, we will want to be able
     2297       * to use TAP for this circuit, so set a flag. */
     2298      if (desired_circuit_purpose == CIRCUIT_PURPOSE_C_REND_JOINED &&
     2299          new_circ_purpose == CIRCUIT_PURPOSE_C_ESTABLISH_REND &&
     2300          ENTRY_TO_EDGE_CONN(conn)->rend_data) {
     2301        flags |= CIRCLAUNCH_IS_V2_RP;
     2302        log_info(LD_GENERAL, "Getting rendezvous circuit to v2 service!");
     2303      }
     2304
    22962305      /* If we are about to pick a v3 RP right now, make sure we pick a
    22972306       * rendezvous point that supports the v3 protocol! */
    22982307      if (desired_circuit_purpose == CIRCUIT_PURPOSE_C_REND_JOINED &&
  • src/or/circuituse.h

    diff --git a/src/or/circuituse.h b/src/or/circuituse.h
    index 2b0f983f1..6f911099b 100644
    a b void circuit_build_failed(origin_circuit_t *circ); 
    4747/** Flag to set when we are trying to launch a v3 rendezvous circuit. We need
    4848 *  to apply some additional filters on the node picked. */
    4949#define CIRCLAUNCH_IS_V3_RP (1<<4)
     50/** Flag to set when we are trying to launch a v2 rendezvous circuit. This is
     51 *  the only time that the TAP handshake should be used. */
     52#define CIRCLAUNCH_IS_V2_RP (1<<5)
    5053origin_circuit_t *circuit_launch_by_extend_info(uint8_t purpose,
    5154                                                extend_info_t *info,
    5255                                                int flags);
  • src/or/hs_ident.h

    diff --git a/src/or/hs_ident.h b/src/or/hs_ident.h
    index 91ec389aa..4bd33159e 100644
    a b typedef enum { 
    3939/* Client and service side circuit identifier that is used for hidden service
    4040 * circuit establishment. Not all fields contain data, it depends on the
    4141 * circuit purpose. This is attached to an origin_circuit_t. All fields are
    42  * used by both client and service. */
     42 * used by both client and service. This is used for v3 connections, see
     43 * rend_data_t for v2 connections. */
    4344typedef struct hs_ident_circuit_t {
    4445  /* (All circuit) The public key used to uniquely identify the service. It is
    4546   * the one found in the onion address. */
  • src/or/or.h

    diff --git a/src/or/or.h b/src/or/or.h
    index b07802232..1649d2f2f 100644
    a b typedef struct rend_service_authorization_t { 
    810810
    811811/** Client- and server-side data that is used for hidden service connection
    812812 * establishment. Not all fields contain data depending on where this struct
    813  * is used. */
     813 * is used. This is only used for v2 connections, see hs_ident_circuit_t
     814 * for v3 connections. */
    814815typedef struct rend_data_t {
    815816  /* Hidden service protocol version of this base object. */
    816817  uint32_t version;
    typedef struct { 
    29482949   * These are for encrypted dir conns that exit to this router, not
    29492950   * for arbitrary exits from the circuit. */
    29502951  unsigned int onehop_tunnel : 1;
     2952  /** Whether this circ is to be used for a v2 onion service. */
     2953  unsigned int is_v2 : 1;
    29512954  /** The crypt_path_t to append after rendezvous: used for rendezvous. */
    29522955  crypt_path_t *pending_final_cpath;
    29532956  /** A ref-counted reference to the crypt_path_t to append after
  • src/or/rendservice.c

    diff --git a/src/or/rendservice.c b/src/or/rendservice.c
    index 06166d7cf..d8df6317d 100644
    a b rend_service_receive_introduction(origin_circuit_t *circuit, 
    20432043  /* Launch a circuit to the client's chosen rendezvous point.
    20442044   */
    20452045  for (i=0;i<MAX_REND_FAILURES;i++) {
    2046     int flags = CIRCLAUNCH_NEED_CAPACITY | CIRCLAUNCH_IS_INTERNAL;
     2046    int flags = CIRCLAUNCH_NEED_CAPACITY | CIRCLAUNCH_IS_INTERNAL
     2047                | CIRCLAUNCH_IS_V2_RP;
    20472048    if (circ_needs_uptime) flags |= CIRCLAUNCH_NEED_UPTIME;
    20482049    /* A Single Onion Service only uses a direct connection if its
    20492050     * firewall rules permit direct connections to the address. */
    rend_service_relaunch_rendezvous(origin_circuit_t *oldcirc) 
    29572958   * proxy, we need a 3-hop connection. */
    29582959  newcirc = circuit_launch_by_extend_info(CIRCUIT_PURPOSE_S_CONNECT_REND,
    29592960                            oldstate->chosen_exit,
    2960                             CIRCLAUNCH_NEED_CAPACITY|CIRCLAUNCH_IS_INTERNAL);
     2961                            CIRCLAUNCH_NEED_CAPACITY|CIRCLAUNCH_IS_INTERNAL
     2962                            |CIRCLAUNCH_IS_V2_RP);
    29612963
    29622964  if (!newcirc) {
    29632965    log_warn(LD_REND,"Couldn't relaunch rendezvous circuit to '%s'.",
    rend_service_launch_establish_intro(rend_service_t *service, 
    29832985                                    rend_intro_point_t *intro)
    29842986{
    29852987  origin_circuit_t *launched;
    2986   int flags = CIRCLAUNCH_NEED_UPTIME|CIRCLAUNCH_IS_INTERNAL;
     2988  int flags = CIRCLAUNCH_NEED_UPTIME|CIRCLAUNCH_IS_INTERNAL|CIRCLAUNCH_IS_V2_RP;
    29872989  const or_options_t *options = get_options();
    29882990  extend_info_t *launch_ei = intro->extend_info;
    29892991  extend_info_t *direct_ei = NULL;