test_hs_service.c 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144
  1. /* Copyright (c) 2016-2018, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. /**
  4. * \file test_hs_service.c
  5. * \brief Test hidden service functionality.
  6. */
  7. #define CIRCUITBUILD_PRIVATE
  8. #define CIRCUITLIST_PRIVATE
  9. #define CONFIG_PRIVATE
  10. #define CONNECTION_PRIVATE
  11. #define CONNECTION_EDGE_PRIVATE
  12. #define CRYPTO_PRIVATE
  13. #define HS_COMMON_PRIVATE
  14. #define HS_SERVICE_PRIVATE
  15. #define HS_INTROPOINT_PRIVATE
  16. #define HS_CIRCUIT_PRIVATE
  17. #define MAINLOOP_PRIVATE
  18. #define NETWORKSTATUS_PRIVATE
  19. #define STATEFILE_PRIVATE
  20. #define TOR_CHANNEL_INTERNAL_
  21. #define HS_CLIENT_PRIVATE
  22. #include "test/test.h"
  23. #include "test/test_helpers.h"
  24. #include "test/log_test_helpers.h"
  25. #include "test/rend_test_helpers.h"
  26. #include "test/hs_test_helpers.h"
  27. #include "core/or/or.h"
  28. #include "app/config/config.h"
  29. #include "app/config/statefile.h"
  30. #include "core/crypto/hs_ntor.h"
  31. #include "core/mainloop/connection.h"
  32. #include "core/mainloop/mainloop.h"
  33. #include "core/or/circuitbuild.h"
  34. #include "core/or/circuitlist.h"
  35. #include "core/or/circuituse.h"
  36. #include "core/or/connection_edge.h"
  37. #include "core/or/edge_connection_st.h"
  38. #include "core/or/relay.h"
  39. #include "core/or/versions.h"
  40. #include "feature/dirauth/dirvote.h"
  41. #include "feature/dirauth/shared_random_state.h"
  42. #include "feature/dircommon/voting_schedule.h"
  43. #include "feature/hs/hs_circuit.h"
  44. #include "feature/hs/hs_circuitmap.h"
  45. #include "feature/hs/hs_client.h"
  46. #include "feature/hs/hs_common.h"
  47. #include "feature/hs/hs_config.h"
  48. #include "feature/hs/hs_ident.h"
  49. #include "feature/hs/hs_intropoint.h"
  50. #include "feature/hs/hs_service.h"
  51. #include "feature/nodelist/networkstatus.h"
  52. #include "feature/nodelist/nodelist.h"
  53. #include "feature/rend/rendservice.h"
  54. #include "lib/crypt_ops/crypto_rand.h"
  55. #include "lib/fs/dir.h"
  56. #include "core/or/cpath_build_state_st.h"
  57. #include "core/or/crypt_path_st.h"
  58. #include "feature/nodelist/networkstatus_st.h"
  59. #include "feature/nodelist/node_st.h"
  60. #include "core/or/origin_circuit_st.h"
  61. #include "app/config/or_state_st.h"
  62. #include "feature/nodelist/routerinfo_st.h"
  63. /* Trunnel */
  64. #include "trunnel/hs/cell_establish_intro.h"
  65. #ifdef HAVE_SYS_STAT_H
  66. #include <sys/stat.h>
  67. #endif
  68. #ifdef HAVE_UNISTD_H
  69. #include <unistd.h>
  70. #endif
  71. static networkstatus_t mock_ns;
  72. static networkstatus_t *
  73. mock_networkstatus_get_live_consensus(time_t now)
  74. {
  75. (void) now;
  76. return &mock_ns;
  77. }
  78. static or_state_t *dummy_state = NULL;
  79. /* Mock function to get fake or state (used for rev counters) */
  80. static or_state_t *
  81. get_or_state_replacement(void)
  82. {
  83. return dummy_state;
  84. }
  85. /* Mock function because we are not trying to test the close circuit that does
  86. * an awful lot of checks on the circuit object. */
  87. static void
  88. mock_circuit_mark_for_close(circuit_t *circ, int reason, int line,
  89. const char *file)
  90. {
  91. (void) circ;
  92. (void) reason;
  93. (void) line;
  94. (void) file;
  95. return;
  96. }
  97. static int
  98. mock_relay_send_command_from_edge(streamid_t stream_id, circuit_t *circ,
  99. uint8_t relay_command, const char *payload,
  100. size_t payload_len,
  101. crypt_path_t *cpath_layer,
  102. const char *filename, int lineno)
  103. {
  104. (void) stream_id;
  105. (void) circ;
  106. (void) relay_command;
  107. (void) payload;
  108. (void) payload_len;
  109. (void) cpath_layer;
  110. (void) filename;
  111. (void) lineno;
  112. return 0;
  113. }
  114. /* Helper: from a set of options in conf, configure a service which will add
  115. * it to the staging list of the HS subsytem. */
  116. static int
  117. helper_config_service(const char *conf)
  118. {
  119. int ret = 0;
  120. or_options_t *options = NULL;
  121. tt_assert(conf);
  122. options = helper_parse_options(conf);
  123. tt_assert(options);
  124. ret = hs_config_service_all(options, 0);
  125. done:
  126. or_options_free(options);
  127. return ret;
  128. }
  129. /* Test: Ensure that setting up rendezvous circuits works correctly. */
  130. static void
  131. test_e2e_rend_circuit_setup(void *arg)
  132. {
  133. ed25519_public_key_t service_pk;
  134. origin_circuit_t *or_circ;
  135. int retval;
  136. /** In this test we create a v3 prop224 service-side rendezvous circuit.
  137. * We simulate an HS ntor key exchange with a client, and check that
  138. * the circuit was setup correctly and is ready to accept rendezvous data */
  139. (void) arg;
  140. /* Now make dummy circuit */
  141. {
  142. or_circ = origin_circuit_new();
  143. or_circ->base_.purpose = CIRCUIT_PURPOSE_S_CONNECT_REND;
  144. or_circ->build_state = tor_malloc_zero(sizeof(cpath_build_state_t));
  145. or_circ->build_state->is_internal = 1;
  146. /* prop224: Setup hs conn identifier on the stream */
  147. ed25519_secret_key_t sk;
  148. tt_int_op(0, OP_EQ, ed25519_secret_key_generate(&sk, 0));
  149. tt_int_op(0, OP_EQ, ed25519_public_key_generate(&service_pk, &sk));
  150. or_circ->hs_ident = hs_ident_circuit_new(&service_pk,
  151. HS_IDENT_CIRCUIT_RENDEZVOUS);
  152. TO_CIRCUIT(or_circ)->state = CIRCUIT_STATE_OPEN;
  153. }
  154. /* Check number of hops */
  155. retval = cpath_get_n_hops(&or_circ->cpath);
  156. tt_int_op(retval, OP_EQ, 0);
  157. /* Setup the circuit: do the ntor key exchange */
  158. {
  159. uint8_t ntor_key_seed[DIGEST256_LEN] = {2};
  160. retval = hs_circuit_setup_e2e_rend_circ(or_circ,
  161. ntor_key_seed, sizeof(ntor_key_seed),
  162. 1);
  163. tt_int_op(retval, OP_EQ, 0);
  164. }
  165. /* See that a hop was added to the circuit's cpath */
  166. retval = cpath_get_n_hops(&or_circ->cpath);
  167. tt_int_op(retval, OP_EQ, 1);
  168. /* Check the digest algo */
  169. tt_int_op(crypto_digest_get_algorithm(or_circ->cpath->crypto.f_digest),
  170. OP_EQ, DIGEST_SHA3_256);
  171. tt_int_op(crypto_digest_get_algorithm(or_circ->cpath->crypto.b_digest),
  172. OP_EQ, DIGEST_SHA3_256);
  173. tt_assert(or_circ->cpath->crypto.f_crypto);
  174. tt_assert(or_circ->cpath->crypto.b_crypto);
  175. /* Ensure that circ purpose was changed */
  176. tt_int_op(or_circ->base_.purpose, OP_EQ, CIRCUIT_PURPOSE_S_REND_JOINED);
  177. done:
  178. circuit_free_(TO_CIRCUIT(or_circ));
  179. }
  180. /* Helper: Return a newly allocated and initialized origin circuit with
  181. * purpose and flags. A default HS identifier is set to an ed25519
  182. * authentication key for introduction point. */
  183. static origin_circuit_t *
  184. helper_create_origin_circuit(int purpose, int flags)
  185. {
  186. origin_circuit_t *circ = NULL;
  187. circ = origin_circuit_init(purpose, flags);
  188. tor_assert(circ);
  189. circ->cpath = tor_malloc_zero(sizeof(crypt_path_t));
  190. circ->cpath->magic = CRYPT_PATH_MAGIC;
  191. circ->cpath->state = CPATH_STATE_OPEN;
  192. circ->cpath->package_window = circuit_initial_package_window();
  193. circ->cpath->deliver_window = CIRCWINDOW_START;
  194. circ->cpath->prev = circ->cpath;
  195. /* Random nonce. */
  196. crypto_rand(circ->cpath->prev->rend_circ_nonce, DIGEST_LEN);
  197. /* Create a default HS identifier. */
  198. circ->hs_ident = tor_malloc_zero(sizeof(hs_ident_circuit_t));
  199. return circ;
  200. }
  201. /* Helper: Return a newly allocated authorized client object with
  202. * and a newly generated public key. */
  203. static hs_service_authorized_client_t *
  204. helper_create_authorized_client(void)
  205. {
  206. int ret;
  207. hs_service_authorized_client_t *client;
  208. curve25519_secret_key_t seckey;
  209. client = tor_malloc_zero(sizeof(hs_service_authorized_client_t));
  210. ret = curve25519_secret_key_generate(&seckey, 0);
  211. tt_int_op(ret, OP_EQ, 0);
  212. curve25519_public_key_generate(&client->client_pk, &seckey);
  213. done:
  214. return client;
  215. }
  216. /* Helper: Return a newly allocated authorized client object with the
  217. * same client name and the same public key as the given client. */
  218. static hs_service_authorized_client_t *
  219. helper_clone_authorized_client(const hs_service_authorized_client_t *client)
  220. {
  221. hs_service_authorized_client_t *client_out;
  222. tor_assert(client);
  223. client_out = tor_malloc_zero(sizeof(hs_service_authorized_client_t));
  224. memcpy(client_out->client_pk.public_key,
  225. client->client_pk.public_key, CURVE25519_PUBKEY_LEN);
  226. return client_out;
  227. }
  228. /* Helper: Return a newly allocated service object with the identity keypair
  229. * sets and the current descriptor. Then register it to the global map.
  230. * Caller should us hs_free_all() to free this service or remove it from the
  231. * global map before freeing. */
  232. static hs_service_t *
  233. helper_create_service(void)
  234. {
  235. /* Set a service for this circuit. */
  236. hs_service_t *service = hs_service_new(get_options());
  237. tor_assert(service);
  238. service->config.version = HS_VERSION_THREE;
  239. ed25519_secret_key_generate(&service->keys.identity_sk, 0);
  240. ed25519_public_key_generate(&service->keys.identity_pk,
  241. &service->keys.identity_sk);
  242. service->desc_current = service_descriptor_new();
  243. tt_assert(service->desc_current);
  244. /* Register service to global map. */
  245. int ret = register_service(get_hs_service_map(), service);
  246. tt_int_op(ret, OP_EQ, 0);
  247. done:
  248. return service;
  249. }
  250. /* Helper: Return a newly allocated service object with clients. */
  251. static hs_service_t *
  252. helper_create_service_with_clients(int num_clients)
  253. {
  254. int i;
  255. hs_service_t *service = helper_create_service();
  256. tt_assert(service);
  257. service->config.is_client_auth_enabled = 1;
  258. service->config.clients = smartlist_new();
  259. for (i = 0; i < num_clients; i++) {
  260. hs_service_authorized_client_t *client;
  261. client = helper_create_authorized_client();
  262. smartlist_add(service->config.clients, client);
  263. }
  264. done:
  265. return service;
  266. }
  267. /* Helper: Return a newly allocated service intro point with two link
  268. * specifiers, one IPv4 and one legacy ID set to As. */
  269. static hs_service_intro_point_t *
  270. helper_create_service_ip(void)
  271. {
  272. hs_desc_link_specifier_t *ls;
  273. hs_service_intro_point_t *ip = service_intro_point_new(NULL, 0, 0);
  274. tor_assert(ip);
  275. /* Add a first unused link specifier. */
  276. ls = tor_malloc_zero(sizeof(*ls));
  277. ls->type = LS_IPV4;
  278. smartlist_add(ip->base.link_specifiers, ls);
  279. /* Add a second link specifier used by a test. */
  280. ls = tor_malloc_zero(sizeof(*ls));
  281. ls->type = LS_LEGACY_ID;
  282. memset(ls->u.legacy_id, 'A', sizeof(ls->u.legacy_id));
  283. smartlist_add(ip->base.link_specifiers, ls);
  284. return ip;
  285. }
  286. static void
  287. test_load_keys(void *arg)
  288. {
  289. int ret;
  290. char *conf = NULL;
  291. char *hsdir_v2 = tor_strdup(get_fname("hs2"));
  292. char *hsdir_v3 = tor_strdup(get_fname("hs3"));
  293. char addr[HS_SERVICE_ADDR_LEN_BASE32 + 1];
  294. (void) arg;
  295. /* We'll register two services, a v2 and a v3, then we'll load keys and
  296. * validate that both are in a correct state. */
  297. hs_init();
  298. #define conf_fmt \
  299. "HiddenServiceDir %s\n" \
  300. "HiddenServiceVersion %d\n" \
  301. "HiddenServicePort 65535\n"
  302. /* v2 service. */
  303. tor_asprintf(&conf, conf_fmt, hsdir_v2, HS_VERSION_TWO);
  304. ret = helper_config_service(conf);
  305. tor_free(conf);
  306. tt_int_op(ret, OP_EQ, 0);
  307. /* This one should now be registered into the v2 list. */
  308. tt_int_op(get_hs_service_staging_list_size(), OP_EQ, 0);
  309. tt_int_op(rend_num_services(), OP_EQ, 1);
  310. /* v3 service. */
  311. tor_asprintf(&conf, conf_fmt, hsdir_v3, HS_VERSION_THREE);
  312. ret = helper_config_service(conf);
  313. tor_free(conf);
  314. tt_int_op(ret, OP_EQ, 0);
  315. /* It's in staging? */
  316. tt_int_op(get_hs_service_staging_list_size(), OP_EQ, 1);
  317. #undef conf_fmt
  318. /* Load the keys for these. After that, the v3 service should be registered
  319. * in the global map. */
  320. hs_service_load_all_keys();
  321. tt_int_op(get_hs_service_map_size(), OP_EQ, 1);
  322. hs_service_t *s = get_first_service();
  323. tt_assert(s);
  324. /* Ok we have the service object. Validate few things. */
  325. tt_assert(!tor_mem_is_zero(s->onion_address, sizeof(s->onion_address)));
  326. tt_int_op(hs_address_is_valid(s->onion_address), OP_EQ, 1);
  327. tt_assert(!tor_mem_is_zero((char *) s->keys.identity_sk.seckey,
  328. ED25519_SECKEY_LEN));
  329. tt_assert(!tor_mem_is_zero((char *) s->keys.identity_pk.pubkey,
  330. ED25519_PUBKEY_LEN));
  331. /* Check onion address from identity key. */
  332. hs_build_address(&s->keys.identity_pk, s->config.version, addr);
  333. tt_int_op(hs_address_is_valid(addr), OP_EQ, 1);
  334. tt_str_op(addr, OP_EQ, s->onion_address);
  335. /* Check that the is_client_auth_enabled is not set. */
  336. tt_assert(!s->config.is_client_auth_enabled);
  337. done:
  338. tor_free(hsdir_v2);
  339. tor_free(hsdir_v3);
  340. hs_free_all();
  341. }
  342. static void
  343. test_client_filename_is_valid(void *arg)
  344. {
  345. (void) arg;
  346. /* Valid file name. */
  347. tt_assert(client_filename_is_valid("a.auth"));
  348. /* Valid file name with special character. */
  349. tt_assert(client_filename_is_valid("a-.auth"));
  350. /* Invalid extension. */
  351. tt_assert(!client_filename_is_valid("a.ath"));
  352. /* Nothing before the extension. */
  353. tt_assert(!client_filename_is_valid(".auth"));
  354. done:
  355. ;
  356. }
  357. static void
  358. test_parse_authorized_client(void *arg)
  359. {
  360. hs_service_authorized_client_t *client = NULL;
  361. (void) arg;
  362. /* Valid authorized client. */
  363. client = parse_authorized_client(
  364. "descriptor:x25519:dz4q5xqlb4ldnbs72iarrml4ephk3du4i7o2cgiva5lwr6wkquja");
  365. tt_assert(client);
  366. /* Wrong number of fields. */
  367. tt_assert(!parse_authorized_client("a:b:c:d:e"));
  368. /* Wrong auth type. */
  369. tt_assert(!parse_authorized_client(
  370. "x:x25519:dz4q5xqlb4ldnbs72iarrml4ephk3du4i7o2cgiva5lwr6wkquja"));
  371. /* Wrong key type. */
  372. tt_assert(!parse_authorized_client(
  373. "descriptor:x:dz4q5xqlb4ldnbs72iarrml4ephk3du4i7o2cgiva5lwr6wkquja"));
  374. /* Some malformed string. */
  375. tt_assert(!parse_authorized_client("descriptor:x25519:aa=="));
  376. tt_assert(!parse_authorized_client("descriptor:"));
  377. tt_assert(!parse_authorized_client("descriptor:x25519"));
  378. tt_assert(!parse_authorized_client("descriptor:x25519:"));
  379. tt_assert(!parse_authorized_client(""));
  380. done:
  381. service_authorized_client_free(client);
  382. }
  383. static char *
  384. mock_read_file_to_str(const char *filename, int flags, struct stat *stat_out)
  385. {
  386. char *ret = NULL;
  387. (void) flags;
  388. (void) stat_out;
  389. if (!strcmp(filename, get_fname("hs3" PATH_SEPARATOR
  390. "authorized_clients" PATH_SEPARATOR
  391. "client1.auth"))) {
  392. ret = tor_strdup("descriptor:x25519:"
  393. "dz4q5xqlb4ldnbs72iarrml4ephk3du4i7o2cgiva5lwr6wkquja");
  394. goto done;
  395. }
  396. if (!strcmp(filename, get_fname("hs3" PATH_SEPARATOR
  397. "authorized_clients" PATH_SEPARATOR
  398. "dummy.xxx"))) {
  399. ret = tor_strdup("descriptor:x25519:"
  400. "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
  401. goto done;
  402. }
  403. if (!strcmp(filename, get_fname("hs3" PATH_SEPARATOR
  404. "authorized_clients" PATH_SEPARATOR
  405. "client2.auth"))) {
  406. ret = tor_strdup("descriptor:x25519:"
  407. "okoi2gml3wd6x7jganlk5d66xxyjgg24sxw4y7javx4giqr66zta");
  408. goto done;
  409. }
  410. done:
  411. return ret;
  412. }
  413. static smartlist_t *
  414. mock_tor_listdir(const char *dirname)
  415. {
  416. smartlist_t *file_list = smartlist_new();
  417. (void) dirname;
  418. smartlist_add(file_list, tor_strdup("client1.auth"));
  419. smartlist_add(file_list, tor_strdup("dummy.xxx"));
  420. smartlist_add(file_list, tor_strdup("client2.auth"));
  421. return file_list;
  422. }
  423. static void
  424. test_load_keys_with_client_auth(void *arg)
  425. {
  426. int ret;
  427. char *conf = NULL;
  428. smartlist_t *pubkey_b32_list = smartlist_new();
  429. char *hsdir_v3 = tor_strdup(get_fname("hs3"));
  430. hs_service_t *service;
  431. (void) arg;
  432. hs_init();
  433. smartlist_add(pubkey_b32_list, tor_strdup(
  434. "dz4q5xqlb4ldnbs72iarrml4ephk3du4i7o2cgiva5lwr6wkquja"));
  435. smartlist_add(pubkey_b32_list, tor_strdup(
  436. "okoi2gml3wd6x7jganlk5d66xxyjgg24sxw4y7javx4giqr66zta"));
  437. #define conf_fmt \
  438. "HiddenServiceDir %s\n" \
  439. "HiddenServiceVersion %d\n" \
  440. "HiddenServicePort 65534\n"
  441. tor_asprintf(&conf, conf_fmt, hsdir_v3, HS_VERSION_THREE);
  442. ret = helper_config_service(conf);
  443. tor_free(conf);
  444. tt_int_op(ret, OP_EQ, 0);
  445. /* It's in staging? */
  446. tt_int_op(get_hs_service_staging_list_size(), OP_EQ, 1);
  447. #undef conf_fmt
  448. MOCK(read_file_to_str, mock_read_file_to_str);
  449. MOCK(tor_listdir, mock_tor_listdir);
  450. /* Load the keys for these. After that, the v3 service should be registered
  451. * in the global map. */
  452. hs_service_load_all_keys();
  453. tt_int_op(get_hs_service_map_size(), OP_EQ, 1);
  454. service = get_first_service();
  455. tt_assert(service->config.clients);
  456. tt_int_op(smartlist_len(service->config.clients), OP_EQ,
  457. smartlist_len(pubkey_b32_list));
  458. /* Test that the is_client_auth_enabled flag is set. */
  459. tt_assert(service->config.is_client_auth_enabled);
  460. /* Test that the keys in clients are correct. */
  461. SMARTLIST_FOREACH_BEGIN(pubkey_b32_list, char *, pubkey_b32) {
  462. curve25519_public_key_t pubkey;
  463. /* This flag will be set if the key is found in clients. */
  464. int is_found = 0;
  465. base32_decode((char *) pubkey.public_key, sizeof(pubkey.public_key),
  466. pubkey_b32, strlen(pubkey_b32));
  467. SMARTLIST_FOREACH_BEGIN(service->config.clients,
  468. hs_service_authorized_client_t *, client) {
  469. if (tor_memeq(&pubkey, &client->client_pk, sizeof(pubkey))) {
  470. is_found = 1;
  471. break;
  472. }
  473. } SMARTLIST_FOREACH_END(client);
  474. tt_assert(is_found);
  475. } SMARTLIST_FOREACH_END(pubkey_b32);
  476. done:
  477. SMARTLIST_FOREACH(pubkey_b32_list, char *, s, tor_free(s));
  478. smartlist_free(pubkey_b32_list);
  479. tor_free(hsdir_v3);
  480. hs_free_all();
  481. UNMOCK(read_file_to_str);
  482. UNMOCK(tor_listdir);
  483. }
  484. static void
  485. test_access_service(void *arg)
  486. {
  487. int ret;
  488. char *conf = NULL;
  489. char *hsdir_v3 = tor_strdup(get_fname("hs3"));
  490. hs_service_ht *global_map;
  491. hs_service_t *s = NULL;
  492. (void) arg;
  493. /* We'll register two services, a v2 and a v3, then we'll load keys and
  494. * validate that both are in a correct state. */
  495. hs_init();
  496. #define conf_fmt \
  497. "HiddenServiceDir %s\n" \
  498. "HiddenServiceVersion %d\n" \
  499. "HiddenServicePort 65535\n"
  500. /* v3 service. */
  501. tor_asprintf(&conf, conf_fmt, hsdir_v3, HS_VERSION_THREE);
  502. ret = helper_config_service(conf);
  503. tor_free(conf);
  504. tt_int_op(ret, OP_EQ, 0);
  505. /* It's in staging? */
  506. tt_int_op(get_hs_service_staging_list_size(), OP_EQ, 1);
  507. /* Load the keys for these. After that, the v3 service should be registered
  508. * in the global map. */
  509. hs_service_load_all_keys();
  510. tt_int_op(get_hs_service_map_size(), OP_EQ, 1);
  511. s = get_first_service();
  512. tt_assert(s);
  513. global_map = get_hs_service_map();
  514. tt_assert(global_map);
  515. /* From here, we'll try the service accessors. */
  516. hs_service_t *query = find_service(global_map, &s->keys.identity_pk);
  517. tt_assert(query);
  518. tt_mem_op(query, OP_EQ, s, sizeof(hs_service_t));
  519. /* Remove service, check if it actually works and then put it back. */
  520. remove_service(global_map, s);
  521. tt_int_op(get_hs_service_map_size(), OP_EQ, 0);
  522. query = find_service(global_map, &s->keys.identity_pk);
  523. tt_ptr_op(query, OP_EQ, NULL);
  524. /* Register back the service in the map. */
  525. ret = register_service(global_map, s);
  526. tt_int_op(ret, OP_EQ, 0);
  527. tt_int_op(get_hs_service_map_size(), OP_EQ, 1);
  528. /* Twice should fail. */
  529. ret = register_service(global_map, s);
  530. tt_int_op(ret, OP_EQ, -1);
  531. /* Remove service from map so we don't double free on cleanup. */
  532. remove_service(global_map, s);
  533. tt_int_op(get_hs_service_map_size(), OP_EQ, 0);
  534. query = find_service(global_map, &s->keys.identity_pk);
  535. tt_ptr_op(query, OP_EQ, NULL);
  536. /* Let's try to remove twice for fun. */
  537. setup_full_capture_of_logs(LOG_WARN);
  538. remove_service(global_map, s);
  539. expect_log_msg_containing("Could not find service in the global map");
  540. teardown_capture_of_logs();
  541. done:
  542. hs_service_free(s);
  543. tor_free(hsdir_v3);
  544. hs_free_all();
  545. }
  546. /** Test that we can create intro point objects, index them and find them */
  547. static void
  548. test_service_intro_point(void *arg)
  549. {
  550. hs_service_t *service = NULL;
  551. hs_service_intro_point_t *ip = NULL;
  552. (void) arg;
  553. /* Test simple creation of an object. */
  554. {
  555. time_t now = time(NULL);
  556. ip = helper_create_service_ip();
  557. tt_assert(ip);
  558. /* Make sure the authentication keypair is not zeroes. */
  559. tt_int_op(tor_mem_is_zero((const char *) &ip->auth_key_kp,
  560. sizeof(ed25519_keypair_t)), OP_EQ, 0);
  561. /* The introduce2_max MUST be in that range. */
  562. tt_u64_op(ip->introduce2_max, OP_GE,
  563. INTRO_POINT_MIN_LIFETIME_INTRODUCTIONS);
  564. tt_u64_op(ip->introduce2_max, OP_LE,
  565. INTRO_POINT_MAX_LIFETIME_INTRODUCTIONS);
  566. /* Time to expire MUST also be in that range. We subtract 500 seconds
  567. * because there could be a gap between setting now and the time taken in
  568. * service_intro_point_new. On ARM and other older CPUs, it can be
  569. * surprisingly slow... */
  570. tt_u64_op(ip->time_to_expire, OP_GE,
  571. now + INTRO_POINT_LIFETIME_MIN_SECONDS - 500);
  572. /* We add 500 seconds, because this time we're testing against the
  573. * maximum allowed time. */
  574. tt_u64_op(ip->time_to_expire, OP_LE,
  575. now + INTRO_POINT_LIFETIME_MAX_SECONDS + 500);
  576. tt_assert(ip->replay_cache);
  577. tt_assert(ip->base.link_specifiers);
  578. /* By default, this is NOT a legacy object. */
  579. tt_int_op(ip->base.is_only_legacy, OP_EQ, 0);
  580. }
  581. /* Test functions that uses a service intropoints map with that previously
  582. * created object (non legacy). */
  583. {
  584. ed25519_public_key_t garbage = { {0} };
  585. hs_service_intro_point_t *query;
  586. service = hs_service_new(get_options());
  587. tt_assert(service);
  588. service->desc_current = service_descriptor_new();
  589. tt_assert(service->desc_current);
  590. /* Add intropoint to descriptor map. */
  591. service_intro_point_add(service->desc_current->intro_points.map, ip);
  592. query = service_intro_point_find(service, &ip->auth_key_kp.pubkey);
  593. tt_mem_op(query, OP_EQ, ip, sizeof(hs_service_intro_point_t));
  594. query = service_intro_point_find(service, &garbage);
  595. tt_ptr_op(query, OP_EQ, NULL);
  596. /* While at it, can I find the descriptor with the intro point? */
  597. hs_service_descriptor_t *desc_lookup =
  598. service_desc_find_by_intro(service, ip);
  599. tt_mem_op(service->desc_current, OP_EQ, desc_lookup,
  600. sizeof(hs_service_descriptor_t));
  601. /* Remove object from service descriptor and make sure it is out. */
  602. service_intro_point_remove(service, ip);
  603. query = service_intro_point_find(service, &ip->auth_key_kp.pubkey);
  604. tt_ptr_op(query, OP_EQ, NULL);
  605. }
  606. done:
  607. /* If the test succeed, this object is no longer referenced in the service
  608. * so we can free it without use after free. Else, it might explode because
  609. * it's still in the service descriptor map. */
  610. service_intro_point_free(ip);
  611. hs_service_free(service);
  612. }
  613. static node_t mock_node;
  614. static const node_t *
  615. mock_node_get_by_id(const char *digest)
  616. {
  617. (void) digest;
  618. memset(mock_node.identity, 'A', DIGEST_LEN);
  619. /* Only return the matchin identity of As */
  620. if (!tor_memcmp(mock_node.identity, digest, DIGEST_LEN)) {
  621. return &mock_node;
  622. }
  623. return NULL;
  624. }
  625. static void
  626. test_helper_functions(void *arg)
  627. {
  628. int ret;
  629. hs_service_t *service = NULL;
  630. hs_service_intro_point_t *ip = NULL;
  631. hs_ident_circuit_t ident;
  632. (void) arg;
  633. MOCK(node_get_by_id, mock_node_get_by_id);
  634. hs_service_init();
  635. service = helper_create_service();
  636. ip = helper_create_service_ip();
  637. /* Immediately add the intro point to the service so the free service at the
  638. * end cleans it as well. */
  639. service_intro_point_add(service->desc_current->intro_points.map, ip);
  640. /* Setup the circuit identifier. */
  641. ed25519_pubkey_copy(&ident.intro_auth_pk, &ip->auth_key_kp.pubkey);
  642. ed25519_pubkey_copy(&ident.identity_pk, &service->keys.identity_pk);
  643. /* Testing get_objects_from_ident(). */
  644. {
  645. hs_service_t *s_lookup = NULL;
  646. hs_service_intro_point_t *ip_lookup = NULL;
  647. hs_service_descriptor_t *desc_lookup = NULL;
  648. get_objects_from_ident(&ident, &s_lookup, &ip_lookup, &desc_lookup);
  649. tt_mem_op(s_lookup, OP_EQ, service, sizeof(hs_service_t));
  650. tt_mem_op(ip_lookup, OP_EQ, ip, sizeof(hs_service_intro_point_t));
  651. tt_mem_op(desc_lookup, OP_EQ, service->desc_current,
  652. sizeof(hs_service_descriptor_t));
  653. /* Reset */
  654. s_lookup = NULL; ip_lookup = NULL; desc_lookup = NULL;
  655. /* NULL parameter should work. */
  656. get_objects_from_ident(&ident, NULL, &ip_lookup, &desc_lookup);
  657. tt_mem_op(ip_lookup, OP_EQ, ip, sizeof(hs_service_intro_point_t));
  658. tt_mem_op(desc_lookup, OP_EQ, service->desc_current,
  659. sizeof(hs_service_descriptor_t));
  660. /* Reset. */
  661. s_lookup = NULL; ip_lookup = NULL; desc_lookup = NULL;
  662. /* Break the ident and we should find nothing. */
  663. memset(&ident, 0, sizeof(ident));
  664. get_objects_from_ident(&ident, &s_lookup, &ip_lookup, &desc_lookup);
  665. tt_ptr_op(s_lookup, OP_EQ, NULL);
  666. tt_ptr_op(ip_lookup, OP_EQ, NULL);
  667. tt_ptr_op(desc_lookup, OP_EQ, NULL);
  668. }
  669. /* Testing get_node_from_intro_point() */
  670. {
  671. const node_t *node = get_node_from_intro_point(ip);
  672. tt_ptr_op(node, OP_EQ, &mock_node);
  673. SMARTLIST_FOREACH_BEGIN(ip->base.link_specifiers,
  674. hs_desc_link_specifier_t *, ls) {
  675. if (ls->type == LS_LEGACY_ID) {
  676. /* Change legacy id in link specifier which is not the mock node. */
  677. memset(ls->u.legacy_id, 'B', sizeof(ls->u.legacy_id));
  678. }
  679. } SMARTLIST_FOREACH_END(ls);
  680. node = get_node_from_intro_point(ip);
  681. tt_ptr_op(node, OP_EQ, NULL);
  682. }
  683. /* Testing can_service_launch_intro_circuit() */
  684. {
  685. time_t now = time(NULL);
  686. /* Put the start of the retry period back in time, we should be allowed.
  687. * to launch intro circuit. */
  688. service->state.num_intro_circ_launched = 2;
  689. service->state.intro_circ_retry_started_time =
  690. (now - INTRO_CIRC_RETRY_PERIOD - 1);
  691. ret = can_service_launch_intro_circuit(service, now);
  692. tt_int_op(ret, OP_EQ, 1);
  693. tt_u64_op(service->state.intro_circ_retry_started_time, OP_EQ, now);
  694. tt_u64_op(service->state.num_intro_circ_launched, OP_EQ, 0);
  695. /* Call it again, we should still be allowed because we are under
  696. * MAX_INTRO_CIRCS_PER_PERIOD which been set to 0 previously. */
  697. ret = can_service_launch_intro_circuit(service, now);
  698. tt_int_op(ret, OP_EQ, 1);
  699. tt_u64_op(service->state.intro_circ_retry_started_time, OP_EQ, now);
  700. tt_u64_op(service->state.num_intro_circ_launched, OP_EQ, 0);
  701. /* Too many intro circuit launched means we are not allowed. */
  702. service->state.num_intro_circ_launched = 20;
  703. ret = can_service_launch_intro_circuit(service, now);
  704. tt_int_op(ret, OP_EQ, 0);
  705. }
  706. /* Testing intro_point_should_expire(). */
  707. {
  708. time_t now = time(NULL);
  709. /* Just some basic test of the current state. */
  710. tt_u64_op(ip->introduce2_max, OP_GE,
  711. INTRO_POINT_MIN_LIFETIME_INTRODUCTIONS);
  712. tt_u64_op(ip->introduce2_max, OP_LE,
  713. INTRO_POINT_MAX_LIFETIME_INTRODUCTIONS);
  714. tt_u64_op(ip->time_to_expire, OP_GE,
  715. now + INTRO_POINT_LIFETIME_MIN_SECONDS);
  716. tt_u64_op(ip->time_to_expire, OP_LE,
  717. now + INTRO_POINT_LIFETIME_MAX_SECONDS);
  718. /* This newly created IP from above shouldn't expire now. */
  719. ret = intro_point_should_expire(ip, now);
  720. tt_int_op(ret, OP_EQ, 0);
  721. /* Maximum number of INTRODUCE2 cell reached, it should expire. */
  722. ip->introduce2_count = INTRO_POINT_MAX_LIFETIME_INTRODUCTIONS + 1;
  723. ret = intro_point_should_expire(ip, now);
  724. tt_int_op(ret, OP_EQ, 1);
  725. ip->introduce2_count = 0;
  726. /* It should expire if time to expire has been reached. */
  727. ip->time_to_expire = now - 1000;
  728. ret = intro_point_should_expire(ip, now);
  729. tt_int_op(ret, OP_EQ, 1);
  730. }
  731. done:
  732. /* This will free the service and all objects associated to it. */
  733. hs_service_free_all();
  734. UNMOCK(node_get_by_id);
  735. }
  736. /** Test that we do the right operations when an intro circuit opens */
  737. static void
  738. test_intro_circuit_opened(void *arg)
  739. {
  740. int flags = CIRCLAUNCH_NEED_UPTIME | CIRCLAUNCH_IS_INTERNAL;
  741. hs_service_t *service;
  742. origin_circuit_t *circ = NULL;
  743. (void) arg;
  744. hs_init();
  745. MOCK(circuit_mark_for_close_, mock_circuit_mark_for_close);
  746. MOCK(relay_send_command_from_edge_, mock_relay_send_command_from_edge);
  747. circ = helper_create_origin_circuit(CIRCUIT_PURPOSE_S_ESTABLISH_INTRO,
  748. flags);
  749. /* No service associated with this circuit. */
  750. setup_full_capture_of_logs(LOG_WARN);
  751. hs_service_circuit_has_opened(circ);
  752. expect_log_msg_containing("Unknown service identity key");
  753. teardown_capture_of_logs();
  754. /* Set a service for this circuit. */
  755. {
  756. service = helper_create_service();
  757. ed25519_pubkey_copy(&circ->hs_ident->identity_pk,
  758. &service->keys.identity_pk);
  759. /* No intro point associated with this circuit. */
  760. setup_full_capture_of_logs(LOG_WARN);
  761. hs_service_circuit_has_opened(circ);
  762. expect_log_msg_containing("Unknown introduction point auth key");
  763. teardown_capture_of_logs();
  764. }
  765. /* Set an IP object now for this circuit. */
  766. {
  767. hs_service_intro_point_t *ip = helper_create_service_ip();
  768. service_intro_point_add(service->desc_current->intro_points.map, ip);
  769. /* Update ident to contain the intro point auth key. */
  770. ed25519_pubkey_copy(&circ->hs_ident->intro_auth_pk,
  771. &ip->auth_key_kp.pubkey);
  772. }
  773. /* This one should go all the way. */
  774. setup_full_capture_of_logs(LOG_INFO);
  775. hs_service_circuit_has_opened(circ);
  776. expect_log_msg_containing("Introduction circuit 0 established for service");
  777. teardown_capture_of_logs();
  778. done:
  779. circuit_free_(TO_CIRCUIT(circ));
  780. hs_free_all();
  781. UNMOCK(circuit_mark_for_close_);
  782. UNMOCK(relay_send_command_from_edge_);
  783. }
  784. /** Test the operations we do on a circuit after we learn that we successfully
  785. * established an intro point on it */
  786. static void
  787. test_intro_established(void *arg)
  788. {
  789. int ret;
  790. int flags = CIRCLAUNCH_NEED_UPTIME | CIRCLAUNCH_IS_INTERNAL;
  791. uint8_t payload[RELAY_PAYLOAD_SIZE] = {0};
  792. origin_circuit_t *circ = NULL;
  793. hs_service_t *service;
  794. hs_service_intro_point_t *ip = NULL;
  795. (void) arg;
  796. hs_init();
  797. MOCK(circuit_mark_for_close_, mock_circuit_mark_for_close);
  798. circ = helper_create_origin_circuit(CIRCUIT_PURPOSE_S_ESTABLISH_INTRO,
  799. flags);
  800. tt_assert(circ);
  801. /* Test a wrong purpose. */
  802. TO_CIRCUIT(circ)->purpose = CIRCUIT_PURPOSE_S_INTRO;
  803. setup_full_capture_of_logs(LOG_WARN);
  804. ret = hs_service_receive_intro_established(circ, payload, sizeof(payload));
  805. tt_int_op(ret, OP_EQ, -1);
  806. expect_log_msg_containing("Received an INTRO_ESTABLISHED cell on a "
  807. "non introduction circuit of purpose");
  808. teardown_capture_of_logs();
  809. /* Back to normal. */
  810. TO_CIRCUIT(circ)->purpose = CIRCUIT_PURPOSE_S_ESTABLISH_INTRO;
  811. /* No service associated to it. */
  812. setup_full_capture_of_logs(LOG_WARN);
  813. ret = hs_service_receive_intro_established(circ, payload, sizeof(payload));
  814. tt_int_op(ret, OP_EQ, -1);
  815. expect_log_msg_containing("Unknown service identity key");
  816. teardown_capture_of_logs();
  817. /* Set a service for this circuit. */
  818. service = helper_create_service();
  819. ed25519_pubkey_copy(&circ->hs_ident->identity_pk,
  820. &service->keys.identity_pk);
  821. /* No introduction point associated to it. */
  822. setup_full_capture_of_logs(LOG_WARN);
  823. ret = hs_service_receive_intro_established(circ, payload, sizeof(payload));
  824. tt_int_op(ret, OP_EQ, -1);
  825. expect_log_msg_containing("Introduction circuit established without an "
  826. "intro point object on circuit");
  827. teardown_capture_of_logs();
  828. /* Set an IP object now for this circuit. */
  829. {
  830. ip = helper_create_service_ip();
  831. service_intro_point_add(service->desc_current->intro_points.map, ip);
  832. /* Update ident to contain the intro point auth key. */
  833. ed25519_pubkey_copy(&circ->hs_ident->intro_auth_pk,
  834. &ip->auth_key_kp.pubkey);
  835. }
  836. /* Send an empty payload. INTRO_ESTABLISHED cells are basically zeroes. */
  837. ret = hs_service_receive_intro_established(circ, payload, sizeof(payload));
  838. tt_int_op(ret, OP_EQ, 0);
  839. tt_u64_op(ip->circuit_established, OP_EQ, 1);
  840. tt_int_op(TO_CIRCUIT(circ)->purpose, OP_EQ, CIRCUIT_PURPOSE_S_INTRO);
  841. done:
  842. if (circ)
  843. circuit_free_(TO_CIRCUIT(circ));
  844. hs_free_all();
  845. UNMOCK(circuit_mark_for_close_);
  846. }
  847. /** Check the operations we do on a rendezvous circuit after we learn it's
  848. * open */
  849. static void
  850. test_rdv_circuit_opened(void *arg)
  851. {
  852. int flags = CIRCLAUNCH_NEED_UPTIME | CIRCLAUNCH_IS_INTERNAL;
  853. origin_circuit_t *circ = NULL;
  854. hs_service_t *service;
  855. (void) arg;
  856. hs_init();
  857. MOCK(circuit_mark_for_close_, mock_circuit_mark_for_close);
  858. MOCK(relay_send_command_from_edge_, mock_relay_send_command_from_edge);
  859. circ = helper_create_origin_circuit(CIRCUIT_PURPOSE_S_CONNECT_REND, flags);
  860. crypto_rand((char *) circ->hs_ident->rendezvous_cookie, REND_COOKIE_LEN);
  861. crypto_rand((char *) circ->hs_ident->rendezvous_handshake_info,
  862. sizeof(circ->hs_ident->rendezvous_handshake_info));
  863. /* No service associated with this circuit. */
  864. setup_full_capture_of_logs(LOG_WARN);
  865. hs_service_circuit_has_opened(circ);
  866. expect_log_msg_containing("Unknown service identity key");
  867. teardown_capture_of_logs();
  868. /* This should be set to a non zero timestamp. */
  869. tt_u64_op(TO_CIRCUIT(circ)->timestamp_dirty, OP_NE, 0);
  870. /* Set a service for this circuit. */
  871. service = helper_create_service();
  872. ed25519_pubkey_copy(&circ->hs_ident->identity_pk,
  873. &service->keys.identity_pk);
  874. /* Should be all good. */
  875. hs_service_circuit_has_opened(circ);
  876. tt_int_op(TO_CIRCUIT(circ)->purpose, OP_EQ, CIRCUIT_PURPOSE_S_REND_JOINED);
  877. done:
  878. circuit_free_(TO_CIRCUIT(circ));
  879. hs_free_all();
  880. UNMOCK(circuit_mark_for_close_);
  881. UNMOCK(relay_send_command_from_edge_);
  882. }
  883. static void
  884. mock_assert_circuit_ok(const circuit_t *c)
  885. {
  886. (void) c;
  887. return;
  888. }
  889. /** Test for the general mechanism for closing intro circs.
  890. * Also a way to identify that #23603 has been fixed. */
  891. static void
  892. test_closing_intro_circs(void *arg)
  893. {
  894. hs_service_t *service = NULL;
  895. hs_service_intro_point_t *ip = NULL, *entry = NULL;
  896. origin_circuit_t *intro_circ = NULL, *tmp_circ;
  897. int flags = CIRCLAUNCH_NEED_UPTIME | CIRCLAUNCH_IS_INTERNAL;
  898. (void) arg;
  899. MOCK(assert_circuit_ok, mock_assert_circuit_ok);
  900. hs_init();
  901. /* Initialize service */
  902. service = helper_create_service();
  903. /* Initialize intro point */
  904. ip = helper_create_service_ip();
  905. tt_assert(ip);
  906. service_intro_point_add(service->desc_current->intro_points.map, ip);
  907. /* Initialize intro circuit */
  908. intro_circ = origin_circuit_init(CIRCUIT_PURPOSE_S_ESTABLISH_INTRO, flags);
  909. intro_circ->hs_ident = hs_ident_circuit_new(&service->keys.identity_pk,
  910. HS_IDENT_CIRCUIT_INTRO);
  911. /* Register circuit in the circuitmap . */
  912. hs_circuitmap_register_intro_circ_v3_service_side(intro_circ,
  913. &ip->auth_key_kp.pubkey);
  914. tmp_circ =
  915. hs_circuitmap_get_intro_circ_v3_service_side(&ip->auth_key_kp.pubkey);
  916. tt_ptr_op(tmp_circ, OP_EQ, intro_circ);
  917. /* Pretend that intro point has failed too much */
  918. ip->circuit_retries = MAX_INTRO_POINT_CIRCUIT_RETRIES+1;
  919. /* Now pretend we are freeing this intro circuit. We want to see that our
  920. * destructor is not gonna kill our intro point structure since that's the
  921. * job of the cleanup routine. */
  922. circuit_free_(TO_CIRCUIT(intro_circ));
  923. intro_circ = NULL;
  924. entry = service_intro_point_find(service, &ip->auth_key_kp.pubkey);
  925. tt_assert(entry);
  926. /* The free should also remove the circuit from the circuitmap. */
  927. tmp_circ =
  928. hs_circuitmap_get_intro_circ_v3_service_side(&ip->auth_key_kp.pubkey);
  929. tt_assert(!tmp_circ);
  930. /* Now pretend that a new intro point circ was launched and opened. Check
  931. * that the intro point will be established correctly. */
  932. intro_circ = origin_circuit_init(CIRCUIT_PURPOSE_S_ESTABLISH_INTRO, flags);
  933. intro_circ->hs_ident = hs_ident_circuit_new(&service->keys.identity_pk,
  934. HS_IDENT_CIRCUIT_INTRO);
  935. ed25519_pubkey_copy(&intro_circ->hs_ident->intro_auth_pk,
  936. &ip->auth_key_kp.pubkey);
  937. /* Register circuit in the circuitmap . */
  938. hs_circuitmap_register_intro_circ_v3_service_side(intro_circ,
  939. &ip->auth_key_kp.pubkey);
  940. tmp_circ =
  941. hs_circuitmap_get_intro_circ_v3_service_side(&ip->auth_key_kp.pubkey);
  942. tt_ptr_op(tmp_circ, OP_EQ, intro_circ);
  943. tt_int_op(TO_CIRCUIT(intro_circ)->marked_for_close, OP_EQ, 0);
  944. circuit_mark_for_close(TO_CIRCUIT(intro_circ), END_CIRC_REASON_INTERNAL);
  945. tt_int_op(TO_CIRCUIT(intro_circ)->marked_for_close, OP_NE, 0);
  946. /* At this point, we should not be able to find it in the circuitmap. */
  947. tmp_circ =
  948. hs_circuitmap_get_intro_circ_v3_service_side(&ip->auth_key_kp.pubkey);
  949. tt_assert(!tmp_circ);
  950. done:
  951. if (intro_circ) {
  952. circuit_free_(TO_CIRCUIT(intro_circ));
  953. }
  954. /* Frees the service object. */
  955. hs_free_all();
  956. UNMOCK(assert_circuit_ok);
  957. }
  958. /** Test sending and receiving introduce2 cells */
  959. static void
  960. test_introduce2(void *arg)
  961. {
  962. int ret;
  963. int flags = CIRCLAUNCH_NEED_UPTIME | CIRCLAUNCH_IS_INTERNAL;
  964. uint8_t payload[RELAY_PAYLOAD_SIZE] = {0};
  965. origin_circuit_t *circ = NULL;
  966. hs_service_t *service;
  967. hs_service_intro_point_t *ip = NULL;
  968. (void) arg;
  969. hs_init();
  970. MOCK(circuit_mark_for_close_, mock_circuit_mark_for_close);
  971. MOCK(get_or_state,
  972. get_or_state_replacement);
  973. dummy_state = tor_malloc_zero(sizeof(or_state_t));
  974. circ = helper_create_origin_circuit(CIRCUIT_PURPOSE_S_INTRO, flags);
  975. tt_assert(circ);
  976. /* Test a wrong purpose. */
  977. TO_CIRCUIT(circ)->purpose = CIRCUIT_PURPOSE_S_ESTABLISH_INTRO;
  978. setup_full_capture_of_logs(LOG_WARN);
  979. ret = hs_service_receive_introduce2(circ, payload, sizeof(payload));
  980. tt_int_op(ret, OP_EQ, -1);
  981. expect_log_msg_containing("Received an INTRODUCE2 cell on a "
  982. "non introduction circuit of purpose");
  983. teardown_capture_of_logs();
  984. /* Back to normal. */
  985. TO_CIRCUIT(circ)->purpose = CIRCUIT_PURPOSE_S_INTRO;
  986. /* No service associated to it. */
  987. setup_full_capture_of_logs(LOG_WARN);
  988. ret = hs_service_receive_introduce2(circ, payload, sizeof(payload));
  989. tt_int_op(ret, OP_EQ, -1);
  990. expect_log_msg_containing("Unknown service identity key");
  991. teardown_capture_of_logs();
  992. /* Set a service for this circuit. */
  993. service = helper_create_service();
  994. ed25519_pubkey_copy(&circ->hs_ident->identity_pk,
  995. &service->keys.identity_pk);
  996. /* No introduction point associated to it. */
  997. setup_full_capture_of_logs(LOG_WARN);
  998. ret = hs_service_receive_introduce2(circ, payload, sizeof(payload));
  999. tt_int_op(ret, OP_EQ, -1);
  1000. expect_log_msg_containing("Unknown introduction auth key when handling "
  1001. "an INTRODUCE2 cell on circuit");
  1002. teardown_capture_of_logs();
  1003. /* Set an IP object now for this circuit. */
  1004. {
  1005. ip = helper_create_service_ip();
  1006. service_intro_point_add(service->desc_current->intro_points.map, ip);
  1007. /* Update ident to contain the intro point auth key. */
  1008. ed25519_pubkey_copy(&circ->hs_ident->intro_auth_pk,
  1009. &ip->auth_key_kp.pubkey);
  1010. }
  1011. /* This will fail because receiving an INTRODUCE2 cell implies a valid cell
  1012. * and then launching circuits so let's not do that and instead test that
  1013. * behaviour differently. */
  1014. ret = hs_service_receive_introduce2(circ, payload, sizeof(payload));
  1015. tt_int_op(ret, OP_EQ, -1);
  1016. tt_u64_op(ip->introduce2_count, OP_EQ, 0);
  1017. done:
  1018. or_state_free(dummy_state);
  1019. dummy_state = NULL;
  1020. if (circ)
  1021. circuit_free_(TO_CIRCUIT(circ));
  1022. hs_free_all();
  1023. UNMOCK(circuit_mark_for_close_);
  1024. }
  1025. /** Test basic hidden service housekeeping operations (maintaining intro
  1026. * points, etc) */
  1027. static void
  1028. test_service_event(void *arg)
  1029. {
  1030. int flags = CIRCLAUNCH_NEED_UPTIME | CIRCLAUNCH_IS_INTERNAL;
  1031. time_t now = time(NULL);
  1032. hs_service_t *service;
  1033. origin_circuit_t *circ = NULL;
  1034. (void) arg;
  1035. hs_init();
  1036. MOCK(circuit_mark_for_close_, mock_circuit_mark_for_close);
  1037. circ = helper_create_origin_circuit(CIRCUIT_PURPOSE_S_INTRO, flags);
  1038. /* Set a service for this circuit. */
  1039. service = helper_create_service();
  1040. ed25519_pubkey_copy(&circ->hs_ident->identity_pk,
  1041. &service->keys.identity_pk);
  1042. /* Currently this consists of cleaning invalid intro points. So adding IPs
  1043. * here that should get cleaned up. */
  1044. {
  1045. hs_service_intro_point_t *ip = helper_create_service_ip();
  1046. service_intro_point_add(service->desc_current->intro_points.map, ip);
  1047. /* This run will remove the IP because we have no circuits nor node_t
  1048. * associated with it. */
  1049. run_housekeeping_event(now);
  1050. tt_int_op(digest256map_size(service->desc_current->intro_points.map),
  1051. OP_EQ, 0);
  1052. /* We'll trigger a removal because we've reached our maximum amount of
  1053. * times we should retry a circuit. For this, we need to have a node_t
  1054. * that matches the identity of this IP. */
  1055. routerinfo_t ri;
  1056. memset(&ri, 0, sizeof(ri));
  1057. ip = helper_create_service_ip();
  1058. service_intro_point_add(service->desc_current->intro_points.map, ip);
  1059. memset(ri.cache_info.identity_digest, 'A', DIGEST_LEN);
  1060. /* This triggers a node_t creation. */
  1061. tt_assert(nodelist_set_routerinfo(&ri, NULL));
  1062. ip->circuit_retries = MAX_INTRO_POINT_CIRCUIT_RETRIES + 1;
  1063. run_housekeeping_event(now);
  1064. tt_int_op(digest256map_size(service->desc_current->intro_points.map),
  1065. OP_EQ, 0);
  1066. /* No removal but no circuit so this means the IP object will stay in the
  1067. * descriptor map so we can retry it. */
  1068. ip = helper_create_service_ip();
  1069. service_intro_point_add(service->desc_current->intro_points.map, ip);
  1070. ip->circuit_established = 1; /* We'll test that, it MUST be 0 after. */
  1071. run_housekeeping_event(now);
  1072. tt_int_op(digest256map_size(service->desc_current->intro_points.map),
  1073. OP_EQ, 1);
  1074. /* Remove the IP object at once for the next test. */
  1075. ip->circuit_retries = MAX_INTRO_POINT_CIRCUIT_RETRIES + 1;
  1076. run_housekeeping_event(now);
  1077. tt_int_op(digest256map_size(service->desc_current->intro_points.map),
  1078. OP_EQ, 0);
  1079. /* Now, we'll create an IP with a registered circuit. The IP object
  1080. * shouldn't go away. */
  1081. ip = helper_create_service_ip();
  1082. service_intro_point_add(service->desc_current->intro_points.map, ip);
  1083. ed25519_pubkey_copy(&circ->hs_ident->intro_auth_pk,
  1084. &ip->auth_key_kp.pubkey);
  1085. hs_circuitmap_register_intro_circ_v3_service_side(
  1086. circ, &ip->auth_key_kp.pubkey);
  1087. run_housekeeping_event(now);
  1088. tt_int_op(digest256map_size(service->desc_current->intro_points.map),
  1089. OP_EQ, 1);
  1090. /* We'll mangle the IP object to expire. */
  1091. ip->time_to_expire = now;
  1092. run_housekeeping_event(now);
  1093. tt_int_op(digest256map_size(service->desc_current->intro_points.map),
  1094. OP_EQ, 0);
  1095. }
  1096. done:
  1097. hs_circuitmap_remove_circuit(TO_CIRCUIT(circ));
  1098. circuit_free_(TO_CIRCUIT(circ));
  1099. hs_free_all();
  1100. UNMOCK(circuit_mark_for_close_);
  1101. }
  1102. /** Test that we rotate descriptors correctly. */
  1103. static void
  1104. test_rotate_descriptors(void *arg)
  1105. {
  1106. int ret;
  1107. time_t next_rotation_time, now;
  1108. hs_service_t *service;
  1109. hs_service_descriptor_t *desc_next;
  1110. (void) arg;
  1111. dummy_state = tor_malloc_zero(sizeof(or_state_t));
  1112. hs_init();
  1113. MOCK(get_or_state, get_or_state_replacement);
  1114. MOCK(circuit_mark_for_close_, mock_circuit_mark_for_close);
  1115. MOCK(networkstatus_get_live_consensus,
  1116. mock_networkstatus_get_live_consensus);
  1117. /* Descriptor rotation happens with a consensus with a new SRV. */
  1118. ret = parse_rfc1123_time("Sat, 26 Oct 1985 13:00:00 UTC",
  1119. &mock_ns.valid_after);
  1120. tt_int_op(ret, OP_EQ, 0);
  1121. ret = parse_rfc1123_time("Sat, 26 Oct 1985 14:00:00 UTC",
  1122. &mock_ns.fresh_until);
  1123. tt_int_op(ret, OP_EQ, 0);
  1124. voting_schedule_recalculate_timing(get_options(), mock_ns.valid_after);
  1125. update_approx_time(mock_ns.valid_after+1);
  1126. now = mock_ns.valid_after+1;
  1127. /* Create a service with a default descriptor and state. It's added to the
  1128. * global map. */
  1129. service = helper_create_service();
  1130. service_descriptor_free(service->desc_current);
  1131. service->desc_current = NULL;
  1132. /* This triggers a build for both descriptors. The time now is only used in
  1133. * the descriptor certificate which is important to be now else the decoding
  1134. * will complain that the cert has expired if we use valid_after. */
  1135. build_all_descriptors(now);
  1136. tt_assert(service->desc_current);
  1137. tt_assert(service->desc_next);
  1138. /* Tweak our service next rotation time so we can use a custom time. */
  1139. service->state.next_rotation_time = next_rotation_time =
  1140. mock_ns.valid_after + (11 * 60 * 60);
  1141. /* Nothing should happen, we are not at a new SRV. Our next rotation time
  1142. * should be untouched. */
  1143. rotate_all_descriptors(mock_ns.valid_after);
  1144. tt_u64_op(service->state.next_rotation_time, OP_EQ, next_rotation_time);
  1145. tt_assert(service->desc_current);
  1146. tt_assert(service->desc_next);
  1147. tt_u64_op(service->desc_current->time_period_num, OP_EQ,
  1148. hs_get_previous_time_period_num(0));
  1149. tt_u64_op(service->desc_next->time_period_num, OP_EQ,
  1150. hs_get_time_period_num(0));
  1151. /* Keep a reference so we can compare it after rotation to the current. */
  1152. desc_next = service->desc_next;
  1153. /* Going right after a new SRV. */
  1154. ret = parse_rfc1123_time("Sat, 27 Oct 1985 01:00:00 UTC",
  1155. &mock_ns.valid_after);
  1156. tt_int_op(ret, OP_EQ, 0);
  1157. ret = parse_rfc1123_time("Sat, 27 Oct 1985 02:00:00 UTC",
  1158. &mock_ns.fresh_until);
  1159. tt_int_op(ret, OP_EQ, 0);
  1160. voting_schedule_recalculate_timing(get_options(), mock_ns.valid_after);
  1161. update_approx_time(mock_ns.valid_after+1);
  1162. now = mock_ns.valid_after+1;
  1163. /* Note down what to expect for the next rotation time which is 01:00 + 23h
  1164. * meaning 00:00:00. */
  1165. next_rotation_time = mock_ns.valid_after + (23 * 60 * 60);
  1166. /* We should have our next rotation time modified, our current descriptor
  1167. * cleaned up and the next descriptor becoming the current. */
  1168. rotate_all_descriptors(mock_ns.valid_after);
  1169. tt_u64_op(service->state.next_rotation_time, OP_EQ, next_rotation_time);
  1170. tt_mem_op(service->desc_current, OP_EQ, desc_next, sizeof(*desc_next));
  1171. tt_assert(service->desc_next == NULL);
  1172. /* A second time should do nothing. */
  1173. rotate_all_descriptors(mock_ns.valid_after);
  1174. tt_u64_op(service->state.next_rotation_time, OP_EQ, next_rotation_time);
  1175. tt_mem_op(service->desc_current, OP_EQ, desc_next, sizeof(*desc_next));
  1176. tt_assert(service->desc_next == NULL);
  1177. build_all_descriptors(now);
  1178. tt_mem_op(service->desc_current, OP_EQ, desc_next, sizeof(*desc_next));
  1179. tt_u64_op(service->desc_current->time_period_num, OP_EQ,
  1180. hs_get_time_period_num(0));
  1181. tt_u64_op(service->desc_next->time_period_num, OP_EQ,
  1182. hs_get_next_time_period_num(0));
  1183. tt_assert(service->desc_next);
  1184. done:
  1185. hs_free_all();
  1186. UNMOCK(get_or_state);
  1187. UNMOCK(circuit_mark_for_close_);
  1188. UNMOCK(networkstatus_get_live_consensus);
  1189. }
  1190. /** Test building descriptors: picking intro points, setting up their link
  1191. * specifiers, etc. */
  1192. static void
  1193. test_build_update_descriptors(void *arg)
  1194. {
  1195. int ret;
  1196. time_t now = time(NULL);
  1197. node_t *node;
  1198. hs_service_t *service;
  1199. hs_service_intro_point_t *ip_cur, *ip_next;
  1200. routerinfo_t ri;
  1201. (void) arg;
  1202. hs_init();
  1203. MOCK(get_or_state,
  1204. get_or_state_replacement);
  1205. MOCK(networkstatus_get_live_consensus,
  1206. mock_networkstatus_get_live_consensus);
  1207. dummy_state = tor_malloc_zero(sizeof(or_state_t));
  1208. ret = parse_rfc1123_time("Sat, 26 Oct 1985 03:00:00 UTC",
  1209. &mock_ns.valid_after);
  1210. tt_int_op(ret, OP_EQ, 0);
  1211. ret = parse_rfc1123_time("Sat, 26 Oct 1985 04:00:00 UTC",
  1212. &mock_ns.fresh_until);
  1213. tt_int_op(ret, OP_EQ, 0);
  1214. voting_schedule_recalculate_timing(get_options(), mock_ns.valid_after);
  1215. update_approx_time(mock_ns.valid_after+1);
  1216. now = mock_ns.valid_after+1;
  1217. /* Create a service without a current descriptor to trigger a build. */
  1218. service = helper_create_service();
  1219. tt_assert(service);
  1220. /* Unfortunately, the helper creates a dummy descriptor so get rid of it. */
  1221. service_descriptor_free(service->desc_current);
  1222. service->desc_current = NULL;
  1223. /* We have a fresh service so this should trigger a build for both
  1224. * descriptors for specific time period that we'll test. */
  1225. build_all_descriptors(now);
  1226. /* Check *current* descriptor. */
  1227. tt_assert(service->desc_current);
  1228. tt_assert(service->desc_current->desc);
  1229. tt_assert(service->desc_current->intro_points.map);
  1230. /* The current time period is the one expected when starting at 03:00. */
  1231. tt_u64_op(service->desc_current->time_period_num, OP_EQ,
  1232. hs_get_time_period_num(0));
  1233. /* This should be untouched, the update descriptor process changes it. */
  1234. tt_u64_op(service->desc_current->next_upload_time, OP_EQ, 0);
  1235. /* Check *next* descriptor. */
  1236. tt_assert(service->desc_next);
  1237. tt_assert(service->desc_next->desc);
  1238. tt_assert(service->desc_next->intro_points.map);
  1239. tt_assert(service->desc_current != service->desc_next);
  1240. tt_u64_op(service->desc_next->time_period_num, OP_EQ,
  1241. hs_get_next_time_period_num(0));
  1242. /* This should be untouched, the update descriptor process changes it. */
  1243. tt_u64_op(service->desc_next->next_upload_time, OP_EQ, 0);
  1244. /* Time to test the update of those descriptors. At first, we have no node
  1245. * in the routerlist so this will find NO suitable node for the IPs. */
  1246. setup_full_capture_of_logs(LOG_INFO);
  1247. update_all_descriptors(now);
  1248. expect_log_msg_containing("Unable to find a suitable node to be an "
  1249. "introduction point for service");
  1250. teardown_capture_of_logs();
  1251. tt_int_op(digest256map_size(service->desc_current->intro_points.map),
  1252. OP_EQ, 0);
  1253. tt_int_op(digest256map_size(service->desc_next->intro_points.map),
  1254. OP_EQ, 0);
  1255. /* Now, we'll setup a node_t. */
  1256. {
  1257. tor_addr_t ipv4_addr;
  1258. curve25519_secret_key_t curve25519_secret_key;
  1259. memset(&ri, 0, sizeof(routerinfo_t));
  1260. tor_addr_parse(&ipv4_addr, "127.0.0.1");
  1261. ri.addr = tor_addr_to_ipv4h(&ipv4_addr);
  1262. ri.or_port = 1337;
  1263. ri.purpose = ROUTER_PURPOSE_GENERAL;
  1264. /* Ugly yes but we never free the "ri" object so this just makes things
  1265. * easier. */
  1266. ri.protocol_list = (char *) "HSDir=1-2 LinkAuth=3";
  1267. summarize_protover_flags(&ri.pv, ri.protocol_list, NULL);
  1268. ret = curve25519_secret_key_generate(&curve25519_secret_key, 0);
  1269. tt_int_op(ret, OP_EQ, 0);
  1270. ri.onion_curve25519_pkey =
  1271. tor_malloc_zero(sizeof(curve25519_public_key_t));
  1272. ri.onion_pkey = tor_malloc_zero(140);
  1273. curve25519_public_key_generate(ri.onion_curve25519_pkey,
  1274. &curve25519_secret_key);
  1275. memset(ri.cache_info.identity_digest, 'A', DIGEST_LEN);
  1276. /* Setup ed25519 identity */
  1277. ed25519_keypair_t kp1;
  1278. ed25519_keypair_generate(&kp1, 0);
  1279. ri.cache_info.signing_key_cert = tor_malloc_zero(sizeof(tor_cert_t));
  1280. tt_assert(ri.cache_info.signing_key_cert);
  1281. ed25519_pubkey_copy(&ri.cache_info.signing_key_cert->signing_key,
  1282. &kp1.pubkey);
  1283. nodelist_set_routerinfo(&ri, NULL);
  1284. node = node_get_mutable_by_id(ri.cache_info.identity_digest);
  1285. tt_assert(node);
  1286. node->is_running = node->is_valid = node->is_fast = node->is_stable = 1;
  1287. }
  1288. /* We have to set this, or the lack of microdescriptors for these
  1289. * nodes will make them unusable. */
  1290. get_options_mutable()->UseMicrodescriptors = 0;
  1291. /* We expect to pick only one intro point from the node above. */
  1292. setup_full_capture_of_logs(LOG_INFO);
  1293. update_all_descriptors(now);
  1294. tor_free(node->ri->onion_curve25519_pkey); /* Avoid memleak. */
  1295. tor_free(node->ri->cache_info.signing_key_cert);
  1296. tor_free(node->ri->onion_pkey);
  1297. expect_log_msg_containing("just picked 1 intro points and wanted 3 for next "
  1298. "descriptor. It currently has 0 intro points. "
  1299. "Launching ESTABLISH_INTRO circuit shortly.");
  1300. teardown_capture_of_logs();
  1301. tt_int_op(digest256map_size(service->desc_current->intro_points.map),
  1302. OP_EQ, 1);
  1303. tt_int_op(digest256map_size(service->desc_next->intro_points.map),
  1304. OP_EQ, 1);
  1305. /* Get the IP object. Because we don't have the auth key of the IP, we can't
  1306. * query it so get the first element in the map. */
  1307. {
  1308. void *obj = NULL;
  1309. const uint8_t *key;
  1310. digest256map_iter_t *iter =
  1311. digest256map_iter_init(service->desc_current->intro_points.map);
  1312. digest256map_iter_get(iter, &key, &obj);
  1313. tt_assert(obj);
  1314. ip_cur = obj;
  1315. /* Get also the IP from the next descriptor. We'll make sure it's not the
  1316. * same object as in the current descriptor. */
  1317. iter = digest256map_iter_init(service->desc_next->intro_points.map);
  1318. digest256map_iter_get(iter, &key, &obj);
  1319. tt_assert(obj);
  1320. ip_next = obj;
  1321. }
  1322. tt_mem_op(ip_cur, OP_NE, ip_next, sizeof(hs_desc_intro_point_t));
  1323. /* We won't test the service IP object because there is a specific test
  1324. * already for this but we'll make sure that the state is coherent.*/
  1325. /* Three link specifiers are mandatoy so make sure we do have them. */
  1326. tt_int_op(smartlist_len(ip_cur->base.link_specifiers), OP_EQ, 3);
  1327. /* Make sure we have a valid encryption keypair generated when we pick an
  1328. * intro point in the update process. */
  1329. tt_assert(!tor_mem_is_zero((char *) ip_cur->enc_key_kp.seckey.secret_key,
  1330. CURVE25519_SECKEY_LEN));
  1331. tt_assert(!tor_mem_is_zero((char *) ip_cur->enc_key_kp.pubkey.public_key,
  1332. CURVE25519_PUBKEY_LEN));
  1333. tt_u64_op(ip_cur->time_to_expire, OP_GE, now +
  1334. INTRO_POINT_LIFETIME_MIN_SECONDS);
  1335. tt_u64_op(ip_cur->time_to_expire, OP_LE, now +
  1336. INTRO_POINT_LIFETIME_MAX_SECONDS);
  1337. /* Now, we will try to set up a service after a new time period has started
  1338. * and see if it behaves as expected. */
  1339. ret = parse_rfc1123_time("Sat, 26 Oct 1985 13:00:00 UTC",
  1340. &mock_ns.valid_after);
  1341. tt_int_op(ret, OP_EQ, 0);
  1342. ret = parse_rfc1123_time("Sat, 26 Oct 1985 14:00:00 UTC",
  1343. &mock_ns.fresh_until);
  1344. tt_int_op(ret, OP_EQ, 0);
  1345. update_approx_time(mock_ns.valid_after+1);
  1346. now = mock_ns.valid_after+1;
  1347. /* Create a service without a current descriptor to trigger a build. */
  1348. service = helper_create_service();
  1349. tt_assert(service);
  1350. /* Unfortunately, the helper creates a dummy descriptor so get rid of it. */
  1351. service_descriptor_free(service->desc_current);
  1352. service->desc_current = NULL;
  1353. /* We have a fresh service so this should trigger a build for both
  1354. * descriptors for specific time period that we'll test. */
  1355. build_all_descriptors(now);
  1356. /* Check *current* descriptor. */
  1357. tt_assert(service->desc_current);
  1358. tt_assert(service->desc_current->desc);
  1359. tt_assert(service->desc_current->intro_points.map);
  1360. /* This should be for the previous time period. */
  1361. tt_u64_op(service->desc_current->time_period_num, OP_EQ,
  1362. hs_get_previous_time_period_num(0));
  1363. /* This should be untouched, the update descriptor process changes it. */
  1364. tt_u64_op(service->desc_current->next_upload_time, OP_EQ, 0);
  1365. /* Check *next* descriptor. */
  1366. tt_assert(service->desc_next);
  1367. tt_assert(service->desc_next->desc);
  1368. tt_assert(service->desc_next->intro_points.map);
  1369. tt_assert(service->desc_current != service->desc_next);
  1370. tt_u64_op(service->desc_next->time_period_num, OP_EQ,
  1371. hs_get_time_period_num(0));
  1372. /* This should be untouched, the update descriptor process changes it. */
  1373. tt_u64_op(service->desc_next->next_upload_time, OP_EQ, 0);
  1374. /* Let's remove the next descriptor to simulate a rotation. */
  1375. service_descriptor_free(service->desc_next);
  1376. service->desc_next = NULL;
  1377. build_all_descriptors(now);
  1378. /* Check *next* descriptor. */
  1379. tt_assert(service->desc_next);
  1380. tt_assert(service->desc_next->desc);
  1381. tt_assert(service->desc_next->intro_points.map);
  1382. tt_assert(service->desc_current != service->desc_next);
  1383. tt_u64_op(service->desc_next->time_period_num, OP_EQ,
  1384. hs_get_next_time_period_num(0));
  1385. /* This should be untouched, the update descriptor process changes it. */
  1386. tt_u64_op(service->desc_next->next_upload_time, OP_EQ, 0);
  1387. done:
  1388. hs_free_all();
  1389. nodelist_free_all();
  1390. }
  1391. /** Test building descriptors. We use this separate function instead of
  1392. * using test_build_update_descriptors because that function is too complex
  1393. * and also too interactive. */
  1394. static void
  1395. test_build_descriptors(void *arg)
  1396. {
  1397. int ret;
  1398. time_t now = time(NULL);
  1399. (void) arg;
  1400. hs_init();
  1401. MOCK(get_or_state,
  1402. get_or_state_replacement);
  1403. MOCK(networkstatus_get_live_consensus,
  1404. mock_networkstatus_get_live_consensus);
  1405. dummy_state = tor_malloc_zero(sizeof(or_state_t));
  1406. ret = parse_rfc1123_time("Sat, 26 Oct 1985 03:00:00 UTC",
  1407. &mock_ns.valid_after);
  1408. tt_int_op(ret, OP_EQ, 0);
  1409. ret = parse_rfc1123_time("Sat, 26 Oct 1985 04:00:00 UTC",
  1410. &mock_ns.fresh_until);
  1411. tt_int_op(ret, OP_EQ, 0);
  1412. voting_schedule_recalculate_timing(get_options(), mock_ns.valid_after);
  1413. /* Generate a valid number of fake auth clients when a client authorization
  1414. * is disabled. */
  1415. {
  1416. hs_service_t *service = helper_create_service();
  1417. service_descriptor_free(service->desc_current);
  1418. service->desc_current = NULL;
  1419. build_all_descriptors(now);
  1420. hs_desc_superencrypted_data_t *superencrypted;
  1421. superencrypted = &service->desc_current->desc->superencrypted_data;
  1422. tt_int_op(smartlist_len(superencrypted->clients), OP_EQ, 16);
  1423. }
  1424. /* Generate a valid number of fake auth clients when the number of
  1425. * clients is zero. */
  1426. {
  1427. hs_service_t *service = helper_create_service_with_clients(0);
  1428. service_descriptor_free(service->desc_current);
  1429. service->desc_current = NULL;
  1430. build_all_descriptors(now);
  1431. hs_desc_superencrypted_data_t *superencrypted;
  1432. superencrypted = &service->desc_current->desc->superencrypted_data;
  1433. tt_int_op(smartlist_len(superencrypted->clients), OP_EQ, 16);
  1434. }
  1435. /* Generate a valid number of fake auth clients when the number of
  1436. * clients is not a multiple of 16. */
  1437. {
  1438. hs_service_t *service = helper_create_service_with_clients(20);
  1439. service_descriptor_free(service->desc_current);
  1440. service->desc_current = NULL;
  1441. build_all_descriptors(now);
  1442. hs_desc_superencrypted_data_t *superencrypted;
  1443. superencrypted = &service->desc_current->desc->superencrypted_data;
  1444. tt_int_op(smartlist_len(superencrypted->clients), OP_EQ, 32);
  1445. }
  1446. /* Do not generate any fake desc client when the number of clients is
  1447. * a multiple of 16 but not zero. */
  1448. {
  1449. hs_service_t *service = helper_create_service_with_clients(32);
  1450. service_descriptor_free(service->desc_current);
  1451. service->desc_current = NULL;
  1452. build_all_descriptors(now);
  1453. hs_desc_superencrypted_data_t *superencrypted;
  1454. superencrypted = &service->desc_current->desc->superencrypted_data;
  1455. tt_int_op(smartlist_len(superencrypted->clients), OP_EQ, 32);
  1456. }
  1457. done:
  1458. hs_free_all();
  1459. }
  1460. static void
  1461. test_upload_descriptors(void *arg)
  1462. {
  1463. int ret;
  1464. time_t now;
  1465. hs_service_t *service;
  1466. (void) arg;
  1467. hs_init();
  1468. MOCK(get_or_state,
  1469. get_or_state_replacement);
  1470. MOCK(networkstatus_get_live_consensus,
  1471. mock_networkstatus_get_live_consensus);
  1472. dummy_state = tor_malloc_zero(sizeof(or_state_t));
  1473. ret = parse_rfc1123_time("Sat, 26 Oct 1985 13:00:00 UTC",
  1474. &mock_ns.valid_after);
  1475. tt_int_op(ret, OP_EQ, 0);
  1476. ret = parse_rfc1123_time("Sat, 26 Oct 1985 14:00:00 UTC",
  1477. &mock_ns.fresh_until);
  1478. tt_int_op(ret, OP_EQ, 0);
  1479. voting_schedule_recalculate_timing(get_options(), mock_ns.valid_after);
  1480. update_approx_time(mock_ns.valid_after+1);
  1481. now = mock_ns.valid_after+1;
  1482. /* Create a service with no descriptor. It's added to the global map. */
  1483. service = hs_service_new(get_options());
  1484. tt_assert(service);
  1485. service->config.version = HS_VERSION_THREE;
  1486. ed25519_secret_key_generate(&service->keys.identity_sk, 0);
  1487. ed25519_public_key_generate(&service->keys.identity_pk,
  1488. &service->keys.identity_sk);
  1489. /* Register service to global map. */
  1490. ret = register_service(get_hs_service_map(), service);
  1491. tt_int_op(ret, OP_EQ, 0);
  1492. /* But first, build our descriptor. */
  1493. build_all_descriptors(now);
  1494. /* Nothing should happen because we have 0 introduction circuit established
  1495. * and we want (by default) 3 intro points. */
  1496. run_upload_descriptor_event(now);
  1497. /* If no upload happened, this should be untouched. */
  1498. tt_u64_op(service->desc_current->next_upload_time, OP_EQ, 0);
  1499. /* We'll simulate that we've opened our intro point circuit and that we only
  1500. * want one intro point. */
  1501. service->config.num_intro_points = 1;
  1502. /* Set our next upload time after now which will skip the upload. */
  1503. service->desc_current->next_upload_time = now + 1000;
  1504. run_upload_descriptor_event(now);
  1505. /* If no upload happened, this should be untouched. */
  1506. tt_u64_op(service->desc_current->next_upload_time, OP_EQ, now + 1000);
  1507. done:
  1508. hs_free_all();
  1509. UNMOCK(get_or_state);
  1510. }
  1511. /** Global vars used by test_rendezvous1_parsing() */
  1512. static char rend1_payload[RELAY_PAYLOAD_SIZE];
  1513. static size_t rend1_payload_len = 0;
  1514. /** Mock for relay_send_command_from_edge() to send a RENDEZVOUS1 cell. Instead
  1515. * of sending it to the network, instead save it to the global `rend1_payload`
  1516. * variable so that we can inspect it in the test_rendezvous1_parsing()
  1517. * test. */
  1518. static int
  1519. mock_relay_send_rendezvous1(streamid_t stream_id, circuit_t *circ,
  1520. uint8_t relay_command, const char *payload,
  1521. size_t payload_len,
  1522. crypt_path_t *cpath_layer,
  1523. const char *filename, int lineno)
  1524. {
  1525. (void) stream_id;
  1526. (void) circ;
  1527. (void) relay_command;
  1528. (void) cpath_layer;
  1529. (void) filename;
  1530. (void) lineno;
  1531. memcpy(rend1_payload, payload, payload_len);
  1532. rend1_payload_len = payload_len;
  1533. return 0;
  1534. }
  1535. /** Send a RENDEZVOUS1 as a service, and parse it as a client. */
  1536. static void
  1537. test_rendezvous1_parsing(void *arg)
  1538. {
  1539. int retval;
  1540. static const char *test_addr =
  1541. "4acth47i6kxnvkewtm6q7ib2s3ufpo5sqbsnzjpbi7utijcltosqemad.onion";
  1542. hs_service_t *service = NULL;
  1543. origin_circuit_t *service_circ = NULL;
  1544. origin_circuit_t *client_circ = NULL;
  1545. ed25519_keypair_t ip_auth_kp;
  1546. curve25519_keypair_t ephemeral_kp;
  1547. curve25519_keypair_t client_kp;
  1548. curve25519_keypair_t ip_enc_kp;
  1549. int flags = CIRCLAUNCH_NEED_UPTIME | CIRCLAUNCH_IS_INTERNAL;
  1550. (void) arg;
  1551. MOCK(relay_send_command_from_edge_, mock_relay_send_rendezvous1);
  1552. {
  1553. /* Let's start by setting up the service that will start the rend */
  1554. service = tor_malloc_zero(sizeof(hs_service_t));
  1555. ed25519_secret_key_generate(&service->keys.identity_sk, 0);
  1556. ed25519_public_key_generate(&service->keys.identity_pk,
  1557. &service->keys.identity_sk);
  1558. memcpy(service->onion_address, test_addr, sizeof(service->onion_address));
  1559. tt_assert(service);
  1560. }
  1561. {
  1562. /* Now let's set up the service rendezvous circuit and its keys. */
  1563. service_circ = helper_create_origin_circuit(CIRCUIT_PURPOSE_S_CONNECT_REND,
  1564. flags);
  1565. tor_free(service_circ->hs_ident);
  1566. hs_ntor_rend_cell_keys_t hs_ntor_rend_cell_keys;
  1567. uint8_t rendezvous_cookie[HS_REND_COOKIE_LEN];
  1568. curve25519_keypair_generate(&ip_enc_kp, 0);
  1569. curve25519_keypair_generate(&ephemeral_kp, 0);
  1570. curve25519_keypair_generate(&client_kp, 0);
  1571. ed25519_keypair_generate(&ip_auth_kp, 0);
  1572. retval = hs_ntor_service_get_rendezvous1_keys(&ip_auth_kp.pubkey,
  1573. &ip_enc_kp,
  1574. &ephemeral_kp,
  1575. &client_kp.pubkey,
  1576. &hs_ntor_rend_cell_keys);
  1577. tt_int_op(retval, OP_EQ, 0);
  1578. memset(rendezvous_cookie, 2, sizeof(rendezvous_cookie));
  1579. service_circ->hs_ident =
  1580. create_rp_circuit_identifier(service, rendezvous_cookie,
  1581. &ephemeral_kp.pubkey,
  1582. &hs_ntor_rend_cell_keys);
  1583. }
  1584. /* Send out the RENDEZVOUS1 and make sure that our mock func worked */
  1585. tt_assert(tor_mem_is_zero(rend1_payload, 32));
  1586. hs_circ_service_rp_has_opened(service, service_circ);
  1587. tt_assert(!tor_mem_is_zero(rend1_payload, 32));
  1588. tt_int_op(rend1_payload_len, OP_EQ, HS_LEGACY_RENDEZVOUS_CELL_SIZE);
  1589. /******************************/
  1590. /** Now let's create the client rendezvous circuit */
  1591. client_circ =
  1592. helper_create_origin_circuit(CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED,
  1593. flags);
  1594. /* fix up its circ ident */
  1595. ed25519_pubkey_copy(&client_circ->hs_ident->intro_auth_pk,
  1596. &ip_auth_kp.pubkey);
  1597. memcpy(&client_circ->hs_ident->rendezvous_client_kp,
  1598. &client_kp, sizeof(client_circ->hs_ident->rendezvous_client_kp));
  1599. memcpy(&client_circ->hs_ident->intro_enc_pk.public_key,
  1600. &ip_enc_kp.pubkey.public_key,
  1601. sizeof(client_circ->hs_ident->intro_enc_pk.public_key));
  1602. /* Now parse the rendezvous2 circuit and make sure it was fine. We are
  1603. * skipping 20 bytes off its payload, since that's the rendezvous cookie
  1604. * which is only present in REND1. */
  1605. retval = handle_rendezvous2(client_circ,
  1606. (uint8_t*)rend1_payload+20,
  1607. rend1_payload_len-20);
  1608. tt_int_op(retval, OP_EQ, 0);
  1609. /* TODO: We are only simulating client/service here. We could also simulate
  1610. * the rendezvous point by plugging in rend_mid_establish_rendezvous(). We
  1611. * would need an extra circuit and some more stuff but it's doable. */
  1612. done:
  1613. circuit_free_(TO_CIRCUIT(service_circ));
  1614. circuit_free_(TO_CIRCUIT(client_circ));
  1615. hs_service_free(service);
  1616. hs_free_all();
  1617. UNMOCK(relay_send_command_from_edge_);
  1618. }
  1619. static void
  1620. test_authorized_client_config_equal(void *arg)
  1621. {
  1622. int ret;
  1623. hs_service_config_t *config1, *config2;
  1624. (void) arg;
  1625. config1 = tor_malloc_zero(sizeof(*config1));
  1626. config2 = tor_malloc_zero(sizeof(*config2));
  1627. /* Both configs are empty. */
  1628. {
  1629. config1->clients = smartlist_new();
  1630. config2->clients = smartlist_new();
  1631. ret = service_authorized_client_config_equal(config1, config2);
  1632. tt_int_op(ret, OP_EQ, 1);
  1633. service_clear_config(config1);
  1634. service_clear_config(config2);
  1635. }
  1636. /* Both configs have exactly the same client config. */
  1637. {
  1638. config1->clients = smartlist_new();
  1639. config2->clients = smartlist_new();
  1640. hs_service_authorized_client_t *client1, *client2;
  1641. client1 = helper_create_authorized_client();
  1642. client2 = helper_create_authorized_client();
  1643. smartlist_add(config1->clients, client1);
  1644. smartlist_add(config1->clients, client2);
  1645. /* We should swap the order of clients here to test that the order
  1646. * does not matter. */
  1647. smartlist_add(config2->clients, helper_clone_authorized_client(client2));
  1648. smartlist_add(config2->clients, helper_clone_authorized_client(client1));
  1649. ret = service_authorized_client_config_equal(config1, config2);
  1650. tt_int_op(ret, OP_EQ, 1);
  1651. service_clear_config(config1);
  1652. service_clear_config(config2);
  1653. }
  1654. /* The numbers of clients in both configs are not equal. */
  1655. {
  1656. config1->clients = smartlist_new();
  1657. config2->clients = smartlist_new();
  1658. hs_service_authorized_client_t *client1, *client2;
  1659. client1 = helper_create_authorized_client();
  1660. client2 = helper_create_authorized_client();
  1661. smartlist_add(config1->clients, client1);
  1662. smartlist_add(config1->clients, client2);
  1663. smartlist_add(config2->clients, helper_clone_authorized_client(client1));
  1664. ret = service_authorized_client_config_equal(config1, config2);
  1665. tt_int_op(ret, OP_EQ, 0);
  1666. service_clear_config(config1);
  1667. service_clear_config(config2);
  1668. }
  1669. /* The first config has two distinct clients while the second config
  1670. * has two clients but they are duplicate. */
  1671. {
  1672. config1->clients = smartlist_new();
  1673. config2->clients = smartlist_new();
  1674. hs_service_authorized_client_t *client1, *client2;
  1675. client1 = helper_create_authorized_client();
  1676. client2 = helper_create_authorized_client();
  1677. smartlist_add(config1->clients, client1);
  1678. smartlist_add(config1->clients, client2);
  1679. smartlist_add(config2->clients, helper_clone_authorized_client(client1));
  1680. smartlist_add(config2->clients, helper_clone_authorized_client(client1));
  1681. ret = service_authorized_client_config_equal(config1, config2);
  1682. tt_int_op(ret, OP_EQ, 0);
  1683. service_clear_config(config1);
  1684. service_clear_config(config2);
  1685. }
  1686. /* Both configs have totally distinct clients. */
  1687. {
  1688. config1->clients = smartlist_new();
  1689. config2->clients = smartlist_new();
  1690. hs_service_authorized_client_t *client1, *client2, *client3, *client4;
  1691. client1 = helper_create_authorized_client();
  1692. client2 = helper_create_authorized_client();
  1693. client3 = helper_create_authorized_client();
  1694. client4 = helper_create_authorized_client();
  1695. smartlist_add(config1->clients, client1);
  1696. smartlist_add(config1->clients, client2);
  1697. smartlist_add(config2->clients, client3);
  1698. smartlist_add(config2->clients, client4);
  1699. ret = service_authorized_client_config_equal(config1, config2);
  1700. tt_int_op(ret, OP_EQ, 0);
  1701. service_clear_config(config1);
  1702. service_clear_config(config2);
  1703. }
  1704. done:
  1705. tor_free(config1);
  1706. tor_free(config2);
  1707. }
  1708. /** Test that client circuit ID gets correctly exported */
  1709. static void
  1710. test_export_client_circuit_id(void *arg)
  1711. {
  1712. origin_circuit_t *or_circ = NULL;
  1713. size_t sz;
  1714. char *cp1=NULL, *cp2=NULL;
  1715. connection_t *conn = NULL;
  1716. (void) arg;
  1717. MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
  1718. hs_service_init();
  1719. /* Create service */
  1720. hs_service_t *service = helper_create_service();
  1721. /* Check that export circuit ID detection works */
  1722. service->config.circuit_id_protocol = HS_CIRCUIT_ID_PROTOCOL_NONE;
  1723. tt_int_op(0, OP_EQ,
  1724. hs_service_exports_circuit_id(&service->keys.identity_pk));
  1725. service->config.circuit_id_protocol = HS_CIRCUIT_ID_PROTOCOL_HAPROXY;
  1726. tt_int_op(1, OP_EQ,
  1727. hs_service_exports_circuit_id(&service->keys.identity_pk));
  1728. /* Create client connection */
  1729. conn = test_conn_get_connection(AP_CONN_STATE_CIRCUIT_WAIT, CONN_TYPE_AP, 0);
  1730. /* Create client edge conn hs_ident */
  1731. edge_connection_t *edge_conn = TO_EDGE_CONN(conn);
  1732. edge_conn->hs_ident = hs_ident_edge_conn_new(&service->keys.identity_pk);
  1733. edge_conn->hs_ident->orig_virtual_port = 42;
  1734. /* Create rend circuit */
  1735. or_circ = origin_circuit_new();
  1736. or_circ->base_.purpose = CIRCUIT_PURPOSE_C_REND_JOINED;
  1737. edge_conn->on_circuit = TO_CIRCUIT(or_circ);
  1738. or_circ->global_identifier = 666;
  1739. /* Export circuit ID */
  1740. export_hs_client_circuit_id(edge_conn, service->config.circuit_id_protocol);
  1741. /* Check contents */
  1742. cp1 = buf_get_contents(conn->outbuf, &sz);
  1743. tt_str_op(cp1, OP_EQ,
  1744. "PROXY TCP6 fc00:dead:beef:4dad::0:29a ::1 666 42\r\n");
  1745. /* Change circ GID and see that the reported circuit ID also changes */
  1746. or_circ->global_identifier = 22;
  1747. /* check changes */
  1748. export_hs_client_circuit_id(edge_conn, service->config.circuit_id_protocol);
  1749. cp2 = buf_get_contents(conn->outbuf, &sz);
  1750. tt_str_op(cp1, OP_NE, cp2);
  1751. tor_free(cp1);
  1752. /* Check that GID with UINT32_MAX works. */
  1753. or_circ->global_identifier = UINT32_MAX;
  1754. export_hs_client_circuit_id(edge_conn, service->config.circuit_id_protocol);
  1755. cp1 = buf_get_contents(conn->outbuf, &sz);
  1756. tt_str_op(cp1, OP_EQ,
  1757. "PROXY TCP6 fc00:dead:beef:4dad::ffff:ffff ::1 65535 42\r\n");
  1758. tor_free(cp1);
  1759. /* Check that GID with UINT16_MAX works. */
  1760. or_circ->global_identifier = UINT16_MAX;
  1761. export_hs_client_circuit_id(edge_conn, service->config.circuit_id_protocol);
  1762. cp1 = buf_get_contents(conn->outbuf, &sz);
  1763. tt_str_op(cp1, OP_EQ,
  1764. "PROXY TCP6 fc00:dead:beef:4dad::0:ffff ::1 65535 42\r\n");
  1765. tor_free(cp1);
  1766. /* Check that GID with UINT16_MAX + 7 works. */
  1767. or_circ->global_identifier = UINT16_MAX + 7;
  1768. export_hs_client_circuit_id(edge_conn, service->config.circuit_id_protocol);
  1769. cp1 = buf_get_contents(conn->outbuf, &sz);
  1770. tt_str_op(cp1, OP_EQ, "PROXY TCP6 fc00:dead:beef:4dad::1:6 ::1 6 42\r\n");
  1771. done:
  1772. UNMOCK(connection_write_to_buf_impl_);
  1773. circuit_free_(TO_CIRCUIT(or_circ));
  1774. connection_free_minimal(conn);
  1775. hs_service_free(service);
  1776. tor_free(cp1);
  1777. tor_free(cp2);
  1778. }
  1779. struct testcase_t hs_service_tests[] = {
  1780. { "e2e_rend_circuit_setup", test_e2e_rend_circuit_setup, TT_FORK,
  1781. NULL, NULL },
  1782. { "load_keys", test_load_keys, TT_FORK,
  1783. NULL, NULL },
  1784. { "client_filename_is_valid", test_client_filename_is_valid, TT_FORK,
  1785. NULL, NULL },
  1786. { "parse_authorized_client", test_parse_authorized_client, TT_FORK,
  1787. NULL, NULL },
  1788. { "load_keys_with_client_auth", test_load_keys_with_client_auth, TT_FORK,
  1789. NULL, NULL },
  1790. { "access_service", test_access_service, TT_FORK,
  1791. NULL, NULL },
  1792. { "service_intro_point", test_service_intro_point, TT_FORK,
  1793. NULL, NULL },
  1794. { "helper_functions", test_helper_functions, TT_FORK,
  1795. NULL, NULL },
  1796. { "intro_circuit_opened", test_intro_circuit_opened, TT_FORK,
  1797. NULL, NULL },
  1798. { "intro_established", test_intro_established, TT_FORK,
  1799. NULL, NULL },
  1800. { "closing_intro_circs", test_closing_intro_circs, TT_FORK,
  1801. NULL, NULL },
  1802. { "rdv_circuit_opened", test_rdv_circuit_opened, TT_FORK,
  1803. NULL, NULL },
  1804. { "introduce2", test_introduce2, TT_FORK,
  1805. NULL, NULL },
  1806. { "service_event", test_service_event, TT_FORK,
  1807. NULL, NULL },
  1808. { "rotate_descriptors", test_rotate_descriptors, TT_FORK,
  1809. NULL, NULL },
  1810. { "build_update_descriptors", test_build_update_descriptors, TT_FORK,
  1811. NULL, NULL },
  1812. { "build_descriptors", test_build_descriptors, TT_FORK,
  1813. NULL, NULL },
  1814. { "upload_descriptors", test_upload_descriptors, TT_FORK,
  1815. NULL, NULL },
  1816. { "rendezvous1_parsing", test_rendezvous1_parsing, TT_FORK,
  1817. NULL, NULL },
  1818. { "authorized_client_config_equal", test_authorized_client_config_equal,
  1819. TT_FORK, NULL, NULL },
  1820. { "export_client_circuit_id", test_export_client_circuit_id, TT_FORK,
  1821. NULL, NULL },
  1822. END_OF_TESTCASES
  1823. };