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

[tor-commits] [tor/master] Make the Extended ORPort understand the TRANSPORT command.



commit 210210f219a1773530dd117d7a48d6edc3a5e714
Author: George Kadianakis <desnacked@xxxxxxxxxx>
Date:   Mon Feb 11 20:45:17 2013 +0100

    Make the Extended ORPort understand the TRANSPORT command.
---
 src/or/connection.c |    1 +
 src/or/ext_orport.c |   43 ++++++++++++++++++++++++++++++++++++++++---
 src/or/or.h         |    3 +++
 3 files changed, 44 insertions(+), 3 deletions(-)

diff --git a/src/or/connection.c b/src/or/connection.c
index 6f66f79..57a9c58 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -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
diff --git a/src/or/ext_orport.c b/src/or/ext_orport.c
index db95843..ff752f4 100644
--- a/src/or/ext_orport.c
+++ b/src/or/ext_orport.c
@@ -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);
diff --git a/src/or/or.h b/src/or/or.h
index 63d137c..7916c47 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -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). */
 



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