aboutsummaryrefslogtreecommitdiff
path: root/src/or/hs_descriptor.c
diff options
context:
space:
mode:
authorGeorge Kadianakis <desnacked@riseup.net>2017-06-01 15:11:03 +0300
committerNick Mathewson <nickm@torproject.org>2017-08-08 20:29:34 -0400
commita6b6227b2141f8d9d36f8555253ec4d56f423b04 (patch)
tree2e5a80dbc62f05439d9ddff0fa83ee68771de26d /src/or/hs_descriptor.c
parentb547c5423930a430f70505a12d587735a7c83e1c (diff)
downloadtor-a6b6227b2141f8d9d36f8555253ec4d56f423b04.tar.gz
tor-a6b6227b2141f8d9d36f8555253ec4d56f423b04.zip
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 <dgoulet@torproject.org>
Diffstat (limited to 'src/or/hs_descriptor.c')
-rw-r--r--src/or/hs_descriptor.c14
1 files changed, 11 insertions, 3 deletions
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;