Skip to content

Commit

Permalink
hs-v3: Make all descriptor content free functions public
Browse files Browse the repository at this point in the history
Series of functions that we now need in hs_service.c.

Signed-off-by: David Goulet <dgoulet@torproject.org>
  • Loading branch information
ppopth authored and dgoulet-tor committed Sep 7, 2018
1 parent 53dd169 commit 3b08b23
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 66 deletions.
128 changes: 64 additions & 64 deletions src/feature/hs/hs_descriptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,62 +152,6 @@ static token_rule_t hs_desc_intro_point_v3_token_table[] = {
END_OF_TABLE
};

/* Free the content of the plaintext section of a descriptor. */
STATIC void
desc_plaintext_data_free_contents(hs_desc_plaintext_data_t *desc)
{
if (!desc) {
return;
}

if (desc->superencrypted_blob) {
tor_free(desc->superencrypted_blob);
}
tor_cert_free(desc->signing_key_cert);

memwipe(desc, 0, sizeof(*desc));
}

/* Free the content of the superencrypted section of a descriptor. */
static void
desc_superencrypted_data_free_contents(hs_desc_superencrypted_data_t *desc)
{
if (!desc) {
return;
}

if (desc->encrypted_blob) {
tor_free(desc->encrypted_blob);
}
if (desc->clients) {
SMARTLIST_FOREACH(desc->clients, hs_desc_authorized_client_t *, client,
hs_desc_authorized_client_free(client));
smartlist_free(desc->clients);
}

memwipe(desc, 0, sizeof(*desc));
}

/* Free the content of the encrypted section of a descriptor. */
static void
desc_encrypted_data_free_contents(hs_desc_encrypted_data_t *desc)
{
if (!desc) {
return;
}

if (desc->intro_auth_types) {
SMARTLIST_FOREACH(desc->intro_auth_types, char *, a, tor_free(a));
smartlist_free(desc->intro_auth_types);
}
if (desc->intro_points) {
SMARTLIST_FOREACH(desc->intro_points, hs_desc_intro_point_t *, ip,
hs_desc_intro_point_free(ip));
smartlist_free(desc->intro_points);
}
memwipe(desc, 0, sizeof(*desc));
}

/* Using a key, salt and encrypted payload, build a MAC and put it in mac_out.
* We use SHA3-256 for the MAC computation.
* This function can't fail. */
Expand Down Expand Up @@ -2288,7 +2232,7 @@ desc_decode_superencrypted_v3(const hs_descriptor_t *desc,

err:
tor_assert(ret < 0);
desc_superencrypted_data_free_contents(desc_superencrypted_out);
hs_desc_superencrypted_data_free_contents(desc_superencrypted_out);

done:
if (tokens) {
Expand Down Expand Up @@ -2388,7 +2332,7 @@ desc_decode_encrypted_v3(const hs_descriptor_t *desc,

err:
tor_assert(ret < 0);
desc_encrypted_data_free_contents(desc_encrypted_out);
hs_desc_encrypted_data_free_contents(desc_encrypted_out);

done:
if (tokens) {
Expand Down Expand Up @@ -2723,27 +2667,83 @@ hs_desc_encode_descriptor,(const hs_descriptor_t *desc,
return ret;
}

/* Free the content of the plaintext section of a descriptor. */
void
hs_desc_plaintext_data_free_contents(hs_desc_plaintext_data_t *desc)
{
if (!desc) {
return;
}

if (desc->superencrypted_blob) {
tor_free(desc->superencrypted_blob);
}
tor_cert_free(desc->signing_key_cert);

memwipe(desc, 0, sizeof(*desc));
}

/* Free the content of the superencrypted section of a descriptor. */
void
hs_desc_superencrypted_data_free_contents(hs_desc_superencrypted_data_t *desc)
{
if (!desc) {
return;
}

if (desc->encrypted_blob) {
tor_free(desc->encrypted_blob);
}
if (desc->clients) {
SMARTLIST_FOREACH(desc->clients, hs_desc_authorized_client_t *, client,
hs_desc_authorized_client_free(client));
smartlist_free(desc->clients);
}

memwipe(desc, 0, sizeof(*desc));
}

/* Free the content of the encrypted section of a descriptor. */
void
hs_desc_encrypted_data_free_contents(hs_desc_encrypted_data_t *desc)
{
if (!desc) {
return;
}

if (desc->intro_auth_types) {
SMARTLIST_FOREACH(desc->intro_auth_types, char *, a, tor_free(a));
smartlist_free(desc->intro_auth_types);
}
if (desc->intro_points) {
SMARTLIST_FOREACH(desc->intro_points, hs_desc_intro_point_t *, ip,
hs_desc_intro_point_free(ip));
smartlist_free(desc->intro_points);
}
memwipe(desc, 0, sizeof(*desc));
}

/* Free the descriptor plaintext data object. */
void
hs_desc_plaintext_data_free_(hs_desc_plaintext_data_t *desc)
{
desc_plaintext_data_free_contents(desc);
hs_desc_plaintext_data_free_contents(desc);
tor_free(desc);
}

/* Free the descriptor plaintext data object. */
void
hs_desc_superencrypted_data_free_(hs_desc_superencrypted_data_t *desc)
{
desc_superencrypted_data_free_contents(desc);
hs_desc_superencrypted_data_free_contents(desc);
tor_free(desc);
}

/* Free the descriptor encrypted data object. */
void
hs_desc_encrypted_data_free_(hs_desc_encrypted_data_t *desc)
{
desc_encrypted_data_free_contents(desc);
hs_desc_encrypted_data_free_contents(desc);
tor_free(desc);
}

Expand All @@ -2755,9 +2755,9 @@ hs_descriptor_free_(hs_descriptor_t *desc)
return;
}

desc_plaintext_data_free_contents(&desc->plaintext_data);
desc_superencrypted_data_free_contents(&desc->superencrypted_data);
desc_encrypted_data_free_contents(&desc->encrypted_data);
hs_desc_plaintext_data_free_contents(&desc->plaintext_data);
hs_desc_superencrypted_data_free_contents(&desc->superencrypted_data);
hs_desc_encrypted_data_free_contents(&desc->encrypted_data);
tor_free(desc);
}

Expand Down
5 changes: 4 additions & 1 deletion src/feature/hs/hs_descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,10 @@ void hs_desc_build_authorized_client(const curve25519_public_key_t *client_pk,
auth_ephemeral_sk,
const uint8_t *descriptor_cookie,
hs_desc_authorized_client_t *client_out);
void hs_desc_plaintext_data_free_contents(hs_desc_plaintext_data_t *desc);
void hs_desc_superencrypted_data_free_contents(
hs_desc_superencrypted_data_t *desc);
void hs_desc_encrypted_data_free_contents(hs_desc_encrypted_data_t *desc);

#ifdef HS_DESCRIPTOR_PRIVATE

Expand All @@ -328,7 +332,6 @@ STATIC int cert_is_valid(tor_cert_t *cert, uint8_t type,
STATIC int desc_sig_is_valid(const char *b64_sig,
const ed25519_public_key_t *signing_pubkey,
const char *encoded_desc, size_t encoded_len);
STATIC void desc_plaintext_data_free_contents(hs_desc_plaintext_data_t *desc);

MOCK_DECL(STATIC size_t, decrypt_desc_layer,(const hs_descriptor_t *desc,
const uint8_t *encrypted_blob,
Expand Down
2 changes: 1 addition & 1 deletion src/test/test_hs_descriptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ test_decode_bad_signature(void *arg)
teardown_capture_of_logs();

done:
desc_plaintext_data_free_contents(&desc_plaintext);
hs_desc_plaintext_data_free_contents(&desc_plaintext);
}

static void
Expand Down

0 comments on commit 3b08b23

Please sign in to comment.