aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2016-07-06 13:43:12 -0400
committerNick Mathewson <nickm@torproject.org>2016-07-06 13:43:12 -0400
commitacba4cc9546f66be95353e37fc22b81d0dc91732 (patch)
treeb0c2adc0c09e589b5394a9e428741aa9ebb0ade5 /src/test
parent08cc0ef8320e614c1a33ea5e70bef4f5809981f2 (diff)
downloadtor-acba4cc9546f66be95353e37fc22b81d0dc91732.tar.gz
tor-acba4cc9546f66be95353e37fc22b81d0dc91732.zip
test coverage on onion_fast: 0%->100%
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/test/test.c b/src/test/test.c
index 2f18346660..f8610168f6 100644
--- a/src/test/test.c
+++ b/src/test/test.c
@@ -55,6 +55,7 @@ double fabs(double x);
#include "memarea.h"
#include "onion.h"
#include "onion_ntor.h"
+#include "onion_fast.h"
#include "onion_tap.h"
#include "policies.h"
#include "rephist.h"
@@ -266,6 +267,42 @@ test_ntor_handshake(void *arg)
dimap_free(s_keymap, NULL);
}
+static void
+test_fast_handshake(void *arg)
+{
+ /* tests for the obsolete "CREATE_FAST" handshake. */
+ (void) arg;
+ fast_handshake_state_t *state = NULL;
+ uint8_t client_handshake[CREATE_FAST_LEN];
+ uint8_t server_handshake[CREATED_FAST_LEN];
+ uint8_t s_keys[100], c_keys[100];
+
+ /* First, test an entire handshake. */
+ memset(client_handshake, 0, sizeof(client_handshake));
+ tt_int_op(0, OP_EQ, fast_onionskin_create(&state, client_handshake));
+ tt_assert(! tor_mem_is_zero((char*)client_handshake,
+ sizeof(client_handshake)));
+
+ tt_int_op(0, OP_EQ,
+ fast_server_handshake(client_handshake, server_handshake,
+ s_keys, 100));
+ const char *msg = NULL;
+ tt_int_op(0, OP_EQ,
+ fast_client_handshake(state, server_handshake, c_keys, 100, &msg));
+ tt_ptr_op(msg, OP_EQ, NULL);
+ tt_mem_op(s_keys, OP_EQ, c_keys, 100);
+
+ /* Now test a failing handshake. */
+ server_handshake[0] ^= 3;
+ tt_int_op(-1, OP_EQ,
+ fast_client_handshake(state, server_handshake, c_keys, 100, &msg));
+ tt_str_op(msg, OP_EQ, "Digest DOES NOT MATCH on fast handshake. "
+ "Bug or attack.");
+
+ done:
+ fast_handshake_state_free(state);
+}
+
/** Run unit tests for the onion queues. */
static void
test_onion_queues(void *arg)
@@ -1130,6 +1167,7 @@ static struct testcase_t test_array[] = {
{ "bad_onion_handshake", test_bad_onion_handshake, 0, NULL, NULL },
ENT(onion_queues),
{ "ntor_handshake", test_ntor_handshake, 0, NULL, NULL },
+ { "fast_handshake", test_fast_handshake, 0, NULL, NULL },
FORK(circuit_timeout),
FORK(rend_fns),
ENT(geoip),