[tor-commits] [stegotorus/master] a reasonable implementation of embed::detect()

zwol at torproject.org zwol at torproject.org
Fri Jul 20 23:17:06 UTC 2012


commit 9fae0496723181c1da06ff856ff951d768371a87
Author: Jeffrey Wang <jeffreyw at stanford.edu>
Date:   Tue Dec 6 07:34:48 2011 +0000

    a reasonable implementation of embed::detect()
    
    git-svn-id: svn+ssh://spartan.csl.sri.com/svn/private/DEFIANCE@175 a58ff0ac-194c-e011-a152-003048836090
---
 src/steg/embed.cc |   32 ++++++++++++++++++++++++++------
 1 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/src/steg/embed.cc b/src/steg/embed.cc
index 9b562d9..1e13851 100644
--- a/src/steg/embed.cc
+++ b/src/steg/embed.cc
@@ -104,9 +104,29 @@ embed::embed() {
 
 embed::~embed() { }
 
-bool embed::detect(conn_t * /* conn */) {
-  // TODO: no good way to detect right now
-  return 0; /* change to 1 when testing */
+bool embed::detect(conn_t *conn) {
+  if (!embed_init) init_embed_traces();
+
+  struct evbuffer *source = conn_get_inbound(conn);
+  size_t src_len = evbuffer_get_length(source);
+  
+  log_debug("detecting buffer of length %d", src_len);
+
+  int cur_idx;
+  if (evbuffer_copyout(source, &cur_idx, 4) != 4) return 0;
+  if (cur_idx < 0 || cur_idx >= embed_num_traces) return 0;
+
+  trace_t *cur = &embed_traces[cur_idx];
+  size_t tot_len = 0;
+  int idx = 0;
+  while (idx < cur->num_pkt && cur->pkt_sizes[idx] >= 0) {
+    tot_len += cur->pkt_sizes[idx++];
+    if (src_len == tot_len) {
+      log_debug("detected embed trace %d", cur_idx);
+      return 1;
+    }
+  }
+  return 0;
 }
 
 size_t embed::transmit_room(conn_t * /* conn */) {
@@ -122,9 +142,9 @@ size_t embed::transmit_room(conn_t * /* conn */) {
   if (is_finished() || !is_outgoing()) return 0;
   if (get_pkt_time() > time_diff+10) return 0;
 
-  // 24 bytes for chop header, 2 bytes for data length
+  // 24 bytes for chop header, 16 bytes for GCM tag, 2 bytes for data length
   // 4 bytes for the index of a new trace
-  room = get_pkt_size() - 26;
+  room = get_pkt_size() - 42;
   if (cur_pkt == 0) {
     room -= 4;
   }
@@ -187,7 +207,7 @@ int embed::receive(conn_t *conn, struct evbuffer *dest) {
     cur_pkt = 0;
     pkt_size += 4;
 
-    log_debug("detected trace %d", cur_idx);
+    log_debug("received first packet of trace %d", cur_idx);
   }
 
   // keep reading data and padding from the source, advancing the packet





More information about the tor-commits mailing list