mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-25 15:10:48 +01:00
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@torproject.org>
This commit is contained in:
parent
e7d606900e
commit
743d0b9d91
8 changed files with 95 additions and 7 deletions
|
@ -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>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>hs_dir</b> is the description of contacting hs directory.
|
||||||
* <b>desc_id_base32</b> is the ID of requested hs descriptor.
|
* <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
|
void
|
||||||
control_event_hs_descriptor_requested(const char *onion_address,
|
control_event_hs_descriptor_requested(const char *onion_address,
|
||||||
rend_auth_type_t auth_type,
|
rend_auth_type_t auth_type,
|
||||||
const char *id_digest,
|
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)) {
|
if (BUG(!id_digest || !desc_id)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (hsdir_index) {
|
||||||
|
tor_asprintf(&hsdir_index_field, " HSDIR_INDEX=%s", hsdir_index);
|
||||||
|
}
|
||||||
|
|
||||||
send_control_event(EVENT_HS_DESC,
|
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_hsaddress_str_or_unknown(onion_address),
|
||||||
rend_auth_type_to_string(auth_type),
|
rend_auth_type_to_string(auth_type),
|
||||||
node_describe_longname_by_id(id_digest),
|
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
|
/** For an HS descriptor query <b>rend_data</b>, using the
|
||||||
|
|
|
@ -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,
|
void control_event_hs_descriptor_requested(const char *onion_address,
|
||||||
rend_auth_type_t auth_type,
|
rend_auth_type_t auth_type,
|
||||||
const char *id_digest,
|
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,
|
void control_event_hs_descriptor_created(const char *onion_address,
|
||||||
const char *desc_id,
|
const char *desc_id,
|
||||||
int replica);
|
int replica);
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "directory.h"
|
#include "directory.h"
|
||||||
#include "hs_client.h"
|
#include "hs_client.h"
|
||||||
|
#include "hs_control.h"
|
||||||
#include "router.h"
|
#include "router.h"
|
||||||
#include "routerset.h"
|
#include "routerset.h"
|
||||||
#include "circuitlist.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(base64_blinded_pubkey),
|
||||||
safe_str_client(routerstatus_describe(hsdir)));
|
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. */
|
/* Cleanup memory. */
|
||||||
memwipe(&blinded_pubkey, 0, sizeof(blinded_pubkey));
|
memwipe(&blinded_pubkey, 0, sizeof(blinded_pubkey));
|
||||||
memwipe(base64_blinded_pubkey, 0, sizeof(base64_blinded_pubkey));
|
memwipe(base64_blinded_pubkey, 0, sizeof(base64_blinded_pubkey));
|
||||||
|
|
52
src/or/hs_control.c
Normal file
52
src/or/hs_control.c
Normal file
|
@ -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));
|
||||||
|
}
|
||||||
|
|
18
src/or/hs_control.h
Normal file
18
src/or/hs_control.h
Normal file
|
@ -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) */
|
||||||
|
|
|
@ -60,6 +60,7 @@ LIBTOR_A_SOURCES = \
|
||||||
src/or/hs_client.c \
|
src/or/hs_client.c \
|
||||||
src/or/hs_common.c \
|
src/or/hs_common.c \
|
||||||
src/or/hs_config.c \
|
src/or/hs_config.c \
|
||||||
|
src/or/hs_control.c \
|
||||||
src/or/hs_descriptor.c \
|
src/or/hs_descriptor.c \
|
||||||
src/or/hs_ident.c \
|
src/or/hs_ident.c \
|
||||||
src/or/hs_intropoint.c \
|
src/or/hs_intropoint.c \
|
||||||
|
@ -196,11 +197,12 @@ ORHEADERS = \
|
||||||
src/or/hibernate.h \
|
src/or/hibernate.h \
|
||||||
src/or/hs_cache.h \
|
src/or/hs_cache.h \
|
||||||
src/or/hs_cell.h \
|
src/or/hs_cell.h \
|
||||||
src/or/hs_config.h \
|
|
||||||
src/or/hs_circuit.h \
|
src/or/hs_circuit.h \
|
||||||
src/or/hs_circuitmap.h \
|
src/or/hs_circuitmap.h \
|
||||||
src/or/hs_client.h \
|
src/or/hs_client.h \
|
||||||
src/or/hs_common.h \
|
src/or/hs_common.h \
|
||||||
|
src/or/hs_config.h \
|
||||||
|
src/or/hs_control.h \
|
||||||
src/or/hs_descriptor.h \
|
src/or/hs_descriptor.h \
|
||||||
src/or/hs_ident.h \
|
src/or/hs_ident.h \
|
||||||
src/or/hs_intropoint.h \
|
src/or/hs_intropoint.h \
|
||||||
|
|
|
@ -519,7 +519,7 @@ directory_get_from_hs_dir(const char *desc_id,
|
||||||
control_event_hs_descriptor_requested(rend_data->onion_address,
|
control_event_hs_descriptor_requested(rend_data->onion_address,
|
||||||
rend_data->auth_type,
|
rend_data->auth_type,
|
||||||
hs_dir->identity_digest,
|
hs_dir->identity_digest,
|
||||||
desc_id_base32);
|
desc_id_base32, NULL);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -260,7 +260,7 @@ test_hs_desc_event(void *arg)
|
||||||
/* test request event */
|
/* test request event */
|
||||||
control_event_hs_descriptor_requested(rend_query.onion_address,
|
control_event_hs_descriptor_requested(rend_query.onion_address,
|
||||||
rend_query.auth_type, HSDIR_EXIST_ID,
|
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 "\
|
expected_msg = "650 HS_DESC REQUESTED "STR_HS_ADDR" NO_AUTH "\
|
||||||
STR_HSDIR_EXIST_LONGNAME " " STR_DESC_ID_BASE32 "\r\n";
|
STR_HSDIR_EXIST_LONGNAME " " STR_DESC_ID_BASE32 "\r\n";
|
||||||
tt_assert(received_msg);
|
tt_assert(received_msg);
|
||||||
|
|
Loading…
Add table
Reference in a new issue