mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-03 00:53:32 +01:00
prop224: Remove INTRODUCE2 legacy handling
Turns out that introduction points don't care about the INTRODUCE2 cell format as long as the top field is LEGACY_KEY_ID as expected. So let's use a single INTRODUCE format regardless of the introduction point being legacy or not. This also removes the polymorphic void* situation. Signed-off-by: David Goulet <dgoulet@torproject.org>
This commit is contained in:
parent
ec0da9a6f1
commit
708789025d
105
src/or/hs_cell.c
105
src/or/hs_cell.c
@ -208,100 +208,35 @@ build_legacy_establish_intro(const char *circ_nonce, crypto_pk_t *enc_key,
|
|||||||
return cell_len;
|
return cell_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Free the given cell pointer. If is_legacy_cell is set, cell_ptr is cast to
|
|
||||||
* a rend_intro_cell_t else to a trn_cell_introduce1_t. */
|
|
||||||
static void
|
|
||||||
introduce2_free_cell(void *cell_ptr, unsigned int is_legacy_cell)
|
|
||||||
{
|
|
||||||
if (cell_ptr == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (is_legacy_cell) {
|
|
||||||
rend_intro_cell_t *legacy_cell = cell_ptr;
|
|
||||||
rend_service_free_intro(legacy_cell);
|
|
||||||
} else {
|
|
||||||
trn_cell_introduce1_free((trn_cell_introduce1_t *) cell_ptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Return the length of the encrypted section of the cell_ptr. If
|
|
||||||
* is_legacy_cell is set, cell_ptr is cast to a rend_intro_cell_t else to a
|
|
||||||
* trn_cell_introduce1_t. */
|
|
||||||
static size_t
|
|
||||||
get_introduce2_encrypted_section_len(const void *cell_ptr,
|
|
||||||
unsigned int is_legacy_cell)
|
|
||||||
{
|
|
||||||
tor_assert(cell_ptr);
|
|
||||||
if (is_legacy_cell) {
|
|
||||||
return ((const rend_intro_cell_t *) cell_ptr)->ciphertext_len;
|
|
||||||
}
|
|
||||||
return trn_cell_introduce1_getlen_encrypted(
|
|
||||||
(const trn_cell_introduce1_t *) cell_ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Return the encrypted section pointer from the the cell_ptr. If
|
|
||||||
* is_legacy_cell is set, cell_ptr is cast to a rend_intro_cell_t else to a
|
|
||||||
* trn_cell_introduce1_t. */
|
|
||||||
static const uint8_t *
|
|
||||||
get_introduce2_encrypted_section(const void *cell_ptr,
|
|
||||||
unsigned int is_legacy_cell)
|
|
||||||
{
|
|
||||||
tor_assert(cell_ptr);
|
|
||||||
if (is_legacy_cell) {
|
|
||||||
return ((const rend_intro_cell_t *) cell_ptr)->ciphertext;
|
|
||||||
}
|
|
||||||
return trn_cell_introduce1_getconstarray_encrypted(
|
|
||||||
(const trn_cell_introduce1_t *) cell_ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Parse an INTRODUCE2 cell from payload of size payload_len for the given
|
/* Parse an INTRODUCE2 cell from payload of size payload_len for the given
|
||||||
* service and circuit which are used only for logging purposes. The resulting
|
* service and circuit which are used only for logging purposes. The resulting
|
||||||
* parsed cell is put in cell_ptr_out. If is_legacy_cell is set, the type of
|
* parsed cell is put in cell_ptr_out.
|
||||||
* the returned cell is rend_intro_cell_t else trn_cell_introduce1_t.
|
|
||||||
*
|
*
|
||||||
* Return 0 on success else a negative value and cell_ptr_out is untouched. */
|
* Return 0 on success else a negative value and cell_ptr_out is untouched. */
|
||||||
static int
|
static int
|
||||||
parse_introduce2_cell(const hs_service_t *service,
|
parse_introduce2_cell(const hs_service_t *service,
|
||||||
const origin_circuit_t *circ, const uint8_t *payload,
|
const origin_circuit_t *circ, const uint8_t *payload,
|
||||||
size_t payload_len, unsigned int is_legacy_cell,
|
size_t payload_len,
|
||||||
void **cell_ptr_out)
|
trn_cell_introduce1_t **cell_ptr_out)
|
||||||
{
|
{
|
||||||
|
trn_cell_introduce1_t *cell = NULL;
|
||||||
|
|
||||||
tor_assert(service);
|
tor_assert(service);
|
||||||
tor_assert(circ);
|
tor_assert(circ);
|
||||||
tor_assert(payload);
|
tor_assert(payload);
|
||||||
tor_assert(cell_ptr_out);
|
tor_assert(cell_ptr_out);
|
||||||
|
|
||||||
/* We parse the cell differently for legacy. */
|
/* Parse the cell so we can start cell validation. */
|
||||||
if (is_legacy_cell) {
|
if (trn_cell_introduce1_parse(&cell, payload, payload_len) < 0) {
|
||||||
char *err_msg;
|
log_info(LD_PROTOCOL, "Unable to parse INTRODUCE2 cell on circuit %u "
|
||||||
rend_intro_cell_t *legacy_cell = NULL;
|
"for service %s",
|
||||||
|
TO_CIRCUIT(circ)->n_circ_id,
|
||||||
legacy_cell = rend_service_begin_parse_intro(payload, payload_len, 2,
|
safe_str_client(service->onion_address));
|
||||||
&err_msg);
|
goto err;
|
||||||
if (legacy_cell == NULL) {
|
|
||||||
log_info(LD_REND, "Unable to parse legacy INTRODUCE2 cell on "
|
|
||||||
"circuit %u for service %s: %s",
|
|
||||||
TO_CIRCUIT(circ)->n_circ_id, err_msg,
|
|
||||||
safe_str_client(service->onion_address));
|
|
||||||
tor_free(err_msg);
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
*cell_ptr_out = legacy_cell;
|
|
||||||
} else {
|
|
||||||
trn_cell_introduce1_t *cell = NULL;
|
|
||||||
/* Parse the cell so we can start cell validation. */
|
|
||||||
if (trn_cell_introduce1_parse(&cell, payload, payload_len) < 0) {
|
|
||||||
log_info(LD_PROTOCOL, "Unable to parse INTRODUCE2 cell on circuit %u "
|
|
||||||
"for service %s",
|
|
||||||
TO_CIRCUIT(circ)->n_circ_id,
|
|
||||||
safe_str_client(service->onion_address));
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
*cell_ptr_out = cell;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* On success, we must have set the cell pointer. */
|
/* Success. */
|
||||||
tor_assert(*cell_ptr_out);
|
*cell_ptr_out = cell;
|
||||||
return 0;
|
return 0;
|
||||||
err:
|
err:
|
||||||
return -1;
|
return -1;
|
||||||
@ -465,9 +400,9 @@ hs_cell_parse_introduce2(hs_cell_introduce2_data_t *data,
|
|||||||
uint8_t *decrypted = NULL;
|
uint8_t *decrypted = NULL;
|
||||||
size_t encrypted_section_len;
|
size_t encrypted_section_len;
|
||||||
const uint8_t *encrypted_section;
|
const uint8_t *encrypted_section;
|
||||||
|
trn_cell_introduce1_t *cell = NULL;
|
||||||
trn_cell_introduce_encrypted_t *enc_cell = NULL;
|
trn_cell_introduce_encrypted_t *enc_cell = NULL;
|
||||||
hs_ntor_intro_cell_keys_t *intro_keys = NULL;
|
hs_ntor_intro_cell_keys_t *intro_keys = NULL;
|
||||||
void *cell_ptr = NULL;
|
|
||||||
|
|
||||||
tor_assert(data);
|
tor_assert(data);
|
||||||
tor_assert(circ);
|
tor_assert(circ);
|
||||||
@ -475,7 +410,7 @@ hs_cell_parse_introduce2(hs_cell_introduce2_data_t *data,
|
|||||||
|
|
||||||
/* Parse the cell into a decoded data structure pointed by cell_ptr. */
|
/* Parse the cell into a decoded data structure pointed by cell_ptr. */
|
||||||
if (parse_introduce2_cell(service, circ, data->payload, data->payload_len,
|
if (parse_introduce2_cell(service, circ, data->payload, data->payload_len,
|
||||||
data->is_legacy, &cell_ptr) < 0) {
|
&cell) < 0) {
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -484,10 +419,8 @@ hs_cell_parse_introduce2(hs_cell_introduce2_data_t *data,
|
|||||||
TO_CIRCUIT(circ)->n_circ_id,
|
TO_CIRCUIT(circ)->n_circ_id,
|
||||||
safe_str_client(service->onion_address));
|
safe_str_client(service->onion_address));
|
||||||
|
|
||||||
encrypted_section =
|
encrypted_section = trn_cell_introduce1_getconstarray_encrypted(cell);
|
||||||
get_introduce2_encrypted_section(cell_ptr, data->is_legacy);
|
encrypted_section_len = trn_cell_introduce1_getlen_encrypted(cell);
|
||||||
encrypted_section_len =
|
|
||||||
get_introduce2_encrypted_section_len(cell_ptr, data->is_legacy);
|
|
||||||
|
|
||||||
/* Encrypted section must at least contain the CLIENT_PK and MAC which is
|
/* Encrypted section must at least contain the CLIENT_PK and MAC which is
|
||||||
* defined in section 3.3.2 of the specification. */
|
* defined in section 3.3.2 of the specification. */
|
||||||
@ -603,7 +536,7 @@ hs_cell_parse_introduce2(hs_cell_introduce2_data_t *data,
|
|||||||
}
|
}
|
||||||
tor_free(decrypted);
|
tor_free(decrypted);
|
||||||
trn_cell_introduce_encrypted_free(enc_cell);
|
trn_cell_introduce_encrypted_free(enc_cell);
|
||||||
introduce2_free_cell(cell_ptr, data->is_legacy);
|
trn_cell_introduce1_free(cell);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,8 +34,6 @@ typedef struct hs_cell_introduce2_data_t {
|
|||||||
const uint8_t *payload;
|
const uint8_t *payload;
|
||||||
/* Size of the payload of the received encoded cell. */
|
/* Size of the payload of the received encoded cell. */
|
||||||
size_t payload_len;
|
size_t payload_len;
|
||||||
/* Is this a legacy introduction point? */
|
|
||||||
unsigned int is_legacy : 1;
|
|
||||||
|
|
||||||
/*** Muttable Section. ***/
|
/*** Muttable Section. ***/
|
||||||
|
|
||||||
|
@ -945,7 +945,6 @@ hs_circ_handle_introduce2(const hs_service_t *service,
|
|||||||
data.payload = payload;
|
data.payload = payload;
|
||||||
data.payload_len = payload_len;
|
data.payload_len = payload_len;
|
||||||
data.link_specifiers = smartlist_new();
|
data.link_specifiers = smartlist_new();
|
||||||
data.is_legacy = ip->base.is_only_legacy;
|
|
||||||
data.replay_cache = ip->replay_cache;
|
data.replay_cache = ip->replay_cache;
|
||||||
|
|
||||||
if (hs_cell_parse_introduce2(&data, circ, service) < 0) {
|
if (hs_cell_parse_introduce2(&data, circ, service) < 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user