test_link_handshake.c 55 KB

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