test_link_handshake.c 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551
  1. /* Copyright (c) 2014-2017, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. #include "orconfig.h"
  4. #define CHANNELTLS_PRIVATE
  5. #define CONNECTION_PRIVATE
  6. #define TOR_CHANNEL_INTERNAL_
  7. #define TORTLS_PRIVATE
  8. #include "compat.h"
  9. /* Some versions of OpenSSL declare SSL_get_selected_srtp_profile twice in
  10. * srtp.h. Suppress the GCC warning so we can build with -Wredundant-decl. */
  11. DISABLE_GCC_WARNING(redundant-decls)
  12. #include <openssl/x509.h>
  13. ENABLE_GCC_WARNING(redundant-decls)
  14. #include "or.h"
  15. #include "config.h"
  16. #include "connection.h"
  17. #include "connection_or.h"
  18. #include "channeltls.h"
  19. #include "link_handshake.h"
  20. #include "router.h"
  21. #include "routerkeys.h"
  22. #include "scheduler.h"
  23. #include "torcert.h"
  24. #include "test.h"
  25. #include "log_test_helpers.h"
  26. static var_cell_t *mock_got_var_cell = NULL;
  27. static void
  28. mock_write_var_cell(const var_cell_t *vc, or_connection_t *conn)
  29. {
  30. (void)conn;
  31. var_cell_t *newcell = var_cell_new(vc->payload_len);
  32. memcpy(newcell, vc, sizeof(var_cell_t));
  33. memcpy(newcell->payload, vc->payload, vc->payload_len);
  34. mock_got_var_cell = newcell;
  35. }
  36. static int
  37. mock_tls_cert_matches_key(const tor_tls_t *tls, const tor_x509_cert_t *cert)
  38. {
  39. (void) tls;
  40. (void) cert; // XXXX look at this.
  41. return 1;
  42. }
  43. static tor_tls_t *mock_peer_cert_expect_tortls = NULL;
  44. static tor_x509_cert_t *mock_peer_cert = NULL;
  45. static tor_x509_cert_t *
  46. mock_get_peer_cert(tor_tls_t *tls)
  47. {
  48. if (mock_peer_cert_expect_tortls &&
  49. mock_peer_cert_expect_tortls != tls)
  50. return NULL;
  51. return mock_peer_cert;
  52. }
  53. static int mock_send_netinfo_called = 0;
  54. static int
  55. mock_send_netinfo(or_connection_t *conn)
  56. {
  57. (void) conn;
  58. ++mock_send_netinfo_called;// XXX check_this
  59. return 0;
  60. }
  61. static int mock_close_called = 0;
  62. static void
  63. mock_close_for_err(or_connection_t *orconn, int flush)
  64. {
  65. (void)orconn;
  66. (void)flush;
  67. ++mock_close_called;
  68. }
  69. static int mock_send_authenticate_called = 0;
  70. static int mock_send_authenticate_called_with_type = 0;
  71. static int
  72. mock_send_authenticate(or_connection_t *conn, int type)
  73. {
  74. (void) conn;
  75. mock_send_authenticate_called_with_type = type;
  76. ++mock_send_authenticate_called;// XXX check_this
  77. return 0;
  78. }
  79. static int
  80. mock_export_key_material(tor_tls_t *tls, uint8_t *secrets_out,
  81. const uint8_t *context,
  82. size_t context_len,
  83. const char *label)
  84. {
  85. (void) tls;
  86. (void)secrets_out;
  87. (void)context;
  88. (void)context_len;
  89. (void)label;
  90. memcpy(secrets_out, "int getRandomNumber(){return 4;}", 32);
  91. return 0;
  92. }
  93. /* Test good certs cells */
  94. static void
  95. test_link_handshake_certs_ok(void *arg)
  96. {
  97. or_connection_t *c1 = or_connection_new(CONN_TYPE_OR, AF_INET);
  98. or_connection_t *c2 = or_connection_new(CONN_TYPE_OR, AF_INET);
  99. var_cell_t *cell1 = NULL, *cell2 = NULL;
  100. certs_cell_t *cc1 = NULL, *cc2 = NULL;
  101. channel_tls_t *chan1 = NULL, *chan2 = NULL;
  102. crypto_pk_t *key1 = NULL, *key2 = NULL;
  103. const int with_ed = !strcmp((const char *)arg, "Ed25519");
  104. tor_addr_from_ipv4h(&c1->base_.addr, 0x7f000001);
  105. tor_addr_from_ipv4h(&c2->base_.addr, 0x7f000001);
  106. scheduler_init();
  107. MOCK(tor_tls_cert_matches_key, mock_tls_cert_matches_key);
  108. MOCK(connection_or_write_var_cell_to_buf, mock_write_var_cell);
  109. MOCK(connection_or_send_netinfo, mock_send_netinfo);
  110. MOCK(tor_tls_get_peer_cert, mock_get_peer_cert);
  111. key1 = pk_generate(2);
  112. key2 = pk_generate(3);
  113. /* We need to make sure that our TLS certificates are set up before we can
  114. * actually generate a CERTS cell.
  115. */
  116. tt_int_op(tor_tls_context_init(TOR_TLS_CTX_IS_PUBLIC_SERVER,
  117. key1, key2, 86400), ==, 0);
  118. if (with_ed) {
  119. /* If we're making a CERTS cell for an ed handshake, let's make sure we
  120. * have some Ed25519 certificates and keys. */
  121. init_mock_ed_keys(key2);
  122. }
  123. /* c1 has started_here == 1 */
  124. c1->base_.state = OR_CONN_STATE_OR_HANDSHAKING_V3;
  125. c1->link_proto = 3;
  126. tt_int_op(connection_init_or_handshake_state(c1, 1), ==, 0);
  127. /* c2 has started_here == 0 */
  128. c2->base_.state = OR_CONN_STATE_OR_HANDSHAKING_V3;
  129. c2->link_proto = 3;
  130. tt_int_op(connection_init_or_handshake_state(c2, 0), ==, 0);
  131. tt_int_op(0, ==, connection_or_send_certs_cell(c1));
  132. tt_assert(mock_got_var_cell);
  133. cell1 = mock_got_var_cell;
  134. tt_int_op(0, ==, connection_or_send_certs_cell(c2));
  135. tt_assert(mock_got_var_cell);
  136. cell2 = mock_got_var_cell;
  137. tt_int_op(cell1->command, ==, CELL_CERTS);
  138. tt_int_op(cell1->payload_len, >, 1);
  139. tt_int_op(cell2->command, ==, CELL_CERTS);
  140. tt_int_op(cell2->payload_len, >, 1);
  141. tt_int_op(cell1->payload_len, ==,
  142. certs_cell_parse(&cc1, cell1->payload, cell1->payload_len));
  143. tt_int_op(cell2->payload_len, ==,
  144. certs_cell_parse(&cc2, cell2->payload, cell2->payload_len));
  145. if (with_ed) {
  146. tt_int_op(5, ==, cc1->n_certs);
  147. tt_int_op(5, ==, cc2->n_certs);
  148. } else {
  149. tt_int_op(2, ==, cc1->n_certs);
  150. tt_int_op(2, ==, cc2->n_certs);
  151. }
  152. tt_int_op(certs_cell_get_certs(cc1, 0)->cert_type, ==,
  153. CERTTYPE_RSA1024_ID_AUTH);
  154. tt_int_op(certs_cell_get_certs(cc1, 1)->cert_type, ==,
  155. CERTTYPE_RSA1024_ID_ID);
  156. tt_int_op(certs_cell_get_certs(cc2, 0)->cert_type, ==,
  157. CERTTYPE_RSA1024_ID_LINK);
  158. tt_int_op(certs_cell_get_certs(cc2, 1)->cert_type, ==,
  159. CERTTYPE_RSA1024_ID_ID);
  160. if (with_ed) {
  161. tt_int_op(certs_cell_get_certs(cc1, 2)->cert_type, ==,
  162. CERTTYPE_ED_ID_SIGN);
  163. tt_int_op(certs_cell_get_certs(cc1, 3)->cert_type, ==,
  164. CERTTYPE_ED_SIGN_AUTH);
  165. tt_int_op(certs_cell_get_certs(cc1, 4)->cert_type, ==,
  166. CERTTYPE_RSA1024_ID_EDID);
  167. tt_int_op(certs_cell_get_certs(cc2, 2)->cert_type, ==,
  168. CERTTYPE_ED_ID_SIGN);
  169. tt_int_op(certs_cell_get_certs(cc2, 3)->cert_type, ==,
  170. CERTTYPE_ED_SIGN_LINK);
  171. tt_int_op(certs_cell_get_certs(cc2, 4)->cert_type, ==,
  172. CERTTYPE_RSA1024_ID_EDID);
  173. }
  174. chan1 = tor_malloc_zero(sizeof(*chan1));
  175. channel_tls_common_init(chan1);
  176. c1->chan = chan1;
  177. chan1->conn = c1;
  178. c1->base_.address = tor_strdup("C1");
  179. c1->tls = tor_tls_new(-1, 0);
  180. c1->link_proto = 4;
  181. c1->base_.conn_array_index = -1;
  182. crypto_pk_get_digest(key2, c1->identity_digest);
  183. if (with_ed) {
  184. const tor_x509_cert_t *linkc, *idc;
  185. tor_tls_get_my_certs(1, &linkc, &idc);
  186. mock_peer_cert_expect_tortls = c1->tls; /* We should see this tls... */
  187. mock_peer_cert = tor_x509_cert_dup(linkc); /* and when we do, the peer's
  188. * cert is this... */
  189. }
  190. channel_tls_process_certs_cell(cell2, chan1);
  191. mock_peer_cert_expect_tortls = NULL;
  192. mock_peer_cert = NULL;
  193. tor_assert(c1->handshake_state->authenticated);
  194. tt_assert(c1->handshake_state->received_certs_cell);
  195. tt_assert(c1->handshake_state->certs->auth_cert == NULL);
  196. tt_assert(c1->handshake_state->certs->ed_sign_auth == NULL);
  197. tt_assert(c1->handshake_state->certs->id_cert);
  198. if (with_ed) {
  199. tt_assert(c1->handshake_state->certs->ed_sign_link);
  200. tt_assert(c1->handshake_state->certs->ed_rsa_crosscert);
  201. tt_assert(c1->handshake_state->certs->ed_id_sign);
  202. tt_assert(c1->handshake_state->authenticated_rsa);
  203. tt_assert(c1->handshake_state->authenticated_ed25519);
  204. } else {
  205. tt_assert(c1->handshake_state->certs->ed_sign_link == NULL);
  206. tt_assert(c1->handshake_state->certs->ed_rsa_crosscert == NULL);
  207. tt_assert(c1->handshake_state->certs->ed_id_sign == NULL);
  208. tt_assert(c1->handshake_state->authenticated_rsa);
  209. tt_assert(! c1->handshake_state->authenticated_ed25519);
  210. }
  211. tt_assert(! tor_mem_is_zero(
  212. (char*)c1->handshake_state->authenticated_rsa_peer_id, 20));
  213. chan2 = tor_malloc_zero(sizeof(*chan2));
  214. channel_tls_common_init(chan2);
  215. c2->chan = chan2;
  216. chan2->conn = c2;
  217. c2->base_.address = tor_strdup("C2");
  218. c2->tls = tor_tls_new(-1, 1);
  219. c2->link_proto = 4;
  220. c2->base_.conn_array_index = -1;
  221. crypto_pk_get_digest(key1, c2->identity_digest);
  222. channel_tls_process_certs_cell(cell1, chan2);
  223. tt_assert(c2->handshake_state->received_certs_cell);
  224. if (with_ed) {
  225. tt_assert(c2->handshake_state->certs->ed_sign_auth);
  226. tt_assert(c2->handshake_state->certs->ed_rsa_crosscert);
  227. tt_assert(c2->handshake_state->certs->ed_id_sign);
  228. } else {
  229. tt_assert(c2->handshake_state->certs->auth_cert);
  230. tt_assert(c2->handshake_state->certs->ed_sign_auth == NULL);
  231. tt_assert(c2->handshake_state->certs->ed_rsa_crosscert == NULL);
  232. tt_assert(c2->handshake_state->certs->ed_id_sign == NULL);
  233. }
  234. tt_assert(c2->handshake_state->certs->id_cert);
  235. tt_assert(tor_mem_is_zero(
  236. (char*)c2->handshake_state->authenticated_rsa_peer_id, 20));
  237. /* no authentication has happened yet, since we haen't gotten an AUTH cell.
  238. */
  239. tt_assert(! c2->handshake_state->authenticated);
  240. tt_assert(! c2->handshake_state->authenticated_rsa);
  241. tt_assert(! c2->handshake_state->authenticated_ed25519);
  242. done:
  243. UNMOCK(tor_tls_cert_matches_key);
  244. UNMOCK(connection_or_write_var_cell_to_buf);
  245. UNMOCK(connection_or_send_netinfo);
  246. UNMOCK(tor_tls_get_peer_cert);
  247. memset(c1->identity_digest, 0, sizeof(c1->identity_digest));
  248. memset(c2->identity_digest, 0, sizeof(c2->identity_digest));
  249. connection_free_(TO_CONN(c1));
  250. connection_free_(TO_CONN(c2));
  251. tor_free(cell1);
  252. tor_free(cell2);
  253. certs_cell_free(cc1);
  254. certs_cell_free(cc2);
  255. if (chan1)
  256. circuitmux_free(chan1->base_.cmux);
  257. tor_free(chan1);
  258. if (chan2)
  259. circuitmux_free(chan2->base_.cmux);
  260. tor_free(chan2);
  261. crypto_pk_free(key1);
  262. crypto_pk_free(key2);
  263. }
  264. typedef struct certs_data_s {
  265. int is_ed;
  266. int is_link_cert;
  267. or_connection_t *c;
  268. channel_tls_t *chan;
  269. certs_cell_t *ccell;
  270. var_cell_t *cell;
  271. crypto_pk_t *key1, *key2;
  272. } certs_data_t;
  273. static int
  274. recv_certs_cleanup(const struct testcase_t *test, void *obj)
  275. {
  276. (void)test;
  277. certs_data_t *d = obj;
  278. UNMOCK(tor_tls_cert_matches_key);
  279. UNMOCK(connection_or_send_netinfo);
  280. UNMOCK(connection_or_close_for_error);
  281. UNMOCK(tor_tls_get_peer_cert);
  282. if (d) {
  283. tor_free(d->cell);
  284. certs_cell_free(d->ccell);
  285. connection_or_clear_identity(d->c);
  286. connection_free_(TO_CONN(d->c));
  287. circuitmux_free(d->chan->base_.cmux);
  288. tor_free(d->chan);
  289. crypto_pk_free(d->key1);
  290. crypto_pk_free(d->key2);
  291. tor_free(d);
  292. }
  293. routerkeys_free_all();
  294. return 1;
  295. }
  296. static void *
  297. recv_certs_setup(const struct testcase_t *test)
  298. {
  299. (void)test;
  300. certs_data_t *d = tor_malloc_zero(sizeof(*d));
  301. certs_cell_cert_t *ccc1 = NULL;
  302. certs_cell_cert_t *ccc2 = NULL;
  303. ssize_t n;
  304. int is_ed = d->is_ed = !strcmpstart(test->setup_data, "Ed25519");
  305. int is_rsa = !strcmpstart(test->setup_data, "RSA");
  306. int is_link = d->is_link_cert = !strcmpend(test->setup_data, "-Link");
  307. int is_auth = !strcmpend(test->setup_data, "-Auth");
  308. tor_assert(is_ed != is_rsa);
  309. tor_assert(is_link != is_auth);
  310. d->c = or_connection_new(CONN_TYPE_OR, AF_INET);
  311. d->chan = tor_malloc_zero(sizeof(*d->chan));
  312. d->c->chan = d->chan;
  313. d->c->base_.address = tor_strdup("HaveAnAddress");
  314. tor_addr_from_ipv4h(&d->c->base_.addr, 0x801f0127);
  315. d->c->base_.state = OR_CONN_STATE_OR_HANDSHAKING_V3;
  316. d->chan->conn = d->c;
  317. tt_int_op(connection_init_or_handshake_state(d->c, 1), ==, 0);
  318. d->c->link_proto = 4;
  319. d->key1 = pk_generate(2);
  320. d->key2 = pk_generate(3);
  321. tt_int_op(tor_tls_context_init(TOR_TLS_CTX_IS_PUBLIC_SERVER,
  322. d->key1, d->key2, 86400), ==, 0);
  323. if (is_ed) {
  324. init_mock_ed_keys(d->key2);
  325. } else {
  326. routerkeys_free_all();
  327. }
  328. d->ccell = certs_cell_new();
  329. ccc1 = certs_cell_cert_new();
  330. certs_cell_add_certs(d->ccell, ccc1);
  331. ccc2 = certs_cell_cert_new();
  332. certs_cell_add_certs(d->ccell, ccc2);
  333. d->ccell->n_certs = 2;
  334. ccc1->cert_type = is_link ? 1 : 3;
  335. ccc2->cert_type = 2;
  336. const tor_x509_cert_t *a,*b;
  337. const uint8_t *enca, *encb;
  338. size_t lena, lenb;
  339. tor_tls_get_my_certs(is_link ? 1 : 0, &a, &b);
  340. tor_x509_cert_get_der(a, &enca, &lena);
  341. tor_x509_cert_get_der(b, &encb, &lenb);
  342. certs_cell_cert_setlen_body(ccc1, lena);
  343. ccc1->cert_len = lena;
  344. certs_cell_cert_setlen_body(ccc2, lenb);
  345. ccc2->cert_len = lenb;
  346. memcpy(certs_cell_cert_getarray_body(ccc1), enca, lena);
  347. memcpy(certs_cell_cert_getarray_body(ccc2), encb, lenb);
  348. if (is_ed) {
  349. certs_cell_cert_t *ccc3 = NULL; /* Id->Sign */
  350. certs_cell_cert_t *ccc4 = NULL; /* Sign->Link or Sign->Auth. */
  351. certs_cell_cert_t *ccc5 = NULL; /* RSAId->Ed Id. */
  352. const tor_cert_t *id_sign = get_master_signing_key_cert();
  353. const tor_cert_t *secondary =
  354. is_link ? get_current_link_cert_cert() : get_current_auth_key_cert();
  355. const uint8_t *cc = NULL;
  356. size_t cc_sz;
  357. get_master_rsa_crosscert(&cc, &cc_sz);
  358. ccc3 = certs_cell_cert_new();
  359. ccc4 = certs_cell_cert_new();
  360. ccc5 = certs_cell_cert_new();
  361. certs_cell_add_certs(d->ccell, ccc3);
  362. certs_cell_add_certs(d->ccell, ccc4);
  363. certs_cell_add_certs(d->ccell, ccc5);
  364. ccc3->cert_len = id_sign->encoded_len;
  365. ccc4->cert_len = secondary->encoded_len;
  366. ccc5->cert_len = cc_sz;
  367. certs_cell_cert_setlen_body(ccc3, ccc3->cert_len);
  368. certs_cell_cert_setlen_body(ccc4, ccc4->cert_len);
  369. certs_cell_cert_setlen_body(ccc5, ccc5->cert_len);
  370. memcpy(certs_cell_cert_getarray_body(ccc3), id_sign->encoded,
  371. ccc3->cert_len);
  372. memcpy(certs_cell_cert_getarray_body(ccc4), secondary->encoded,
  373. ccc4->cert_len);
  374. memcpy(certs_cell_cert_getarray_body(ccc5), cc, ccc5->cert_len);
  375. ccc3->cert_type = 4;
  376. ccc4->cert_type = is_link ? 5 : 6;
  377. ccc5->cert_type = 7;
  378. d->ccell->n_certs = 5;
  379. }
  380. d->cell = var_cell_new(4096);
  381. d->cell->command = CELL_CERTS;
  382. n = certs_cell_encode(d->cell->payload, 4096, d->ccell);
  383. tt_int_op(n, >, 0);
  384. d->cell->payload_len = n;
  385. MOCK(tor_tls_cert_matches_key, mock_tls_cert_matches_key);
  386. MOCK(connection_or_send_netinfo, mock_send_netinfo);
  387. MOCK(connection_or_close_for_error, mock_close_for_err);
  388. MOCK(tor_tls_get_peer_cert, mock_get_peer_cert);
  389. if (is_link) {
  390. /* Say that this is the peer's certificate */
  391. mock_peer_cert = tor_x509_cert_dup(a);
  392. }
  393. tt_int_op(0, ==, d->c->handshake_state->received_certs_cell);
  394. tt_int_op(0, ==, mock_send_authenticate_called);
  395. tt_int_op(0, ==, mock_send_netinfo_called);
  396. return d;
  397. done:
  398. recv_certs_cleanup(test, d);
  399. return NULL;
  400. }
  401. static struct testcase_setup_t setup_recv_certs = {
  402. .setup_fn = recv_certs_setup,
  403. .cleanup_fn = recv_certs_cleanup
  404. };
  405. static void
  406. test_link_handshake_recv_certs_ok(void *arg)
  407. {
  408. certs_data_t *d = arg;
  409. channel_tls_process_certs_cell(d->cell, d->chan);
  410. tt_int_op(0, ==, mock_close_called);
  411. tt_int_op(d->c->handshake_state->authenticated, ==, 1);
  412. tt_int_op(d->c->handshake_state->authenticated_rsa, ==, 1);
  413. tt_int_op(d->c->handshake_state->received_certs_cell, ==, 1);
  414. tt_assert(d->c->handshake_state->certs->id_cert != NULL);
  415. tt_assert(d->c->handshake_state->certs->auth_cert == NULL);
  416. if (d->is_ed) {
  417. tt_assert(d->c->handshake_state->certs->ed_id_sign != NULL);
  418. tt_assert(d->c->handshake_state->certs->ed_sign_link != NULL);
  419. tt_assert(d->c->handshake_state->certs->ed_sign_auth == NULL);
  420. tt_assert(d->c->handshake_state->certs->ed_rsa_crosscert != NULL);
  421. tt_int_op(d->c->handshake_state->authenticated_ed25519, ==, 1);
  422. } else {
  423. tt_assert(d->c->handshake_state->certs->ed_id_sign == NULL);
  424. tt_assert(d->c->handshake_state->certs->ed_sign_link == NULL);
  425. tt_assert(d->c->handshake_state->certs->ed_sign_auth == NULL);
  426. tt_assert(d->c->handshake_state->certs->ed_rsa_crosscert == NULL);
  427. tt_int_op(d->c->handshake_state->authenticated_ed25519, ==, 0);
  428. }
  429. done:
  430. ;
  431. }
  432. static void
  433. test_link_handshake_recv_certs_ok_server(void *arg)
  434. {
  435. certs_data_t *d = arg;
  436. d->c->handshake_state->started_here = 0;
  437. d->c->handshake_state->certs->started_here = 0;
  438. channel_tls_process_certs_cell(d->cell, d->chan);
  439. tt_int_op(0, ==, mock_close_called);
  440. tt_int_op(d->c->handshake_state->authenticated, ==, 0);
  441. tt_int_op(d->c->handshake_state->received_certs_cell, ==, 1);
  442. tt_assert(d->c->handshake_state->certs->id_cert != NULL);
  443. tt_assert(d->c->handshake_state->certs->link_cert == NULL);
  444. if (d->is_ed) {
  445. tt_assert(d->c->handshake_state->certs->ed_sign_auth != NULL);
  446. tt_assert(d->c->handshake_state->certs->auth_cert == NULL);
  447. } else {
  448. tt_assert(d->c->handshake_state->certs->ed_sign_auth == NULL);
  449. tt_assert(d->c->handshake_state->certs->auth_cert != NULL);
  450. }
  451. done:
  452. ;
  453. }
  454. #define CERTS_FAIL(name, code) \
  455. static void \
  456. test_link_handshake_recv_certs_ ## name(void *arg) \
  457. { \
  458. certs_data_t *d = arg; \
  459. const char *require_failure_message = NULL; \
  460. setup_capture_of_logs(LOG_INFO); \
  461. { code ; } \
  462. channel_tls_process_certs_cell(d->cell, d->chan); \
  463. tt_int_op(1, ==, mock_close_called); \
  464. tt_int_op(0, ==, mock_send_authenticate_called); \
  465. tt_int_op(0, ==, mock_send_netinfo_called); \
  466. tt_int_op(0, ==, d->c->handshake_state->authenticated_rsa); \
  467. tt_int_op(0, ==, d->c->handshake_state->authenticated_ed25519); \
  468. if (require_failure_message) { \
  469. expect_log_msg_containing(require_failure_message); \
  470. } \
  471. done: \
  472. teardown_capture_of_logs(); \
  473. }
  474. CERTS_FAIL(badstate,
  475. require_failure_message = "We're not doing a v3 handshake!";
  476. d->c->base_.state = OR_CONN_STATE_CONNECTING;)
  477. CERTS_FAIL(badproto,
  478. require_failure_message = "not using link protocol >= 3";
  479. d->c->link_proto = 2)
  480. CERTS_FAIL(duplicate,
  481. require_failure_message = "We already got one";
  482. d->c->handshake_state->received_certs_cell = 1)
  483. CERTS_FAIL(already_authenticated,
  484. require_failure_message = "We're already authenticated!";
  485. d->c->handshake_state->authenticated = 1)
  486. CERTS_FAIL(empty,
  487. require_failure_message = "It had no body";
  488. d->cell->payload_len = 0)
  489. CERTS_FAIL(bad_circid,
  490. require_failure_message = "It had a nonzero circuit ID";
  491. d->cell->circ_id = 1)
  492. CERTS_FAIL(truncated_1,
  493. require_failure_message = "It couldn't be parsed";
  494. d->cell->payload[0] = 5)
  495. CERTS_FAIL(truncated_2,
  496. {
  497. require_failure_message = "It couldn't be parsed";
  498. d->cell->payload_len = 4;
  499. memcpy(d->cell->payload, "\x01\x01\x00\x05", 4);
  500. })
  501. CERTS_FAIL(truncated_3,
  502. {
  503. require_failure_message = "It couldn't be parsed";
  504. d->cell->payload_len = 7;
  505. memcpy(d->cell->payload, "\x01\x01\x00\x05""abc", 7);
  506. })
  507. CERTS_FAIL(truncated_4, /* ed25519 */
  508. {
  509. require_failure_message = "It couldn't be parsed";
  510. d->cell->payload_len -= 10;
  511. })
  512. CERTS_FAIL(truncated_5, /* ed25519 */
  513. {
  514. require_failure_message = "It couldn't be parsed";
  515. d->cell->payload_len -= 100;
  516. })
  517. #define REENCODE() do { \
  518. const char *msg = certs_cell_check(d->ccell); \
  519. if (msg) puts(msg); \
  520. ssize_t n = certs_cell_encode(d->cell->payload, 4096, d->ccell); \
  521. tt_int_op(n, >, 0); \
  522. d->cell->payload_len = n; \
  523. } while (0)
  524. CERTS_FAIL(truncated_6, /* ed25519 */
  525. {
  526. /* truncate the link certificate */
  527. require_failure_message = "undecodable Ed certificate";
  528. certs_cell_cert_setlen_body(certs_cell_get_certs(d->ccell, 3), 7);
  529. certs_cell_get_certs(d->ccell, 3)->cert_len = 7;
  530. REENCODE();
  531. })
  532. CERTS_FAIL(truncated_7, /* ed25519 */
  533. {
  534. /* truncate the crosscert */
  535. require_failure_message = "Unparseable or overlong crosscert";
  536. certs_cell_cert_setlen_body(certs_cell_get_certs(d->ccell, 4), 7);
  537. certs_cell_get_certs(d->ccell, 4)->cert_len = 7;
  538. REENCODE();
  539. })
  540. CERTS_FAIL(not_x509,
  541. {
  542. require_failure_message = "Received undecodable certificate";
  543. certs_cell_cert_setlen_body(certs_cell_get_certs(d->ccell, 0), 3);
  544. certs_cell_get_certs(d->ccell, 0)->cert_len = 3;
  545. REENCODE();
  546. })
  547. CERTS_FAIL(both_link,
  548. {
  549. require_failure_message = "Duplicate x509 certificate";
  550. certs_cell_get_certs(d->ccell, 0)->cert_type = 1;
  551. certs_cell_get_certs(d->ccell, 1)->cert_type = 1;
  552. REENCODE();
  553. })
  554. CERTS_FAIL(both_id_rsa,
  555. {
  556. require_failure_message = "Duplicate x509 certificate";
  557. certs_cell_get_certs(d->ccell, 0)->cert_type = 2;
  558. certs_cell_get_certs(d->ccell, 1)->cert_type = 2;
  559. REENCODE();
  560. })
  561. CERTS_FAIL(both_auth,
  562. {
  563. require_failure_message = "Duplicate x509 certificate";
  564. certs_cell_get_certs(d->ccell, 0)->cert_type = 3;
  565. certs_cell_get_certs(d->ccell, 1)->cert_type = 3;
  566. REENCODE();
  567. })
  568. CERTS_FAIL(duplicate_id, /* ed25519 */
  569. {
  570. require_failure_message = "Duplicate Ed25519 certificate";
  571. certs_cell_get_certs(d->ccell, 2)->cert_type = 4;
  572. certs_cell_get_certs(d->ccell, 3)->cert_type = 4;
  573. REENCODE();
  574. })
  575. CERTS_FAIL(duplicate_link, /* ed25519 */
  576. {
  577. require_failure_message = "Duplicate Ed25519 certificate";
  578. certs_cell_get_certs(d->ccell, 2)->cert_type = 5;
  579. certs_cell_get_certs(d->ccell, 3)->cert_type = 5;
  580. REENCODE();
  581. })
  582. CERTS_FAIL(duplicate_crosscert, /* ed25519 */
  583. {
  584. require_failure_message = "Duplicate RSA->Ed25519 crosscert";
  585. certs_cell_get_certs(d->ccell, 2)->cert_type = 7;
  586. certs_cell_get_certs(d->ccell, 3)->cert_type = 7;
  587. REENCODE();
  588. })
  589. static void
  590. test_link_handshake_recv_certs_missing_id(void *arg) /* ed25519 */
  591. {
  592. certs_data_t *d = arg;
  593. tt_int_op(certs_cell_getlen_certs(d->ccell), OP_EQ, 5);
  594. certs_cell_set_certs(d->ccell, 2, certs_cell_get_certs(d->ccell, 4));
  595. certs_cell_set0_certs(d->ccell, 4, NULL); /* prevent free */
  596. certs_cell_setlen_certs(d->ccell, 4);
  597. d->ccell->n_certs = 4;
  598. REENCODE();
  599. /* This handshake succeeds, but since we have no ID cert, we will
  600. * just do the RSA handshake. */
  601. channel_tls_process_certs_cell(d->cell, d->chan);
  602. tt_int_op(0, ==, mock_close_called);
  603. tt_int_op(0, ==, d->c->handshake_state->authenticated_ed25519);
  604. tt_int_op(1, ==, d->c->handshake_state->authenticated_rsa);
  605. done:
  606. ;
  607. }
  608. CERTS_FAIL(missing_signing_key, /* ed25519 */
  609. {
  610. require_failure_message = "No Ed25519 signing key";
  611. tt_int_op(certs_cell_getlen_certs(d->ccell), OP_EQ, 5);
  612. certs_cell_cert_t *cert = certs_cell_get_certs(d->ccell, 2);
  613. tt_int_op(cert->cert_type, ==, CERTTYPE_ED_ID_SIGN);
  614. /* replace this with a valid master->signing cert, but with no
  615. * signing key. */
  616. const ed25519_keypair_t *mk = get_master_identity_keypair();
  617. const ed25519_keypair_t *sk = get_master_signing_keypair();
  618. tor_cert_t *bad_cert = tor_cert_create(mk, CERT_TYPE_ID_SIGNING,
  619. &sk->pubkey, time(NULL), 86400,
  620. 0 /* don't include signer */);
  621. certs_cell_cert_setlen_body(cert, bad_cert->encoded_len);
  622. memcpy(certs_cell_cert_getarray_body(cert),
  623. bad_cert->encoded, bad_cert->encoded_len);
  624. cert->cert_len = bad_cert->encoded_len;
  625. tor_cert_free(bad_cert);
  626. REENCODE();
  627. })
  628. CERTS_FAIL(missing_link, /* ed25519 */
  629. {
  630. require_failure_message = "No Ed25519 link key";
  631. tt_int_op(certs_cell_getlen_certs(d->ccell), OP_EQ, 5);
  632. certs_cell_set_certs(d->ccell, 3, certs_cell_get_certs(d->ccell, 4));
  633. certs_cell_set0_certs(d->ccell, 4, NULL); /* prevent free */
  634. certs_cell_setlen_certs(d->ccell, 4);
  635. d->ccell->n_certs = 4;
  636. REENCODE();
  637. })
  638. CERTS_FAIL(missing_auth, /* ed25519 */
  639. {
  640. d->c->handshake_state->started_here = 0;
  641. d->c->handshake_state->certs->started_here = 0;
  642. require_failure_message = "No Ed25519 link authentication key";
  643. tt_int_op(certs_cell_getlen_certs(d->ccell), OP_EQ, 5);
  644. certs_cell_set_certs(d->ccell, 3, certs_cell_get_certs(d->ccell, 4));
  645. certs_cell_set0_certs(d->ccell, 4, NULL); /* prevent free */
  646. certs_cell_setlen_certs(d->ccell, 4);
  647. d->ccell->n_certs = 4;
  648. REENCODE();
  649. })
  650. CERTS_FAIL(missing_crosscert, /* ed25519 */
  651. {
  652. require_failure_message = "Missing RSA->Ed25519 crosscert";
  653. tt_int_op(certs_cell_getlen_certs(d->ccell), OP_EQ, 5);
  654. certs_cell_setlen_certs(d->ccell, 4);
  655. d->ccell->n_certs = 4;
  656. REENCODE();
  657. })
  658. CERTS_FAIL(missing_rsa_id, /* ed25519 */
  659. {
  660. require_failure_message = "Missing legacy RSA ID cert";
  661. tt_int_op(certs_cell_getlen_certs(d->ccell), OP_EQ, 5);
  662. certs_cell_set_certs(d->ccell, 1, certs_cell_get_certs(d->ccell, 4));
  663. certs_cell_set0_certs(d->ccell, 4, NULL); /* prevent free */
  664. certs_cell_setlen_certs(d->ccell, 4);
  665. d->ccell->n_certs = 4;
  666. REENCODE();
  667. })
  668. CERTS_FAIL(link_mismatch, /* ed25519 */
  669. {
  670. require_failure_message = "Link certificate does not match "
  671. "TLS certificate";
  672. const tor_x509_cert_t *idc;
  673. tor_tls_get_my_certs(1, NULL, &idc);
  674. tor_x509_cert_free(mock_peer_cert);
  675. /* Pretend that the peer cert was something else. */
  676. mock_peer_cert = tor_x509_cert_dup(idc);
  677. /* No reencode needed. */
  678. })
  679. CERTS_FAIL(bad_ed_sig, /* ed25519 */
  680. {
  681. require_failure_message = "At least one Ed25519 certificate was "
  682. "badly signed";
  683. certs_cell_cert_t *cert = certs_cell_get_certs(d->ccell, 3);
  684. uint8_t *body = certs_cell_cert_getarray_body(cert);
  685. ssize_t body_len = certs_cell_cert_getlen_body(cert);
  686. /* Frob a byte in the signature */
  687. body[body_len - 13] ^= 7;
  688. REENCODE();
  689. })
  690. CERTS_FAIL(bad_crosscert, /*ed25519*/
  691. {
  692. require_failure_message = "Invalid RSA->Ed25519 crosscert";
  693. certs_cell_cert_t *cert = certs_cell_get_certs(d->ccell, 4);
  694. uint8_t *body = certs_cell_cert_getarray_body(cert);
  695. ssize_t body_len = certs_cell_cert_getlen_body(cert);
  696. /* Frob a byte in the signature */
  697. body[body_len - 13] ^= 7;
  698. REENCODE();
  699. })
  700. CERTS_FAIL(bad_rsa_id_cert, /*ed25519*/
  701. {
  702. require_failure_message = "legacy RSA ID certificate was not valid";
  703. certs_cell_cert_t *cert = certs_cell_get_certs(d->ccell, 1);
  704. uint8_t *body = certs_cell_cert_getarray_body(cert);
  705. ssize_t body_len = certs_cell_cert_getlen_body(cert);
  706. /* Frob a byte in the signature */
  707. body[body_len - 13] ^= 7;
  708. REENCODE();
  709. })
  710. CERTS_FAIL(expired_rsa_id, /* both */
  711. {
  712. require_failure_message = "Certificate already expired";
  713. /* we're going to replace the identity cert with an expired one. */
  714. certs_cell_cert_t *cert = certs_cell_get_certs(d->ccell, 1);
  715. const tor_x509_cert_t *idc;
  716. tor_tls_get_my_certs(1, NULL, &idc);
  717. X509 *newc = X509_dup(idc->cert);
  718. time_t new_end = time(NULL) - 86400 * 10;
  719. X509_time_adj(X509_get_notAfter(newc), 0, &new_end);
  720. EVP_PKEY *pk = crypto_pk_get_evp_pkey_(d->key2, 1);
  721. tt_assert(X509_sign(newc, pk, EVP_sha1()));
  722. int len = i2d_X509(newc, NULL);
  723. certs_cell_cert_setlen_body(cert, len);
  724. uint8_t *body = certs_cell_cert_getarray_body(cert);
  725. int len2 = i2d_X509(newc, &body);
  726. tt_int_op(len, ==, len2);
  727. REENCODE();
  728. X509_free(newc);
  729. EVP_PKEY_free(pk);
  730. })
  731. CERTS_FAIL(expired_ed_id, /* ed25519 */
  732. {
  733. /* we're going to replace the Ed Id->sign cert with an expired one. */
  734. require_failure_message = "At least one certificate expired";
  735. /* We don't need to re-sign, since we check for expiration first. */
  736. certs_cell_cert_t *cert = certs_cell_get_certs(d->ccell, 2);
  737. uint8_t *body = certs_cell_cert_getarray_body(cert);
  738. /* The expiration field is bytes [2..5]. It is in HOURS since the
  739. * epoch. */
  740. set_uint32(body+2, htonl(24)); /* Back to jan 2, 1970. */
  741. REENCODE();
  742. })
  743. CERTS_FAIL(expired_ed_link, /* ed25519 */
  744. {
  745. /* we're going to replace the Ed Sign->link cert with an expired one. */
  746. require_failure_message = "At least one certificate expired";
  747. /* We don't need to re-sign, since we check for expiration first. */
  748. certs_cell_cert_t *cert = certs_cell_get_certs(d->ccell, 3);
  749. uint8_t *body = certs_cell_cert_getarray_body(cert);
  750. /* The expiration field is bytes [2..5]. It is in HOURS since the
  751. * epoch. */
  752. set_uint32(body+2, htonl(24)); /* Back to jan 2, 1970. */
  753. REENCODE();
  754. })
  755. CERTS_FAIL(expired_crosscert, /* ed25519 */
  756. {
  757. /* we're going to replace the Ed Sign->link cert with an expired one. */
  758. require_failure_message = "Crosscert is expired";
  759. /* We don't need to re-sign, since we check for expiration first. */
  760. certs_cell_cert_t *cert = certs_cell_get_certs(d->ccell, 4);
  761. uint8_t *body = certs_cell_cert_getarray_body(cert);
  762. /* The expiration field is bytes [32..35]. once again, HOURS. */
  763. set_uint32(body+32, htonl(24)); /* Back to jan 2, 1970. */
  764. REENCODE();
  765. })
  766. CERTS_FAIL(wrong_labels_1,
  767. {
  768. require_failure_message = "The link certificate was not valid";
  769. certs_cell_get_certs(d->ccell, 0)->cert_type = 2;
  770. certs_cell_get_certs(d->ccell, 1)->cert_type = 1;
  771. REENCODE();
  772. })
  773. CERTS_FAIL(wrong_labels_2,
  774. {
  775. const tor_x509_cert_t *a;
  776. const tor_x509_cert_t *b;
  777. const uint8_t *enca;
  778. size_t lena;
  779. require_failure_message = "The link certificate was not valid";
  780. tor_tls_get_my_certs(1, &a, &b);
  781. tor_x509_cert_get_der(a, &enca, &lena);
  782. certs_cell_cert_setlen_body(certs_cell_get_certs(d->ccell, 1), lena);
  783. memcpy(certs_cell_cert_getarray_body(certs_cell_get_certs(d->ccell, 1)),
  784. enca, lena);
  785. certs_cell_get_certs(d->ccell, 1)->cert_len = lena;
  786. REENCODE();
  787. })
  788. CERTS_FAIL(wrong_labels_3,
  789. {
  790. require_failure_message =
  791. "The certs we wanted (ID, Link) were missing";
  792. certs_cell_get_certs(d->ccell, 0)->cert_type = 2;
  793. certs_cell_get_certs(d->ccell, 1)->cert_type = 3;
  794. REENCODE();
  795. })
  796. CERTS_FAIL(server_missing_certs,
  797. {
  798. require_failure_message =
  799. "The certs we wanted (ID, Auth) were missing";
  800. d->c->handshake_state->started_here = 0;
  801. d->c->handshake_state->certs->started_here = 0;
  802. })
  803. CERTS_FAIL(server_wrong_labels_1,
  804. {
  805. require_failure_message =
  806. "The authentication certificate was not valid";
  807. d->c->handshake_state->started_here = 0;
  808. d->c->handshake_state->certs->started_here = 0;
  809. certs_cell_get_certs(d->ccell, 0)->cert_type = 2;
  810. certs_cell_get_certs(d->ccell, 1)->cert_type = 3;
  811. REENCODE();
  812. })
  813. static void
  814. test_link_handshake_send_authchallenge(void *arg)
  815. {
  816. (void)arg;
  817. or_connection_t *c1 = or_connection_new(CONN_TYPE_OR, AF_INET);
  818. var_cell_t *cell1=NULL, *cell2=NULL;
  819. MOCK(connection_or_write_var_cell_to_buf, mock_write_var_cell);
  820. tt_int_op(connection_init_or_handshake_state(c1, 0), ==, 0);
  821. c1->base_.state = OR_CONN_STATE_OR_HANDSHAKING_V3;
  822. tt_assert(! mock_got_var_cell);
  823. tt_int_op(0, ==, connection_or_send_auth_challenge_cell(c1));
  824. cell1 = mock_got_var_cell;
  825. tt_int_op(0, ==, connection_or_send_auth_challenge_cell(c1));
  826. cell2 = mock_got_var_cell;
  827. tt_int_op(38, ==, cell1->payload_len);
  828. tt_int_op(38, ==, cell2->payload_len);
  829. tt_int_op(0, ==, cell1->circ_id);
  830. tt_int_op(0, ==, cell2->circ_id);
  831. tt_int_op(CELL_AUTH_CHALLENGE, ==, cell1->command);
  832. tt_int_op(CELL_AUTH_CHALLENGE, ==, cell2->command);
  833. tt_mem_op("\x00\x02\x00\x01\x00\x03", ==, cell1->payload + 32, 6);
  834. tt_mem_op("\x00\x02\x00\x01\x00\x03", ==, cell2->payload + 32, 6);
  835. tt_mem_op(cell1->payload, !=, cell2->payload, 32);
  836. done:
  837. UNMOCK(connection_or_write_var_cell_to_buf);
  838. connection_free_(TO_CONN(c1));
  839. tor_free(cell1);
  840. tor_free(cell2);
  841. }
  842. typedef struct authchallenge_data_s {
  843. or_connection_t *c;
  844. channel_tls_t *chan;
  845. var_cell_t *cell;
  846. } authchallenge_data_t;
  847. static int
  848. recv_authchallenge_cleanup(const struct testcase_t *test, void *obj)
  849. {
  850. (void)test;
  851. authchallenge_data_t *d = obj;
  852. UNMOCK(connection_or_send_netinfo);
  853. UNMOCK(connection_or_close_for_error);
  854. UNMOCK(connection_or_send_authenticate_cell);
  855. if (d) {
  856. tor_free(d->cell);
  857. connection_free_(TO_CONN(d->c));
  858. circuitmux_free(d->chan->base_.cmux);
  859. tor_free(d->chan);
  860. tor_free(d);
  861. }
  862. return 1;
  863. }
  864. static void *
  865. recv_authchallenge_setup(const struct testcase_t *test)
  866. {
  867. (void)test;
  868. authchallenge_data_t *d = tor_malloc_zero(sizeof(*d));
  869. d->c = or_connection_new(CONN_TYPE_OR, AF_INET);
  870. d->chan = tor_malloc_zero(sizeof(*d->chan));
  871. d->c->chan = d->chan;
  872. d->c->base_.address = tor_strdup("HaveAnAddress");
  873. d->c->base_.state = OR_CONN_STATE_OR_HANDSHAKING_V3;
  874. d->chan->conn = d->c;
  875. tt_int_op(connection_init_or_handshake_state(d->c, 1), ==, 0);
  876. d->c->link_proto = 4;
  877. d->c->handshake_state->received_certs_cell = 1;
  878. d->cell = var_cell_new(128);
  879. d->cell->payload_len = 38;
  880. d->cell->payload[33] = 2; /* 2 methods */
  881. d->cell->payload[35] = 7; /* This one isn't real */
  882. d->cell->payload[37] = 1; /* This is the old RSA one. */
  883. d->cell->command = CELL_AUTH_CHALLENGE;
  884. get_options_mutable()->ORPort_set = 1;
  885. MOCK(connection_or_close_for_error, mock_close_for_err);
  886. MOCK(connection_or_send_netinfo, mock_send_netinfo);
  887. MOCK(connection_or_send_authenticate_cell, mock_send_authenticate);
  888. tt_int_op(0, ==, d->c->handshake_state->received_auth_challenge);
  889. tt_int_op(0, ==, mock_send_authenticate_called);
  890. tt_int_op(0, ==, mock_send_netinfo_called);
  891. return d;
  892. done:
  893. recv_authchallenge_cleanup(test, d);
  894. return NULL;
  895. }
  896. static struct testcase_setup_t setup_recv_authchallenge = {
  897. .setup_fn = recv_authchallenge_setup,
  898. .cleanup_fn = recv_authchallenge_cleanup
  899. };
  900. static void
  901. test_link_handshake_recv_authchallenge_ok(void *arg)
  902. {
  903. authchallenge_data_t *d = arg;
  904. channel_tls_process_auth_challenge_cell(d->cell, d->chan);
  905. tt_int_op(0, ==, mock_close_called);
  906. tt_int_op(1, ==, d->c->handshake_state->received_auth_challenge);
  907. tt_int_op(1, ==, mock_send_authenticate_called);
  908. tt_int_op(1, ==, mock_send_netinfo_called);
  909. tt_int_op(1, ==, mock_send_authenticate_called_with_type); /* RSA */
  910. done:
  911. ;
  912. }
  913. static void
  914. test_link_handshake_recv_authchallenge_ok_ed25519(void *arg)
  915. {
  916. authchallenge_data_t *d = arg;
  917. /* Add the ed25519 authentication mechanism here. */
  918. d->cell->payload[33] = 3; /* 3 types are supported now. */
  919. d->cell->payload[39] = 3;
  920. d->cell->payload_len += 2;
  921. channel_tls_process_auth_challenge_cell(d->cell, d->chan);
  922. tt_int_op(0, ==, mock_close_called);
  923. tt_int_op(1, ==, d->c->handshake_state->received_auth_challenge);
  924. tt_int_op(1, ==, mock_send_authenticate_called);
  925. tt_int_op(1, ==, mock_send_netinfo_called);
  926. tt_int_op(3, ==, mock_send_authenticate_called_with_type); /* Ed25519 */
  927. done:
  928. ;
  929. }
  930. static void
  931. test_link_handshake_recv_authchallenge_ok_noserver(void *arg)
  932. {
  933. authchallenge_data_t *d = arg;
  934. get_options_mutable()->ORPort_set = 0;
  935. channel_tls_process_auth_challenge_cell(d->cell, d->chan);
  936. tt_int_op(0, ==, mock_close_called);
  937. tt_int_op(1, ==, d->c->handshake_state->received_auth_challenge);
  938. tt_int_op(0, ==, mock_send_authenticate_called);
  939. tt_int_op(0, ==, mock_send_netinfo_called);
  940. done:
  941. ;
  942. }
  943. static void
  944. test_link_handshake_recv_authchallenge_ok_unrecognized(void *arg)
  945. {
  946. authchallenge_data_t *d = arg;
  947. d->cell->payload[37] = 99;
  948. channel_tls_process_auth_challenge_cell(d->cell, d->chan);
  949. tt_int_op(0, ==, mock_close_called);
  950. tt_int_op(1, ==, d->c->handshake_state->received_auth_challenge);
  951. tt_int_op(0, ==, mock_send_authenticate_called);
  952. tt_int_op(1, ==, mock_send_netinfo_called);
  953. done:
  954. ;
  955. }
  956. #define AUTHCHALLENGE_FAIL(name, code) \
  957. static void \
  958. test_link_handshake_recv_authchallenge_ ## name(void *arg) \
  959. { \
  960. authchallenge_data_t *d = arg; \
  961. const char *require_failure_message = NULL; \
  962. setup_capture_of_logs(LOG_INFO); \
  963. { code ; } \
  964. channel_tls_process_auth_challenge_cell(d->cell, d->chan); \
  965. tt_int_op(1, ==, mock_close_called); \
  966. tt_int_op(0, ==, mock_send_authenticate_called); \
  967. tt_int_op(0, ==, mock_send_netinfo_called); \
  968. if (require_failure_message) { \
  969. expect_log_msg_containing(require_failure_message); \
  970. } \
  971. done: \
  972. teardown_capture_of_logs(); \
  973. }
  974. AUTHCHALLENGE_FAIL(badstate,
  975. require_failure_message = "We're not currently doing a "
  976. "v3 handshake";
  977. d->c->base_.state = OR_CONN_STATE_CONNECTING)
  978. AUTHCHALLENGE_FAIL(badproto,
  979. require_failure_message = "not using link protocol >= 3";
  980. d->c->link_proto = 2)
  981. AUTHCHALLENGE_FAIL(as_server,
  982. require_failure_message = "We didn't originate this "
  983. "connection";
  984. d->c->handshake_state->started_here = 0;
  985. d->c->handshake_state->certs->started_here = 0;)
  986. AUTHCHALLENGE_FAIL(duplicate,
  987. require_failure_message = "We already received one";
  988. d->c->handshake_state->received_auth_challenge = 1)
  989. AUTHCHALLENGE_FAIL(nocerts,
  990. require_failure_message = "We haven't gotten a CERTS "
  991. "cell yet";
  992. d->c->handshake_state->received_certs_cell = 0)
  993. AUTHCHALLENGE_FAIL(tooshort,
  994. require_failure_message = "It was not well-formed";
  995. d->cell->payload_len = 33)
  996. AUTHCHALLENGE_FAIL(truncated,
  997. require_failure_message = "It was not well-formed";
  998. d->cell->payload_len = 34)
  999. AUTHCHALLENGE_FAIL(nonzero_circid,
  1000. require_failure_message = "It had a nonzero circuit ID";
  1001. d->cell->circ_id = 1337)
  1002. static int
  1003. mock_get_tlssecrets(tor_tls_t *tls, uint8_t *secrets_out)
  1004. {
  1005. (void)tls;
  1006. memcpy(secrets_out, "int getRandomNumber(){return 4;}", 32);
  1007. return 0;
  1008. }
  1009. static void
  1010. mock_set_circid_type(channel_t *chan,
  1011. crypto_pk_t *identity_rcvd,
  1012. int consider_identity)
  1013. {
  1014. (void) chan;
  1015. (void) identity_rcvd;
  1016. (void) consider_identity;
  1017. }
  1018. typedef struct authenticate_data_s {
  1019. int is_ed;
  1020. or_connection_t *c1, *c2;
  1021. channel_tls_t *chan2;
  1022. var_cell_t *cell;
  1023. crypto_pk_t *key1, *key2;
  1024. } authenticate_data_t;
  1025. static int
  1026. authenticate_data_cleanup(const struct testcase_t *test, void *arg)
  1027. {
  1028. (void) test;
  1029. UNMOCK(connection_or_write_var_cell_to_buf);
  1030. UNMOCK(tor_tls_get_peer_cert);
  1031. UNMOCK(tor_tls_get_tlssecrets);
  1032. UNMOCK(connection_or_close_for_error);
  1033. UNMOCK(channel_set_circid_type);
  1034. UNMOCK(tor_tls_export_key_material);
  1035. authenticate_data_t *d = arg;
  1036. if (d) {
  1037. tor_free(d->cell);
  1038. connection_or_clear_identity(d->c1);
  1039. connection_or_clear_identity(d->c2);
  1040. connection_free_(TO_CONN(d->c1));
  1041. connection_free_(TO_CONN(d->c2));
  1042. circuitmux_free(d->chan2->base_.cmux);
  1043. tor_free(d->chan2);
  1044. crypto_pk_free(d->key1);
  1045. crypto_pk_free(d->key2);
  1046. tor_free(d);
  1047. }
  1048. mock_peer_cert = NULL;
  1049. return 1;
  1050. }
  1051. static void *
  1052. authenticate_data_setup(const struct testcase_t *test)
  1053. {
  1054. authenticate_data_t *d = tor_malloc_zero(sizeof(*d));
  1055. int is_ed = d->is_ed = (test->setup_data == (void*)3);
  1056. scheduler_init();
  1057. MOCK(connection_or_write_var_cell_to_buf, mock_write_var_cell);
  1058. MOCK(tor_tls_get_peer_cert, mock_get_peer_cert);
  1059. MOCK(tor_tls_get_tlssecrets, mock_get_tlssecrets);
  1060. MOCK(connection_or_close_for_error, mock_close_for_err);
  1061. MOCK(channel_set_circid_type, mock_set_circid_type);
  1062. MOCK(tor_tls_export_key_material, mock_export_key_material);
  1063. d->c1 = or_connection_new(CONN_TYPE_OR, AF_INET);
  1064. d->c2 = or_connection_new(CONN_TYPE_OR, AF_INET);
  1065. tor_addr_from_ipv4h(&d->c1->base_.addr, 0x01020304);
  1066. tor_addr_from_ipv4h(&d->c2->base_.addr, 0x05060708);
  1067. d->key1 = pk_generate(2);
  1068. d->key2 = pk_generate(3);
  1069. tt_int_op(tor_tls_context_init(TOR_TLS_CTX_IS_PUBLIC_SERVER,
  1070. d->key1, d->key2, 86400), ==, 0);
  1071. init_mock_ed_keys(d->key2);
  1072. d->c1->base_.state = OR_CONN_STATE_OR_HANDSHAKING_V3;
  1073. d->c1->link_proto = 3;
  1074. tt_int_op(connection_init_or_handshake_state(d->c1, 1), ==, 0);
  1075. d->c2->base_.state = OR_CONN_STATE_OR_HANDSHAKING_V3;
  1076. d->c2->link_proto = 3;
  1077. tt_int_op(connection_init_or_handshake_state(d->c2, 0), ==, 0);
  1078. var_cell_t *cell = var_cell_new(16);
  1079. cell->command = CELL_CERTS;
  1080. or_handshake_state_record_var_cell(d->c1, d->c1->handshake_state, cell, 1);
  1081. or_handshake_state_record_var_cell(d->c2, d->c2->handshake_state, cell, 0);
  1082. memset(cell->payload, 0xf0, 16);
  1083. or_handshake_state_record_var_cell(d->c1, d->c1->handshake_state, cell, 0);
  1084. or_handshake_state_record_var_cell(d->c2, d->c2->handshake_state, cell, 1);
  1085. tor_free(cell);
  1086. d->chan2 = tor_malloc_zero(sizeof(*d->chan2));
  1087. channel_tls_common_init(d->chan2);
  1088. d->c2->chan = d->chan2;
  1089. d->chan2->conn = d->c2;
  1090. d->c2->base_.address = tor_strdup("C2");
  1091. d->c2->tls = tor_tls_new(-1, 1);
  1092. d->c2->handshake_state->received_certs_cell = 1;
  1093. const tor_x509_cert_t *id_cert=NULL, *link_cert=NULL, *auth_cert=NULL;
  1094. tt_assert(! tor_tls_get_my_certs(1, &link_cert, &id_cert));
  1095. const uint8_t *der;
  1096. size_t sz;
  1097. tor_x509_cert_get_der(id_cert, &der, &sz);
  1098. d->c1->handshake_state->certs->id_cert = tor_x509_cert_decode(der, sz);
  1099. d->c2->handshake_state->certs->id_cert = tor_x509_cert_decode(der, sz);
  1100. if (is_ed) {
  1101. d->c1->handshake_state->certs->ed_id_sign =
  1102. tor_cert_dup(get_master_signing_key_cert());
  1103. d->c2->handshake_state->certs->ed_id_sign =
  1104. tor_cert_dup(get_master_signing_key_cert());
  1105. d->c2->handshake_state->certs->ed_sign_auth =
  1106. tor_cert_dup(get_current_auth_key_cert());
  1107. } else {
  1108. tt_assert(! tor_tls_get_my_certs(0, &auth_cert, &id_cert));
  1109. tor_x509_cert_get_der(auth_cert, &der, &sz);
  1110. d->c2->handshake_state->certs->auth_cert = tor_x509_cert_decode(der, sz);
  1111. }
  1112. tor_x509_cert_get_der(link_cert, &der, &sz);
  1113. mock_peer_cert = tor_x509_cert_decode(der, sz);
  1114. tt_assert(mock_peer_cert);
  1115. /* Make an authenticate cell ... */
  1116. int authtype;
  1117. if (is_ed)
  1118. authtype = AUTHTYPE_ED25519_SHA256_RFC5705;
  1119. else
  1120. authtype = AUTHTYPE_RSA_SHA256_TLSSECRET;
  1121. tt_int_op(0, ==, connection_or_send_authenticate_cell(d->c1, authtype));
  1122. tt_assert(mock_got_var_cell);
  1123. d->cell = mock_got_var_cell;
  1124. mock_got_var_cell = NULL;
  1125. return d;
  1126. done:
  1127. authenticate_data_cleanup(test, d);
  1128. return NULL;
  1129. }
  1130. static struct testcase_setup_t setup_authenticate = {
  1131. .setup_fn = authenticate_data_setup,
  1132. .cleanup_fn = authenticate_data_cleanup
  1133. };
  1134. static void
  1135. test_link_handshake_auth_cell(void *arg)
  1136. {
  1137. authenticate_data_t *d = arg;
  1138. auth1_t *auth1 = NULL;
  1139. crypto_pk_t *auth_pubkey = NULL;
  1140. /* Is the cell well-formed on the outer layer? */
  1141. tt_int_op(d->cell->command, ==, CELL_AUTHENTICATE);
  1142. tt_int_op(d->cell->payload[0], ==, 0);
  1143. if (d->is_ed)
  1144. tt_int_op(d->cell->payload[1], ==, 3);
  1145. else
  1146. tt_int_op(d->cell->payload[1], ==, 1);
  1147. tt_int_op(ntohs(get_uint16(d->cell->payload + 2)), ==,
  1148. d->cell->payload_len - 4);
  1149. /* Check it out for plausibility... */
  1150. auth_ctx_t ctx;
  1151. ctx.is_ed = d->is_ed;
  1152. tt_int_op(d->cell->payload_len-4, ==, auth1_parse(&auth1,
  1153. d->cell->payload+4,
  1154. d->cell->payload_len - 4, &ctx));
  1155. tt_assert(auth1);
  1156. if (d->is_ed) {
  1157. tt_mem_op(auth1->type, ==, "AUTH0003", 8);
  1158. } else {
  1159. tt_mem_op(auth1->type, ==, "AUTH0001", 8);
  1160. }
  1161. tt_mem_op(auth1->tlssecrets, ==, "int getRandomNumber(){return 4;}", 32);
  1162. /* Is the signature okay? */
  1163. const uint8_t *start = d->cell->payload+4, *end = auth1->end_of_signed;
  1164. if (d->is_ed) {
  1165. ed25519_signature_t sig;
  1166. tt_int_op(auth1_getlen_sig(auth1), ==, ED25519_SIG_LEN);
  1167. memcpy(&sig.sig, auth1_getarray_sig(auth1), ED25519_SIG_LEN);
  1168. tt_assert(!ed25519_checksig(&sig, start, end-start,
  1169. &get_current_auth_keypair()->pubkey));
  1170. } else {
  1171. uint8_t sig[128];
  1172. uint8_t digest[32];
  1173. tt_int_op(auth1_getlen_sig(auth1), >, 120);
  1174. auth_pubkey = tor_tls_cert_get_key(
  1175. d->c2->handshake_state->certs->auth_cert);
  1176. int n = crypto_pk_public_checksig(
  1177. auth_pubkey,
  1178. (char*)sig, sizeof(sig), (char*)auth1_getarray_sig(auth1),
  1179. auth1_getlen_sig(auth1));
  1180. tt_int_op(n, ==, 32);
  1181. crypto_digest256((char*)digest,
  1182. (const char*)start, end-start, DIGEST_SHA256);
  1183. tt_mem_op(sig, ==, digest, 32);
  1184. }
  1185. /* Then feed it to c2. */
  1186. tt_int_op(d->c2->handshake_state->authenticated, ==, 0);
  1187. channel_tls_process_authenticate_cell(d->cell, d->chan2);
  1188. tt_int_op(mock_close_called, ==, 0);
  1189. tt_int_op(d->c2->handshake_state->authenticated, ==, 1);
  1190. if (d->is_ed) {
  1191. tt_int_op(d->c2->handshake_state->authenticated_ed25519, ==, 1);
  1192. tt_int_op(d->c2->handshake_state->authenticated_rsa, ==, 1);
  1193. } else {
  1194. tt_int_op(d->c2->handshake_state->authenticated_ed25519, ==, 0);
  1195. tt_int_op(d->c2->handshake_state->authenticated_rsa, ==, 1);
  1196. }
  1197. done:
  1198. auth1_free(auth1);
  1199. crypto_pk_free(auth_pubkey);
  1200. }
  1201. #define AUTHENTICATE_FAIL(name, code) \
  1202. static void \
  1203. test_link_handshake_auth_ ## name(void *arg) \
  1204. { \
  1205. authenticate_data_t *d = arg; \
  1206. const char *require_failure_message = NULL; \
  1207. setup_capture_of_logs(LOG_INFO); \
  1208. { code ; } \
  1209. tt_int_op(d->c2->handshake_state->authenticated, ==, 0); \
  1210. channel_tls_process_authenticate_cell(d->cell, d->chan2); \
  1211. tt_int_op(mock_close_called, ==, 1); \
  1212. tt_int_op(d->c2->handshake_state->authenticated, ==, 0); \
  1213. if (require_failure_message) { \
  1214. expect_log_msg_containing(require_failure_message); \
  1215. } \
  1216. done: \
  1217. teardown_capture_of_logs(); \
  1218. }
  1219. AUTHENTICATE_FAIL(badstate,
  1220. require_failure_message = "We're not doing a v3 handshake";
  1221. d->c2->base_.state = OR_CONN_STATE_CONNECTING)
  1222. AUTHENTICATE_FAIL(badproto,
  1223. require_failure_message = "not using link protocol >= 3";
  1224. d->c2->link_proto = 2)
  1225. AUTHENTICATE_FAIL(atclient,
  1226. require_failure_message = "We originated this connection";
  1227. d->c2->handshake_state->started_here = 1;
  1228. d->c2->handshake_state->certs->started_here = 1;)
  1229. AUTHENTICATE_FAIL(duplicate,
  1230. require_failure_message = "We already got one";
  1231. d->c2->handshake_state->received_authenticate = 1)
  1232. static void
  1233. test_link_handshake_auth_already_authenticated(void *arg)
  1234. {
  1235. authenticate_data_t *d = arg;
  1236. setup_capture_of_logs(LOG_INFO);
  1237. d->c2->handshake_state->authenticated = 1;
  1238. channel_tls_process_authenticate_cell(d->cell, d->chan2);
  1239. tt_int_op(mock_close_called, ==, 1);
  1240. tt_int_op(d->c2->handshake_state->authenticated, ==, 1);
  1241. expect_log_msg_containing("The peer is already authenticated");
  1242. done:
  1243. teardown_capture_of_logs();
  1244. }
  1245. AUTHENTICATE_FAIL(nocerts,
  1246. require_failure_message = "We never got a certs cell";
  1247. d->c2->handshake_state->received_certs_cell = 0)
  1248. AUTHENTICATE_FAIL(noidcert,
  1249. require_failure_message = "We never got an identity "
  1250. "certificate";
  1251. tor_x509_cert_free(d->c2->handshake_state->certs->id_cert);
  1252. d->c2->handshake_state->certs->id_cert = NULL)
  1253. AUTHENTICATE_FAIL(noauthcert,
  1254. require_failure_message = "We never got an RSA "
  1255. "authentication certificate";
  1256. tor_x509_cert_free(d->c2->handshake_state->certs->auth_cert);
  1257. d->c2->handshake_state->certs->auth_cert = NULL)
  1258. AUTHENTICATE_FAIL(tooshort,
  1259. require_failure_message = "Cell was way too short";
  1260. d->cell->payload_len = 3)
  1261. AUTHENTICATE_FAIL(badtype,
  1262. require_failure_message = "Authenticator type was not "
  1263. "recognized";
  1264. d->cell->payload[0] = 0xff)
  1265. AUTHENTICATE_FAIL(truncated_1,
  1266. require_failure_message = "Authenticator was truncated";
  1267. d->cell->payload[2]++)
  1268. AUTHENTICATE_FAIL(truncated_2,
  1269. require_failure_message = "Authenticator was truncated";
  1270. d->cell->payload[3]++)
  1271. AUTHENTICATE_FAIL(tooshort_1,
  1272. require_failure_message = "Authenticator was too short";
  1273. tt_int_op(d->cell->payload_len, >=, 260);
  1274. d->cell->payload[2] -= 1;
  1275. d->cell->payload_len -= 256;)
  1276. AUTHENTICATE_FAIL(badcontent,
  1277. require_failure_message = "Some field in the AUTHENTICATE "
  1278. "cell body was not as expected";
  1279. d->cell->payload[10] ^= 0xff)
  1280. AUTHENTICATE_FAIL(badsig_1,
  1281. if (d->is_ed)
  1282. require_failure_message = "Ed25519 signature wasn't valid";
  1283. else
  1284. require_failure_message = "RSA signature wasn't valid";
  1285. d->cell->payload[d->cell->payload_len - 5] ^= 0xff)
  1286. AUTHENTICATE_FAIL(missing_ed_id,
  1287. {
  1288. tor_cert_free(d->c2->handshake_state->certs->ed_id_sign);
  1289. d->c2->handshake_state->certs->ed_id_sign = NULL;
  1290. require_failure_message = "Ed authenticate without Ed ID "
  1291. "cert from peer";
  1292. })
  1293. AUTHENTICATE_FAIL(missing_ed_auth,
  1294. {
  1295. tor_cert_free(d->c2->handshake_state->certs->ed_sign_auth);
  1296. d->c2->handshake_state->certs->ed_sign_auth = NULL;
  1297. require_failure_message = "We never got an Ed25519 "
  1298. "authentication certificate";
  1299. })
  1300. #define TEST_RSA(name, flags) \
  1301. { #name , test_link_handshake_ ## name, (flags), \
  1302. &passthrough_setup, (void*)"RSA" }
  1303. #define TEST_ED(name, flags) \
  1304. { #name "_ed25519" , test_link_handshake_ ## name, (flags), \
  1305. &passthrough_setup, (void*)"Ed25519" }
  1306. #define TEST_RCV_AUTHCHALLENGE(name) \
  1307. { "recv_authchallenge/" #name , \
  1308. test_link_handshake_recv_authchallenge_ ## name, TT_FORK, \
  1309. &setup_recv_authchallenge, NULL }
  1310. #define TEST_RCV_CERTS(name) \
  1311. { "recv_certs/" #name , \
  1312. test_link_handshake_recv_certs_ ## name, TT_FORK, \
  1313. &setup_recv_certs, (void*)"RSA-Link" }
  1314. #define TEST_RCV_CERTS_RSA(name,type) \
  1315. { "recv_certs/" #name , \
  1316. test_link_handshake_recv_certs_ ## name, TT_FORK, \
  1317. &setup_recv_certs, (void*)type }
  1318. #define TEST_RCV_CERTS_ED(name, type) \
  1319. { "recv_certs/" #name "_ed25519", \
  1320. test_link_handshake_recv_certs_ ## name, TT_FORK, \
  1321. &setup_recv_certs, (void*)type }
  1322. #define TEST_AUTHENTICATE(name) \
  1323. { "authenticate/" #name , test_link_handshake_auth_ ## name, TT_FORK, \
  1324. &setup_authenticate, NULL }
  1325. #define TEST_AUTHENTICATE_ED(name) \
  1326. { "authenticate/" #name "_ed25519" , test_link_handshake_auth_ ## name, \
  1327. TT_FORK, &setup_authenticate, (void*)3 }
  1328. struct testcase_t link_handshake_tests[] = {
  1329. TEST_RSA(certs_ok, TT_FORK),
  1330. TEST_ED(certs_ok, TT_FORK),
  1331. TEST_RCV_CERTS(ok),
  1332. TEST_RCV_CERTS_ED(ok, "Ed25519-Link"),
  1333. TEST_RCV_CERTS_RSA(ok_server, "RSA-Auth"),
  1334. TEST_RCV_CERTS_ED(ok_server, "Ed25519-Auth"),
  1335. TEST_RCV_CERTS(badstate),
  1336. TEST_RCV_CERTS(badproto),
  1337. TEST_RCV_CERTS(duplicate),
  1338. TEST_RCV_CERTS(already_authenticated),
  1339. TEST_RCV_CERTS(empty),
  1340. TEST_RCV_CERTS(bad_circid),
  1341. TEST_RCV_CERTS(truncated_1),
  1342. TEST_RCV_CERTS(truncated_2),
  1343. TEST_RCV_CERTS(truncated_3),
  1344. TEST_RCV_CERTS_ED(truncated_4, "Ed25519-Link"),
  1345. TEST_RCV_CERTS_ED(truncated_5, "Ed25519-Link"),
  1346. TEST_RCV_CERTS_ED(truncated_6, "Ed25519-Link"),
  1347. TEST_RCV_CERTS_ED(truncated_7, "Ed25519-Link"),
  1348. TEST_RCV_CERTS(not_x509),
  1349. TEST_RCV_CERTS(both_link),
  1350. TEST_RCV_CERTS(both_id_rsa),
  1351. TEST_RCV_CERTS(both_auth),
  1352. TEST_RCV_CERTS_ED(duplicate_id, "Ed25519-Link"),
  1353. TEST_RCV_CERTS_ED(duplicate_link, "Ed25519-Link"),
  1354. TEST_RCV_CERTS_ED(duplicate_crosscert, "Ed25519-Link"),
  1355. TEST_RCV_CERTS_ED(missing_crosscert, "Ed25519-Link"),
  1356. TEST_RCV_CERTS_ED(missing_id, "Ed25519-Link"),
  1357. TEST_RCV_CERTS_ED(missing_signing_key, "Ed25519-Link"),
  1358. TEST_RCV_CERTS_ED(missing_link, "Ed25519-Link"),
  1359. TEST_RCV_CERTS_ED(missing_auth, "Ed25519-Auth"),
  1360. TEST_RCV_CERTS_ED(missing_rsa_id, "Ed25519-Link"),
  1361. TEST_RCV_CERTS_ED(link_mismatch, "Ed25519-Link"),
  1362. TEST_RCV_CERTS_ED(bad_ed_sig, "Ed25519-Link"),
  1363. TEST_RCV_CERTS_ED(bad_rsa_id_cert, "Ed25519-Link"),
  1364. TEST_RCV_CERTS_ED(bad_crosscert, "Ed25519-Link"),
  1365. TEST_RCV_CERTS_RSA(expired_rsa_id, "RSA-Link"),
  1366. TEST_RCV_CERTS_ED(expired_rsa_id, "Ed25519-Link"),
  1367. TEST_RCV_CERTS_ED(expired_ed_id, "Ed25519-Link"),
  1368. TEST_RCV_CERTS_ED(expired_ed_link, "Ed25519-Link"),
  1369. TEST_RCV_CERTS_ED(expired_crosscert, "Ed25519-Link"),
  1370. TEST_RCV_CERTS(wrong_labels_1),
  1371. TEST_RCV_CERTS(wrong_labels_2),
  1372. TEST_RCV_CERTS(wrong_labels_3),
  1373. TEST_RCV_CERTS(server_missing_certs),
  1374. TEST_RCV_CERTS(server_wrong_labels_1),
  1375. TEST_RSA(send_authchallenge, TT_FORK),
  1376. TEST_RCV_AUTHCHALLENGE(ok),
  1377. TEST_RCV_AUTHCHALLENGE(ok_ed25519),
  1378. TEST_RCV_AUTHCHALLENGE(ok_noserver),
  1379. TEST_RCV_AUTHCHALLENGE(ok_unrecognized),
  1380. TEST_RCV_AUTHCHALLENGE(badstate),
  1381. TEST_RCV_AUTHCHALLENGE(badproto),
  1382. TEST_RCV_AUTHCHALLENGE(as_server),
  1383. TEST_RCV_AUTHCHALLENGE(duplicate),
  1384. TEST_RCV_AUTHCHALLENGE(nocerts),
  1385. TEST_RCV_AUTHCHALLENGE(tooshort),
  1386. TEST_RCV_AUTHCHALLENGE(truncated),
  1387. TEST_RCV_AUTHCHALLENGE(nonzero_circid),
  1388. TEST_AUTHENTICATE(cell),
  1389. TEST_AUTHENTICATE_ED(cell),
  1390. TEST_AUTHENTICATE(badstate),
  1391. TEST_AUTHENTICATE(badproto),
  1392. TEST_AUTHENTICATE(atclient),
  1393. TEST_AUTHENTICATE(duplicate),
  1394. TEST_AUTHENTICATE(already_authenticated),
  1395. TEST_AUTHENTICATE(nocerts),
  1396. TEST_AUTHENTICATE(noidcert),
  1397. TEST_AUTHENTICATE(noauthcert),
  1398. TEST_AUTHENTICATE(tooshort),
  1399. TEST_AUTHENTICATE(badtype),
  1400. TEST_AUTHENTICATE(truncated_1),
  1401. TEST_AUTHENTICATE(truncated_2),
  1402. TEST_AUTHENTICATE(tooshort_1),
  1403. TEST_AUTHENTICATE(badcontent),
  1404. TEST_AUTHENTICATE(badsig_1),
  1405. TEST_AUTHENTICATE_ED(badsig_1),
  1406. TEST_AUTHENTICATE_ED(missing_ed_id),
  1407. TEST_AUTHENTICATE_ED(missing_ed_auth),
  1408. //TEST_AUTHENTICATE(),
  1409. END_OF_TESTCASES
  1410. };