[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Extract intro point onion key even with multiple types.



commit 471489ca035a50733205f97c8d589d80c58e36e8
Author: George Kadianakis <desnacked@xxxxxxxxxx>
Date:   Fri Aug 4 23:35:04 2017 +0300

    Extract intro point onion key even with multiple types.
---
 src/or/hs_descriptor.c | 58 +++++++++++++++++++++++++++++++++++++++-----------
 src/or/parsecommon.c   |  2 +-
 src/or/parsecommon.h   |  2 +-
 3 files changed, 47 insertions(+), 15 deletions(-)

diff --git a/src/or/hs_descriptor.c b/src/or/hs_descriptor.c
index 0b10f205a..3e8343691 100644
--- a/src/or/hs_descriptor.c
+++ b/src/or/hs_descriptor.c
@@ -1657,6 +1657,50 @@ decode_intro_legacy_key(const directory_token_t *tok,
   return -1;
 }
 
+/* Dig into the descriptor <b>tokens</b> to find the onion key we should use
+ * for this intro point, and set it into <b>onion_key_out</b>. Return 0 if it
+ * was found and well-formed, otherwise return -1 in case of errors. */
+static int
+set_intro_point_onion_key(curve25519_public_key_t *onion_key_out,
+                          const smartlist_t *tokens)
+{
+  int retval = -1;
+  smartlist_t *onion_keys = NULL;
+
+  tor_assert(onion_key_out);
+
+  onion_keys = find_all_by_keyword(tokens, R3_INTRO_ONION_KEY);
+  if (!onion_keys) {
+    log_warn(LD_REND, "Descriptor did not contain intro onion keys");
+    goto err;
+  }
+
+  SMARTLIST_FOREACH_BEGIN(onion_keys, directory_token_t *, tok) {
+    /* This field is using GE(2) so for possible forward compatibility, we
+     * accept more fields but must be at least 2. */
+    tor_assert(tok->n_args >= 2);
+
+    /* Try to find an ntor key, it's the only recognized type right now */
+    if (!strcmp(tok->args[0], "ntor")) {
+      if (curve25519_public_from_base64(onion_key_out, tok->args[1]) < 0) {
+        log_warn(LD_REND, "Introduction point ntor onion-key is invalid");
+        goto err;
+      }
+      /* Got the onion key! Set the appropriate retval */
+      retval = 0;
+    }
+  } SMARTLIST_FOREACH_END(tok);
+
+  /* Log an error if we didn't find it :( */
+  if (retval < 0) {
+    log_warn(LD_REND, "Descriptor did not contain ntor onion keys");
+  }
+
+ err:
+  smartlist_free(onion_keys);
+  return retval;
+}
+
 /* Given the start of a section and the end of it, decode a single
  * introduction point from that section. Return a newly allocated introduction
  * point object containing the decoded data. Return NULL if the section can't
@@ -1696,19 +1740,7 @@ decode_introduction_point(const hs_descriptor_t *desc, const char *start)
   }
 
   /* "onion-key" SP ntor SP key NL */
-  tok = find_by_keyword(tokens, R3_INTRO_ONION_KEY);
-  if (!strcmp(tok->args[0], "ntor")) {
-    /* This field is using GE(2) so for possible forward compatibility, we
-     * accept more fields but must be at least 2. */
-    tor_assert(tok->n_args >= 2);
-
-    if (curve25519_public_from_base64(&ip->onion_key, tok->args[1]) < 0) {
-      log_warn(LD_REND, "Introduction point ntor onion-key is invalid");
-      goto err;
-    }
-  } else {
-    /* Unknown key type so we can't use that introduction point. */
-    log_warn(LD_REND, "Introduction point onion key is unrecognized.");
+  if (set_intro_point_onion_key(&ip->onion_key, tokens) < 0) {
     goto err;
   }
 
diff --git a/src/or/parsecommon.c b/src/or/parsecommon.c
index 795986787..6b5359303 100644
--- a/src/or/parsecommon.c
+++ b/src/or/parsecommon.c
@@ -436,7 +436,7 @@ find_opt_by_keyword(smartlist_t *s, directory_keyword keyword)
  * in the same order in which they occur in <b>s</b>.  Otherwise return
  * NULL. */
 smartlist_t *
-find_all_by_keyword(smartlist_t *s, directory_keyword k)
+find_all_by_keyword(const smartlist_t *s, directory_keyword k)
 {
   smartlist_t *out = NULL;
   SMARTLIST_FOREACH(s, directory_token_t *, t,
diff --git a/src/or/parsecommon.h b/src/or/parsecommon.h
index a76b104fd..5e5f9f4db 100644
--- a/src/or/parsecommon.h
+++ b/src/or/parsecommon.h
@@ -316,7 +316,7 @@ directory_token_t *find_by_keyword_(smartlist_t *s,
 
 directory_token_t *find_opt_by_keyword(smartlist_t *s,
                                        directory_keyword keyword);
-smartlist_t * find_all_by_keyword(smartlist_t *s, directory_keyword k);
+smartlist_t * find_all_by_keyword(const smartlist_t *s, directory_keyword k);
 
 #endif /* TOR_PARSECOMMON_H */
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits