浏览代码

refactor; start adding debugging logs to midpoint rend stuff

svn:r1445
Nick Mathewson 21 年之前
父节点
当前提交
e8345bfced
共有 11 个文件被更改,包括 36 次插入13 次删除
  1. 0 2
      src/common/crypto.c
  2. 1 0
      src/common/crypto.h
  3. 11 0
      src/common/util.c
  4. 2 0
      src/common/util.h
  5. 1 1
      src/or/circuit.c
  6. 1 1
      src/or/command.c
  7. 1 0
      src/or/connection_edge.c
  8. 1 1
      src/or/or.h
  9. 3 1
      src/or/rendcommon.c
  10. 15 6
      src/or/rendmid.c
  11. 0 1
      src/or/rendservice.c

+ 0 - 2
src/common/crypto.c

@@ -1403,8 +1403,6 @@ base64_decode(char *dest, int destlen, const char *src, int srclen)
   return ret;
   return ret;
 }
 }
 
 
-static const char BASE32_CHARS[] = "abcdefghijklmnopqrstuvwxyz012345";
-
 int
 int
 base32_encode(char *dest, int destlen, const char *src, int srclen)
 base32_encode(char *dest, int destlen, const char *src, int srclen)
 {
 {

+ 1 - 0
src/common/crypto.h

@@ -77,6 +77,7 @@ int crypto_pk_check_fingerprint_syntax(const char *s);
 
 
 int base64_encode(char *dest, int destlen, const char *src, int srclen);
 int base64_encode(char *dest, int destlen, const char *src, int srclen);
 int base64_decode(char *dest, int destlen, const char *src, int srclen);
 int base64_decode(char *dest, int destlen, const char *src, int srclen);
+#define BASE32_CHARS "abcdefghijklmnopqrstuvwxyz012345"
 int base32_encode(char *dest, int destlen, const char *src, int srclen);
 int base32_encode(char *dest, int destlen, const char *src, int srclen);
 
 
 /* Key negotiation */
 /* Key negotiation */

+ 11 - 0
src/common/util.c

@@ -109,6 +109,17 @@ void set_uint32(char *cp, uint32_t v)
 }
 }
 #endif
 #endif
 
 
+void hex_encode(const char *from, int fromlen, char *to)
+{
+  const unsigned char *fp = from;
+  static const char TABLE[] = "0123456789abcdef";
+  while (fromlen) {
+    *to++ = TABLE[*fp >> 4];
+    *to++ = TABLE[*fp & 7];
+    ++fp;
+  }
+  *to = '\0';
+}
 
 
 /*
 /*
  * A simple smartlist interface to make an unordered list of acceptable
  * A simple smartlist interface to make an unordered list of acceptable

+ 2 - 0
src/common/util.h

@@ -81,6 +81,8 @@ void set_uint32(char *cp, uint32_t v);
 #endif
 #endif
 #endif
 #endif
 
 
+void hex_encode(const char *from, int fromlen, char *to);
+
 typedef struct smartlist_t {
 typedef struct smartlist_t {
   void **list;
   void **list;
   int num_used;
   int num_used;

+ 1 - 1
src/or/circuit.c

@@ -347,7 +347,7 @@ circuit_t *circuit_get_next_by_service_and_purpose(circuit_t *start,
       continue;
       continue;
     if (circ->purpose != purpose)
     if (circ->purpose != purpose)
       continue;
       continue;
-    if (!memcmp(circ->rend_service, servid, REND_COOKIE_LEN))
+    if (!memcmp(circ->rend_service, servid, CRYPTO_SHA1_DIGEST_LEN))
       return circ;
       return circ;
   }
   }
   return NULL;
   return NULL;

+ 1 - 1
src/or/command.c

@@ -103,7 +103,7 @@ static void command_process_create_cell(cell_t *cell, connection_t *conn) {
 
 
   circ = circuit_new(cell->circ_id, conn);
   circ = circuit_new(cell->circ_id, conn);
   circ->state = CIRCUIT_STATE_ONIONSKIN_PENDING;
   circ->state = CIRCUIT_STATE_ONIONSKIN_PENDING;
-  circ->purpose = CIRCUIT_PURPOSE_INTERMEDIATE;
+  circ->purpose = CIRCUIT_PURPOSE_OR;
 
 
   memcpy(circ->onionskin, cell->payload, ONIONSKIN_CHALLENGE_LEN);
   memcpy(circ->onionskin, cell->payload, ONIONSKIN_CHALLENGE_LEN);
 
 

+ 1 - 0
src/or/connection_edge.c

@@ -792,6 +792,7 @@ static int connection_ap_handshake_attach_circuit(connection_t *conn) {
       desired_circuit_purpose = CIRCUIT_PURPOSE_C_INTRODUCING;
       desired_circuit_purpose = CIRCUIT_PURPOSE_C_INTRODUCING;
       break;
       break;
     default:
     default:
+      log_fn(LOG_ERR, "Got unexpected purpose: %d", conn->purpose);
       assert(0); /* never reached */
       assert(0); /* never reached */
   }
   }
 
 

+ 1 - 1
src/or/or.h

@@ -201,7 +201,7 @@
 
 
 #define _CIRCUIT_PURPOSE_MIN 1
 #define _CIRCUIT_PURPOSE_MIN 1
 /* these circuits were initiated elsewhere */
 /* these circuits were initiated elsewhere */
-#define CIRCUIT_PURPOSE_INTERMEDIATE 1 /* normal circuit, at OR. */
+#define CIRCUIT_PURPOSE_OR 1 /* normal circuit, at OR. */
 #define CIRCUIT_PURPOSE_INTRO_POINT 2 /* At OR, from Bob, waiting for intro from Alices */
 #define CIRCUIT_PURPOSE_INTRO_POINT 2 /* At OR, from Bob, waiting for intro from Alices */
 #define CIRCUIT_PURPOSE_REND_POINT_WAITING 3 /* At OR, from Alice, waiting for Bob */
 #define CIRCUIT_PURPOSE_REND_POINT_WAITING 3 /* At OR, from Alice, waiting for Bob */
 #define CIRCUIT_PURPOSE_REND_ESTABLISHED 4 /* At OR, both circuits have this purpose */
 #define CIRCUIT_PURPOSE_REND_ESTABLISHED 4 /* At OR, both circuits have this purpose */

+ 3 - 1
src/or/rendcommon.c

@@ -169,7 +169,9 @@ int rend_valid_service_id(char *query) {
   if(strlen(query) != REND_SERVICE_ID_LEN)
   if(strlen(query) != REND_SERVICE_ID_LEN)
     return 0;
     return 0;
 
 
-  /* XXXX also check for bad chars. */
+  if (strspn(query, BASE32_CHARS) != REND_SERVICE_ID_LEN)
+    return 0;
+
   return 1;
   return 1;
 }
 }
 
 

+ 15 - 6
src/or/rendmid.c

@@ -16,9 +16,12 @@ rend_mid_establish_intro(circuit_t *circ, char *request, int request_len)
   char pk_digest[20];
   char pk_digest[20];
   int asn1len;
   int asn1len;
   circuit_t *c;
   circuit_t *c;
+  char hexid[9];
 
 
-  if (circ->purpose != CIRCUIT_PURPOSE_INTERMEDIATE) {
-    log_fn(LOG_WARN, "Rejecting ESTABLISH_INTRO on non-intermediate circuit");
+  log_fn(LOG_INFO, "Received an ESTABLISH_INTRO request on circuit %d", circ->p_circ_id);
+
+  if (circ->purpose != CIRCUIT_PURPOSE_OR || circ->n_conn) {
+    log_fn(LOG_WARN, "Rejecting ESTABLISH_INTRO on non-OR or non-edge circuit");
     goto err;
     goto err;
   }
   }
   if (request_len < 22)
   if (request_len < 22)
@@ -60,10 +63,13 @@ rend_mid_establish_intro(circuit_t *circ, char *request, int request_len)
     goto err;
     goto err;
   }
   }
 
 
+  hex_encode(pk_digest, 4, hexid);
+
   /* Close any other intro circuits with the same pk. */
   /* Close any other intro circuits with the same pk. */
   c = NULL;
   c = NULL;
   while ((c = circuit_get_next_by_service_and_purpose(
   while ((c = circuit_get_next_by_service_and_purpose(
                                 c,pk_digest,CIRCUIT_PURPOSE_INTRO_POINT))) {
                                 c,pk_digest,CIRCUIT_PURPOSE_INTRO_POINT))) {
+    log_fn(LOG_INFO, "Replacing old circuit %d for service %s", c->p_circ_id, hexid);
     circuit_mark_for_close(c);
     circuit_mark_for_close(c);
   }
   }
 
 
@@ -71,6 +77,9 @@ rend_mid_establish_intro(circuit_t *circ, char *request, int request_len)
   circ->purpose = CIRCUIT_PURPOSE_INTRO_POINT;
   circ->purpose = CIRCUIT_PURPOSE_INTRO_POINT;
   memcpy(circ->rend_service, pk_digest, 20);
   memcpy(circ->rend_service, pk_digest, 20);
 
 
+  log_fn(LOG_INFO, "Established introduction point on circuit %d for service %s",
+         circ->p_circ_id, hexid);
+
   return 0;
   return 0;
  truncated:
  truncated:
   log_fn(LOG_WARN, "Rejecting truncated ESTABLISH_INTRO cell");
   log_fn(LOG_WARN, "Rejecting truncated ESTABLISH_INTRO cell");
@@ -123,8 +132,8 @@ rend_mid_introduce(circuit_t *circ, char *request, int request_len)
 int
 int
 rend_mid_establish_rendezvous(circuit_t *circ, char *request, int request_len)
 rend_mid_establish_rendezvous(circuit_t *circ, char *request, int request_len)
 {
 {
-  if (circ->purpose != CIRCUIT_PURPOSE_INTERMEDIATE) {
-    log_fn(LOG_WARN, "Tried to establish rendezvous on non-intermediate circuit");
+  if (circ->purpose != CIRCUIT_PURPOSE_OR || circ->n_conn) {
+    log_fn(LOG_WARN, "Tried to establish rendezvous on non-OR or non-edge circuit");
     goto err;
     goto err;
   }
   }
 
 
@@ -155,8 +164,8 @@ rend_mid_rendezvous(circuit_t *circ, char *request, int request_len)
 {
 {
   circuit_t *rend_circ;
   circuit_t *rend_circ;
 
 
-  if (circ->purpose != CIRCUIT_PURPOSE_INTERMEDIATE) {
-    log_fn(LOG_WARN, "Tried to complete rendezvous on non-intermediate circuit");
+  if (circ->purpose != CIRCUIT_PURPOSE_OR || circ->n_conn) {
+    log_fn(LOG_WARN, "Tried to complete rendezvous on non-OR or non-edge circuit");
     goto err;
     goto err;
   }
   }
 
 

+ 0 - 1
src/or/rendservice.c

@@ -166,7 +166,6 @@ static rend_service_port_config_t *parse_port_config(const char *string)
   return result;
   return result;
 }
 }
 
 
-
 /* Set up rend_service_list, based on the values of HiddenServiceDir and
 /* Set up rend_service_list, based on the values of HiddenServiceDir and
  * HiddenServicePort in 'options'.  Return 0 on success and -1 on
  * HiddenServicePort in 'options'.  Return 0 on success and -1 on
  * failure.
  * failure.