aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_cell_formats.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2012-12-05 23:59:12 -0500
committerNick Mathewson <nickm@torproject.org>2013-01-03 11:29:47 -0500
commit1ed4786dba8912ab7a6eb16adf7554cf9a5c1ed1 (patch)
treea2b5d39e835482408b8100c8b1e73c437605e266 /src/test/test_cell_formats.c
parent115e8fe9a5342d9f04e14d155d11e8c88f551c84 (diff)
downloadtor-1ed4786dba8912ab7a6eb16adf7554cf9a5c1ed1.tar
tor-1ed4786dba8912ab7a6eb16adf7554cf9a5c1ed1.tar.gz
Implement scheme to allow ntor requests/responses via older servers
Diffstat (limited to 'src/test/test_cell_formats.c')
-rw-r--r--src/test/test_cell_formats.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/test/test_cell_formats.c b/src/test/test_cell_formats.c
index 2af87af72..bdbc555eb 100644
--- a/src/test/test_cell_formats.c
+++ b/src/test/test_cell_formats.c
@@ -456,6 +456,26 @@ test_cfmt_create_cells(void *arg)
tt_int_op(-1, ==, create_cell_parse(&cc, &cell));
#endif
+ /* A valid create cell with an ntor payload, in legacy format. */
+ memset(&cell, 0, sizeof(cell));
+ memset(b, 0, sizeof(b));
+ crypto_rand((char*)b, NTOR_ONIONSKIN_LEN);
+ cell.command = CELL_CREATE;
+ memcpy(cell.payload, "ntorNTORntorNTOR", 16);
+ memcpy(cell.payload+16, b, NTOR_ONIONSKIN_LEN);
+#ifdef CURVE25519_ENABLED
+ tt_int_op(0, ==, create_cell_parse(&cc, &cell));
+ tt_int_op(CELL_CREATE, ==, cc.cell_type);
+ tt_int_op(ONION_HANDSHAKE_TYPE_NTOR, ==, cc.handshake_type);
+ tt_int_op(NTOR_ONIONSKIN_LEN, ==, cc.handshake_len);
+ test_memeq(cc.onionskin, b, NTOR_ONIONSKIN_LEN + 10);
+ tt_int_op(0, ==, create_cell_format(&cell2, &cc));
+ tt_int_op(cell.command, ==, cell2.command);
+ test_memeq(cell.payload, cell2.payload, CELL_PAYLOAD_SIZE);
+#else
+ tt_int_op(-1, ==, create_cell_parse(&cc, &cell));
+#endif
+
/* == Okay, now let's try to parse some impossible stuff. */
/* It has to be some kind of a create cell! */
@@ -573,6 +593,7 @@ test_cfmt_created_cells(void *arg)
static void
test_cfmt_extend_cells(void *arg)
{
+ cell_t cell;
uint8_t b[512];
extend_cell_t ec;
create_cell_t *cc = &ec.create_cell;
@@ -607,6 +628,31 @@ test_cfmt_extend_cells(void *arg)
tt_int_op(p2_len, ==, 26+TAP_ONIONSKIN_CHALLENGE_LEN);
test_memeq(p2, p, RELAY_PAYLOAD_SIZE);
+ /* Let's do an ntor stuffed in a legacy EXTEND cell */
+ memset(p, 0, sizeof(p));
+ memset(b, 0, sizeof(b));
+ crypto_rand((char*)b, NTOR_ONIONSKIN_LEN);
+ memcpy(p, "\x12\xf4\x00\x01\x01\x02", 6); /* 18 244 0 1 : 258 */
+ memcpy(p+6,"ntorNTORntorNTOR", 16);
+ memcpy(p+22, b, NTOR_ONIONSKIN_LEN);
+ memcpy(p+6+TAP_ONIONSKIN_CHALLENGE_LEN, "electroencephalogram", 20);
+ tt_int_op(0, ==, extend_cell_parse(&ec, RELAY_COMMAND_EXTEND,
+ p, 26+TAP_ONIONSKIN_CHALLENGE_LEN));
+ tt_int_op(RELAY_COMMAND_EXTEND, ==, ec.cell_type);
+ tt_str_op("18.244.0.1", ==, fmt_addr(&ec.orport_ipv4.addr));
+ tt_int_op(258, ==, ec.orport_ipv4.port);
+ tt_int_op(AF_UNSPEC, ==, tor_addr_family(&ec.orport_ipv6.addr));
+ test_memeq(ec.node_id, "electroencephalogram", 20);
+ tt_int_op(cc->cell_type, ==, CELL_CREATE2);
+ tt_int_op(cc->handshake_type, ==, ONION_HANDSHAKE_TYPE_NTOR);
+ tt_int_op(cc->handshake_len, ==, NTOR_ONIONSKIN_LEN);
+ test_memeq(cc->onionskin, b, NTOR_ONIONSKIN_LEN+20);
+ tt_int_op(0, ==, extend_cell_format(&p2_cmd, &p2_len, p2, &ec));
+ tt_int_op(p2_cmd, ==, RELAY_COMMAND_EXTEND);
+ tt_int_op(p2_len, ==, 26+TAP_ONIONSKIN_CHALLENGE_LEN);
+ test_memeq(p2, p, RELAY_PAYLOAD_SIZE);
+ tt_int_op(0, ==, create_cell_format(&cell, cc));
+
/* Now let's do a minimal ntor EXTEND2 cell. */
memset(&ec, 0xff, sizeof(ec));
memset(p, 0, sizeof(p));