[tor-commits] [obfsproxy/master] Add support for managed proxies to dummy and obfs2.

nickm at torproject.org nickm at torproject.org
Fri Sep 9 17:08:59 UTC 2011


commit 80d91a5305f2a3fdf2d9f074867643e874718dde
Author: George Kadianakis <desnacked at gmail.com>
Date:   Sat Aug 20 06:36:16 2011 +0200

    Add support for managed proxies to dummy and obfs2.
---
 src/protocols/dummy.c     |   37 +++++++++++++++++++++++++++++++++++++
 src/protocols/obfs2.c     |   45 +++++++++++++++++++++++++++++++++++++++++++--
 src/test/unittest_obfs2.c |    5 +++++
 3 files changed, 85 insertions(+), 2 deletions(-)

diff --git a/src/protocols/dummy.c b/src/protocols/dummy.c
index 6489f58..27e6340 100644
--- a/src/protocols/dummy.c
+++ b/src/protocols/dummy.c
@@ -101,6 +101,43 @@ dummy_config_create(int n_options, const char *const *options)
   return NULL;
 }
 
+/**
+   Return a config_t for a managed proxy listener.
+*/
+static config_t *
+dummy_config_create_managed(int is_server, const char *protocol,
+                            const char *bindaddr, const char *orport)
+{
+  const char* defport;
+
+  dummy_config_t *cfg = xzalloc(sizeof(dummy_config_t));
+  cfg->super.vtable = &dummy_vtable;
+
+  if (is_server) {
+    defport = "11253"; /* 2bf5 */
+    cfg->mode = LSN_SIMPLE_SERVER;
+  } else {
+    defport = "23548"; /* 5bf5 */
+    cfg->mode = LSN_SOCKS_CLIENT;
+  }
+
+  cfg->listen_addr = resolve_address_port(bindaddr, 1, 1, defport);
+  if (!cfg->listen_addr)
+    goto err;
+
+  if (is_server) {
+    cfg->target_addr = resolve_address_port(orport, 1, 0, NULL);
+    if (!cfg->target_addr)
+      goto err;
+  }
+
+  return &cfg->super;
+
+ err:
+  dummy_config_free(&cfg->super);
+  return NULL;
+}
+
 /** Retrieve the 'n'th set of listen addresses for this configuration. */
 static struct evutil_addrinfo *
 dummy_config_get_listen_addrs(config_t *cfg, size_t n)
diff --git a/src/protocols/obfs2.c b/src/protocols/obfs2.c
index 366bc45..42a1c04 100644
--- a/src/protocols/obfs2.c
+++ b/src/protocols/obfs2.c
@@ -44,7 +44,11 @@ shared_seed_nonzero(const uchar *seed)
   return memcmp(seed, SHARED_ZERO_SEED, SHARED_SECRET_LENGTH) != 0;
 }
 
-/** stupid function returning the other conn of the circuit */
+/**
+   Stupid temporary function returning the other conn of a circuit.
+   For example, if 'conn' is the downstream connection on a circuit,
+   this function returns the upstream connection.
+*/
 static inline conn_t *
 get_other_conn(conn_t *conn)
 {
@@ -99,6 +103,43 @@ obfs2_config_create(int n_options, const char *const *options)
 }
 
 /**
+   Populate a config_t for a managed proxy listener.
+*/
+static config_t *
+obfs2_config_create_managed(int is_server, const char *protocol,
+                            const char *bindaddr, const char *orport)
+{
+  const char* defport;
+
+  obfs2_config_t *cfg = xzalloc(sizeof(obfs2_config_t));
+  cfg->super.vtable = &obfs2_vtable;
+
+  if (is_server) {
+    defport = "11253"; /* 2bf5 */
+    cfg->mode = LSN_SIMPLE_SERVER;
+  } else {
+    defport = "23548"; /* 5bf5 */
+    cfg->mode = LSN_SOCKS_CLIENT;
+  }
+
+  cfg->listen_addr = resolve_address_port(bindaddr, 1, 1, defport);
+  if (!cfg->listen_addr)
+    goto err;
+
+  if (is_server) {
+    cfg->target_addr = resolve_address_port(orport, 1, 0, NULL);
+    if (!cfg->target_addr)
+      goto err;
+  }
+
+  return &cfg->super;
+
+ err:
+  obfs2_config_free(&cfg->super);
+  return NULL;
+}
+
+/**
    Helper: Parses 'options' and fills 'cfg'.
 */
 int
@@ -195,7 +236,7 @@ obfs2_config_get_target_addr(config_t *cfg)
 }
 
 /*
-  This is called everytime we get a connection for the dummy
+  This is called everytime we get a connection for the obfs2
   protocol.
 */
 
diff --git a/src/test/unittest_obfs2.c b/src/test/unittest_obfs2.c
index 211f6af..6e14b1e 100644
--- a/src/test/unittest_obfs2.c
+++ b/src/test/unittest_obfs2.c
@@ -7,6 +7,7 @@
 
 #define PROTOCOL_OBFS2_PRIVATE
 #define CRYPT_PRIVATE
+#define NETWORK_PRIVATE
 #include "protocols/obfs2.h"
 #include "crypt.h"
 
@@ -192,6 +193,10 @@ test_obfs2_transfer(void *state)
   int n;
   struct evbuffer_iovec v[2];
 
+  /* evil trick to bypass get_other_conn() */
+  circuit_create(s->conn_client, s->conn_client);
+  circuit_create(s->conn_server, s->conn_server);
+
   /* Handshake */
   tt_int_op(0, <=, proto_handshake(s->conn_client, s->output_buffer));
   tt_assert(RECV_GOOD == proto_recv(s->conn_server, s->output_buffer,





More information about the tor-commits mailing list