[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] hs-v3: Implement HS_DESC REQUESTED event



commit 743d0b9d91c0c26045aa9a725865870f0c052794
Author: David Goulet <dgoulet@xxxxxxxxxxxxxx>
Date:   Fri Nov 10 12:07:57 2017 -0500

    hs-v3: Implement HS_DESC REQUESTED event
    
    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@xxxxxxxxxxxxxx>
---
 src/or/control.c    | 16 +++++++++++++---
 src/or/control.h    |  3 ++-
 src/or/hs_client.c  |  5 +++++
 src/or/hs_control.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/or/hs_control.h | 18 ++++++++++++++++++
 src/or/include.am   |  4 +++-
 src/or/rendclient.c |  2 +-
 src/test/test_hs.c  |  2 +-
 8 files changed, 95 insertions(+), 7 deletions(-)

diff --git a/src/or/control.c b/src/or/control.c
index e7ec23817..cd1be5bf4 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -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
diff --git a/src/or/control.h b/src/or/control.h
index 1744baba2..5a7a87c06 100644
--- a/src/or/control.h
+++ b/src/or/control.h
@@ -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);
diff --git a/src/or/hs_client.c b/src/or/hs_client.c
index 9ac653c72..666860155 100644
--- a/src/or/hs_client.c
+++ b/src/or/hs_client.c
@@ -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
index 000000000..0bcb41dcc
--- /dev/null
+++ b/src/or/hs_control.c
@@ -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
index 000000000..2878ba5bc
--- /dev/null
+++ b/src/or/hs_control.h
@@ -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) */
+
diff --git a/src/or/include.am b/src/or/include.am
index b783f4855..1c66cd2de 100644
--- a/src/or/include.am
+++ b/src/or/include.am
@@ -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				\
diff --git a/src/or/rendclient.c b/src/or/rendclient.c
index eb097a50f..8291e5abf 100644
--- a/src/or/rendclient.c
+++ b/src/or/rendclient.c
@@ -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;
 }
 
diff --git a/src/test/test_hs.c b/src/test/test_hs.c
index 14799c993..55c6218dd 100644
--- a/src/test/test_hs.c
+++ b/src/test/test_hs.c
@@ -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);



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits