test_link_handshake.c 55 KB

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