]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Check fetched rendezvous descriptors' service IDs
authorRobert Ransom <rransom.8774@gmail.com>
Wed, 27 Apr 2011 20:37:08 +0000 (13:37 -0700)
committerNick Mathewson <nickm@torproject.org>
Mon, 16 May 2011 18:07:24 +0000 (14:07 -0400)
changes/check-fetched-rend-desc-service-id [new file with mode: 0644]
src/or/directory.c
src/or/or.h
src/or/rendcommon.c

diff --git a/changes/check-fetched-rend-desc-service-id b/changes/check-fetched-rend-desc-service-id
new file mode 100644 (file)
index 0000000..2f37c30
--- /dev/null
@@ -0,0 +1,7 @@
+  o Security fixes:
+    - When fetching a hidden service descriptor, check that it is for
+      the hidden service we were trying to connect to, in order to
+      stop a directory from pre-seeding a client with a descriptor for
+      a hidden service that they didn't want.  Bugfix on 0.0.6.
+
+
index 01f33752ff8393b836f471ebc49ed72533b3ca36..9f9b2c1577b23c2a609945c28cf26d6187428c7f 100644 (file)
@@ -1909,7 +1909,8 @@ connection_dir_client_reached_eof(dir_connection_t *conn)
              (int)body_len, status_code, escaped(reason));
     switch (status_code) {
       case 200:
-        if (rend_cache_store(body, body_len, 0) < -1) {
+        if (rend_cache_store(body, body_len, 0,
+                             conn->rend_data->onion_address) < -1) {
           log_warn(LD_REND,"Failed to parse rendezvous descriptor.");
           /* Any pending rendezvous attempts will notice when
            * connection_about_to_close_connection()
@@ -3114,7 +3115,7 @@ directory_handle_command_post(dir_connection_t *conn, const char *headers,
       !strcmpstart(url,"/tor/rendezvous/publish")) {
     /* rendezvous descriptor post */
     log_info(LD_REND, "Handling rendezvous descriptor post.");
-    if (rend_cache_store(body, body_len, 1) < 0) {
+    if (rend_cache_store(body, body_len, 1, NULL) < 0) {
       log_fn(LOG_PROTOCOL_WARN, LD_DIRSERV,
              "Rejected rend descriptor (length %d) from %s.",
              (int)body_len, conn->_base.address);
index 897ad32a432174ab18138ef0de0bf210b331e8f5..976ba9f8e5f251eb95c8fff395faf781b8db83cf 100644 (file)
@@ -4146,7 +4146,8 @@ int rend_cache_lookup_desc(const char *query, int version, const char **desc,
 int rend_cache_lookup_entry(const char *query, int version,
                             rend_cache_entry_t **entry_out);
 int rend_cache_lookup_v2_desc_as_dir(const char *query, const char **desc);
-int rend_cache_store(const char *desc, size_t desc_len, int published);
+int rend_cache_store(const char *desc, size_t desc_len, int published,
+                     const char *service_id);
 int rend_cache_store_v2_desc_as_client(const char *desc,
                                        const rend_data_t *rend_query);
 int rend_cache_store_v2_desc_as_dir(const char *desc);
index c83573b208cd609003105d2f97bff5e7c40001cc..8727a70c2ea43d93de5f405ee4911261df457fcb 100644 (file)
@@ -1047,9 +1047,14 @@ rend_cache_lookup_v2_desc_as_dir(const char *desc_id, const char **desc)
  *
  * The published flag tells us if we store the descriptor
  * in our role as directory (1) or if we cache it as client (0).
+ *
+ * If <b>service_id</b> is non-NULL and the descriptor is not for that
+ * service ID, reject it.  <b>service_id</b> must be specified if and
+ * only if <b>published</b> is 0 (we fetched this descriptor).
  */
 int
-rend_cache_store(const char *desc, size_t desc_len, int published)
+rend_cache_store(const char *desc, size_t desc_len, int published,
+                 const char *service_id)
 {
   rend_cache_entry_t *e;
   rend_service_descriptor_t *parsed;
@@ -1068,6 +1073,12 @@ rend_cache_store(const char *desc, size_t desc_len, int published)
     rend_service_descriptor_free(parsed);
     return -2;
   }
+  if ((service_id != NULL) && strcmp(query, service_id)) {
+    log_warn(LD_REND, "Received service descriptor for service ID %s; "
+             "expected descriptor for service ID %s.",
+             query, safe_str(service_id));
+    return -2;
+  }
   now = time(NULL);
   if (parsed->timestamp < now-REND_CACHE_MAX_AGE-REND_CACHE_MAX_SKEW) {
     log_fn(LOG_PROTOCOL_WARN, LD_REND,
@@ -1253,6 +1264,8 @@ rend_cache_store_v2_desc_as_dir(const char *desc)
  * If we have an older descriptor with the same ID, replace it.
  * If we have any v0 descriptor with the same ID, reject this one in order
  * to not get confused with having both versions for the same service.
+ * If the descriptor's service ID does not match
+ * <b>rend_query</b>-\>onion_address, reject it.
  * Return -2 if it's malformed or otherwise rejected; return -1 if we
  * already have a v0 descriptor here; return 0 if it's the same or older
  * than one we've already got; return 1 if it's novel.
@@ -1303,6 +1316,13 @@ rend_cache_store_v2_desc_as_client(const char *desc,
     retval = -2;
     goto err;
   }
+  if (strcmp(rend_query->onion_address, service_id)) {
+    log_warn(LD_REND, "Received service descriptor for service ID %s; "
+             "expected descriptor for service ID %s.",
+             service_id, safe_str(rend_query->onion_address));
+    retval = -2;
+    goto err;
+  }
   /* Decode/decrypt introduction points. */
   if (intro_content) {
     if (rend_query->auth_type != REND_NO_AUTH &&