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

[tor-commits] [obfsproxy/master] Added dummy plugin. A plugin that just leaves data pass by.



commit f3f7d7d00e92835fc0db3e7731147898c46480e2
Author: George Kadianakis <desnacked@xxxxxxxxx>
Date:   Wed Mar 23 19:31:09 2011 +0100

    Added dummy plugin. A plugin that just leaves data pass by.
---
 Makefile.am                  |    6 +++-
 src/main.c                   |   24 +++++++++++-----
 src/network.c                |   15 +++++-----
 src/plugins/dummy.c          |   61 ++++++++++++++++++++++++++++++++++++++++++
 src/plugins/dummy.h          |   21 ++++++++++++++
 src/plugins/obfs2.c          |    4 +--
 src/protocol.c               |   18 +++++++-----
 src/protocol.h               |    4 ++-
 src/socks.c                  |    9 ++++--
 src/test/unittest_protocol.c |   24 ++++++++--------
 10 files changed, 143 insertions(+), 43 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 67cd34d..32d5c05 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -13,7 +13,8 @@ libobfsproxy_a_SOURCES = \
 	src/socks.c  \
 	src/util.c   \
 	src/plugins/obfs2.c \
-	src/plugins/obfs2_crypt.c
+	src/plugins/obfs2_crypt.c \
+	src/plugins/dummy.c
 
 obfsproxy_SOURCES = \
 	src/main.c
@@ -35,7 +36,8 @@ noinst_HEADERS = \
 	src/test/tinytest.h \
 	src/test/tinytest_macros.h \
 	src/plugins/obfs2.h \
-	src/plugins/obfs2_crypt.h
+	src/plugins/obfs2_crypt.h \
+	src/plugins/dummy.h
 
 EXTRA_DIST = doc/protocol-spec.txt src/sha256.c
 
diff --git a/src/main.c b/src/main.c
index 93d5820..4f29005 100644
--- a/src/main.c
+++ b/src/main.c
@@ -25,7 +25,7 @@ static void
 usage(void)
 {
   fprintf(stderr,
-    "Usage: obfsproxy {client/server/socks} listenaddr[:port] targetaddr:port\n"
+    "Usage: obfsproxy {client/server/socks} {obfs2/dummy} listenaddr[:port] targetaddr:port\n"
     "  (Default listen port is 48988 for client; 23548 for socks; 11253 for server)\n"
           );
   exit(1);
@@ -43,6 +43,7 @@ handle_signal_cb(evutil_socket_t fd, short what, void *arg)
 int
 main(int argc, const char **argv)
 {
+  int protocol;
   int is_client, is_socks = 0, mode;
   struct sockaddr_storage ss_listen, ss_target;
   struct sockaddr *sa_target=NULL;
@@ -54,7 +55,7 @@ main(int argc, const char **argv)
   listener_t *listener;
 
   /* XXXXX the interface is crap.  Fix that. XXXXX */
-  if (argc < 3)
+  if (argc < 4)
     usage();
   if (!strcmp(argv[1], "client")) {
     is_client = 1;
@@ -73,21 +74,28 @@ main(int argc, const char **argv)
     usage();
   }
 
+  if (!strcmp(argv[2], "obfs2"))
+    protocol = OBFS2_PROTOCOL;
+  else if (!strcmp(argv[2], "dummy"))
+    protocol = DUMMY_PROTOCOL;
+  else
+    usage();
+
   /* figure out what port(s) to listen on as client/server */
-  if (resolve_address_port(argv[2], 1, 1, &ss_listen, &sl_listen, defport) < 0)
+  if (resolve_address_port(argv[3], 1, 1, &ss_listen, &sl_listen, defport) < 0)
     usage();
 
   if (is_socks) {
-    if (argc != 3)
+    if (argc != 4)
       usage();
   } else {
-    if (argc != 4)
+    if (argc != 5)
       usage();
 
     /* figure out what place to connect to as a client/server. */
     /* XXXX when we add socks support, clients will not have a fixed "target"
      * XXXX address but will instead connect to a client-selected address. */
-    if (resolve_address_port(argv[3], 1, 0, &ss_target, &sl_target, NULL) < 0)
+    if (resolve_address_port(argv[4], 1, 0, &ss_target, &sl_target, NULL) < 0)
       usage();
     sa_target = (struct sockaddr *)&ss_target;
   }
@@ -109,9 +117,9 @@ main(int argc, const char **argv)
   sigevent = evsignal_new(base, SIGINT, handle_signal_cb, (void*) base);
 
   /* start an evconnlistener on the appropriate port(s) */
-  /* ASN We hardcode BRL_PROTOCOL for now. */
+  /* ASN We hardcode OBFS2_PROTOCOL for now. */
   listener = listener_new(base,
-                          mode, BRL_PROTOCOL,
+                          mode, protocol,
                           (struct sockaddr *)&ss_listen, sl_listen,
                           sa_target, sl_target,
                           NULL, 0);
diff --git a/src/network.c b/src/network.c
index 833b939..3e23cdc 100644
--- a/src/network.c
+++ b/src/network.c
@@ -45,7 +45,7 @@ static void plaintext_read_cb(struct bufferevent *bev, void *arg);
 static void socks_read_cb(struct bufferevent *bev, void *arg);
 /* ASN Changed encrypted_read_cb() to obfuscated_read_cb(), it sounds
    a bit more obfsproxy generic. I still don't like it though. */
-static void obfsucated_read_cb(struct bufferevent *bev, void *arg);
+static void obfuscated_read_cb(struct bufferevent *bev, void *arg);
 static void input_event_cb(struct bufferevent *bev, short what, void *arg);
 static void output_event_cb(struct bufferevent *bev, short what, void *arg);
 
@@ -129,6 +129,7 @@ simple_listener_cb(struct evconnlistener *evcl,
   int is_initiator = (conn->mode != LSN_SIMPLE_SERVER) ? 1 : 0;
   conn->proto->state = proto_init(conn->proto, &is_initiator);
 
+  /* ASN Which means that all plugins need a state... */
   if (!conn->proto->state)
     goto err;
 
@@ -150,7 +151,7 @@ simple_listener_cb(struct evconnlistener *evcl,
 
   if (conn->mode == LSN_SIMPLE_SERVER) {
     bufferevent_setcb(conn->input,
-                      obfsucated_read_cb, NULL, input_event_cb, conn);
+                      obfuscated_read_cb, NULL, input_event_cb, conn);
   } else if (conn->mode == LSN_SIMPLE_CLIENT) {
     bufferevent_setcb(conn->input,
                       plaintext_read_cb, NULL, input_event_cb, conn);
@@ -174,7 +175,7 @@ simple_listener_cb(struct evconnlistener *evcl,
                       plaintext_read_cb, NULL, output_event_cb, conn);
   else
     bufferevent_setcb(conn->output,
-                      obfsucated_read_cb, NULL, output_event_cb, conn);
+                      obfuscated_read_cb, NULL, output_event_cb, conn);
 
   /* Queue output right now. */
   struct bufferevent *encrypted =
@@ -206,8 +207,8 @@ simple_listener_cb(struct evconnlistener *evcl,
 static void
 conn_free(conn_t *conn)
 {
-  if (conn->proto->state)
-    proto_destroy(conn->proto->state);
+  if (conn->proto)
+    proto_destroy(conn->proto);
   if (conn->socks_state)
     socks_state_free(conn->socks_state);
   if (conn->input)
@@ -289,7 +290,7 @@ plaintext_read_cb(struct bufferevent *bev, void *arg)
 }
 
 static void
-obfsucated_read_cb(struct bufferevent *bev, void *arg)
+obfuscated_read_cb(struct bufferevent *bev, void *arg)
 {
   conn_t *conn = arg;
   struct bufferevent *other;
@@ -375,7 +376,7 @@ output_event_cb(struct bufferevent *bev, short what, void *arg)
       bufferevent_setcb(conn->input,
                         plaintext_read_cb, NULL, input_event_cb, conn);
       if (evbuffer_get_length(bufferevent_get_input(conn->input)) != 0)
-        obfsucated_read_cb(bev, conn->input);
+        obfuscated_read_cb(bev, conn->input);
     }
   }
   /* XXX we don't expect any other events */
diff --git a/src/plugins/dummy.c b/src/plugins/dummy.c
new file mode 100644
index 0000000..957c30b
--- /dev/null
+++ b/src/plugins/dummy.c
@@ -0,0 +1,61 @@
+/* Copyright 2011 Princess Peach Toadstool
+
+   You may do anything with this work that copyright law would normally
+   restrict, so long as you retain the above notice(s) and this license
+   in all redistributed copies and derived works.  There is no warranty.
+*/
+
+#include <assert.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <unistd.h>
+
+#include <openssl/rand.h>
+#include <event2/buffer.h>
+
+#include "dummy.h"
+#include "../util.h"
+#include "../protocol.h"
+
+int
+dummy_new(struct protocol_t *proto_struct) {
+  proto_struct->destroy = (void *)NULL;
+  proto_struct->init = (void *)dummy_init;
+  proto_struct->handshake = (void *)NULL;
+  proto_struct->send = (void *)dummy_send;
+  proto_struct->recv = (void *)dummy_recv;
+
+  return 0;
+}
+
+int *
+dummy_init(int *initiator) {
+  /* Dodging state check. */
+  return initiator;
+}
+
+int
+dummy_send(void *nothing,
+           struct evbuffer *source, struct evbuffer *dest) {
+  (void)nothing;
+
+  /* ASN evbuffer_add_buffer() doesn't work for some reason. */
+  while (1) {
+    int n = evbuffer_remove_buffer(source, dest, 1024);
+    if (n <= 0)
+      return 0;
+  }
+}
+
+int
+dummy_recv(void *nothing,
+           struct evbuffer *source, struct evbuffer *dest) {
+  (void)nothing;
+  while (1) {
+    int n = evbuffer_remove_buffer(source, dest, 1024);
+    if (n <= 0)
+      return 0;
+  }
+}
diff --git a/src/plugins/dummy.h b/src/plugins/dummy.h
new file mode 100644
index 0000000..cf9342a
--- /dev/null
+++ b/src/plugins/dummy.h
@@ -0,0 +1,21 @@
+/* Copyright 2011 Princess Peach Toadstool
+
+   You may do anything with this work that copyright law would normally
+   restrict, so long as you retain the above notice(s) and this license
+   in all redistributed copies and derived works.  There is no warranty.
+*/
+
+#ifndef DUMMY_H
+#define DUMMY_H
+
+struct protocol_t;
+struct evbuffer;
+
+int *dummy_init(int *initiator);
+int dummy_send(void *nothing,
+               struct evbuffer *source, struct evbuffer *dest);
+int dummy_recv(void *nothing, struct evbuffer *source,
+               struct evbuffer *dest);
+int dummy_new(struct protocol_t *proto_struct);
+
+#endif
diff --git a/src/plugins/obfs2.c b/src/plugins/obfs2.c
index 01c74f3..ef8be8e 100644
--- a/src/plugins/obfs2.c
+++ b/src/plugins/obfs2.c
@@ -37,7 +37,7 @@ obfs2_new(struct protocol_t *proto_struct) {
     return -1;
   }
 
-  return 0;
+  return 1;
 }
 
 /** Return true iff the OBFUSCATE_SEED_LENGTH-byte seed in 'seed' is nonzero */
@@ -167,8 +167,6 @@ obfs2_send_initial_message(obfs2_state_t *state, struct evbuffer *buf)
   plength %= OBFUSCATE_MAX_PADDING;
   send_plength = htonl(plength);
 
-  printf("death and dest\n");
-
   if (state->we_are_initiator)
     seed = state->initiator_seed;
   else
diff --git a/src/protocol.c b/src/protocol.c
index 6df93ca..339feae 100644
--- a/src/protocol.c
+++ b/src/protocol.c
@@ -6,6 +6,7 @@
 #include "network.h"
 
 #include "plugins/obfs2.h"
+#include "plugins/dummy.h"
 
 /**
     This function returns a protocol_t structure based on the mode
@@ -15,13 +16,15 @@ struct protocol_t *
 set_up_protocol(int protocol) {
   struct protocol_t *proto = calloc(1, sizeof(struct protocol_t));
 
-  if (protocol == BRL_PROTOCOL) {
+  if (protocol == OBFS2_PROTOCOL)
     proto->new = &obfs2_new;
-    if (proto->new(proto))
-      printf("Protocol constructed\n");
-  }
+  else if (protocol == DUMMY_PROTOCOL)
+    proto->new = &dummy_new;
   /* elif { other protocols } */
 
+  if (proto->new(proto)>0)
+    printf("Protocol constructed\n");
+
   return proto;
 }
 
@@ -39,8 +42,8 @@ proto_handshake(struct protocol_t *proto, void *buf) {
   assert(proto);
   if (proto->handshake)
     return proto->handshake(proto->state, buf);
-  else
-    return -1;
+  else /* It's okay with me, protocol didn't have a handshake */
+    return 0;
 }
 
 int
@@ -48,7 +51,7 @@ proto_send(struct protocol_t *proto, void *source, void *dest) {
   assert(proto);
   if (proto->send)
     return proto->send(proto->state, source, dest);
-  else
+  else 
     return -1;
 }
 
@@ -63,6 +66,7 @@ proto_recv(struct protocol_t *proto, void *source, void *dest) {
 
 void proto_destroy(struct protocol_t *proto) {
   assert(proto);
+  assert(proto->state);
 
   if (proto->destroy)
     proto->destroy(proto->state);
diff --git a/src/protocol.h b/src/protocol.h
index 9e58ea8..781bde0 100644
--- a/src/protocol.h
+++ b/src/protocol.h
@@ -2,7 +2,9 @@
 #define PROTOCOL_H
 
 /* ASN I'm gonna be calling crypt_protocol.c BRL_RPOTOCOL for now. Yes. */
-#define BRL_PROTOCOL      1
+#define DUMMY_PROTOCOL    0
+#define OBFS2_PROTOCOL      1
+
 
 struct protocol_t *set_up_protocol(int protocol);
 void *proto_init(struct protocol_t *proto, void *arg);
diff --git a/src/socks.c b/src/socks.c
index 8f432e1..a3fb729 100644
--- a/src/socks.c
+++ b/src/socks.c
@@ -17,7 +17,7 @@
 
 
 /**
-   General idea:
+   General SOCKS5 idea:
 
    Client ------------------------> Server
           Method Negotiation Packet
@@ -32,8 +32,9 @@
                Server reply
 
    "Method Negotiation Packet" is handled by: socks5_handle_negotiation()
-   "Method Negotiation Reply" is done by: socks5_reply_negotiation()
-   "Client request" is handled by: socks5_validate_request()
+   "Method Negotiation Reply" is done by: socks5_do_negotiation()
+   "Client request" is handled by: socks5_handle_request()
+   "Server reply" is done by: socks5_send_reply
 */
 
 static int socks5_do_negotiation(struct evbuffer *dest,
@@ -191,6 +192,8 @@ socks5_send_reply(struct evbuffer *reply_dest, socks_state_t *state,
   /* We either failed or succeded.
      Either way, we should send something back to the client */
   p[0] = SOCKS5_VERSION;    /* Version field */
+  if (status == SOCKS5_REP_FAIL)
+    printf("Sending negative shit\n");
   p[1] = (unsigned char) status; /* Reply field */
   p[2] = 0;                 /* Reserved */
   if (state->parsereq.af == AF_UNSPEC) {
diff --git a/src/test/unittest_protocol.c b/src/test/unittest_protocol.c
index ceb666d..1864a3a 100644
--- a/src/test/unittest_protocol.c
+++ b/src/test/unittest_protocol.c
@@ -26,8 +26,8 @@
 static void
 test_proto_setup(void *data)
 {
-  struct protocol_t *client_proto = set_up_protocol(BRL_PROTOCOL);
-  struct protocol_t *server_proto = set_up_protocol(BRL_PROTOCOL);
+  struct protocol_t *client_proto = set_up_protocol(OBFS2_PROTOCOL);
+  struct protocol_t *server_proto = set_up_protocol(OBFS2_PROTOCOL);
 
   int initiator = 1;
   int no_initiator = 0;
@@ -55,8 +55,8 @@ test_proto_handshake(void *data)
   output_buffer = evbuffer_new();
   dummy_buffer = evbuffer_new();
 
-  struct protocol_t *client_proto = set_up_protocol(BRL_PROTOCOL);
-  struct protocol_t *server_proto = set_up_protocol(BRL_PROTOCOL);
+  struct protocol_t *client_proto = set_up_protocol(OBFS2_PROTOCOL);
+  struct protocol_t *server_proto = set_up_protocol(OBFS2_PROTOCOL);
 
   int initiator = 1;
   int no_initiator = 0;
@@ -114,8 +114,8 @@ test_proto_transfer(void *data)
   output_buffer = evbuffer_new();
   dummy_buffer = evbuffer_new();
 
-  struct protocol_t *client_proto = set_up_protocol(BRL_PROTOCOL);
-  struct protocol_t *server_proto = set_up_protocol(BRL_PROTOCOL);
+  struct protocol_t *client_proto = set_up_protocol(OBFS2_PROTOCOL);
+  struct protocol_t *server_proto = set_up_protocol(OBFS2_PROTOCOL);
 
   int initiator = 1;
   int no_initiator = 0;
@@ -197,8 +197,8 @@ test_proto_splitted_handshake(void *data)
   output_buffer = evbuffer_new();
   dummy_buffer = evbuffer_new();
 
-  struct protocol_t *client_proto = set_up_protocol(BRL_PROTOCOL);
-  struct protocol_t *server_proto = set_up_protocol(BRL_PROTOCOL);
+  struct protocol_t *client_proto = set_up_protocol(OBFS2_PROTOCOL);
+  struct protocol_t *server_proto = set_up_protocol(OBFS2_PROTOCOL);
 
   int initiator = 1;
   int no_initiator = 0;
@@ -337,8 +337,8 @@ test_proto_wrong_handshake_magic(void *data)
   output_buffer = evbuffer_new();
   dummy_buffer = evbuffer_new();
 
-  struct protocol_t *client_proto = set_up_protocol(BRL_PROTOCOL);
-  struct protocol_t *server_proto = set_up_protocol(BRL_PROTOCOL);
+  struct protocol_t *client_proto = set_up_protocol(OBFS2_PROTOCOL);
+  struct protocol_t *server_proto = set_up_protocol(OBFS2_PROTOCOL);
 
   int initiator = 1;
   int no_initiator = 0;
@@ -402,8 +402,8 @@ test_proto_wrong_handshake_plength(void *data)
   output_buffer = evbuffer_new();
   dummy_buffer = evbuffer_new();
   
-  struct protocol_t *client_proto = set_up_protocol(BRL_PROTOCOL);
-  struct protocol_t *server_proto = set_up_protocol(BRL_PROTOCOL);
+  struct protocol_t *client_proto = set_up_protocol(OBFS2_PROTOCOL);
+  struct protocol_t *server_proto = set_up_protocol(OBFS2_PROTOCOL);
   int initiator = 1;
   int no_initiator = 0;
   client_proto->state = proto_init(client_proto, &initiator);



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