]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Validate ed25519 keys and canonicity from circuit_n_conn_done()
authorNick Mathewson <nickm@torproject.org>
Thu, 6 Aug 2020 15:47:01 +0000 (11:47 -0400)
committerNick Mathewson <nickm@torproject.org>
Thu, 6 Aug 2020 19:59:28 +0000 (15:59 -0400)
Fixes bug 40080. Bugfix on 0.2.7.2-alpha.

changes/bug40080 [new file with mode: 0644]
src/core/or/channel.c
src/core/or/channel.h
src/core/or/circuitbuild.c

diff --git a/changes/bug40080 b/changes/bug40080
new file mode 100644 (file)
index 0000000..8162466
--- /dev/null
@@ -0,0 +1,6 @@
+  o Minor bugfixes (security):
+    - When completing a channel, relays now check more thoroughly to make
+      sure that it matches any pending circuits before attaching those
+      circuits. Previously, address correctness and Ed25519 identities were not
+      checked in this case, but only when extending circuits on an existing
+      channel. Fixes bug 40080; bugfix on 0.2.7.2-alpha.
index 3886906875211147e092ba78cabf3519c57e645d..3bef6218ef4e8766d08063f0cfb6fa0b7d1219cf 100644 (file)
@@ -663,7 +663,7 @@ channel_find_by_global_id(uint64_t global_identifier)
 
 /** Return true iff <b>chan</b> matches <b>rsa_id_digest</b> and <b>ed_id</b>.
  * as its identity keys.  If either is NULL, do not check for a match. */
-static int
+int
 channel_remote_identity_matches(const channel_t *chan,
                                 const char *rsa_id_digest,
                                 const ed25519_public_key_t *ed_id)
index 97aa0003370e1389adb25320d393b0f69b98fa5b..4c0c9aeb4cdb27919527d5d895814b3923a1c2e7 100644 (file)
@@ -741,6 +741,9 @@ int channel_is_outgoing(channel_t *chan);
 void channel_mark_client(channel_t *chan);
 void channel_clear_client(channel_t *chan);
 int channel_matches_extend_info(channel_t *chan, extend_info_t *extend_info);
+int channel_remote_identity_matches(const channel_t *chan,
+                                    const char *rsa_id_digest,
+                                    const ed25519_public_key_t *ed_id);
 int channel_matches_target_addr_for_extend(channel_t *chan,
                                            const tor_addr_t *target);
 unsigned int channel_num_circuits(channel_t *chan);
index f3a5791d6c43a3afb3c5c058e1b5bcb8bfd29e74..67b47b38f10b62b4be76e42e5dfbedb9830aedf7 100644 (file)
@@ -623,21 +623,37 @@ circuit_n_chan_done(channel_t *chan, int status, int close_origin_circuits)
           circ->state != CIRCUIT_STATE_CHAN_WAIT)
         continue;
 
-      if (tor_digest_is_zero(circ->n_hop->identity_digest)) {
+      const char *rsa_ident = NULL;
+      const ed25519_public_key_t *ed_ident = NULL;
+      if (! tor_digest_is_zero(circ->n_hop->identity_digest)) {
+        rsa_ident = circ->n_hop->identity_digest;
+      }
+      if (! ed25519_public_key_is_zero(&circ->n_hop->ed_identity)) {
+        ed_ident = &circ->n_hop->ed_identity;
+      }
+
+      if (rsa_ident == NULL && ed_ident == NULL) {
         /* Look at addr/port. This is an unkeyed connection. */
         if (!channel_matches_extend_info(chan, circ->n_hop))
           continue;
       } else {
-        /* We expected a key. See if it's the right one. */
-        if (tor_memneq(chan->identity_digest,
-                   circ->n_hop->identity_digest, DIGEST_LEN))
+        /* We expected a key or keys. See if they matched. */
+        if (!channel_remote_identity_matches(chan, rsa_ident, ed_ident))
           continue;
+
+        /* If the channel is canonical, great.  If not, it needs to match
+         * the requested address exactly. */
+        if (! chan->is_canonical &&
+            ! channel_matches_extend_info(chan, circ->n_hop)) {
+          continue;
+        }
       }
       if (!status) { /* chan failed; close circ */
         log_info(LD_CIRC,"Channel failed; closing circ.");
         circuit_mark_for_close(circ, END_CIRC_REASON_CHANNEL_CLOSED);
         continue;
       }
+
       if (close_origin_circuits && CIRCUIT_IS_ORIGIN(circ)) {
         log_info(LD_CIRC,"Channel deprecated for origin circs; closing circ.");
         circuit_mark_for_close(circ, END_CIRC_REASON_CHANNEL_CLOSED);