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

[tor-commits] [tor/master] Add version 3 onion service support to HSFETCH



commit c985940de9ec743cbb3e9a3e32fd482bd859c9ed
Author: Neel Chauhan <neel@xxxxxxxxx>
Date:   Mon Jan 14 14:09:53 2019 -0500

    Add version 3 onion service support to HSFETCH
---
 changes/ticket25417           |  4 ++++
 src/feature/control/control.c | 26 ++++++++++++++++++++------
 src/feature/hs/hs_client.c    | 18 ++++++++++++++++++
 src/feature/hs/hs_client.h    |  4 ++++
 src/feature/hs/hs_control.c   | 14 ++++++++++++++
 src/feature/hs/hs_control.h   |  4 ++++
 6 files changed, 64 insertions(+), 6 deletions(-)

diff --git a/changes/ticket25417 b/changes/ticket25417
new file mode 100644
index 000000000..41f2acc98
--- /dev/null
+++ b/changes/ticket25417
@@ -0,0 +1,4 @@
+  o Minor features (controller):
+    - Add onion service version 3 support to HSFETCH. Previously, only
+      version 2 onion services were supported. Closes ticket 25417.
+      Patch by Neel Chauhan
diff --git a/src/feature/control/control.c b/src/feature/control/control.c
index 170037e06..d7299a4cf 100644
--- a/src/feature/control/control.c
+++ b/src/feature/control/control.c
@@ -4426,6 +4426,8 @@ handle_control_hsfetch(control_connection_t *conn, uint32_t len,
   static const char *v2_str = "v2-";
   const size_t v2_str_len = strlen(v2_str);
   rend_data_t *rend_query = NULL;
+  ed25519_public_key_t v3_pk;
+  uint32_t version;
 
   /* Make sure we have at least one argument, the HSAddress. */
   args = getargs_helper(hsfetch_command, conn, body, 1, -1);
@@ -4438,6 +4440,7 @@ handle_control_hsfetch(control_connection_t *conn, uint32_t len,
   /* Test if it's an HS address without the .onion part. */
   if (rend_valid_v2_service_id(arg1)) {
     hsaddress = arg1;
+    version = HS_VERSION_TWO;
   } else if (strcmpstart(arg1, v2_str) == 0 &&
              rend_valid_descriptor_id(arg1 + v2_str_len) &&
              base32_decode(digest, sizeof(digest), arg1 + v2_str_len,
@@ -4445,6 +4448,11 @@ handle_control_hsfetch(control_connection_t *conn, uint32_t len,
     /* We have a well formed version 2 descriptor ID. Keep the decoded value
      * of the id. */
     desc_id = digest;
+    version = HS_VERSION_TWO;
+  } else if (hs_address_is_valid(arg1)) {
+    hsaddress = arg1;
+    version = HS_VERSION_THREE;
+    hs_parse_address(hsaddress, &v3_pk, NULL, NULL);
   } else {
     connection_printf_to_buf(conn, "513 Invalid argument \"%s\"\r\n",
                              arg1);
@@ -4481,11 +4489,13 @@ handle_control_hsfetch(control_connection_t *conn, uint32_t len,
     }
   }
 
-  rend_query = rend_data_client_create(hsaddress, desc_id, NULL,
-                                       REND_NO_AUTH);
-  if (rend_query == NULL) {
-    connection_printf_to_buf(conn, "551 Error creating the HS query\r\n");
-    goto done;
+  if (version == HS_VERSION_TWO) {
+    rend_query = rend_data_client_create(hsaddress, desc_id, NULL,
+                                         REND_NO_AUTH);
+    if (rend_query == NULL) {
+      connection_printf_to_buf(conn, "551 Error creating the HS query\r\n");
+      goto done;
+    }
   }
 
   /* Using a descriptor ID, we force the user to provide at least one
@@ -4504,7 +4514,11 @@ handle_control_hsfetch(control_connection_t *conn, uint32_t len,
   /* Trigger the fetch using the built rend query and possibly a list of HS
    * directory to use. This function ignores the client cache thus this will
    * always send a fetch command. */
-  rend_client_fetch_v2_desc(rend_query, hsdirs);
+  if (version == HS_VERSION_TWO) {
+    rend_client_fetch_v2_desc(rend_query, hsdirs);
+  } else if (version == HS_VERSION_THREE) {
+    hs_control_hsfetch_command(&v3_pk, hsdirs);
+  }
 
  done:
   SMARTLIST_FOREACH(args, char *, cp, tor_free(cp));
diff --git a/src/feature/hs/hs_client.c b/src/feature/hs/hs_client.c
index 5fded92fe..7dc856ae5 100644
--- a/src/feature/hs/hs_client.c
+++ b/src/feature/hs/hs_client.c
@@ -459,6 +459,24 @@ fetch_v3_desc, (const ed25519_public_key_t *onion_identity_pk))
   return directory_launch_v3_desc_fetch(onion_identity_pk, hsdir_rs);
 }
 
+/* With a given <b>onion_identity_pk</b>, fetch its descriptor. If
+ * <b>hsdirs</b> is specified, use the directory servers specified in the list.
+ * Else, use a random server. */
+void
+hs_client_launch_v3_desc_fetch(const ed25519_public_key_t *onion_identity_pk,
+                               const smartlist_t *hsdirs)
+{
+  tor_assert(onion_identity_pk);
+
+  if (hsdirs != NULL) {
+    SMARTLIST_FOREACH_BEGIN(hsdirs, const routerstatus_t *, hsdir) {
+      directory_launch_v3_desc_fetch(onion_identity_pk, hsdir);
+    } SMARTLIST_FOREACH_END(hsdir);
+  } else {
+    fetch_v3_desc(onion_identity_pk);
+  }
+}
+
 /* Make sure that the given v3 origin circuit circ is a valid correct
  * introduction circuit. This will BUG() on any problems and hard assert if
  * the anonymity of the circuit is not ok. Return 0 on success else -1 where
diff --git a/src/feature/hs/hs_client.h b/src/feature/hs/hs_client.h
index f6fb167ea..47c525242 100644
--- a/src/feature/hs/hs_client.h
+++ b/src/feature/hs/hs_client.h
@@ -44,6 +44,10 @@ typedef struct hs_client_service_authorization_t {
 void hs_client_note_connection_attempt_succeeded(
                                        const edge_connection_t *conn);
 
+void hs_client_launch_v3_desc_fetch(
+                               const ed25519_public_key_t *onion_identity_pk,
+                               const smartlist_t *hsdirs);
+
 int hs_client_decode_descriptor(
                      const char *desc_str,
                      const ed25519_public_key_t *service_identity_pk,
diff --git a/src/feature/hs/hs_control.c b/src/feature/hs/hs_control.c
index a21788ecd..df8c1958b 100644
--- a/src/feature/hs/hs_control.c
+++ b/src/feature/hs/hs_control.c
@@ -10,6 +10,7 @@
 #include "feature/control/control.h"
 #include "lib/crypt_ops/crypto_format.h"
 #include "lib/crypt_ops/crypto_util.h"
+#include "feature/hs/hs_client.h"
 #include "feature/hs/hs_common.h"
 #include "feature/hs/hs_control.h"
 #include "feature/hs/hs_descriptor.h"
@@ -259,3 +260,16 @@ hs_control_hspost_command(const char *body, const char *onion_address,
   smartlist_free(hsdirs);
   return ret;
 }
+
+/* With a given <b>onion_identity_pk</b>, fetch its descriptor, optionally
+ * using the list of directory servers given in <b>hsdirs</b>, or a random
+ * server if it is NULL. This function calls hs_client_launch_v3_desc_fetch().
+ */
+void
+hs_control_hsfetch_command(const ed25519_public_key_t *onion_identity_pk,
+                           const smartlist_t *hsdirs)
+{
+  tor_assert(onion_identity_pk);
+
+  hs_client_launch_v3_desc_fetch(onion_identity_pk, hsdirs);
+}
diff --git a/src/feature/hs/hs_control.h b/src/feature/hs/hs_control.h
index 63e3fe13d..2f5dcd215 100644
--- a/src/feature/hs/hs_control.h
+++ b/src/feature/hs/hs_control.h
@@ -48,5 +48,9 @@ void hs_control_desc_event_content(const hs_ident_dir_conn_t *ident,
 int hs_control_hspost_command(const char *body, const char *onion_address,
                               const smartlist_t *hsdirs_rs);
 
+/* Command "HSFETCH [...]" */
+void hs_control_hsfetch_command(const ed25519_public_key_t *onion_identity_pk,
+                                const smartlist_t *hsdirs);
+
 #endif /* !defined(TOR_HS_CONTROL_H) */
 



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