]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
hs-v3: Implement HS_DESC REQUESTED event
authorDavid Goulet <dgoulet@torproject.org>
Fri, 10 Nov 2017 17:07:57 +0000 (12:07 -0500)
committerNick Mathewson <nickm@torproject.org>
Wed, 6 Dec 2017 00:39:46 +0000 (19:39 -0500)
This changes the control_event_hs_descriptor_requested() call to add the hsdir
index optional value. v2 passes NULL all the time.

This commit creates hs_control.{c|h} that contains wrappers for the HS
subsystem to interact with the control port subsystem.

The descriptor REQUESTED event is implemented following proposal 284 extension
for v3.

Signed-off-by: David Goulet <dgoulet@torproject.org>
src/or/control.c
src/or/control.h
src/or/hs_client.c
src/or/hs_control.c [new file with mode: 0644]
src/or/hs_control.h [new file with mode: 0644]
src/or/include.am
src/or/rendclient.c
src/test/test_hs.c

index e7ec238170d9af5b6d7711bc793503d1de37f139..cd1be5bf4d884d73a60fcbae1fb547575f8ee693 100644 (file)
@@ -7175,23 +7175,33 @@ rend_hsaddress_str_or_unknown(const char *onion_address)
  * <b>rend_query</b> is used to fetch requested onion address and auth type.
  * <b>hs_dir</b> is the description of contacting hs directory.
  * <b>desc_id_base32</b> is the ID of requested hs descriptor.
+ * <b>hsdir_index</b> is the HSDir fetch index value for v3, an hex string.
  */
 void
 control_event_hs_descriptor_requested(const char *onion_address,
                                       rend_auth_type_t auth_type,
                                       const char *id_digest,
-                                      const char *desc_id)
+                                      const char *desc_id,
+                                      const char *hsdir_index)
 {
+  char *hsdir_index_field = NULL;
+
   if (BUG(!id_digest || !desc_id)) {
     return;
   }
 
+  if (hsdir_index) {
+    tor_asprintf(&hsdir_index_field, " HSDIR_INDEX=%s", hsdir_index);
+  }
+
   send_control_event(EVENT_HS_DESC,
-                     "650 HS_DESC REQUESTED %s %s %s %s\r\n",
+                     "650 HS_DESC REQUESTED %s %s %s %s%s\r\n",
                      rend_hsaddress_str_or_unknown(onion_address),
                      rend_auth_type_to_string(auth_type),
                      node_describe_longname_by_id(id_digest),
-                     desc_id);
+                     desc_id,
+                     hsdir_index_field ? hsdir_index_field : "");
+  tor_free(hsdir_index_field);
 }
 
 /** For an HS descriptor query <b>rend_data</b>, using the
index 1744baba2e118e66a2b25ec0ae46a271b8447479..5a7a87c06fc8e830e8c31b2c6ca5c0f8863a6c94 100644 (file)
@@ -118,7 +118,8 @@ MOCK_DECL(const char *, node_describe_longname_by_id,(const char *id_digest));
 void control_event_hs_descriptor_requested(const char *onion_address,
                                            rend_auth_type_t auth_type,
                                            const char *id_digest,
-                                           const char *desc_id);
+                                           const char *desc_id,
+                                           const char *hsdir_index);
 void control_event_hs_descriptor_created(const char *onion_address,
                                          const char *desc_id,
                                          int replica);
index 9ac653c721411f2f6dd8034340835e45bee02e5b..666860155c852056d9728faad133db199451bcab 100644 (file)
@@ -21,6 +21,7 @@
 #include "config.h"
 #include "directory.h"
 #include "hs_client.h"
+#include "hs_control.h"
 #include "router.h"
 #include "routerset.h"
 #include "circuitlist.h"
@@ -349,6 +350,10 @@ directory_launch_v3_desc_fetch(const ed25519_public_key_t *onion_identity_pk,
            safe_str_client(base64_blinded_pubkey),
            safe_str_client(routerstatus_describe(hsdir)));
 
+  /* Fire a REQUESTED event on the control port. */
+  hs_control_desc_event_requested(onion_identity_pk, base64_blinded_pubkey,
+                                  hsdir);
+
   /* Cleanup memory. */
   memwipe(&blinded_pubkey, 0, sizeof(blinded_pubkey));
   memwipe(base64_blinded_pubkey, 0, sizeof(base64_blinded_pubkey));
diff --git a/src/or/hs_control.c b/src/or/hs_control.c
new file mode 100644 (file)
index 0000000..0bcb41d
--- /dev/null
@@ -0,0 +1,52 @@
+/* Copyright (c) 2017, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+/**
+ * \file hs_control.c
+ * \brief Contains control port event related code.
+ **/
+
+#include "or.h"
+#include "control.h"
+#include "hs_common.h"
+#include "hs_control.h"
+#include "nodelist.h"
+
+/* Send on the control port the "HS_DESC REQUESTED [...]" event.
+ *
+ * The onion_pk is the onion service public key, base64_blinded_pk is the
+ * base64 encoded blinded key for the service and hsdir_rs is the routerstatus
+ * object of the HSDir that this request is for. */
+void
+hs_control_desc_event_requested(const ed25519_public_key_t *onion_pk,
+                                const char *base64_blinded_pk,
+                                const routerstatus_t *hsdir_rs)
+{
+  char onion_address[HS_SERVICE_ADDR_LEN_BASE32 + 1];
+  const uint8_t *hsdir_index;
+  const node_t *hsdir_node;
+
+  tor_assert(onion_pk);
+  tor_assert(base64_blinded_pk);
+  tor_assert(hsdir_rs);
+
+  hs_build_address(onion_pk, HS_VERSION_THREE, onion_address);
+
+  /* Get the node from the routerstatus object to get the HSDir index used for
+   * this request. We can't have a routerstatus entry without a node and we
+   * can't pick a node without an hsdir_index. */
+  hsdir_node = node_get_by_id(hsdir_rs->identity_digest);
+  tor_assert(hsdir_node);
+  tor_assert(hsdir_node->hsdir_index);
+  /* This is a fetch event. */
+  hsdir_index = hsdir_node->hsdir_index->fetch;
+
+  /* Trigger the event. */
+  control_event_hs_descriptor_requested(onion_address, REND_NO_AUTH,
+                                        hsdir_rs->identity_digest,
+                                        base64_blinded_pk,
+                                        hex_str((const char *) hsdir_index,
+                                                DIGEST256_LEN));
+  memwipe(onion_address, 0, sizeof(onion_address));
+}
+
diff --git a/src/or/hs_control.h b/src/or/hs_control.h
new file mode 100644 (file)
index 0000000..2878ba5
--- /dev/null
@@ -0,0 +1,18 @@
+/* Copyright (c) 2017, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+/**
+ * \file hs_control.h
+ * \brief Header file containing control port event related code.
+ **/
+
+#ifndef TOR_HS_CONTROL_H
+#define TOR_HS_CONTROL_H
+
+/* Event "HS_DESC REQUESTED [...]" */
+void hs_control_desc_event_requested(const ed25519_public_key_t *onion_pk,
+                                     const char *base64_blinded_pk,
+                                     const routerstatus_t *hsdir_rs);
+
+#endif /* !defined(TOR_HS_CONTROL_H) */
+
index b783f4855a6e819f089ec11a419fef615d80ddb1..1c66cd2de3fba67421ec828727f977eaf95c6942 100644 (file)
@@ -60,6 +60,7 @@ LIBTOR_A_SOURCES = \
        src/or/hs_client.c                              \
        src/or/hs_common.c                              \
        src/or/hs_config.c                              \
+       src/or/hs_control.c                             \
        src/or/hs_descriptor.c                          \
        src/or/hs_ident.c                               \
        src/or/hs_intropoint.c                          \
@@ -196,11 +197,12 @@ ORHEADERS = \
        src/or/hibernate.h                              \
        src/or/hs_cache.h                               \
        src/or/hs_cell.h                                \
-       src/or/hs_config.h                              \
        src/or/hs_circuit.h                             \
        src/or/hs_circuitmap.h                          \
        src/or/hs_client.h                              \
        src/or/hs_common.h                              \
+       src/or/hs_config.h                              \
+       src/or/hs_control.h                             \
        src/or/hs_descriptor.h                          \
        src/or/hs_ident.h                               \
        src/or/hs_intropoint.h                          \
index eb097a50f6332db9856bd1693ba9406be19bc128..8291e5abfb4e8e9ea339d6f8fd6c49425918ac2d 100644 (file)
@@ -519,7 +519,7 @@ directory_get_from_hs_dir(const char *desc_id,
   control_event_hs_descriptor_requested(rend_data->onion_address,
                                         rend_data->auth_type,
                                         hs_dir->identity_digest,
-                                        desc_id_base32);
+                                        desc_id_base32, NULL);
   return 1;
 }
 
index 14799c9935be3453ff17869650819e7e6254a987..55c6218dd166e7aebf7b820593e9408209f1f1bc 100644 (file)
@@ -260,7 +260,7 @@ test_hs_desc_event(void *arg)
   /* test request event */
   control_event_hs_descriptor_requested(rend_query.onion_address,
                                         rend_query.auth_type, HSDIR_EXIST_ID,
-                                        STR_DESC_ID_BASE32);
+                                        STR_DESC_ID_BASE32, NULL);
   expected_msg = "650 HS_DESC REQUESTED "STR_HS_ADDR" NO_AUTH "\
                   STR_HSDIR_EXIST_LONGNAME " " STR_DESC_ID_BASE32 "\r\n";
   tt_assert(received_msg);