commit 8365de1da3de53fc02d463d78187625d16a5180b Author: David Goulet dgoulet@torproject.org Date: Fri Nov 10 14:01:33 2017 -0500
hs-v3: Implement HS_DESC FAILED event
A new v3 specific function has been added named control_event_hsv3_descriptor_failed().
The HS v3 subsystem now uses it.
Signed-off-by: David Goulet dgoulet@torproject.org --- src/or/control.c | 27 +++++++++++++++++++++++++++ src/or/control.h | 5 +++++ src/or/directory.c | 14 +++++++++++++- src/or/hs_control.c | 27 +++++++++++++++++++++++++++ src/or/hs_control.h | 7 +++++++ 5 files changed, 79 insertions(+), 1 deletion(-)
diff --git a/src/or/control.c b/src/or/control.c index cd1be5bf4..3ba3a4b3a 100644 --- a/src/or/control.c +++ b/src/or/control.c @@ -7296,6 +7296,7 @@ control_event_hs_descriptor_upload(const char *onion_address, * NOTE: this is an internal function used by following functions: * control_event_hsv2_descriptor_received * control_event_hsv2_descriptor_failed + * control_event_hsv3_descriptor_failed * * So do not call this function directly. */ @@ -7447,6 +7448,32 @@ control_event_hsv2_descriptor_failed(const rend_data_t *rend_data, tor_free(desc_id_field); }
+/** Send HS_DESC event to inform controller that the query to + * <b>onion_address</b> failed to retrieve hidden service descriptor + * <b>desc_id</b> from directory identified by <b>hsdir_id_digest</b>. If + * NULL, "UNKNOWN" is used. If <b>reason</b> is not NULL, add it to REASON= + * field. */ +void +control_event_hsv3_descriptor_failed(const char *onion_address, + const char *desc_id, + const char *hsdir_id_digest, + const char *reason) +{ + char *desc_id_field = NULL; + + if (BUG(!onion_address || !desc_id || !reason)) { + return; + } + + /* Because DescriptorID is an optional positional value, we need to add a + * whitespace before in order to not be next to the HsDir value. */ + tor_asprintf(&desc_id_field, " %s", desc_id); + + event_hs_descriptor_receive_end("FAILED", onion_address, desc_id_field, + REND_NO_AUTH, hsdir_id_digest, reason); + tor_free(desc_id_field); +} + /** Send HS_DESC_CONTENT event after completion of a successful fetch from hs * directory. If <b>hsdir_id_digest</b> is NULL, it is replaced by "UNKNOWN". * If <b>content</b> is NULL, it is replaced by an empty string. The diff --git a/src/or/control.h b/src/or/control.h index 5a7a87c06..4c9adb681 100644 --- a/src/or/control.h +++ b/src/or/control.h @@ -139,6 +139,11 @@ void control_event_hsv2_descriptor_failed(const rend_data_t *rend_data, void control_event_hsv2_descriptor_received(const char *onion_address, const rend_data_t *rend_data, const char *id_digest); +/* Hidden service v3 HS_DESC specific. */ +void control_event_hsv3_descriptor_failed(const char *onion_address, + const char *desc_id, + const char *hsdir_id_digest, + const char *reason); void control_event_hs_descriptor_upload_failed(const char *hs_dir, const char *onion_address, const char *reason); diff --git a/src/or/directory.c b/src/or/directory.c index 884ec2555..1b6f7500b 100644 --- a/src/or/directory.c +++ b/src/or/directory.c @@ -25,6 +25,7 @@ #include "geoip.h" #include "hs_cache.h" #include "hs_common.h" +#include "hs_control.h" #include "hs_client.h" #include "main.h" #include "microdesc.h" @@ -3090,6 +3091,9 @@ handle_response_fetch_hsdesc_v3(dir_connection_t *conn, /* We got something: Try storing it in the cache. */ if (hs_cache_store_as_client(body, &conn->hs_ident->identity_pk) < 0) { log_warn(LD_REND, "Failed to store hidden service descriptor"); + /* Fire control port FAILED event. */ + hs_control_desc_event_failed(conn->hs_ident, conn->identity_digest, + "BAD_DESC"); } else { log_info(LD_REND, "Stored hidden service descriptor successfully."); TO_CONN(conn)->purpose = DIR_PURPOSE_HAS_FETCHED_HSDESC; @@ -3101,13 +3105,18 @@ handle_response_fetch_hsdesc_v3(dir_connection_t *conn, * tries to clean this conn up. */ log_info(LD_REND, "Fetching hidden service v3 descriptor not found: " "Retrying at another directory."); - /* TODO: Inform the control port */ + /* Fire control port FAILED event. */ + hs_control_desc_event_failed(conn->hs_ident, conn->identity_digest, + "NOT_FOUND"); break; case 400: log_warn(LD_REND, "Fetching v3 hidden service descriptor failed: " "http status 400 (%s). Dirserver didn't like our " "query? Retrying at another directory.", escaped(reason)); + /* Fire control port FAILED event. */ + hs_control_desc_event_failed(conn->hs_ident, conn->identity_digest, + "QUERY_REJECTED"); break; default: log_warn(LD_REND, "Fetching v3 hidden service descriptor failed: " @@ -3115,6 +3124,9 @@ handle_response_fetch_hsdesc_v3(dir_connection_t *conn, "'%s:%d'. Retrying at another directory.", status_code, escaped(reason), TO_CONN(conn)->address, TO_CONN(conn)->port); + /* Fire control port FAILED event. */ + hs_control_desc_event_failed(conn->hs_ident, conn->identity_digest, + "UNEXPECTED"); break; }
diff --git a/src/or/hs_control.c b/src/or/hs_control.c index 0bcb41dcc..ed77c8e1d 100644 --- a/src/or/hs_control.c +++ b/src/or/hs_control.c @@ -50,3 +50,30 @@ hs_control_desc_event_requested(const ed25519_public_key_t *onion_pk, memwipe(onion_address, 0, sizeof(onion_address)); }
+/* Send on the control port the "HS_DESC FAILED [...]" event. + * + * Using a directory connection identifier, the HSDir identity digest and a + * reason for the failure. None can be NULL. */ +void +hs_control_desc_event_failed(const hs_ident_dir_conn_t *ident, + const char *hsdir_id_digest, + const char *reason) +{ + char onion_address[HS_SERVICE_ADDR_LEN_BASE32 + 1]; + char base64_blinded_pk[ED25519_BASE64_LEN + 1]; + + tor_assert(ident); + tor_assert(hsdir_id_digest); + tor_assert(reason); + + /* Build onion address and encoded blinded key. */ + IF_BUG_ONCE(ed25519_public_to_base64(base64_blinded_pk, + &ident->blinded_pk) < 0) { + return; + } + hs_build_address(&ident->identity_pk, HS_VERSION_THREE, onion_address); + + control_event_hsv3_descriptor_failed(onion_address, base64_blinded_pk, + hsdir_id_digest, reason); +} + diff --git a/src/or/hs_control.h b/src/or/hs_control.h index 2878ba5bc..fb8f3859f 100644 --- a/src/or/hs_control.h +++ b/src/or/hs_control.h @@ -9,10 +9,17 @@ #ifndef TOR_HS_CONTROL_H #define TOR_HS_CONTROL_H
+#include "hs_ident.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);
+/* Event "HS_DESC FAILED [...]" */ +void hs_control_desc_event_failed(const hs_ident_dir_conn_t *ident, + const char *hsdir_id_digest, + const char *reason); + #endif /* !defined(TOR_HS_CONTROL_H) */