Ticket #23577: 006-setup_introduce1_data_node.patch

File 006-setup_introduce1_data_node.patch, 8.7 KB (added by neel, 3 years ago)

Revised Patch (Revision 5)

  • src/or/nodelist.c

    From 9b2879cebb2688a334ed411cf208a568d4cb5dba Mon Sep 17 00:00:00 2001
    From: Neel Chauhan <neel@neelc.org>
    Date: Wed, 8 Nov 2017 18:33:30 -0500
    Subject: [PATCH 1/2] Introduce node_get_curve25519_onion_key()
    
    ---
     src/or/nodelist.c | 10 ++++++++++
     src/or/nodelist.h |  1 +
     2 files changed, 11 insertions(+)
    
    diff --git a/src/or/nodelist.c b/src/or/nodelist.c
    index f2e979be8..31f5c488d 100644
    a b node_has_curve25519_onion_key(const node_t *node) 
    16331633    return 0;
    16341634}
    16351635
     1636/** Return the curve25519 key of <b>node</b>, or NULL if none. */
     1637curve25519_public_key_t *node_get_curve25519_onion_key(const node_t *node) {
     1638  if (node->ri)
     1639    return node->ri->onion_curve25519_pkey;
     1640  else if (node->md)
     1641    return node->md->onion_curve25519_pkey;
     1642  else
     1643    return NULL;
     1644}
     1645
    16361646/** Refresh the country code of <b>ri</b>.  This function MUST be called on
    16371647 * each router when the GeoIP database is reloaded, and on all new routers. */
    16381648void
  • src/or/nodelist.h

    diff --git a/src/or/nodelist.h b/src/or/nodelist.h
    index 754990ac8..0ff5ecca0 100644
    a b int node_get_prim_dirport(const node_t *node, tor_addr_port_t *ap_out); 
    8585void node_get_pref_dirport(const node_t *node, tor_addr_port_t *ap_out);
    8686void node_get_pref_ipv6_dirport(const node_t *node, tor_addr_port_t *ap_out);
    8787int node_has_curve25519_onion_key(const node_t *node);
     88curve25519_public_key_t *node_get_curve25519_onion_key(const node_t *node);
    8889
    8990MOCK_DECL(smartlist_t *, nodelist_get_list, (void));
    9091
  • new file changes/ticket23577

    -- 
    2.15.0
    
    
    From 009e80f271b656cc1f635d8e9baa90c667d7f2c4 Mon Sep 17 00:00:00 2001
    From: Neel Chauhan <neel@neelc.org>
    Date: Wed, 8 Nov 2017 18:36:10 -0500
    Subject: [PATCH 2/2] Make setup_introduce1_data() take a node_t instead of an
     extend_info_t
    
    ---
     changes/ticket23577 | 11 +++++++++
     src/or/hs_circuit.c | 67 ++++++++++++++++++++++++++++++++++-------------------
     2 files changed, 54 insertions(+), 24 deletions(-)
     create mode 100644 changes/ticket23577
    
    diff --git a/changes/ticket23577 b/changes/ticket23577
    new file mode 100644
    index 000000000..17ff25ad5
    - +  
     1  o Major features (v3 onion services):
     2    - When v3 onion service clients send introduce cells, include the IPv6
     3      address of the rendezvous point, if it has one. v3 onion services running
     4      0.3.2 ignore IPv6 addresses. In future Tor versions, IPv6-only v3 single
     5      onion services can use IPv6 addresses to connect directly to the
     6      rendezvous point.
     7
     8  o Code simplification and refactoring:
     9    - To allow v3 onion services to use IPv6 addresses, setup_introduce1_data()
     10      was modified to take in a node_t instead of an extend_into_t. Closes
     11      ticket 23577.
  • src/or/hs_circuit.c

    diff --git a/src/or/hs_circuit.c b/src/or/hs_circuit.c
    index ee952f4d6..8f1810ff5 100644
    a b  
    1313#include "circuitlist.h"
    1414#include "circuituse.h"
    1515#include "config.h"
     16#include "nodelist.h"
    1617#include "policies.h"
    1718#include "relay.h"
    1819#include "rendservice.h"
    retry_service_rendezvous_point(const origin_circuit_t *circ) 
    553554  return;
    554555}
    555556
    556 /* Using an extend info object ei, set all possible link specifiers in lspecs.
    557  * legacy ID is mandatory thus MUST be present in ei. If IPv4 is not present,
    558  * logs a BUG() warning, and returns an empty smartlist. Clients never make
    559  * direct connections to rendezvous points, so they should always have an
    560  * IPv4 address in ei. */
     557/* Using an node object node, set all possible link specifiers in lspecs.
     558 * legacy ID is mandatory thus MUST be present in node. If the primary address
     559 * is not IPv4, log a BUG() warning, and return an empty smartlist. Clients
     560 * never make direct connections to rendezvous points, so they should always
     561 * have an IPv4 address in node. Includes ed25519 id and IPv6 if present. */
    561562static void
    562 get_lspecs_from_extend_info(const extend_info_t *ei, smartlist_t *lspecs)
     563get_lspecs_from_node(const node_t *node, smartlist_t *lspecs)
    563564{
    564565  link_specifier_t *ls;
     566  tor_addr_port_t ap;
    565567
    566   tor_assert(ei);
     568  tor_assert(node);
    567569  tor_assert(lspecs);
    568570
    569   /* We require IPv4, we will add IPv6 support in a later tor version */
    570   if (BUG(!tor_addr_is_v4(&ei->addr))) {
     571  /* Get the relay's IPv4 address, and IPv6 address if it is present. */
     572  node_get_prim_orport(node, &ap);
     573
     574  /* We require IPv4, and we will add IPv6 if it is present. */
     575  if (BUG(!tor_addr_is_v4(&ap.addr))) {
    571576    return;
    572577  }
    573578
    574579  ls = link_specifier_new();
    575580  link_specifier_set_ls_type(ls, LS_IPV4);
    576   link_specifier_set_un_ipv4_addr(ls, tor_addr_to_ipv4h(&ei->addr));
    577   link_specifier_set_un_ipv4_port(ls, ei->port);
     581  link_specifier_set_un_ipv4_addr(ls, tor_addr_to_ipv4h(&ap.addr));
     582  link_specifier_set_un_ipv4_port(ls, ap.port);
    578583  /* Four bytes IPv4 and two bytes port. */
    579   link_specifier_set_ls_len(ls, sizeof(ei->addr.addr.in_addr) +
    580                             sizeof(ei->port));
     584  link_specifier_set_ls_len(ls, sizeof(ap.addr.addr.in_addr) +
     585                            sizeof(ap.port));
    581586  smartlist_add(lspecs, ls);
    582587
    583   /* Legacy ID is mandatory. */
     588  /* Legacy ID is mandatory and will always be present in node. */
    584589  ls = link_specifier_new();
    585590  link_specifier_set_ls_type(ls, LS_LEGACY_ID);
    586   memcpy(link_specifier_getarray_un_legacy_id(ls), ei->identity_digest,
     591  memcpy(link_specifier_getarray_un_legacy_id(ls), node->identity,
    587592         link_specifier_getlen_un_legacy_id(ls));
    588593  link_specifier_set_ls_len(ls, link_specifier_getlen_un_legacy_id(ls));
    589594  smartlist_add(lspecs, ls);
    590595
    591   /* ed25519 ID is only included if the extend_info has it. */
    592   if (!ed25519_public_key_is_zero(&ei->ed_identity)) {
     596  /* ed25519 ID is only included if the node has it. */
     597  if (!ed25519_public_key_is_zero(&node->ed25519_id)) {
    593598    ls = link_specifier_new();
    594599    link_specifier_set_ls_type(ls, LS_ED25519_ID);
    595     memcpy(link_specifier_getarray_un_ed25519_id(ls), &ei->ed_identity,
     600    memcpy(link_specifier_getarray_un_ed25519_id(ls), &node->ed25519_id,
    596601           link_specifier_getlen_un_ed25519_id(ls));
    597602    link_specifier_set_ls_len(ls, link_specifier_getlen_un_ed25519_id(ls));
    598603    smartlist_add(lspecs, ls);
    599604  }
     605
     606  /* Check for IPv6. If so, include it as well. */
     607  if (node_has_ipv6_orport(node)) {
     608    ls = link_specifier_new();
     609    node_get_pref_ipv6_orport(node, &ap);
     610    link_specifier_set_ls_type(ls, LS_IPV6);
     611    size_t addr_len = link_specifier_getlen_un_ipv6_addr(ls);
     612    const uint8_t *in6_addr = tor_addr_to_in6_addr8(&ap.addr);
     613    uint8_t *ipv6_array = link_specifier_getarray_un_ipv6_addr(ls);
     614    memcpy(ipv6_array, in6_addr, addr_len);
     615    link_specifier_set_un_ipv6_port(ls, ap.port);
     616    /* Sixteen bytes IPv6 and two bytes port. */
     617    link_specifier_set_ls_len(ls, addr_len + sizeof(ap.port));
     618  }
    600619}
    601620
    602621/* Using the given descriptor intro point ip, the extend information of the
    get_lspecs_from_extend_info(const extend_info_t *ei, smartlist_t *lspecs) 
    608627 * keys and authentication method. */
    609628static void
    610629setup_introduce1_data(const hs_desc_intro_point_t *ip,
    611                       const extend_info_t *rp_ei,
     630                      const node_t *rp_node,
    612631                      const uint8_t *subcredential,
    613632                      hs_cell_introduce1_data_t *intro1_data)
    614633{
    615634  smartlist_t *rp_lspecs;
    616635
    617636  tor_assert(ip);
    618   tor_assert(rp_ei);
     637  tor_assert(rp_node);
    619638  tor_assert(subcredential);
    620639  tor_assert(intro1_data);
    621640
    622641  /* Build the link specifiers from the extend information of the rendezvous
    623642   * circuit that we've picked previously. */
    624643  rp_lspecs = smartlist_new();
    625   get_lspecs_from_extend_info(rp_ei, rp_lspecs);
     644  get_lspecs_from_node(rp_node, rp_lspecs);
    626645
    627646  /* Populate the introduce1 data object. */
    628647  memset(intro1_data, 0, sizeof(hs_cell_introduce1_data_t));
    setup_introduce1_data(const hs_desc_intro_point_t *ip, 
    633652  intro1_data->auth_pk = &ip->auth_key_cert->signed_key;
    634653  intro1_data->enc_pk = &ip->enc_key;
    635654  intro1_data->subcredential = subcredential;
    636   intro1_data->onion_pk = &rp_ei->curve25519_onion_key;
     655  intro1_data->onion_pk = node_get_curve25519_onion_key(rp_node);
    637656  intro1_data->link_specifiers = rp_lspecs;
    638657}
    639658
    hs_circ_send_introduce1(origin_circuit_t *intro_circ, 
    10791098
    10801099  /* This takes various objects in order to populate the introduce1 data
    10811100   * object which is used to build the content of the cell. */
    1082   setup_introduce1_data(ip, rend_circ->build_state->chosen_exit,
    1083                         subcredential, &intro1_data);
     1101  const node_t *exit_node = build_state_get_exit_node(rend_circ->build_state);
     1102  setup_introduce1_data(ip, exit_node, subcredential, &intro1_data);
    10841103  /* If we didn't get any link specifiers, it's because our extend info was
    10851104   * bad. */
    10861105  if (BUG(!intro1_data.link_specifiers) ||