Ticket #23577: 001-setup_introduce1_data_node.patch

File 001-setup_introduce1_data_node.patch, 5.1 KB (added by neel, 3 years ago)

Patch to make setup_introduce1_data() take a node & create get_lspecs_from_node() & remove legacy get_lspecs_from_extend_info() in hs_circuit.c

  • src/or/hs_circuit.c

    From e7d0591ce71d2b04cf43c8a7f779a409cdc725c4 Mon Sep 17 00:00:00 2001
    From: Neel Chauhan <neel@neelc.org>
    Date: Tue, 3 Oct 2017 11:09:40 -0400
    Subject: [PATCH] hs_circuit.c: Make setup_introduce1_data() take a node &
     create get_lspecs_from_node() & remove legacy get_lspecs_from_extend_info()
    
    ---
     src/or/hs_circuit.c | 36 ++++++++++++++++++++----------------
     1 file changed, 20 insertions(+), 16 deletions(-)
    
    diff --git a/src/or/hs_circuit.c b/src/or/hs_circuit.c
    index e1e513c5f..b2b771bc7 100644
    a b retry_service_rendezvous_point(const origin_circuit_t *circ) 
    532532  return;
    533533}
    534534
    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. */
     535/* Using an node info object node, set all possible link specifiers in lspecs.
     536 * IPv4, legacy ID and ed25519 ID are mandatory thus MUST be present in
     537 * node. */
    537538static void
    538 get_lspecs_from_extend_info(const extend_info_t *ei, smartlist_t *lspecs)
     539get_lspecs_from_node(const node_t *node, smartlist_t *lspecs)
    539540{
    540541  link_specifier_t *ls;
    541542
    542   tor_assert(ei);
     543  tor_assert(node);
    543544  tor_assert(lspecs);
    544545
    545546  /* IPv4 is mandatory. */
    546547  ls = link_specifier_new();
    547548  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);
     549  link_specifier_set_un_ipv4_addr(ls, node->ri->addr);
     550  link_specifier_set_un_ipv4_port(ls, node->ri->or_port);
    550551  /* Four bytes IPv4 and two bytes port. */
    551   link_specifier_set_ls_len(ls, sizeof(ei->addr.addr.in_addr) +
    552                             sizeof(ei->port));
     552  tor_addr_t addr;
     553  tor_addr_from_ipv4h(&addr, node->ri->addr);
     554  link_specifier_set_ls_len(ls, sizeof(addr.addr.in_addr) +
     555                            sizeof(node->ri->or_port));
    553556  smartlist_add(lspecs, ls);
    554557
    555558  /* Legacy ID is mandatory. */
    556559  ls = link_specifier_new();
    557560  link_specifier_set_ls_type(ls, LS_LEGACY_ID);
    558   memcpy(link_specifier_getarray_un_legacy_id(ls), ei->identity_digest,
     561  memcpy(link_specifier_getarray_un_legacy_id(ls), node->identity,
    559562         link_specifier_getlen_un_legacy_id(ls));
    560563  link_specifier_set_ls_len(ls, link_specifier_getlen_un_legacy_id(ls));
    561564  smartlist_add(lspecs, ls);
    get_lspecs_from_extend_info(const extend_info_t *ei, smartlist_t *lspecs) 
    563566  /* ed25519 ID is mandatory. */
    564567  ls = link_specifier_new();
    565568  link_specifier_set_ls_type(ls, LS_ED25519_ID);
    566   memcpy(link_specifier_getarray_un_ed25519_id(ls), &ei->ed_identity,
     569  memcpy(link_specifier_getarray_un_ed25519_id(ls), &node->ed25519_id,
    567570         link_specifier_getlen_un_ed25519_id(ls));
    568571  link_specifier_set_ls_len(ls, link_specifier_getlen_un_ed25519_id(ls));
    569572  smartlist_add(lspecs, ls);
    get_lspecs_from_extend_info(const extend_info_t *ei, smartlist_t *lspecs) 
    571574  /* XXX: IPv6 is not clearly a thing in extend_info_t? */
    572575}
    573576
     577
    574578/* Using the given descriptor intro point ip, the extend information of the
    575579 * rendezvous point rp_ei and the service's subcredential, populate the
    576580 * already allocated intro1_data object with the needed key material and link
    get_lspecs_from_extend_info(const extend_info_t *ei, smartlist_t *lspecs) 
    580584 * keys and authentication method. */
    581585static void
    582586setup_introduce1_data(const hs_desc_intro_point_t *ip,
    583                       const extend_info_t *rp_ei,
     587                      const node_t *rp_node,
    584588                      const uint8_t *subcredential,
    585589                      hs_cell_introduce1_data_t *intro1_data)
    586590{
    587591  smartlist_t *rp_lspecs;
    588592
    589593  tor_assert(ip);
    590   tor_assert(rp_ei);
     594  tor_assert(rp_node);
    591595  tor_assert(subcredential);
    592596  tor_assert(intro1_data);
    593597
    594598  /* Build the link specifiers from the extend information of the rendezvous
    595599   * circuit that we've picked previously. */
    596600  rp_lspecs = smartlist_new();
    597   get_lspecs_from_extend_info(rp_ei, rp_lspecs);
     601  get_lspecs_from_node(rp_node, rp_lspecs);
    598602
    599603  /* Populate the introduce1 data object. */
    600604  memset(intro1_data, 0, sizeof(hs_cell_introduce1_data_t));
    setup_introduce1_data(const hs_desc_intro_point_t *ip, 
    605609  intro1_data->auth_pk = &ip->auth_key_cert->signed_key;
    606610  intro1_data->enc_pk = &ip->enc_key;
    607611  intro1_data->subcredential = subcredential;
    608   intro1_data->onion_pk = &rp_ei->curve25519_onion_key;
     612  intro1_data->onion_pk = rp_node->ri->onion_curve25519_pkey;
    609613  intro1_data->link_specifiers = rp_lspecs;
    610614}
    611615
    hs_circ_send_introduce1(origin_circuit_t *intro_circ, 
    10511055
    10521056  /* This takes various objects in order to populate the introduce1 data
    10531057   * 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);
     1058  const node_t *exitnode = build_state_get_exit_node(rend_circ->build_state);
     1059  setup_introduce1_data(ip, exitnode, subcredential, &intro1_data);
    10561060
    10571061  /* Final step before we encode a cell, we setup the circuit identifier which
    10581062   * will generate both the rendezvous cookie and client keypair for this