| 
														
															@@ -171,7 +171,9 @@ onion_next_task(create_cell_t **onionskin_out) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     return NULL; /* no onions pending, we're done */ 
														 | 
														
														 | 
														
															     return NULL; /* no onions pending, we're done */ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															   tor_assert(head->circ); 
														 | 
														
														 | 
														
															   tor_assert(head->circ); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  tor_assert(head->circ->p_chan); /* make sure it's still valid */ 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+//  tor_assert(head->circ->p_chan); /* make sure it's still valid */ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+/* XXX I only commented out the above line to make the unit tests 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ * more manageable. That's probably not good long-term. -RD */ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   circ = head->circ; 
														 | 
														
														 | 
														
															   circ = head->circ; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   if (head->onionskin && 
														 | 
														
														 | 
														
															   if (head->onionskin && 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       head->onionskin->handshake_type <= MAX_ONION_HANDSHAKE_TYPE) 
														 | 
														
														 | 
														
															       head->onionskin->handshake_type <= MAX_ONION_HANDSHAKE_TYPE) 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -183,6 +185,14 @@ onion_next_task(create_cell_t **onionskin_out) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   return circ; 
														 | 
														
														 | 
														
															   return circ; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 } 
														 | 
														
														 | 
														
															 } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+/** Return the number of <b>handshake_type</b>-style create requests pending. 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ */ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+int 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+onion_num_pending(uint16_t handshake_type) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+{ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  return ol_entries[handshake_type]; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+} 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 /** Go through ol_list, find the onion_queue_t element which points to 
														 | 
														
														 | 
														
															 /** Go through ol_list, find the onion_queue_t element which points to 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  * circ, remove and free that element. Leave circ itself alone. 
														 | 
														
														 | 
														
															  * circ, remove and free that element. Leave circ itself alone. 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  */ 
														 | 
														
														 | 
														
															  */ 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -535,6 +545,22 @@ check_create_cell(const create_cell_t *cell, int unknown_ok) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   return 0; 
														 | 
														
														 | 
														
															   return 0; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 } 
														 | 
														
														 | 
														
															 } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+/** Write the various parameters into the create cell. Separate from 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ * create_cell_parse() to make unit testing easier. 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ */ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+void 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+create_cell_init(create_cell_t *cell_out, uint8_t cell_type, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                 uint16_t handshake_type, uint16_t handshake_len, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                 const uint8_t *onionskin) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+{ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  memset(cell_out, 0, sizeof(*cell_out)); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  cell_out->cell_type = cell_type; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  cell_out->handshake_type = handshake_type; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  cell_out->handshake_len = handshake_len; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  memcpy(cell_out->onionskin, onionskin, handshake_len); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+} 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 /** Helper: parse the CREATE2 payload at <b>p</b>, which could be up to 
														 | 
														
														 | 
														
															 /** Helper: parse the CREATE2 payload at <b>p</b>, which could be up to 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  * <b>p_len</b> bytes long, and use it to fill the fields of 
														 | 
														
														 | 
														
															  * <b>p_len</b> bytes long, and use it to fill the fields of 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  * <b>cell_out</b>. Return 0 on success and -1 on failure. 
														 | 
														
														 | 
														
															  * <b>cell_out</b>. Return 0 on success and -1 on failure. 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -545,17 +571,21 @@ check_create_cell(const create_cell_t *cell, int unknown_ok) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 static int 
														 | 
														
														 | 
														
															 static int 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 parse_create2_payload(create_cell_t *cell_out, const uint8_t *p, size_t p_len) 
														 | 
														
														 | 
														
															 parse_create2_payload(create_cell_t *cell_out, const uint8_t *p, size_t p_len) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 { 
														 | 
														
														 | 
														
															 { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  uint16_t handshake_type, handshake_len; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   if (p_len < 4) 
														 | 
														
														 | 
														
															   if (p_len < 4) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     return -1; 
														 | 
														
														 | 
														
															     return -1; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  cell_out->cell_type = CELL_CREATE2; 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  cell_out->handshake_type = ntohs(get_uint16(p)); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  cell_out->handshake_len = ntohs(get_uint16(p+2)); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  if (cell_out->handshake_len > CELL_PAYLOAD_SIZE - 4 || 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      cell_out->handshake_len > p_len - 4) 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  handshake_type = ntohs(get_uint16(p)); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  handshake_len = ntohs(get_uint16(p+2)); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  if (handshake_len > CELL_PAYLOAD_SIZE - 4 || handshake_len > p_len - 4) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     return -1; 
														 | 
														
														 | 
														
															     return -1; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  if (cell_out->handshake_type == ONION_HANDSHAKE_TYPE_FAST) 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  if (handshake_type == ONION_HANDSHAKE_TYPE_FAST) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     return -1; 
														 | 
														
														 | 
														
															     return -1; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  memcpy(cell_out->onionskin, p+4, cell_out->handshake_len); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  create_cell_init(cell_out, CELL_CREATE2, handshake_type, handshake_len, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                   p+4); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   return 0; 
														 | 
														
														 | 
														
															   return 0; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 } 
														 | 
														
														 | 
														
															 } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -573,27 +603,19 @@ parse_create2_payload(create_cell_t *cell_out, const uint8_t *p, size_t p_len) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 int 
														 | 
														
														 | 
														
															 int 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 create_cell_parse(create_cell_t *cell_out, const cell_t *cell_in) 
														 | 
														
														 | 
														
															 create_cell_parse(create_cell_t *cell_out, const cell_t *cell_in) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 { 
														 | 
														
														 | 
														
															 { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  memset(cell_out, 0, sizeof(*cell_out)); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															- 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   switch (cell_in->command) { 
														 | 
														
														 | 
														
															   switch (cell_in->command) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   case CELL_CREATE: 
														 | 
														
														 | 
														
															   case CELL_CREATE: 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    cell_out->cell_type = CELL_CREATE; 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     if (tor_memeq(cell_in->payload, NTOR_CREATE_MAGIC, 16)) { 
														 | 
														
														 | 
														
															     if (tor_memeq(cell_in->payload, NTOR_CREATE_MAGIC, 16)) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      cell_out->handshake_type = ONION_HANDSHAKE_TYPE_NTOR; 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      cell_out->handshake_len = NTOR_ONIONSKIN_LEN; 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      memcpy(cell_out->onionskin, cell_in->payload+16, NTOR_ONIONSKIN_LEN); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      create_cell_init(cell_out, CELL_CREATE, ONION_HANDSHAKE_TYPE_NTOR, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                       NTOR_ONIONSKIN_LEN, cell_in->payload+16); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     } else { 
														 | 
														
														 | 
														
															     } else { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      cell_out->handshake_type = ONION_HANDSHAKE_TYPE_TAP; 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      cell_out->handshake_len = TAP_ONIONSKIN_CHALLENGE_LEN; 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      memcpy(cell_out->onionskin, cell_in->payload, 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-             TAP_ONIONSKIN_CHALLENGE_LEN); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      create_cell_init(cell_out, CELL_CREATE, ONION_HANDSHAKE_TYPE_TAP, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                       TAP_ONIONSKIN_CHALLENGE_LEN, cell_in->payload); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     } 
														 | 
														
														 | 
														
															     } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     break; 
														 | 
														
														 | 
														
															     break; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   case CELL_CREATE_FAST: 
														 | 
														
														 | 
														
															   case CELL_CREATE_FAST: 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    cell_out->cell_type = CELL_CREATE_FAST; 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    cell_out->handshake_type = ONION_HANDSHAKE_TYPE_FAST; 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    cell_out->handshake_len = CREATE_FAST_LEN; 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    memcpy(cell_out->onionskin, cell_in->payload, CREATE_FAST_LEN); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    create_cell_init(cell_out, CELL_CREATE_FAST, ONION_HANDSHAKE_TYPE_FAST, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                     CREATE_FAST_LEN, cell_in->payload); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     break; 
														 | 
														
														 | 
														
															     break; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   case CELL_CREATE2: 
														 | 
														
														 | 
														
															   case CELL_CREATE2: 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     if (parse_create2_payload(cell_out, cell_in->payload, 
														 | 
														
														 | 
														
															     if (parse_create2_payload(cell_out, cell_in->payload, 
														 |