test_link_handshake.c 56 KB

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