]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Make the Extended ORPort understand the TRANSPORT command.
authorGeorge Kadianakis <desnacked@riseup.net>
Mon, 11 Feb 2013 19:45:17 +0000 (20:45 +0100)
committerNick Mathewson <nickm@torproject.org>
Thu, 18 Jul 2013 18:59:56 +0000 (14:59 -0400)
src/or/connection.c
src/or/ext_orport.c
src/or/or.h

index 6f66f797bdfe7248ae901ba1691b312776ff7831..57a9c5838bd4e90af14fc7d2003c2fe95fe5745f 100644 (file)
@@ -603,6 +603,7 @@ connection_free_(connection_t *conn)
     connection_or_remove_from_ext_or_id_map(TO_OR_CONN(conn));
     tor_free(TO_OR_CONN(conn)->ext_or_conn_id);
     tor_free(TO_OR_CONN(conn)->ext_or_auth_correct_client_hash);
+    tor_free(TO_OR_CONN(conn)->ext_or_transport);
   }
 
 #ifdef USE_BUFFEREVENTS
index db95843c7caa8a0fcf35a84c69f3df5b457bfe3f..ff752f4865525076ee56702ae6da6ec8b719588c 100644 (file)
@@ -12,6 +12,7 @@
 #include "ext_orport.h"
 #include "control.h"
 #include "config.h"
+#include "util.h"
 #include "main.h"
 
 /** Allocate and return a structure capable of holding an Extended
@@ -381,6 +382,7 @@ connection_ext_or_auth_process_inbuf(or_connection_t *or_conn)
 /** Extended ORPort commands (Transport-to-Bridge) */
 #define EXT_OR_CMD_TB_DONE 0x0000
 #define EXT_OR_CMD_TB_USERADDR 0x0001
+#define EXT_OR_CMD_TB_TRANSPORT 0x0002
 
 /** Extended ORPort commands (Bridge-to-Transport) */
 #define EXT_OR_CMD_BT_OKAY 0x1000
@@ -395,8 +397,8 @@ connection_ext_or_auth_process_inbuf(or_connection_t *or_conn)
  *
  *  Return 0 on success and -1 on error. */
 static int
-connection_ext_or_handle_useraddr(connection_t *conn,
-                                  const char *payload, uint16_t len)
+connection_ext_or_handle_cmd_useraddr(connection_t *conn,
+                                      const char *payload, uint16_t len)
 {
   /* Copy address string. */
   tor_addr_t addr;
@@ -437,6 +439,32 @@ connection_ext_or_handle_useraddr(connection_t *conn,
   return 0;
 }
 
+/** Process a TRANSPORT command from the Extended
+ *  ORPort. <b>payload</b> is a payload of size <b>len</b>.
+ *
+ *  If the TRANSPORT command was well formed, register the name of the
+ *  transport on <b>conn</b>.
+ *
+ *  Return 0 on success and -1 on error. */
+static int
+connection_ext_or_handle_cmd_transport(or_connection_t *conn,
+                                       const char *payload, uint16_t len)
+{
+  char *transport_str = tor_malloc(len + 1); /* NUL-terminate the string */
+  memcpy(transport_str, payload, len);
+  transport_str[len] = 0;
+
+  /* Transport names MUST be C-identifiers. */
+  if (!string_is_C_identifier(transport_str)) {
+    tor_free(transport_str);
+    return -1;
+  }
+
+  conn->ext_or_transport = transport_str;
+  return 0;
+}
+
+
 /** Process Extended ORPort messages from <b>or_conn</b>. */
 int
 connection_ext_or_process_inbuf(or_connection_t *or_conn)
@@ -480,15 +508,24 @@ connection_ext_or_process_inbuf(or_connection_t *or_conn)
 
       log_debug(LD_NET, "Received DONE.");
 
+      /* If the transport proxy did not use the TRANSPORT command to
+       * specify the transport name, mark this as unknown transport. */
+      if (!or_conn->ext_or_transport)
+        or_conn->ext_or_transport = tor_strdup("<?\?>");
+
       connection_write_ext_or_command(conn, EXT_OR_CMD_BT_OKAY, NULL, 0);
 
       /* can't transition immediately; need to flush first. */
       conn->state = EXT_OR_CONN_STATE_FLUSHING;
       connection_stop_reading(conn);
     } else if (command->cmd == EXT_OR_CMD_TB_USERADDR) {
-      if (connection_ext_or_handle_useraddr(conn,
+      if (connection_ext_or_handle_cmd_useraddr(conn,
                                             command->body, command->len) < 0)
         goto err;
+    } else if (command->cmd == EXT_OR_CMD_TB_TRANSPORT) {
+      if (connection_ext_or_handle_cmd_transport(or_conn,
+                                             command->body, command->len) < 0)
+        goto err;
     } else {
       log_notice(LD_NET,"Got Extended ORPort command we don't regognize (%u).",
                  command->cmd);
index 63d137cf15435196ff969df90103041e4ea5dc1c..7916c476add5479300388e2a34eab37c9cb5a29a 100644 (file)
@@ -1452,6 +1452,9 @@ typedef struct or_connection_t {
   char *ext_or_conn_id;
   /** Client hash of the Extended ORPort authentication scheme */
   char *ext_or_auth_correct_client_hash;
+  /** Name of the pluggable transport that is obfuscating this
+      connection. If no pluggable transports are used, it's NULL. */
+  char *ext_or_transport;
 
   char *nickname; /**< Nickname of OR on other side (if any). */