Browse Source

hs-v3: Implement HS_DESC CREATED event

This makes the REPLICA= field optional for the control port event. A v2
service will always pass it and v3 is ignored.

Signed-off-by: David Goulet <dgoulet@torproject.org>
David Goulet 6 years ago
parent
commit
b71a9b60cc
4 changed files with 43 additions and 4 deletions
  1. 12 4
      src/or/control.c
  2. 23 0
      src/or/hs_control.c
  3. 4 0
      src/or/hs_control.h
  4. 4 0
      src/or/hs_service.c

+ 12 - 4
src/or/control.c

@@ -7252,21 +7252,29 @@ get_desc_id_from_query(const rend_data_t *rend_data, const char *hsdir_fp)
  *
  * <b>onion_address</b> is service address.
  * <b>desc_id</b> is the descriptor ID.
- * <b>replica</b> is the the descriptor replica number.
+ * <b>replica</b> is the the descriptor replica number. If it is negative, it
+ * is ignored.
  */
 void
 control_event_hs_descriptor_created(const char *onion_address,
                                     const char *desc_id,
                                     int replica)
 {
+  char *replica_field = NULL;
+
   if (BUG(!onion_address || !desc_id)) {
     return;
   }
 
+  if (replica >= 0) {
+    tor_asprintf(&replica_field, " REPLICA=%d", replica);
+  }
+
   send_control_event(EVENT_HS_DESC,
-                     "650 HS_DESC CREATED %s UNKNOWN UNKNOWN %s "
-                     "REPLICA=%d\r\n",
-                     onion_address, desc_id, replica);
+                     "650 HS_DESC CREATED %s UNKNOWN UNKNOWN %s%s\r\n",
+                     onion_address, desc_id,
+                     replica_field ? replica_field : "");
+  tor_free(replica_field);
 }
 
 /** send HS_DESC upload event.

+ 23 - 0
src/or/hs_control.c

@@ -102,3 +102,26 @@ hs_control_desc_event_received(const hs_ident_dir_conn_t *ident,
                                          hsdir_id_digest);
 }
 
+/* Send on the control port the "HS_DESC CREATED [...]" event.
+ *
+ * Using the onion address of the descriptor's service and the blinded public
+ * key of the descriptor as a descriptor ID. None can be NULL. */
+void
+hs_control_desc_event_created(const char *onion_address,
+                              const ed25519_public_key_t *blinded_pk)
+{
+  char base64_blinded_pk[ED25519_BASE64_LEN + 1];
+
+  tor_assert(onion_address);
+  tor_assert(blinded_pk);
+
+  /* Build base64 encoded blinded key. */
+  IF_BUG_ONCE(ed25519_public_to_base64(base64_blinded_pk, blinded_pk) < 0) {
+    return;
+  }
+
+  /* Version 3 doesn't use the replica number in its descriptor ID computation
+   * so we pass negative value so the control port subsystem can ignore it. */
+  control_event_hs_descriptor_created(onion_address, base64_blinded_pk, -1);
+}
+

+ 4 - 0
src/or/hs_control.h

@@ -25,5 +25,9 @@ void hs_control_desc_event_failed(const hs_ident_dir_conn_t *ident,
 void hs_control_desc_event_received(const hs_ident_dir_conn_t *ident,
                                     const char *hsdir_id_digest);
 
+/* Event "HS_DESC CREATED [...]" */
+void hs_control_desc_event_created(const char *onion_address,
+                                   const ed25519_public_key_t *blinded_pk);
+
 #endif /* !defined(TOR_HS_CONTROL_H) */
 

+ 4 - 0
src/or/hs_service.c

@@ -30,6 +30,7 @@
 #include "hs_circuit.h"
 #include "hs_common.h"
 #include "hs_config.h"
+#include "hs_control.h"
 #include "hs_circuit.h"
 #include "hs_descriptor.h"
 #include "hs_ident.h"
@@ -1431,6 +1432,9 @@ build_service_descriptor(hs_service_t *service, time_t now,
 
   /* Assign newly built descriptor to the next slot. */
   *desc_out = desc;
+  /* Fire a CREATED control port event. */
+  hs_control_desc_event_created(service->onion_address,
+                                &desc->blinded_kp.pubkey);
   return;
 
  err: