test_link_handshake.c 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521
  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(40, ==, cell1->payload_len);
  821. tt_int_op(40, ==, 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\x03\x00\x01\x00\x02\x00\x03", ==, cell1->payload + 32, 8);
  827. tt_mem_op("\x00\x03\x00\x01\x00\x02\x00\x03", ==, cell2->payload + 32, 8);
  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(d->c2->handshake_state->certs->auth_cert);
  1168. int n = crypto_pk_public_checksig(
  1169. auth_pubkey,
  1170. (char*)sig, sizeof(sig), (char*)auth1_getarray_sig(auth1),
  1171. auth1_getlen_sig(auth1));
  1172. tt_int_op(n, ==, 32);
  1173. crypto_digest256((char*)digest,
  1174. (const char*)start, end-start, DIGEST_SHA256);
  1175. tt_mem_op(sig, ==, digest, 32);
  1176. }
  1177. /* Then feed it to c2. */
  1178. tt_int_op(d->c2->handshake_state->authenticated, ==, 0);
  1179. channel_tls_process_authenticate_cell(d->cell, d->chan2);
  1180. tt_int_op(mock_close_called, ==, 0);
  1181. tt_int_op(d->c2->handshake_state->authenticated, ==, 1);
  1182. if (d->is_ed) {
  1183. tt_int_op(d->c2->handshake_state->authenticated_ed25519, ==, 1);
  1184. tt_int_op(d->c2->handshake_state->authenticated_rsa, ==, 1);
  1185. } else {
  1186. tt_int_op(d->c2->handshake_state->authenticated_ed25519, ==, 0);
  1187. tt_int_op(d->c2->handshake_state->authenticated_rsa, ==, 1);
  1188. }
  1189. done:
  1190. auth1_free(auth1);
  1191. crypto_pk_free(auth_pubkey);
  1192. }
  1193. #define AUTHENTICATE_FAIL(name, code) \
  1194. static void \
  1195. test_link_handshake_auth_ ## name(void *arg) \
  1196. { \
  1197. authenticate_data_t *d = arg; \
  1198. const char *require_failure_message = NULL; \
  1199. setup_capture_of_logs(LOG_INFO); \
  1200. { code ; } \
  1201. tt_int_op(d->c2->handshake_state->authenticated, ==, 0); \
  1202. channel_tls_process_authenticate_cell(d->cell, d->chan2); \
  1203. tt_int_op(mock_close_called, ==, 1); \
  1204. tt_int_op(d->c2->handshake_state->authenticated, ==, 0); \
  1205. if (require_failure_message) { \
  1206. expect_log_msg_containing(require_failure_message); \
  1207. } \
  1208. done: \
  1209. teardown_capture_of_logs(); \
  1210. }
  1211. AUTHENTICATE_FAIL(badstate,
  1212. require_failure_message = "We're not doing a v3 handshake";
  1213. d->c2->base_.state = OR_CONN_STATE_CONNECTING)
  1214. AUTHENTICATE_FAIL(badproto,
  1215. require_failure_message = "not using link protocol >= 3";
  1216. d->c2->link_proto = 2)
  1217. AUTHENTICATE_FAIL(atclient,
  1218. require_failure_message = "We originated this connection";
  1219. d->c2->handshake_state->started_here = 1;
  1220. d->c2->handshake_state->certs->started_here = 1;)
  1221. AUTHENTICATE_FAIL(duplicate,
  1222. require_failure_message = "We already got one";
  1223. d->c2->handshake_state->received_authenticate = 1)
  1224. static void
  1225. test_link_handshake_auth_already_authenticated(void *arg)
  1226. {
  1227. authenticate_data_t *d = arg;
  1228. setup_capture_of_logs(LOG_INFO);
  1229. d->c2->handshake_state->authenticated = 1;
  1230. channel_tls_process_authenticate_cell(d->cell, d->chan2);
  1231. tt_int_op(mock_close_called, ==, 1);
  1232. tt_int_op(d->c2->handshake_state->authenticated, ==, 1);
  1233. expect_log_msg_containing("The peer is already authenticated");
  1234. done:
  1235. teardown_capture_of_logs();
  1236. }
  1237. AUTHENTICATE_FAIL(nocerts,
  1238. require_failure_message = "We never got a certs cell";
  1239. d->c2->handshake_state->received_certs_cell = 0)
  1240. AUTHENTICATE_FAIL(noidcert,
  1241. require_failure_message = "We never got an identity "
  1242. "certificate";
  1243. tor_x509_cert_free(d->c2->handshake_state->certs->id_cert);
  1244. d->c2->handshake_state->certs->id_cert = NULL)
  1245. AUTHENTICATE_FAIL(noauthcert,
  1246. require_failure_message = "We never got an RSA "
  1247. "authentication certificate";
  1248. tor_x509_cert_free(d->c2->handshake_state->certs->auth_cert);
  1249. d->c2->handshake_state->certs->auth_cert = NULL)
  1250. AUTHENTICATE_FAIL(tooshort,
  1251. require_failure_message = "Cell was way too short";
  1252. d->cell->payload_len = 3)
  1253. AUTHENTICATE_FAIL(badtype,
  1254. require_failure_message = "Authenticator type was not "
  1255. "recognized";
  1256. d->cell->payload[0] = 0xff)
  1257. AUTHENTICATE_FAIL(truncated_1,
  1258. require_failure_message = "Authenticator was truncated";
  1259. d->cell->payload[2]++)
  1260. AUTHENTICATE_FAIL(truncated_2,
  1261. require_failure_message = "Authenticator was truncated";
  1262. d->cell->payload[3]++)
  1263. AUTHENTICATE_FAIL(tooshort_1,
  1264. require_failure_message = "Authenticator was too short";
  1265. tt_int_op(d->cell->payload_len, >=, 260);
  1266. d->cell->payload[2] -= 1;
  1267. d->cell->payload_len -= 256;)
  1268. AUTHENTICATE_FAIL(badcontent,
  1269. require_failure_message = "Some field in the AUTHENTICATE "
  1270. "cell body was not as expected";
  1271. d->cell->payload[10] ^= 0xff)
  1272. AUTHENTICATE_FAIL(badsig_1,
  1273. require_failure_message = "RSA signature wasn't valid";
  1274. d->cell->payload[d->cell->payload_len - 5] ^= 0xff)
  1275. #define TEST_RSA(name, flags) \
  1276. { #name , test_link_handshake_ ## name, (flags), \
  1277. &passthrough_setup, (void*)"RSA" }
  1278. #define TEST_ED(name, flags) \
  1279. { #name "_ed25519" , test_link_handshake_ ## name, (flags), \
  1280. &passthrough_setup, (void*)"Ed25519" }
  1281. #define TEST_RCV_AUTHCHALLENGE(name) \
  1282. { "recv_authchallenge/" #name , \
  1283. test_link_handshake_recv_authchallenge_ ## name, TT_FORK, \
  1284. &setup_recv_authchallenge, NULL }
  1285. #define TEST_RCV_CERTS(name) \
  1286. { "recv_certs/" #name , \
  1287. test_link_handshake_recv_certs_ ## name, TT_FORK, \
  1288. &setup_recv_certs, (void*)"RSA-Link" }
  1289. #define TEST_RCV_CERTS_RSA(name,type) \
  1290. { "recv_certs/" #name , \
  1291. test_link_handshake_recv_certs_ ## name, TT_FORK, \
  1292. &setup_recv_certs, (void*)type }
  1293. #define TEST_RCV_CERTS_ED(name, type) \
  1294. { "recv_certs/" #name "_ed25519", \
  1295. test_link_handshake_recv_certs_ ## name, TT_FORK, \
  1296. &setup_recv_certs, (void*)type }
  1297. #define TEST_AUTHENTICATE(name) \
  1298. { "authenticate/" #name , test_link_handshake_auth_ ## name, TT_FORK, \
  1299. &setup_authenticate, NULL }
  1300. #define TEST_AUTHENTICATE_ED(name) \
  1301. { "authenticate/" #name "_ed25519" , test_link_handshake_auth_ ## name, \
  1302. TT_FORK, &setup_authenticate, (void*)3 }
  1303. struct testcase_t link_handshake_tests[] = {
  1304. TEST_RSA(certs_ok, TT_FORK),
  1305. TEST_ED(certs_ok, TT_FORK),
  1306. TEST_RCV_CERTS(ok),
  1307. TEST_RCV_CERTS_ED(ok, "Ed25519-Link"),
  1308. TEST_RCV_CERTS_RSA(ok_server, "RSA-Auth"),
  1309. TEST_RCV_CERTS_ED(ok_server, "Ed25519-Auth"),
  1310. TEST_RCV_CERTS(badstate),
  1311. TEST_RCV_CERTS(badproto),
  1312. TEST_RCV_CERTS(duplicate),
  1313. TEST_RCV_CERTS(already_authenticated),
  1314. TEST_RCV_CERTS(empty),
  1315. TEST_RCV_CERTS(bad_circid),
  1316. TEST_RCV_CERTS(truncated_1),
  1317. TEST_RCV_CERTS(truncated_2),
  1318. TEST_RCV_CERTS(truncated_3),
  1319. TEST_RCV_CERTS_ED(truncated_4, "Ed25519-Link"),
  1320. TEST_RCV_CERTS_ED(truncated_5, "Ed25519-Link"),
  1321. TEST_RCV_CERTS_ED(truncated_6, "Ed25519-Link"),
  1322. TEST_RCV_CERTS_ED(truncated_7, "Ed25519-Link"),
  1323. TEST_RCV_CERTS(not_x509),
  1324. TEST_RCV_CERTS(both_link),
  1325. TEST_RCV_CERTS(both_id_rsa),
  1326. TEST_RCV_CERTS(both_auth),
  1327. TEST_RCV_CERTS_ED(duplicate_id, "Ed25519-Link"),
  1328. TEST_RCV_CERTS_ED(duplicate_link, "Ed25519-Link"),
  1329. TEST_RCV_CERTS_ED(duplicate_crosscert, "Ed25519-Link"),
  1330. TEST_RCV_CERTS_ED(missing_crosscert, "Ed25519-Link"),
  1331. TEST_RCV_CERTS_ED(missing_id, "Ed25519-Link"),
  1332. TEST_RCV_CERTS_ED(missing_signing_key, "Ed25519-Link"),
  1333. TEST_RCV_CERTS_ED(missing_link, "Ed25519-Link"),
  1334. TEST_RCV_CERTS_ED(missing_auth, "Ed25519-Auth"),
  1335. TEST_RCV_CERTS_ED(missing_rsa_id, "Ed25519-Link"),
  1336. TEST_RCV_CERTS_ED(link_mismatch, "Ed25519-Link"),
  1337. TEST_RCV_CERTS_ED(bad_ed_sig, "Ed25519-Link"),
  1338. TEST_RCV_CERTS_ED(bad_rsa_id_cert, "Ed25519-Link"),
  1339. TEST_RCV_CERTS_ED(bad_crosscert, "Ed25519-Link"),
  1340. TEST_RCV_CERTS_RSA(expired_rsa_id, "RSA-Link"),
  1341. TEST_RCV_CERTS_ED(expired_rsa_id, "Ed25519-Link"),
  1342. TEST_RCV_CERTS_ED(expired_ed_id, "Ed25519-Link"),
  1343. TEST_RCV_CERTS_ED(expired_ed_link, "Ed25519-Link"),
  1344. TEST_RCV_CERTS_ED(expired_crosscert, "Ed25519-Link"),
  1345. TEST_RCV_CERTS(wrong_labels_1),
  1346. TEST_RCV_CERTS(wrong_labels_2),
  1347. TEST_RCV_CERTS(wrong_labels_3),
  1348. TEST_RCV_CERTS(server_missing_certs),
  1349. TEST_RCV_CERTS(server_wrong_labels_1),
  1350. TEST_RSA(send_authchallenge, TT_FORK),
  1351. TEST_RCV_AUTHCHALLENGE(ok),
  1352. TEST_RCV_AUTHCHALLENGE(ok_ed25519),
  1353. TEST_RCV_AUTHCHALLENGE(ok_noserver),
  1354. TEST_RCV_AUTHCHALLENGE(ok_unrecognized),
  1355. TEST_RCV_AUTHCHALLENGE(badstate),
  1356. TEST_RCV_AUTHCHALLENGE(badproto),
  1357. TEST_RCV_AUTHCHALLENGE(as_server),
  1358. TEST_RCV_AUTHCHALLENGE(duplicate),
  1359. TEST_RCV_AUTHCHALLENGE(nocerts),
  1360. TEST_RCV_AUTHCHALLENGE(tooshort),
  1361. TEST_RCV_AUTHCHALLENGE(truncated),
  1362. TEST_RCV_AUTHCHALLENGE(nonzero_circid),
  1363. TEST_AUTHENTICATE(cell),
  1364. TEST_AUTHENTICATE_ED(cell),
  1365. TEST_AUTHENTICATE(badstate),
  1366. TEST_AUTHENTICATE(badproto),
  1367. TEST_AUTHENTICATE(atclient),
  1368. TEST_AUTHENTICATE(duplicate),
  1369. TEST_AUTHENTICATE(already_authenticated),
  1370. TEST_AUTHENTICATE(nocerts),
  1371. TEST_AUTHENTICATE(noidcert),
  1372. TEST_AUTHENTICATE(noauthcert),
  1373. TEST_AUTHENTICATE(tooshort),
  1374. TEST_AUTHENTICATE(badtype),
  1375. TEST_AUTHENTICATE(truncated_1),
  1376. TEST_AUTHENTICATE(truncated_2),
  1377. TEST_AUTHENTICATE(tooshort_1),
  1378. TEST_AUTHENTICATE(badcontent),
  1379. TEST_AUTHENTICATE(badsig_1),
  1380. //TEST_AUTHENTICATE(),
  1381. END_OF_TESTCASES
  1382. };