test_link_handshake.c 55 KB

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