tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

commit 3b436d495fc6ad59ff5d9406d7ef17494286c299
parent 8365de1da3de53fc02d463d78187625d16a5180b
Author: David Goulet <dgoulet@torproject.org>
Date:   Fri, 10 Nov 2017 14:12:34 -0500

hs-v3: Implement HS_DESC RECEIVED event

Adds a v3 specific function to handle a received event.

Signed-off-by: David Goulet <dgoulet@torproject.org>

Diffstat:
Msrc/or/control.c | 23+++++++++++++++++++++++
Msrc/or/control.h | 3+++
Msrc/or/directory.c | 2++
Msrc/or/hs_control.c | 25+++++++++++++++++++++++++
Msrc/or/hs_control.h | 4++++
5 files changed, 57 insertions(+), 0 deletions(-)

diff --git a/src/or/control.c b/src/or/control.c @@ -7398,6 +7398,29 @@ control_event_hsv2_descriptor_received(const char *onion_address, tor_free(desc_id_field); } +/* Send HS_DESC RECEIVED event + * + * Called when we successfully received a hidden service descriptor. */ +void +control_event_hsv3_descriptor_received(const char *onion_address, + const char *desc_id, + const char *hsdir_id_digest) +{ + char *desc_id_field = NULL; + + if (BUG(!onion_address || !desc_id || !hsdir_id_digest)) { + 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("RECEIVED", onion_address, desc_id_field, + REND_NO_AUTH, hsdir_id_digest, NULL); + tor_free(desc_id_field); +} + /** send HS_DESC UPLOADED event * * called when we successfully uploaded a hidden service descriptor. diff --git a/src/or/control.h b/src/or/control.h @@ -144,6 +144,9 @@ 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_hsv3_descriptor_received(const char *onion_address, + const char *desc_id, + const char *hsdir_id_digest); 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 @@ -3098,6 +3098,8 @@ handle_response_fetch_hsdesc_v3(dir_connection_t *conn, log_info(LD_REND, "Stored hidden service descriptor successfully."); TO_CONN(conn)->purpose = DIR_PURPOSE_HAS_FETCHED_HSDESC; hs_client_desc_has_arrived(conn->hs_ident); + /* Fire control port RECEIVED event. */ + hs_control_desc_event_received(conn->hs_ident, conn->identity_digest); } break; case 404: diff --git a/src/or/hs_control.c b/src/or/hs_control.c @@ -77,3 +77,28 @@ hs_control_desc_event_failed(const hs_ident_dir_conn_t *ident, hsdir_id_digest, reason); } +/* Send on the control port the "HS_DESC RECEIVED [...]" event. + * + * Using a directory connection identifier and the HSDir identity digest. + * None can be NULL. */ +void +hs_control_desc_event_received(const hs_ident_dir_conn_t *ident, + const char *hsdir_id_digest) +{ + 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); + + /* 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_received(onion_address, base64_blinded_pk, + hsdir_id_digest); +} + diff --git a/src/or/hs_control.h b/src/or/hs_control.h @@ -21,5 +21,9 @@ void hs_control_desc_event_failed(const hs_ident_dir_conn_t *ident, const char *hsdir_id_digest, const char *reason); +/* Event "HS_DESC RECEIVED [...]" */ +void hs_control_desc_event_received(const hs_ident_dir_conn_t *ident, + const char *hsdir_id_digest); + #endif /* !defined(TOR_HS_CONTROL_H) */