commit c76d00abfa779059b2936e5b84c032d0e36726d4 Author: David Goulet dgoulet@torproject.org Date: Wed Sep 5 13:37:37 2018 -0400
hs-v3: Make hs_desc_build_fake_authorized_client() return an object
Return a newly allocated fake client authorization object instead of taking the object as a parameter.
Signed-off-by: David Goulet dgoulet@torproject.org --- src/feature/hs/hs_descriptor.c | 28 ++++++++++++++++------------ src/feature/hs/hs_descriptor.h | 3 +-- src/feature/hs/hs_service.c | 6 ++---- src/test/hs_test_helpers.c | 6 ++---- src/test/test_hs_descriptor.c | 3 +-- 5 files changed, 22 insertions(+), 24 deletions(-)
diff --git a/src/feature/hs/hs_descriptor.c b/src/feature/hs/hs_descriptor.c index 0cabe5036..9c3d4fc96 100644 --- a/src/feature/hs/hs_descriptor.c +++ b/src/feature/hs/hs_descriptor.c @@ -2833,18 +2833,22 @@ hs_desc_intro_point_free_(hs_desc_intro_point_t *ip) tor_free(ip); }
-/* Build a fake client info for the descriptor */ -void -hs_desc_build_fake_authorized_client(hs_desc_authorized_client_t *client_out) -{ - tor_assert(client_out); - - crypto_rand((char *) client_out->client_id, - sizeof(client_out->client_id)); - crypto_rand((char *) client_out->iv, - sizeof(client_out->iv)); - crypto_rand((char *) client_out->encrypted_cookie, - sizeof(client_out->encrypted_cookie)); +/* Allocate and build a new fake client info for the descriptor. Return a + * newly allocated object. This can't fail. */ +hs_desc_authorized_client_t * +hs_desc_build_fake_authorized_client(void) +{ + hs_desc_authorized_client_t *client_auth = + tor_malloc_zero(sizeof(*client_auth)); + + crypto_rand((char *) client_auth->client_id, + sizeof(client_auth->client_id)); + crypto_rand((char *) client_auth->iv, + sizeof(client_auth->iv)); + crypto_rand((char *) client_auth->encrypted_cookie, + sizeof(client_auth->encrypted_cookie)); + + return client_auth; }
/* Using the client public key, auth ephemeral secret key, and descriptor diff --git a/src/feature/hs/hs_descriptor.h b/src/feature/hs/hs_descriptor.h index 8ce5fd6a1..9d447105f 100644 --- a/src/feature/hs/hs_descriptor.h +++ b/src/feature/hs/hs_descriptor.h @@ -302,8 +302,7 @@ void hs_desc_authorized_client_free_(hs_desc_authorized_client_t *client); link_specifier_t *hs_desc_lspec_to_trunnel( const hs_desc_link_specifier_t *spec);
-void -hs_desc_build_fake_authorized_client(hs_desc_authorized_client_t *client_out); +hs_desc_authorized_client_t *hs_desc_build_fake_authorized_client(void); void hs_desc_build_authorized_client(const curve25519_public_key_t * client_auth_pk, const curve25519_secret_key_t * diff --git a/src/feature/hs/hs_service.c b/src/feature/hs/hs_service.c index 09329340c..79ef0a35e 100644 --- a/src/feature/hs/hs_service.c +++ b/src/feature/hs/hs_service.c @@ -1786,10 +1786,8 @@ build_service_desc_superencrypted(const hs_service_t *service, }
for (i = 0; i < num_clients_to_add; i++) { - hs_desc_authorized_client_t *desc_client; - desc_client = tor_malloc_zero(sizeof(hs_desc_authorized_client_t)); - - hs_desc_build_fake_authorized_client(desc_client); + hs_desc_authorized_client_t *desc_client = + hs_desc_build_fake_authorized_client(); smartlist_add(superencrypted->clients, desc_client); }
diff --git a/src/test/hs_test_helpers.c b/src/test/hs_test_helpers.c index f8c582afc..4e13ba43a 100644 --- a/src/test/hs_test_helpers.c +++ b/src/test/hs_test_helpers.c @@ -138,10 +138,8 @@ hs_helper_build_hs_desc_impl(unsigned int no_ip,
desc->superencrypted_data.clients = smartlist_new(); for (i = 0; i < HS_DESC_AUTH_CLIENT_MULTIPLE; i++) { - hs_desc_authorized_client_t *desc_client; - desc_client = tor_malloc_zero(sizeof(hs_desc_authorized_client_t)); - - hs_desc_build_fake_authorized_client(desc_client); + hs_desc_authorized_client_t *desc_client = + hs_desc_build_fake_authorized_client(); smartlist_add(desc->superencrypted_data.clients, desc_client); }
diff --git a/src/test/test_hs_descriptor.c b/src/test/test_hs_descriptor.c index de977599a..be7932cd2 100644 --- a/src/test/test_hs_descriptor.c +++ b/src/test/test_hs_descriptor.c @@ -412,8 +412,7 @@ test_decode_descriptor(void *arg)
/* We need to add fake auth clients here. */ for (i=0; i < 15; ++i) { - fake_client = tor_malloc_zero(sizeof(hs_desc_authorized_client_t)); - hs_desc_build_fake_authorized_client(fake_client); + fake_client = hs_desc_build_fake_authorized_client(); smartlist_add(clients, fake_client); } desc->superencrypted_data.clients = clients;
tor-commits@lists.torproject.org