1 /* Copyright (c) 2017-2019, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
6 * \brief Test hidden service ntor functionality.
10 #include "test/test_helpers.h"
11 #include "test/log_test_helpers.h"
12 #include "lib/crypt_ops/crypto_curve25519.h"
13 #include "lib/crypt_ops/crypto_ed25519.h"
15 #include "core/crypto/hs_ntor.h"
17 /* Test the HS ntor handshake. Simulate the sending of an encrypted INTRODUCE1
18 * cell, and verify the proper derivation of decryption keys on the other end.
19 * Then simulate the sending of an authenticated RENDEZVOUS1 cell and verify
20 * the proper verification on the other end. */
22 test_hs_ntor(void *arg
)
26 uint8_t subcredential
[DIGEST256_LEN
];
28 ed25519_keypair_t service_intro_auth_keypair
;
29 curve25519_keypair_t service_intro_enc_keypair
;
30 curve25519_keypair_t service_ephemeral_rend_keypair
;
32 curve25519_keypair_t client_ephemeral_enc_keypair
;
34 hs_ntor_intro_cell_keys_t client_hs_ntor_intro_cell_keys
;
35 hs_ntor_intro_cell_keys_t service_hs_ntor_intro_cell_keys
;
37 hs_ntor_rend_cell_keys_t service_hs_ntor_rend_cell_keys
;
38 hs_ntor_rend_cell_keys_t client_hs_ntor_rend_cell_keys
;
42 /* Generate fake data for this unittest */
44 /* Generate fake subcredential */
45 memset(subcredential
, 'Z', DIGEST256_LEN
);
48 curve25519_keypair_generate(&service_intro_enc_keypair
, 0);
49 ed25519_keypair_generate(&service_intro_auth_keypair
, 0);
50 curve25519_keypair_generate(&service_ephemeral_rend_keypair
, 0);
52 curve25519_keypair_generate(&client_ephemeral_enc_keypair
, 0);
55 /* Client: Simulate the sending of an encrypted INTRODUCE1 cell */
57 hs_ntor_client_get_introduce1_keys(&service_intro_auth_keypair
.pubkey
,
58 &service_intro_enc_keypair
.pubkey
,
59 &client_ephemeral_enc_keypair
,
61 &client_hs_ntor_intro_cell_keys
);
62 tt_int_op(retval
, OP_EQ
, 0);
64 /* Service: Simulate the decryption of the received INTRODUCE1 */
66 hs_ntor_service_get_introduce1_keys(&service_intro_auth_keypair
.pubkey
,
67 &service_intro_enc_keypair
,
68 &client_ephemeral_enc_keypair
.pubkey
,
70 &service_hs_ntor_intro_cell_keys
);
71 tt_int_op(retval
, OP_EQ
, 0);
73 /* Test that the INTRODUCE1 encryption/mac keys match! */
74 tt_mem_op(client_hs_ntor_intro_cell_keys
.enc_key
, OP_EQ
,
75 service_hs_ntor_intro_cell_keys
.enc_key
,
77 tt_mem_op(client_hs_ntor_intro_cell_keys
.mac_key
, OP_EQ
,
78 service_hs_ntor_intro_cell_keys
.mac_key
,
81 /* Service: Simulate creation of RENDEZVOUS1 key material. */
83 hs_ntor_service_get_rendezvous1_keys(&service_intro_auth_keypair
.pubkey
,
84 &service_intro_enc_keypair
,
85 &service_ephemeral_rend_keypair
,
86 &client_ephemeral_enc_keypair
.pubkey
,
87 &service_hs_ntor_rend_cell_keys
);
88 tt_int_op(retval
, OP_EQ
, 0);
90 /* Client: Simulate the verification of a received RENDEZVOUS1 cell */
92 hs_ntor_client_get_rendezvous1_keys(&service_intro_auth_keypair
.pubkey
,
93 &client_ephemeral_enc_keypair
,
94 &service_intro_enc_keypair
.pubkey
,
95 &service_ephemeral_rend_keypair
.pubkey
,
96 &client_hs_ntor_rend_cell_keys
);
97 tt_int_op(retval
, OP_EQ
, 0);
99 /* Test that the RENDEZVOUS1 key material match! */
100 tt_mem_op(client_hs_ntor_rend_cell_keys
.rend_cell_auth_mac
, OP_EQ
,
101 service_hs_ntor_rend_cell_keys
.rend_cell_auth_mac
,
103 tt_mem_op(client_hs_ntor_rend_cell_keys
.ntor_key_seed
, OP_EQ
,
104 service_hs_ntor_rend_cell_keys
.ntor_key_seed
,
110 struct testcase_t hs_ntor_tests
[] = {
111 { "hs_ntor", test_hs_ntor
, TT_FORK
,