From a6b6227b2141f8d9d36f8555253ec4d56f423b04 Mon Sep 17 00:00:00 2001 From: George Kadianakis Date: Thu, 1 Jun 2017 15:11:03 +0300 Subject: test: Fix prop224 HS descriptor to use subcredential We used to use NULL subcredential which is a terrible terrible idea. Refactor HS unittests to use subcredentials. Also add some non-fatal asserts to make sure that we always use subcredentials when decoding/encoding descs. Signed-off-by: David Goulet --- src/or/hs_descriptor.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/or') diff --git a/src/or/hs_descriptor.c b/src/or/hs_descriptor.c index 5a230759a4..6f304d6d2d 100644 --- a/src/or/hs_descriptor.c +++ b/src/or/hs_descriptor.c @@ -1006,6 +1006,11 @@ desc_encode_v3(const hs_descriptor_t *desc, tor_assert(encoded_out); tor_assert(desc->plaintext_data.version == 3); + if (BUG(desc->subcredential == NULL)) { + log_warn(LD_GENERAL, "Asked to encode desc with no subcred. No!"); + goto err; + } + /* Build the non-encrypted values. */ { char *encoded_cert; @@ -2261,7 +2266,7 @@ hs_desc_decode_descriptor(const char *encoded, const uint8_t *subcredential, hs_descriptor_t **desc_out) { - int ret; + int ret = -1; hs_descriptor_t *desc; tor_assert(encoded); @@ -2269,10 +2274,13 @@ hs_desc_decode_descriptor(const char *encoded, desc = tor_malloc_zero(sizeof(hs_descriptor_t)); /* Subcredentials are optional. */ - if (subcredential) { - memcpy(desc->subcredential, subcredential, sizeof(desc->subcredential)); + if (BUG(!subcredential)) { + log_warn(LD_GENERAL, "Tried to decrypt without subcred. Impossible!"); + goto err; } + memcpy(desc->subcredential, subcredential, sizeof(desc->subcredential)); + ret = hs_desc_decode_plaintext(encoded, &desc->plaintext_data); if (ret < 0) { goto err; -- cgit v1.2.3-54-g00ecf