Ticket #23577: 003-desriptive_msg.patch

File 003-desriptive_msg.patch, 7.1 KB (added by neel, 3 years ago)

Revised Patch (Revision 2) with node_get_curve25519_key()

  • src/or/nodelist.c

    From b0e075aa021294b7dd4b56dd5857ba9a940a6063 Mon Sep 17 00:00:00 2001
    From: Neel Chauhan <neel@neelc.org>
    Date: Mon, 23 Oct 2017 21:22:39 -0400
    Subject: [PATCH 1/2] Introduce node_get_curve25519_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 0743be180..e023ae286 100644
    a b node_has_curve25519_onion_key(const node_t *node) 
    16291629    return 0;
    16301630}
    16311631
     1632/** Return the curve25519 key of <b>node</b>, or NULL if none. */
     1633curve25519_public_key_t *node_get_curve25519_key(const node_t *node) {
     1634  if (node->ri)
     1635    return node->ri->onion_curve25519_pkey;
     1636  else if (node->md)
     1637    return node->md->onion_curve25519_pkey;
     1638  else
     1639    return NULL;
     1640}
     1641
    16321642/** Refresh the country code of <b>ri</b>.  This function MUST be called on
    16331643 * each router when the GeoIP database is reloaded, and on all new routers. */
    16341644void
  • src/or/nodelist.h

    diff --git a/src/or/nodelist.h b/src/or/nodelist.h
    index 754990ac8..9e4d1610a 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_key(const node_t *node);
    8889
    8990MOCK_DECL(smartlist_t *, nodelist_get_list, (void));
    9091
  • src/or/hs_circuit.c

    -- 
    2.14.2
    
    
    From 4bb9397d866f84a2258cd325504c9a2694a06dbe Mon Sep 17 00:00:00 2001
    From: Neel Chauhan <neel@neelc.org>
    Date: Mon, 23 Oct 2017 21:23:20 -0400
    Subject: [PATCH 2/2] Switch from get_lspecs_from_extend_info() to
     get_lspecs_from_node()
    
    ---
     src/or/hs_circuit.c | 49 ++++++++++++++++++++++++++++++++-----------------
     1 file changed, 32 insertions(+), 17 deletions(-)
    
    diff --git a/src/or/hs_circuit.c b/src/or/hs_circuit.c
    index e1e513c5f..81c57a5d1 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) 
    532533  return;
    533534}
    534535
    535 /* Using an extend info object ei, set all possible link specifiers in lspecs.
    536  * IPv4, legacy ID and ed25519 ID are mandatory thus MUST be present in ei. */
     536/* Using an node info object node, set all possible link specifiers in lspecs.
     537 * IPv4, legacy ID and ed25519 ID are mandatory thus MUST be present in
     538 * node. */
    537539static void
    538 get_lspecs_from_extend_info(const extend_info_t *ei, smartlist_t *lspecs)
     540get_lspecs_from_node(const node_t *node, smartlist_t *lspecs)
    539541{
    540542  link_specifier_t *ls;
     543  tor_addr_port_t ap;
    541544
    542   tor_assert(ei);
     545  tor_assert(node);
    543546  tor_assert(lspecs);
    544547
    545548  /* IPv4 is mandatory. */
    546549  ls = link_specifier_new();
     550  node_get_prim_orport(node, &ap);
    547551  link_specifier_set_ls_type(ls, LS_IPV4);
    548   link_specifier_set_un_ipv4_addr(ls, tor_addr_to_ipv4h(&ei->addr));
    549   link_specifier_set_un_ipv4_port(ls, ei->port);
     552  link_specifier_set_un_ipv4_addr(ls, tor_addr_to_ipv4h(&ap.addr));
     553  link_specifier_set_un_ipv4_port(ls, ap.port);
    550554  /* Four bytes IPv4 and two bytes port. */
    551   link_specifier_set_ls_len(ls, sizeof(ei->addr.addr.in_addr) +
    552                             sizeof(ei->port));
     555  link_specifier_set_ls_len(ls, sizeof(ap.addr.addr.in_addr) +
     556                            sizeof(ap.port));
    553557  smartlist_add(lspecs, ls);
    554558
    555559  /* Legacy ID is mandatory. */
    556560  ls = link_specifier_new();
    557561  link_specifier_set_ls_type(ls, LS_LEGACY_ID);
    558   memcpy(link_specifier_getarray_un_legacy_id(ls), ei->identity_digest,
     562  memcpy(link_specifier_getarray_un_legacy_id(ls), node->identity,
    559563         link_specifier_getlen_un_legacy_id(ls));
    560564  link_specifier_set_ls_len(ls, link_specifier_getlen_un_legacy_id(ls));
    561565  smartlist_add(lspecs, ls);
    get_lspecs_from_extend_info(const extend_info_t *ei, smartlist_t *lspecs) 
    563567  /* ed25519 ID is mandatory. */
    564568  ls = link_specifier_new();
    565569  link_specifier_set_ls_type(ls, LS_ED25519_ID);
    566   memcpy(link_specifier_getarray_un_ed25519_id(ls), &ei->ed_identity,
     570  memcpy(link_specifier_getarray_un_ed25519_id(ls), &node->ed25519_id,
    567571         link_specifier_getlen_un_ed25519_id(ls));
    568572  link_specifier_set_ls_len(ls, link_specifier_getlen_un_ed25519_id(ls));
    569573  smartlist_add(lspecs, ls);
    570574
    571   /* XXX: IPv6 is not clearly a thing in extend_info_t? */
     575  /* Check for IPv6. If so, include it as well. */
     576  if (node_ipv6_or_preferred(node)) {
     577    node_get_pref_ipv6_orport(node, &ap);
     578    link_specifier_set_ls_type(ls, LS_IPV6);
     579    size_t addr_len = link_specifier_getlen_un_ipv6_addr(ls);
     580    const uint8_t *in6_addr = tor_addr_to_in6_addr8(&ap.addr);
     581    uint8_t *ipv6_array = link_specifier_getarray_un_ipv6_addr(ls);
     582    memcpy(ipv6_array, in6_addr, addr_len);
     583    link_specifier_set_un_ipv6_port(ls, ap.port);
     584    /* Sixteen bytes IPv6 and two bytes port. */
     585    link_specifier_set_ls_len(ls, addr_len + sizeof(ap.port));
     586  }
    572587}
    573588
    574589/* 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) 
    580595 * keys and authentication method. */
    581596static void
    582597setup_introduce1_data(const hs_desc_intro_point_t *ip,
    583                       const extend_info_t *rp_ei,
     598                      const node_t *rp_node,
    584599                      const uint8_t *subcredential,
    585600                      hs_cell_introduce1_data_t *intro1_data)
    586601{
    587602  smartlist_t *rp_lspecs;
    588603
    589604  tor_assert(ip);
    590   tor_assert(rp_ei);
     605  tor_assert(rp_node);
    591606  tor_assert(subcredential);
    592607  tor_assert(intro1_data);
    593608
    594609  /* Build the link specifiers from the extend information of the rendezvous
    595610   * circuit that we've picked previously. */
    596611  rp_lspecs = smartlist_new();
    597   get_lspecs_from_extend_info(rp_ei, rp_lspecs);
     612  get_lspecs_from_node(rp_node, rp_lspecs);
    598613
    599614  /* Populate the introduce1 data object. */
    600615  memset(intro1_data, 0, sizeof(hs_cell_introduce1_data_t));
    setup_introduce1_data(const hs_desc_intro_point_t *ip, 
    605620  intro1_data->auth_pk = &ip->auth_key_cert->signed_key;
    606621  intro1_data->enc_pk = &ip->enc_key;
    607622  intro1_data->subcredential = subcredential;
    608   intro1_data->onion_pk = &rp_ei->curve25519_onion_key;
     623  intro1_data->onion_pk = node_get_curve25519_key(rp_node);
    609624  intro1_data->link_specifiers = rp_lspecs;
    610625}
    611626
    hs_circ_send_introduce1(origin_circuit_t *intro_circ, 
    10511066
    10521067  /* This takes various objects in order to populate the introduce1 data
    10531068   * object which is used to build the content of the cell. */
    1054   setup_introduce1_data(ip, rend_circ->build_state->chosen_exit,
    1055                         subcredential, &intro1_data);
     1069  const node_t *exit_node = build_state_get_exit_node(rend_circ->build_state);
     1070  setup_introduce1_data(ip, exit_node, subcredential, &intro1_data);
    10561071
    10571072  /* Final step before we encode a cell, we setup the circuit identifier which
    10581073   * will generate both the rendezvous cookie and client keypair for this