[tor-commits] [tor/master] Add test that parses a hardcoded v2 descriptor.

nickm at torproject.org nickm at torproject.org
Wed Jul 5 14:27:03 UTC 2017


commit 17bd118b4c3785873e61c2d0b03845e5bd6fefb3
Author: George Kadianakis <desnacked at riseup.net>
Date:   Tue Jun 20 17:29:20 2017 +0300

    Add test that parses a hardcoded v2 descriptor.
---
 src/or/rendcommon.c |  4 ++-
 src/or/rendcommon.h |  7 ++++
 src/test/test_hs.c  | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 3 files changed, 104 insertions(+), 5 deletions(-)

diff --git a/src/or/rendcommon.c b/src/or/rendcommon.c
index e1236bd..986bfde 100644
--- a/src/or/rendcommon.c
+++ b/src/or/rendcommon.c
@@ -8,6 +8,8 @@
  * introducers, services, clients, and rendezvous points.
  **/
 
+#define RENDCOMMON_PRIVATE
+
 #include "or.h"
 #include "circuitbuild.h"
 #include "config.h"
@@ -395,7 +397,7 @@ rend_encrypt_v2_intro_points_stealth(char **encrypted_out,
 
 /** Attempt to parse the given <b>desc_str</b> and return true if this
  * succeeds, false otherwise. */
-static int
+STATIC int
 rend_desc_v2_is_parsable(rend_encoded_v2_service_descriptor_t *desc)
 {
   rend_service_descriptor_t *test_parsed = NULL;
diff --git a/src/or/rendcommon.h b/src/or/rendcommon.h
index 94c2480..292f927 100644
--- a/src/or/rendcommon.h
+++ b/src/or/rendcommon.h
@@ -63,5 +63,12 @@ int rend_non_anonymous_mode_enabled(const or_options_t *options);
 void assert_circ_anonymity_ok(origin_circuit_t *circ,
                               const or_options_t *options);
 
+#ifdef RENDCOMMON_PRIVATE
+
+STATIC int
+rend_desc_v2_is_parsable(rend_encoded_v2_service_descriptor_t *desc);
+
+#endif
+
 #endif
 
diff --git a/src/test/test_hs.c b/src/test/test_hs.c
index b4817a2..178f94d 100644
--- a/src/test/test_hs.c
+++ b/src/test/test_hs.c
@@ -8,6 +8,7 @@
 
 #define CONTROL_PRIVATE
 #define CIRCUITBUILD_PRIVATE
+#define RENDCOMMON_PRIVATE
 #define RENDSERVICE_PRIVATE
 
 #include "or.h"
@@ -32,8 +33,9 @@
 #define STR_HSDIR_NONE_EXIST_LONGNAME \
                        "$BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
 
-/* DuckDuckGo descriptor as an example. */
-static const char *hs_desc_content = "\
+/* DuckDuckGo descriptor as an example. This one has extra "\r" at the end so
+ * the control port is happy. */
+static const char *hs_desc_content_control = "\
 rendezvous-service-descriptor g5ojobzupf275beh5ra72uyhb3dkpxwg\r\n\
 version 2\r\n\
 permanent-key\r\n\
@@ -94,6 +96,68 @@ PcftsZf2ztN0sbNCtPgDL3d0PqvxY3iHTQAI8EbaGq/IAJUZ8U4y963dD5+Bn6JQ\r\n\
 myE3ctmh0vy5+QxSiRjmQBkuEpCyks7LvWvHYrhnmcg=\r\n\
 -----END SIGNATURE-----";
 
+/* DuckDuckGo descriptor as an example. */
+static const char *hs_desc_content = "\
+rendezvous-service-descriptor g5ojobzupf275beh5ra72uyhb3dkpxwg\n\
+version 2\n\
+permanent-key\n\
+-----BEGIN RSA PUBLIC KEY-----\n\
+MIGJAoGBAJ/SzzgrXPxTlFrKVhXh3buCWv2QfcNgncUpDpKouLn3AtPH5Ocys0jE\n\
+aZSKdvaiQ62md2gOwj4x61cFNdi05tdQjS+2thHKEm/KsB9BGLSLBNJYY356bupg\n\
+I5gQozM65ENelfxYlysBjJ52xSDBd8C4f/p9umdzaaaCmzXG/nhzAgMBAAE=\n\
+-----END RSA PUBLIC KEY-----\n\
+secret-id-part anmjoxxwiupreyajjt5yasimfmwcnxlf\n\
+publication-time 2015-03-11 19:00:00\n\
+protocol-versions 2,3\n\
+introduction-points\n\
+-----BEGIN MESSAGE-----\n\
+aW50cm9kdWN0aW9uLXBvaW50IDd1bnd4cmg2dG5kNGh6eWt1Z3EzaGZzdHduc2ll\n\
+cmhyCmlwLWFkZHJlc3MgMTg4LjEzOC4xMjEuMTE4Cm9uaW9uLXBvcnQgOTAwMQpv\n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CQUFFPQotLS0tLUVORCBSU0EgUFVCTElDIEtFWS0t\n\
+LS0tCnNlcnZpY2Uta2V5Ci0tLS0tQkVHSU4gUlNBIFBVQkxJQyBLRVktLS0tLQpN\n\
+SUdKQW9HQkFMVjNKSmtWN3lTNU9jc1lHMHNFYzFQOTVRclFRR3ZzbGJ6Wi9zRGxl\n\
+RlpKYXFSOUYvYjRUVERNClNGcFMxcU1GbldkZDgxVmRGMEdYRmN2WVpLamRJdHU2\n\
+SndBaTRJeEhxeXZtdTRKdUxrcXNaTEFLaXRLVkx4eGsKeERlMjlDNzRWMmJrOTRJ\n\
+MEgybTNKS2tzTHVwc3VxWWRVUmhOVXN0SElKZmgyZmNIalF0bEFnTUJBQUU9Ci0t\n\
+LS0tRU5EIFJTQSBQVUJMSUMgS0VZLS0tLS0KCg==\n\
+-----END MESSAGE-----\n\
+signature\n\
+-----BEGIN SIGNATURE-----\n\
+d4OuCE5OLAOnRB6cQN6WyMEmg/BHem144Vec+eYgeWoKwx3MxXFplUjFxgnMlmwN\n\
+PcftsZf2ztN0sbNCtPgDL3d0PqvxY3iHTQAI8EbaGq/IAJUZ8U4y963dD5+Bn6JQ\n\
+myE3ctmh0vy5+QxSiRjmQBkuEpCyks7LvWvHYrhnmcg=\n\
+-----END SIGNATURE-----";
+
 /* Helper global variable for hidden service descriptor event test.
  * It's used as a pointer to dynamically created message buffer in
  * send_control_event_string_replacement function, which mocks
@@ -125,6 +189,30 @@ node_describe_longname_by_id_replacement(const char *id_digest)
   }
 }
 
+/** Test that we can parse a hardcoded v2 HS desc. */
+static void
+test_hs_parse_static_v2_desc(void *arg)
+{
+  int ret;
+  rend_encoded_v2_service_descriptor_t desc;
+
+  (void) arg;
+
+  /* Test an obviously not parseable string */
+  desc.desc_str = tor_strdup("ceci n'est pas un HS descriptor");
+  ret = rend_desc_v2_is_parsable(&desc);
+  tor_free(desc.desc_str);
+  tt_int_op(ret, OP_EQ, 0);
+
+  /* Test an actual descriptor */
+  desc.desc_str = tor_strdup(hs_desc_content);
+  ret = rend_desc_v2_is_parsable(&desc);
+  tor_free(desc.desc_str);
+  tt_int_op(ret, OP_EQ, 1);
+
+ done: ;
+}
+
 /** Make sure each hidden service descriptor async event generation
  *
  * function generates the message in expected format.
@@ -235,10 +323,10 @@ test_hs_desc_event(void *arg)
   /* test valid content. */
   control_event_hs_descriptor_content(rend_query.onion_address,
                                       STR_HS_CONTENT_DESC_ID, HSDIR_EXIST_ID,
-                                      hs_desc_content);
+                                      hs_desc_content_control);
   tor_asprintf(&exp_msg, "650+HS_DESC_CONTENT " STR_HS_ADDR " "\
                STR_HS_CONTENT_DESC_ID " " STR_HSDIR_EXIST_LONGNAME\
-               "\r\n%s\r\n.\r\n650 OK\r\n", hs_desc_content);
+               "\r\n%s\r\n.\r\n650 OK\r\n", hs_desc_content_control);
 
   tt_assert(received_msg);
   tt_str_op(received_msg, OP_EQ, exp_msg);
@@ -941,6 +1029,8 @@ test_prune_services_on_reload(void *arg)
 struct testcase_t hs_tests[] = {
   { "hs_rend_data", test_hs_rend_data, TT_FORK,
     NULL, NULL },
+  { "hs_parse_static_v2_desc", test_hs_parse_static_v2_desc, TT_FORK,
+    NULL, NULL },
   { "hs_desc_event", test_hs_desc_event, TT_FORK,
     NULL, NULL },
   { "pick_tor2web_rendezvous_node", test_pick_tor2web_rendezvous_node, TT_FORK,





More information about the tor-commits mailing list