[tor-commits] [tor/master] hs: Remove introduction point v2 support

dgoulet at torproject.org dgoulet at torproject.org
Fri Feb 19 21:22:23 UTC 2021


commit ca04e9b8edd1752c802b053be12594c948405d36
Author: David Goulet <dgoulet at torproject.org>
Date:   Tue Feb 16 09:27:45 2021 -0500

    hs: Remove introduction point v2 support
    
    Related to #40266
    
    Signed-off-by: David Goulet <dgoulet at torproject.org>
---
 src/feature/hs/hs_intropoint.c |  40 +-------
 src/feature/hs/hs_intropoint.h |   1 -
 src/feature/rend/rendmid.c     | 205 -----------------------------------------
 3 files changed, 5 insertions(+), 241 deletions(-)

diff --git a/src/feature/hs/hs_intropoint.c b/src/feature/hs/hs_intropoint.c
index 69d60f21c3..7ae6deffa2 100644
--- a/src/feature/hs/hs_intropoint.c
+++ b/src/feature/hs/hs_intropoint.c
@@ -494,8 +494,8 @@ hs_intro_circuit_is_suitable_for_establish_intro(const or_circuit_t *circ)
   return circuit_is_suitable_intro_point(circ, "ESTABLISH_INTRO");
 }
 
-/** We just received an ESTABLISH_INTRO cell in <b>circ</b>. Figure out of it's
- * a legacy or a next gen cell, and pass it to the appropriate handler. */
+/** We just received an ESTABLISH_INTRO cell in <b>circ</b>. Pass it to the
+ * appropriate handler. */
 int
 hs_intro_received_establish_intro(or_circuit_t *circ, const uint8_t *request,
                             size_t request_len)
@@ -512,9 +512,6 @@ hs_intro_received_establish_intro(or_circuit_t *circ, const uint8_t *request,
    * ESTABLISH_INTRO and pass it to the appropriate cell handler */
   const uint8_t first_byte = request[0];
   switch (first_byte) {
-    case TRUNNEL_HS_INTRO_AUTH_KEY_TYPE_LEGACY0:
-    case TRUNNEL_HS_INTRO_AUTH_KEY_TYPE_LEGACY1:
-      return rend_mid_establish_intro_legacy(circ, request, request_len);
     case TRUNNEL_HS_INTRO_AUTH_KEY_TYPE_ED25519:
       return handle_establish_intro(circ, request, request_len);
     default:
@@ -717,23 +714,6 @@ handle_introduce1(or_circuit_t *client_circ, const uint8_t *request,
   return ret;
 }
 
-/** Identify if the encoded cell we just received is a legacy one or not. The
- * <b>request</b> should be at least DIGEST_LEN bytes long. */
-STATIC int
-introduce1_cell_is_legacy(const uint8_t *request)
-{
-  tor_assert(request);
-
-  /* If the first 20 bytes of the cell (DIGEST_LEN) are NOT zeroes, it
-   * indicates a legacy cell (v2). */
-  if (!fast_mem_is_zero((const char *) request, DIGEST_LEN)) {
-    /* Legacy cell. */
-    return 1;
-  }
-  /* Not a legacy cell. */
-  return 0;
-}
-
 /** Return true iff the circuit <b>circ</b> is suitable for receiving an
  * INTRODUCE1 cell. */
 STATIC int
@@ -772,13 +752,10 @@ int
 hs_intro_received_introduce1(or_circuit_t *circ, const uint8_t *request,
                              size_t request_len)
 {
-  int ret;
-
   tor_assert(circ);
   tor_assert(request);
 
-  /* A cell that can't hold a DIGEST_LEN is invalid as we need to check if
-   * it's a legacy cell or not using the first DIGEST_LEN bytes. */
+  /* A cell that can't hold a DIGEST_LEN is invalid. */
   if (request_len < DIGEST_LEN) {
     log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL, "Invalid INTRODUCE1 cell length.");
     goto err;
@@ -794,15 +771,8 @@ hs_intro_received_introduce1(or_circuit_t *circ, const uint8_t *request,
    * DoS mitigation since one circuit with one client can hammer a service. */
   circ->already_received_introduce1 = 1;
 
-  /* We are sure here to have at least DIGEST_LEN bytes. */
-  if (introduce1_cell_is_legacy(request)) {
-    /* Handle a legacy cell. */
-    ret = rend_mid_introduce_legacy(circ, request, request_len);
-  } else {
-    /* Handle a non legacy cell. */
-    ret = handle_introduce1(circ, request, request_len);
-  }
-  return ret;
+  /* Handle the cell. */
+  return handle_introduce1(circ, request, request_len);
 
  err:
   circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_TORPROTOCOL);
diff --git a/src/feature/hs/hs_intropoint.h b/src/feature/hs/hs_intropoint.h
index 8b2b9892b3..f08cef9afe 100644
--- a/src/feature/hs/hs_intropoint.h
+++ b/src/feature/hs/hs_intropoint.h
@@ -52,7 +52,6 @@ STATIC void
 get_auth_key_from_cell(ed25519_public_key_t *auth_key_out,
                        unsigned int cell_type, const void *cell);
 
-STATIC int introduce1_cell_is_legacy(const uint8_t *request);
 STATIC int handle_introduce1(or_circuit_t *client_circ,
                              const uint8_t *request, size_t request_len);
 STATIC int validate_introduce1_parsed_cell(const trn_cell_introduce1_t *cell);
diff --git a/src/feature/rend/rendmid.c b/src/feature/rend/rendmid.c
index b497362857..fdd5202a95 100644
--- a/src/feature/rend/rendmid.c
+++ b/src/feature/rend/rendmid.c
@@ -16,217 +16,12 @@
 #include "core/or/dos.h"
 #include "core/or/relay.h"
 #include "feature/rend/rendmid.h"
-#include "feature/stats/rephist.h"
 #include "feature/hs/hs_circuitmap.h"
 #include "feature/hs/hs_dos.h"
 #include "feature/hs/hs_intropoint.h"
 
 #include "core/or/or_circuit_st.h"
 
-/** Respond to an ESTABLISH_INTRO cell by checking the signed data and
- * setting the circuit's purpose and service pk digest.
- */
-int
-rend_mid_establish_intro_legacy(or_circuit_t *circ, const uint8_t *request,
-                                size_t request_len)
-{
-  crypto_pk_t *pk = NULL;
-  char buf[DIGEST_LEN+9];
-  char expected_digest[DIGEST_LEN];
-  char pk_digest[DIGEST_LEN];
-  size_t asn1len;
-  or_circuit_t *c;
-  char serviceid[REND_SERVICE_ID_LEN_BASE32+1];
-  int reason = END_CIRC_REASON_INTERNAL;
-
-  log_info(LD_REND,
-           "Received a legacy ESTABLISH_INTRO request on circuit %u",
-           (unsigned) circ->p_circ_id);
-
-  if (!hs_intro_circuit_is_suitable_for_establish_intro(circ)) {
-    reason = END_CIRC_REASON_TORPROTOCOL;
-    goto err;
-  }
-
-  if (request_len < 2+DIGEST_LEN)
-    goto truncated;
-  /* First 2 bytes: length of asn1-encoded key. */
-  asn1len = ntohs(get_uint16(request));
-
-  /* Next asn1len bytes: asn1-encoded key. */
-  if (request_len < 2+DIGEST_LEN+asn1len)
-    goto truncated;
-  pk = crypto_pk_asn1_decode((char*)(request+2), asn1len);
-  if (!pk) {
-    reason = END_CIRC_REASON_TORPROTOCOL;
-    log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL, "Couldn't decode public key.");
-    goto err;
-  }
-
-  /* Next 20 bytes: Hash of rend_circ_nonce | "INTRODUCE" */
-  memcpy(buf, circ->rend_circ_nonce, DIGEST_LEN);
-  memcpy(buf+DIGEST_LEN, "INTRODUCE", 9);
-  if (crypto_digest(expected_digest, buf, DIGEST_LEN+9) < 0) {
-    log_warn(LD_BUG, "Internal error computing digest.");
-    goto err;
-  }
-  if (tor_memneq(expected_digest, request+2+asn1len, DIGEST_LEN)) {
-    log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
-           "Hash of session info was not as expected.");
-    reason = END_CIRC_REASON_TORPROTOCOL;
-    goto err;
-  }
-  /* Rest of body: signature of previous data */
-  if (crypto_pk_public_checksig_digest(pk,
-                                       (char*)request, 2+asn1len+DIGEST_LEN,
-                                       (char*)(request+2+DIGEST_LEN+asn1len),
-                                       request_len-(2+DIGEST_LEN+asn1len))<0) {
-    log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
-             "Incorrect signature on ESTABLISH_INTRO cell; rejecting.");
-    reason = END_CIRC_REASON_TORPROTOCOL;
-    goto err;
-  }
-
-  /* The request is valid.  First, compute the hash of the service's PK.*/
-  if (crypto_pk_get_digest(pk, pk_digest)<0) {
-    log_warn(LD_BUG, "Internal error: couldn't hash public key.");
-    goto err;
-  }
-
-  crypto_pk_free(pk); /* don't need it anymore */
-  pk = NULL; /* so we don't free it again if err */
-
-  base32_encode(serviceid, REND_SERVICE_ID_LEN_BASE32+1,
-                pk_digest, REND_SERVICE_ID_LEN);
-
-  /* Close any other intro circuits with the same pk. */
-  c = NULL;
-  while ((c = hs_circuitmap_get_intro_circ_v2_relay_side(
-                                                (const uint8_t *)pk_digest))) {
-    log_info(LD_REND, "Replacing old circuit for service %s",
-             safe_str(serviceid));
-    circuit_mark_for_close(TO_CIRCUIT(c), END_CIRC_REASON_FINISHED);
-    /* Now it's marked, and it won't be returned next time. */
-  }
-
-  /* Acknowledge the request. */
-  if (hs_intro_send_intro_established_cell(circ) < 0) {
-    log_info(LD_GENERAL, "Couldn't send INTRO_ESTABLISHED cell.");
-    goto err_no_close;
-  }
-
-  /* Now, set up this circuit. */
-  circuit_change_purpose(TO_CIRCUIT(circ), CIRCUIT_PURPOSE_INTRO_POINT);
-  hs_circuitmap_register_intro_circ_v2_relay_side(circ, (uint8_t *)pk_digest);
-  hs_dos_setup_default_intro2_defenses(circ);
-
-  log_info(LD_REND,
-           "Established introduction point on circuit %u for service %s",
-           (unsigned) circ->p_circ_id, safe_str(serviceid));
-
-  return 0;
- truncated:
-  log_warn(LD_PROTOCOL, "Rejecting truncated ESTABLISH_INTRO cell.");
-  reason = END_CIRC_REASON_TORPROTOCOL;
- err:
-  circuit_mark_for_close(TO_CIRCUIT(circ), reason);
- err_no_close:
-  if (pk) crypto_pk_free(pk);
-  return -1;
-}
-
-/** Process an INTRODUCE1 cell by finding the corresponding introduction
- * circuit, and relaying the body of the INTRODUCE1 cell inside an
- * INTRODUCE2 cell.
- */
-int
-rend_mid_introduce_legacy(or_circuit_t *circ, const uint8_t *request,
-                          size_t request_len)
-{
-  or_circuit_t *intro_circ;
-  char serviceid[REND_SERVICE_ID_LEN_BASE32+1];
-  char nak_body[1];
-
-  log_info(LD_REND, "Received an INTRODUCE1 request on circuit %u",
-           (unsigned)circ->p_circ_id);
-
-  /* At this point, we know that the circuit is valid for an INTRODUCE1
-   * because the validation has been made before calling this function. */
-  tor_assert(circ->base_.purpose == CIRCUIT_PURPOSE_OR);
-  tor_assert(!circ->base_.n_chan);
-
-  /* We could change this to MAX_HEX_NICKNAME_LEN now that 0.0.9.x is
-   * obsolete; however, there isn't much reason to do so, and we're going
-   * to revise this protocol anyway.
-   */
-  if (request_len < (DIGEST_LEN+(MAX_NICKNAME_LEN+1)+REND_COOKIE_LEN+
-                     DH1024_KEY_LEN+CIPHER_KEY_LEN+
-                     PKCS1_OAEP_PADDING_OVERHEAD)) {
-    log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
-           "Impossibly short INTRODUCE1 cell on circuit %u; "
-           "responding with nack.", (unsigned)circ->p_circ_id);
-    goto err;
-  }
-
-  base32_encode(serviceid, REND_SERVICE_ID_LEN_BASE32+1,
-                (char*)request, REND_SERVICE_ID_LEN);
-
-  /* The first 20 bytes are all we look at: they have a hash of the service's
-   * PK. */
-  intro_circ = hs_circuitmap_get_intro_circ_v2_relay_side(
-                                                      (const uint8_t*)request);
-  if (!intro_circ) {
-    log_info(LD_REND,
-             "No intro circ found for INTRODUCE1 cell (%s) from circuit %u; "
-             "responding with nack.",
-             safe_str(serviceid), (unsigned)circ->p_circ_id);
-    goto err;
-  }
-
-  /* Before sending, lets make sure this cell can be sent on the service
-   * circuit asking the DoS defenses. */
-  if (!hs_dos_can_send_intro2(intro_circ)) {
-    log_info(LD_PROTOCOL, "Can't relay INTRODUCE1 v2 cell due to DoS "
-                          "limitations. Sending NACK to client.");
-    goto err;
-  }
-
-  log_info(LD_REND,
-           "Sending introduction request for service %s "
-           "from circ %u to circ %u",
-           safe_str(serviceid), (unsigned)circ->p_circ_id,
-           (unsigned)intro_circ->p_circ_id);
-
-  /* Great.  Now we just relay the cell down the circuit. */
-  if (relay_send_command_from_edge(0, TO_CIRCUIT(intro_circ),
-                                   RELAY_COMMAND_INTRODUCE2,
-                                   (char*)request, request_len, NULL)) {
-    log_warn(LD_GENERAL,
-             "Unable to send INTRODUCE2 cell to Tor client.");
-    /* Stop right now, the circuit has been closed. */
-    return -1;
-  }
-  /* And send an ack down the client's circuit.  Empty body means succeeded. */
-  if (relay_send_command_from_edge(0,TO_CIRCUIT(circ),
-                                   RELAY_COMMAND_INTRODUCE_ACK,
-                                   NULL,0,NULL)) {
-    log_warn(LD_GENERAL, "Unable to send INTRODUCE_ACK cell to Tor client.");
-    /* Stop right now, the circuit has been closed. */
-    return -1;
-  }
-
-  return 0;
- err:
-  /* Send the client a NACK */
-  nak_body[0] = 1;
-  if (relay_send_command_from_edge(0,TO_CIRCUIT(circ),
-                                   RELAY_COMMAND_INTRODUCE_ACK,
-                                   nak_body, 1, NULL)) {
-    log_warn(LD_GENERAL, "Unable to send NAK to Tor client.");
-  }
-  return -1;
-}
-
 /** Process an ESTABLISH_RENDEZVOUS cell by setting the circuit's purpose and
  * rendezvous cookie.
  */





More information about the tor-commits mailing list