Ticket #23107: b23107-r001.patch

File b23107-r001.patch, 3.4 KB (added by neel, 13 months ago)

Patch (Revision 1)

  • new file changes/bug23107

    From 2151b81a2ed1f48d1e805972659b6fe20fdc989e Mon Sep 17 00:00:00 2001
    From: Neel Chauhan <neel@neelc.org>
    Date: Fri, 27 Apr 2018 14:11:43 -0400
    Subject: [PATCH] Add a cached SHA1 public key digest nii
     hs_service_intro_point_t and use it in register_intro_circ() and
     service_intro_point_new()
    
    ---
     changes/bug23107    |  6 ++++++
     src/or/hs_circuit.c | 18 ++++++++++--------
     src/or/hs_service.c |  3 +++
     src/or/hs_service.h |  3 +++
     4 files changed, 22 insertions(+), 8 deletions(-)
     create mode 100644 changes/bug23107
    
    diff --git a/changes/bug23107 b/changes/bug23107
    new file mode 100644
    index 000000000..d47b12500
    - +  
     1  o Code simplification and refactoring:
     2    - Put a cached SHA1 public key digest in hs_service_intro_point_t, and use
     3      it in register_intro_circ() and service_intro_point_new(). This prevents
     4      the digest from being re-calculated each time. Fixes bug 23107. Patch by
     5      Neel Chauhan.
     6
  • src/or/hs_circuit.c

    diff --git a/src/or/hs_circuit.c b/src/or/hs_circuit.c
    index 3a674f622..b34a78892 100644
    a b register_intro_circ(const hs_service_intro_point_t *ip, 
    193193  tor_assert(circ);
    194194
    195195  if (ip->base.is_only_legacy) {
    196     uint8_t digest[DIGEST_LEN];
    197     if (BUG(crypto_pk_get_digest(ip->legacy_key, (char *) digest) < 0)) {
    198       return;
     196    if (tor_digest_is_zero((const char *) ip->digest)) {
     197      if (BUG(crypto_pk_get_digest(ip->legacy_key, (char *) ip->digest) < 0)) {
     198        return;
     199      }
    199200    }
    200     hs_circuitmap_register_intro_circ_v2_service_side(circ, digest);
     201    hs_circuitmap_register_intro_circ_v2_service_side(circ, ip->digest);
    201202  } else {
    202203    hs_circuitmap_register_intro_circ_v3_service_side(circ,
    203204                                         &ip->auth_key_kp.pubkey);
    hs_circ_service_get_intro_circ(const hs_service_intro_point_t *ip) 
    680681  tor_assert(ip);
    681682
    682683  if (ip->base.is_only_legacy) {
    683     uint8_t digest[DIGEST_LEN];
    684     if (BUG(crypto_pk_get_digest(ip->legacy_key, (char *) digest) < 0)) {
    685       goto end;
     684    if (tor_digest_is_zero((const char *) ip->digest)) {
     685      if (BUG(crypto_pk_get_digest(ip->legacy_key, (char *) ip->digest) < 0)) {
     686        goto end;
     687      }
    686688    }
    687     circ = hs_circuitmap_get_intro_circ_v2_service_side(digest);
     689    circ = hs_circuitmap_get_intro_circ_v2_service_side(ip->digest);
    688690  } else {
    689691    circ = hs_circuitmap_get_intro_circ_v3_service_side(
    690692                                        &ip->auth_key_kp.pubkey);
  • src/or/hs_service.c

    diff --git a/src/or/hs_service.c b/src/or/hs_service.c
    index f6c7e3cd8..2584aeefa 100644
    a b service_intro_point_new(const extend_info_t *ei, unsigned int is_legacy) 
    458458    smartlist_add(ip->base.link_specifiers, ls);
    459459  }
    460460
     461  /* Blank the cached SHA1 public key digest. */
     462  memset(ip->digest, 0, sizeof(ip->digest));
     463
    461464  /* IPv6 is not supported in this release. */
    462465
    463466  /* Finally, copy onion key from the extend_info_t object. */
  • src/or/hs_service.h

    diff --git a/src/or/hs_service.h b/src/or/hs_service.h
    index d163eeef2..ed61eea53 100644
    a b typedef struct hs_service_intro_point_t { 
    5151   * the base object legacy flag is set. */
    5252  crypto_pk_t *legacy_key;
    5353
     54  /* Cached SHA1 public key digest. */
     55  uint8_t digest[DIGEST_LEN];
     56
    5457  /* Amount of INTRODUCE2 cell accepted from this intro point. */
    5558  uint64_t introduce2_count;
    5659