summaryrefslogtreecommitdiff
path: root/src/test/test_link_handshake.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2017-06-05 15:44:12 -0400
committerNick Mathewson <nickm@torproject.org>2017-06-05 15:44:12 -0400
commitd1c1dc229e189cbf4e463b82751af007801a02eb (patch)
treef4600f4663e62b0466c01da56dd3df6edccb2bb8 /src/test/test_link_handshake.c
parent7c54d2f3f0bcf483fd14dedb1a5dcbece6976411 (diff)
parent9fea00928cb680f550a5ea9c64227efc025ea69b (diff)
downloadtor-d1c1dc229e189cbf4e463b82751af007801a02eb.tar.gz
tor-d1c1dc229e189cbf4e463b82751af007801a02eb.zip
Merge branch 'maint-0.2.9' into maint-0.3.0
Diffstat (limited to 'src/test/test_link_handshake.c')
-rw-r--r--src/test/test_link_handshake.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/test/test_link_handshake.c b/src/test/test_link_handshake.c
index 421f3aaedf..b3e854ef76 100644
--- a/src/test/test_link_handshake.c
+++ b/src/test/test_link_handshake.c
@@ -59,7 +59,7 @@ mock_get_peer_cert(tor_tls_t *tls)
if (mock_peer_cert_expect_tortls &&
mock_peer_cert_expect_tortls != tls)
return NULL;
- return mock_peer_cert;
+ return tor_x509_cert_dup(mock_peer_cert);
}
static int mock_send_netinfo_called = 0;
@@ -105,6 +105,14 @@ mock_export_key_material(tor_tls_t *tls, uint8_t *secrets_out,
return 0;
}
+static tor_x509_cert_t *mock_own_cert = NULL;
+static tor_x509_cert_t *
+mock_get_own_cert(tor_tls_t *tls)
+{
+ (void)tls;
+ return tor_x509_cert_dup(mock_own_cert);
+}
+
/* Test good certs cells */
static void
test_link_handshake_certs_ok(void *arg)
@@ -126,6 +134,7 @@ test_link_handshake_certs_ok(void *arg)
MOCK(connection_or_write_var_cell_to_buf, mock_write_var_cell);
MOCK(connection_or_send_netinfo, mock_send_netinfo);
MOCK(tor_tls_get_peer_cert, mock_get_peer_cert);
+ MOCK(tor_tls_get_own_cert, mock_get_own_cert);
key1 = pk_generate(2);
key2 = pk_generate(3);
@@ -143,6 +152,12 @@ test_link_handshake_certs_ok(void *arg)
}
/* c1 has started_here == 1 */
+ {
+ const tor_x509_cert_t *link = NULL;
+ tt_assert(!tor_tls_get_my_certs(1, &link, NULL));
+ mock_own_cert = tor_x509_cert_dup(link);
+ }
+
c1->base_.state = OR_CONN_STATE_OR_HANDSHAKING_V3;
c1->link_proto = 3;
tt_int_op(connection_init_or_handshake_state(c1, 1), ==, 0);
@@ -285,6 +300,9 @@ test_link_handshake_certs_ok(void *arg)
UNMOCK(connection_or_write_var_cell_to_buf);
UNMOCK(connection_or_send_netinfo);
UNMOCK(tor_tls_get_peer_cert);
+ UNMOCK(tor_tls_get_own_cert);
+ tor_x509_cert_free(mock_own_cert);
+ mock_own_cert = NULL;
memset(c1->identity_digest, 0, sizeof(c1->identity_digest));
memset(c2->identity_digest, 0, sizeof(c2->identity_digest));
connection_free_(TO_CONN(c1));
@@ -322,6 +340,7 @@ recv_certs_cleanup(const struct testcase_t *test, void *obj)
UNMOCK(connection_or_send_netinfo);
UNMOCK(connection_or_close_for_error);
UNMOCK(tor_tls_get_peer_cert);
+ UNMOCK(tor_tls_get_own_cert);
if (d) {
tor_free(d->cell);
@@ -1130,6 +1149,7 @@ authenticate_data_cleanup(const struct testcase_t *test, void *arg)
(void) test;
UNMOCK(connection_or_write_var_cell_to_buf);
UNMOCK(tor_tls_get_peer_cert);
+ UNMOCK(tor_tls_get_own_cert);
UNMOCK(tor_tls_get_tlssecrets);
UNMOCK(connection_or_close_for_error);
UNMOCK(channel_set_circid_type);
@@ -1147,7 +1167,11 @@ authenticate_data_cleanup(const struct testcase_t *test, void *arg)
crypto_pk_free(d->key2);
tor_free(d);
}
+ tor_x509_cert_free(mock_peer_cert);
+ tor_x509_cert_free(mock_own_cert);
mock_peer_cert = NULL;
+ mock_own_cert = NULL;
+
return 1;
}
@@ -1161,6 +1185,7 @@ authenticate_data_setup(const struct testcase_t *test)
MOCK(connection_or_write_var_cell_to_buf, mock_write_var_cell);
MOCK(tor_tls_get_peer_cert, mock_get_peer_cert);
+ MOCK(tor_tls_get_own_cert, mock_get_own_cert);
MOCK(tor_tls_get_tlssecrets, mock_get_tlssecrets);
MOCK(connection_or_close_for_error, mock_close_for_err);
MOCK(channel_set_circid_type, mock_set_circid_type);
@@ -1227,6 +1252,9 @@ authenticate_data_setup(const struct testcase_t *test)
mock_peer_cert = tor_x509_cert_decode(der, sz);
tt_assert(mock_peer_cert);
+ mock_own_cert = tor_x509_cert_decode(der, sz);
+ tt_assert(mock_own_cert);
+
/* Make an authenticate cell ... */
int authtype;
if (is_ed)