hs_service.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. /* Copyright (c) 2016-2017, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. /**
  4. * \file hs_service.c
  5. * \brief Implement next generation hidden service functionality
  6. **/
  7. #include "or.h"
  8. #include "circuitlist.h"
  9. #include "config.h"
  10. #include "relay.h"
  11. #include "rendservice.h"
  12. #include "router.h"
  13. #include "hs_common.h"
  14. #include "hs_config.h"
  15. #include "hs_intropoint.h"
  16. #include "hs_service.h"
  17. #include "hs/cell_establish_intro.h"
  18. #include "hs/cell_common.h"
  19. /* Staging list of service object. When configuring service, we add them to
  20. * this list considered a staging area and they will get added to our global
  21. * map once the keys have been loaded. These two steps are seperated because
  22. * loading keys requires that we are an actual running tor process. */
  23. static smartlist_t *hs_service_staging_list;
  24. /* Helper: Function to compare two objects in the service map. Return 1 if the
  25. * two service have the same master public identity key. */
  26. static inline int
  27. hs_service_ht_eq(const hs_service_t *first, const hs_service_t *second)
  28. {
  29. tor_assert(first);
  30. tor_assert(second);
  31. /* Simple key compare. */
  32. return ed25519_pubkey_eq(&first->keys.identity_pk,
  33. &second->keys.identity_pk);
  34. }
  35. /* Helper: Function for the service hash table code below. The key used is the
  36. * master public identity key which is ultimately the onion address. */
  37. static inline unsigned int
  38. hs_service_ht_hash(const hs_service_t *service)
  39. {
  40. tor_assert(service);
  41. return (unsigned int) siphash24g(service->keys.identity_pk.pubkey,
  42. sizeof(service->keys.identity_pk.pubkey));
  43. }
  44. /* For the service global hash map, we define a specific type for it which
  45. * will make it safe to use and specific to some controlled parameters such as
  46. * the hashing function and how to compare services. */
  47. typedef HT_HEAD(hs_service_ht, hs_service_t) hs_service_ht;
  48. /* This is _the_ global hash map of hidden services which indexed the service
  49. * contained in it by master public identity key which is roughly the onion
  50. * address of the service. */
  51. static struct hs_service_ht *hs_service_map;
  52. /* Register the service hash table. */
  53. HT_PROTOTYPE(hs_service_ht, /* Name of hashtable. */
  54. hs_service_t, /* Object contained in the map. */
  55. hs_service_node, /* The name of the HT_ENTRY member. */
  56. hs_service_ht_hash, /* Hashing function. */
  57. hs_service_ht_eq) /* Compare function for objects. */
  58. HT_GENERATE2(hs_service_ht, hs_service_t, hs_service_node,
  59. hs_service_ht_hash, hs_service_ht_eq,
  60. 0.6, tor_reallocarray, tor_free_)
  61. /* Query the given service map with a public key and return a service object
  62. * if found else NULL. It is also possible to set a directory path in the
  63. * search query. If pk is NULL, then it will be set to zero indicating the
  64. * hash table to compare the directory path instead. */
  65. static hs_service_t *
  66. find_service(hs_service_ht *map, const ed25519_public_key_t *pk)
  67. {
  68. hs_service_t dummy_service = {0};
  69. tor_assert(map);
  70. tor_assert(pk);
  71. ed25519_pubkey_copy(&dummy_service.keys.identity_pk, pk);
  72. return HT_FIND(hs_service_ht, map, &dummy_service);
  73. }
  74. /* Register the given service in the given map. If the service already exists
  75. * in the map, -1 is returned. On success, 0 is returned and the service
  76. * ownership has been transfered to the global map. */
  77. static int
  78. register_service(hs_service_ht *map, hs_service_t *service)
  79. {
  80. tor_assert(map);
  81. tor_assert(service);
  82. tor_assert(!ed25519_public_key_is_zero(&service->keys.identity_pk));
  83. if (find_service(map, &service->keys.identity_pk)) {
  84. /* Existing service with the same key. Do not register it. */
  85. return -1;
  86. }
  87. /* Taking ownership of the object at this point. */
  88. HT_INSERT(hs_service_ht, map, service);
  89. return 0;
  90. }
  91. /* Remove a given service from the given map. If service is NULL or the
  92. * service key is unset, return gracefully. */
  93. static void
  94. remove_service(hs_service_ht *map, hs_service_t *service)
  95. {
  96. hs_service_t *elm;
  97. tor_assert(map);
  98. /* Ignore if no service or key is zero. */
  99. if (BUG(service == NULL) ||
  100. BUG(ed25519_public_key_is_zero(&service->keys.identity_pk))) {
  101. return;
  102. }
  103. elm = HT_REMOVE(hs_service_ht, map, service);
  104. if (elm) {
  105. tor_assert(elm == service);
  106. } else {
  107. log_warn(LD_BUG, "Could not find service in the global map "
  108. "while removing service %s",
  109. escaped(service->config.directory_path));
  110. }
  111. }
  112. /* Set the default values for a service configuration object <b>c</b>. */
  113. static void
  114. set_service_default_config(hs_service_config_t *c,
  115. const or_options_t *options)
  116. {
  117. tor_assert(c);
  118. c->ports = smartlist_new();
  119. c->directory_path = NULL;
  120. c->descriptor_post_period = options->RendPostPeriod;
  121. c->max_streams_per_rdv_circuit = 0;
  122. c->max_streams_close_circuit = 0;
  123. c->num_intro_points = NUM_INTRO_POINTS_DEFAULT;
  124. c->allow_unknown_ports = 0;
  125. c->is_single_onion = 0;
  126. c->dir_group_readable = 0;
  127. c->is_ephemeral = 0;
  128. }
  129. /* Helper: Function that needs to return 1 for the HT for each loop which
  130. * frees every service in an hash map. */
  131. static int
  132. ht_free_service_(struct hs_service_t *service, void *data)
  133. {
  134. (void) data;
  135. hs_service_free(service);
  136. /* This function MUST return 1 so the given object is then removed from the
  137. * service map leading to this free of the object being safe. */
  138. return 1;
  139. }
  140. /* Free every service that can be found in the global map. Once done, clear
  141. * and free the global map. */
  142. static void
  143. service_free_all(void)
  144. {
  145. if (hs_service_map == NULL) {
  146. return;
  147. }
  148. /* The free helper function returns 1 so this is safe. */
  149. hs_service_ht_HT_FOREACH_FN(hs_service_map, ht_free_service_, NULL);
  150. HT_CLEAR(hs_service_ht, hs_service_map);
  151. tor_free(hs_service_map);
  152. hs_service_map = NULL;
  153. /* Cleanup staging list. */
  154. SMARTLIST_FOREACH(hs_service_staging_list, hs_service_t *, s,
  155. hs_service_free(s));
  156. smartlist_free(hs_service_staging_list);
  157. hs_service_staging_list = NULL;
  158. }
  159. /* Close all rendezvous circuits for the given service. */
  160. static void
  161. close_service_rp_circuits(hs_service_t *service)
  162. {
  163. tor_assert(service);
  164. /* XXX: To implement. */
  165. return;
  166. }
  167. /* Close the circuit(s) for the given map of introduction points. */
  168. static void
  169. close_intro_circuits(hs_service_intropoints_t *intro_points)
  170. {
  171. tor_assert(intro_points);
  172. DIGEST256MAP_FOREACH(intro_points->map, key,
  173. const hs_service_intro_point_t *, ip) {
  174. origin_circuit_t *ocirc =
  175. hs_circuitmap_get_intro_circ_v3_service_side(
  176. &ip->auth_key_kp.pubkey);
  177. if (ocirc) {
  178. hs_circuitmap_remove_circuit(TO_CIRCUIT(ocirc));
  179. /* Reason is FINISHED because service has been removed and thus the
  180. * circuit is considered old/uneeded. */
  181. circuit_mark_for_close(TO_CIRCUIT(ocirc), END_CIRC_REASON_FINISHED);
  182. }
  183. } DIGEST256MAP_FOREACH_END;
  184. }
  185. /* Close all introduction circuits for the given service. */
  186. static void
  187. close_service_intro_circuits(hs_service_t *service)
  188. {
  189. tor_assert(service);
  190. if (service->desc_current) {
  191. close_intro_circuits(&service->desc_current->intro_points);
  192. }
  193. if (service->desc_next) {
  194. close_intro_circuits(&service->desc_next->intro_points);
  195. }
  196. }
  197. /* Close any circuits related to the given service. */
  198. static void
  199. close_service_circuits(hs_service_t *service)
  200. {
  201. tor_assert(service);
  202. /* Only support for version >= 3. */
  203. if (BUG(service->version < HS_VERSION_THREE)) {
  204. return;
  205. }
  206. /* Close intro points. */
  207. close_service_intro_circuits(service);
  208. /* Close rendezvous points. */
  209. close_service_rp_circuits(service);
  210. }
  211. /* Move introduction points from the src descriptor to the dst descriptor. The
  212. * destination service intropoints are wiped out if any before moving. */
  213. static void
  214. move_descriptor_intro_points(hs_service_descriptor_t *src,
  215. hs_service_descriptor_t *dst)
  216. {
  217. tor_assert(src);
  218. tor_assert(dst);
  219. /* XXX: Free dst introduction points. */
  220. dst->intro_points.map = src->intro_points.map;
  221. /* Nullify the source. */
  222. src->intro_points.map = NULL;
  223. }
  224. /* Move introduction points from the src service to the dst service. The
  225. * destination service intropoints are wiped out if any before moving. */
  226. static void
  227. move_intro_points(hs_service_t *src, hs_service_t *dst)
  228. {
  229. tor_assert(src);
  230. tor_assert(dst);
  231. /* Cleanup destination. */
  232. if (src->desc_current && dst->desc_current) {
  233. move_descriptor_intro_points(src->desc_current, dst->desc_current);
  234. }
  235. if (src->desc_next && dst->desc_next) {
  236. move_descriptor_intro_points(src->desc_next, dst->desc_next);
  237. }
  238. }
  239. /* Move every ephemeral services from the src service map to the dst service
  240. * map. It is possible that a service can't be register to the dst map which
  241. * won't stop the process of moving them all but will trigger a log warn. */
  242. static void
  243. move_ephemeral_services(hs_service_ht *src, hs_service_ht *dst)
  244. {
  245. hs_service_t **iter, **next;
  246. tor_assert(src);
  247. tor_assert(dst);
  248. /* Iterate over the map to find ephemeral service and move them to the other
  249. * map. We loop using this method to have a safe removal process. */
  250. for (iter = HT_START(hs_service_ht, src); iter != NULL; iter = next) {
  251. hs_service_t *s = *iter;
  252. if (!s->config.is_ephemeral) {
  253. /* Yeah, we are in a very manual loop :). */
  254. next = HT_NEXT(hs_service_ht, src, iter);
  255. continue;
  256. }
  257. /* Remove service from map and then register to it to the other map.
  258. * Reminder that "*iter" and "s" are the same thing. */
  259. next = HT_NEXT_RMV(hs_service_ht, src, iter);
  260. if (register_service(dst, s) < 0) {
  261. log_warn(LD_BUG, "Ephemeral service key is already being used. "
  262. "Skipping.");
  263. }
  264. }
  265. }
  266. /* Register services that are in the list. Once this function returns, the
  267. * global service map will be set with the right content and all non surviving
  268. * services will be cleaned up. */
  269. void
  270. hs_service_register_services(smartlist_t *new_service_list)
  271. {
  272. struct hs_service_ht *new_service_map;
  273. hs_service_t *s, **iter;
  274. tor_assert(new_service_list);
  275. /* We'll save us some allocation and computing time. */
  276. if (smartlist_len(new_service_list) == 0) {
  277. return;
  278. }
  279. /* Allocate a new map that will replace the current one. */
  280. new_service_map = tor_malloc_zero(sizeof(*new_service_map));
  281. HT_INIT(hs_service_ht, new_service_map);
  282. /* First step is to transfer all ephemeral services from the current global
  283. * map to the new one we are constructing. We do not prune ephemeral
  284. * services as the only way to kill them is by deleting it from the control
  285. * port or stopping the tor daemon. */
  286. move_ephemeral_services(hs_service_map, new_service_map);
  287. SMARTLIST_FOREACH_BEGIN(new_service_list, hs_service_t *, snew) {
  288. /* Check if that service is already in our global map and if so, we'll
  289. * transfer the intro points to it. */
  290. s = find_service(hs_service_map, &snew->keys.identity_pk);
  291. if (s) {
  292. /* Pass ownership of intro points from s (the current service) to snew
  293. * (the newly configured one). */
  294. move_intro_points(s, snew);
  295. /* Remove the service from the global map because after this, we need to
  296. * go over the remaining service in that map that aren't surviving the
  297. * reload to close their circuits. */
  298. remove_service(hs_service_map, s);
  299. }
  300. /* Great, this service is now ready to be added to our new map. */
  301. if (BUG(register_service(new_service_map, snew) < 0)) {
  302. /* This should never happen because prior to registration, we validate
  303. * every service against the entire set. Not being able to register a
  304. * service means we failed to validate correctly. In that case, don't
  305. * break tor and ignore the service but tell user. */
  306. log_warn(LD_BUG, "Unable to register service with directory %s",
  307. snew->config.directory_path);
  308. SMARTLIST_DEL_CURRENT(new_service_list, snew);
  309. hs_service_free(snew);
  310. }
  311. } SMARTLIST_FOREACH_END(snew);
  312. /* Close any circuits associated with the non surviving services. Every
  313. * service in the current global map are roaming. */
  314. HT_FOREACH(iter, hs_service_ht, hs_service_map) {
  315. close_service_circuits(*iter);
  316. }
  317. /* Time to make the switch. We'll wipe the current list and switch. */
  318. service_free_all();
  319. hs_service_map = new_service_map;
  320. }
  321. /* Put all service object in the given service list. After this, the caller
  322. * looses ownership of every elements in the list and responsible to free the
  323. * list pointer. */
  324. void
  325. hs_service_stage_services(const smartlist_t *service_list)
  326. {
  327. tor_assert(service_list);
  328. /* This list is freed at registration time but this function can be called
  329. * multiple time. */
  330. if (hs_service_staging_list == NULL) {
  331. hs_service_staging_list = smartlist_new();
  332. }
  333. /* Add all service object to our staging list. Caller is responsible for
  334. * freeing the service_list. */
  335. smartlist_add_all(hs_service_staging_list, service_list);
  336. }
  337. /* Allocate and initilize a service object. The service configuration will
  338. * contain the default values. Return the newly allocated object pointer. This
  339. * function can't fail. */
  340. hs_service_t *
  341. hs_service_new(const or_options_t *options)
  342. {
  343. hs_service_t *service = tor_malloc_zero(sizeof(hs_service_t));
  344. /* Set default configuration value. */
  345. set_service_default_config(&service->config, options);
  346. /* Set the default service version. */
  347. service->version = HS_SERVICE_DEFAULT_VERSION;
  348. return service;
  349. }
  350. /* Free the given <b>service</b> object and all its content. This function
  351. * also takes care of wiping service keys from memory. It is safe to pass a
  352. * NULL pointer. */
  353. void
  354. hs_service_free(hs_service_t *service)
  355. {
  356. if (service == NULL) {
  357. return;
  358. }
  359. /* Free descriptors. */
  360. if (service->desc_current) {
  361. hs_descriptor_free(service->desc_current->desc);
  362. /* Wipe keys. */
  363. memwipe(&service->desc_current->signing_kp, 0,
  364. sizeof(service->desc_current->signing_kp));
  365. memwipe(&service->desc_current->blinded_kp, 0,
  366. sizeof(service->desc_current->blinded_kp));
  367. /* XXX: Free intro points. */
  368. tor_free(service->desc_current);
  369. }
  370. if (service->desc_next) {
  371. hs_descriptor_free(service->desc_next->desc);
  372. /* Wipe keys. */
  373. memwipe(&service->desc_next->signing_kp, 0,
  374. sizeof(service->desc_next->signing_kp));
  375. memwipe(&service->desc_next->blinded_kp, 0,
  376. sizeof(service->desc_next->blinded_kp));
  377. /* XXX: Free intro points. */
  378. tor_free(service->desc_next);
  379. }
  380. /* Free service configuration. */
  381. tor_free(service->config.directory_path);
  382. if (service->config.ports) {
  383. SMARTLIST_FOREACH(service->config.ports, rend_service_port_config_t *, p,
  384. rend_service_port_config_free(p););
  385. smartlist_free(service->config.ports);
  386. }
  387. /* Wipe service keys. */
  388. memwipe(&service->keys.identity_sk, 0, sizeof(service->keys.identity_sk));
  389. tor_free(service);
  390. }
  391. /* Initialize the service HS subsystem. */
  392. void
  393. hs_service_init(void)
  394. {
  395. /* Should never be called twice. */
  396. tor_assert(!hs_service_map);
  397. tor_assert(!hs_service_staging_list);
  398. hs_service_map = tor_malloc_zero(sizeof(struct hs_service_ht));
  399. HT_INIT(hs_service_ht, hs_service_map);
  400. hs_service_staging_list = smartlist_new();
  401. }
  402. /* Release all global storage of the hidden service subsystem. */
  403. void
  404. hs_service_free_all(void)
  405. {
  406. rend_service_free_all();
  407. service_free_all();
  408. }
  409. /* XXX We don't currently use these functions, apart from generating unittest
  410. data. When we start implementing the service-side support for prop224 we
  411. should revisit these functions and use them. */
  412. /** Given an ESTABLISH_INTRO <b>cell</b>, encode it and place its payload in
  413. * <b>buf_out</b> which has size <b>buf_out_len</b>. Return the number of
  414. * bytes written, or a negative integer if there was an error. */
  415. ssize_t
  416. get_establish_intro_payload(uint8_t *buf_out, size_t buf_out_len,
  417. const trn_cell_establish_intro_t *cell)
  418. {
  419. ssize_t bytes_used = 0;
  420. if (buf_out_len < RELAY_PAYLOAD_SIZE) {
  421. return -1;
  422. }
  423. bytes_used = trn_cell_establish_intro_encode(buf_out, buf_out_len,
  424. cell);
  425. return bytes_used;
  426. }
  427. /* Set the cell extensions of <b>cell</b>. */
  428. static void
  429. set_trn_cell_extensions(trn_cell_establish_intro_t *cell)
  430. {
  431. trn_cell_extension_t *trn_cell_extensions = trn_cell_extension_new();
  432. /* For now, we don't use extensions at all. */
  433. trn_cell_extensions->num = 0; /* It's already zeroed, but be explicit. */
  434. trn_cell_establish_intro_set_extensions(cell, trn_cell_extensions);
  435. }
  436. /** Given the circuit handshake info in <b>circuit_key_material</b>, create and
  437. * return an ESTABLISH_INTRO cell. Return NULL if something went wrong. The
  438. * returned cell is allocated on the heap and it's the responsibility of the
  439. * caller to free it. */
  440. trn_cell_establish_intro_t *
  441. generate_establish_intro_cell(const uint8_t *circuit_key_material,
  442. size_t circuit_key_material_len)
  443. {
  444. trn_cell_establish_intro_t *cell = NULL;
  445. ssize_t encoded_len;
  446. log_warn(LD_GENERAL,
  447. "Generating ESTABLISH_INTRO cell (key_material_len: %u)",
  448. (unsigned) circuit_key_material_len);
  449. /* Generate short-term keypair for use in ESTABLISH_INTRO */
  450. ed25519_keypair_t key_struct;
  451. if (ed25519_keypair_generate(&key_struct, 0) < 0) {
  452. goto err;
  453. }
  454. cell = trn_cell_establish_intro_new();
  455. /* Set AUTH_KEY_TYPE: 2 means ed25519 */
  456. trn_cell_establish_intro_set_auth_key_type(cell,
  457. HS_INTRO_AUTH_KEY_TYPE_ED25519);
  458. /* Set AUTH_KEY_LEN field */
  459. /* Must also set byte-length of AUTH_KEY to match */
  460. int auth_key_len = ED25519_PUBKEY_LEN;
  461. trn_cell_establish_intro_set_auth_key_len(cell, auth_key_len);
  462. trn_cell_establish_intro_setlen_auth_key(cell, auth_key_len);
  463. /* Set AUTH_KEY field */
  464. uint8_t *auth_key_ptr = trn_cell_establish_intro_getarray_auth_key(cell);
  465. memcpy(auth_key_ptr, key_struct.pubkey.pubkey, auth_key_len);
  466. /* No cell extensions needed */
  467. set_trn_cell_extensions(cell);
  468. /* Set signature size.
  469. We need to do this up here, because _encode() needs it and we need to call
  470. _encode() to calculate the MAC and signature.
  471. */
  472. int sig_len = ED25519_SIG_LEN;
  473. trn_cell_establish_intro_set_sig_len(cell, sig_len);
  474. trn_cell_establish_intro_setlen_sig(cell, sig_len);
  475. /* XXX How to make this process easier and nicer? */
  476. /* Calculate the cell MAC (aka HANDSHAKE_AUTH). */
  477. {
  478. /* To calculate HANDSHAKE_AUTH, we dump the cell in bytes, and then derive
  479. the MAC from it. */
  480. uint8_t cell_bytes_tmp[RELAY_PAYLOAD_SIZE] = {0};
  481. uint8_t mac[TRUNNEL_SHA3_256_LEN];
  482. encoded_len = trn_cell_establish_intro_encode(cell_bytes_tmp,
  483. sizeof(cell_bytes_tmp),
  484. cell);
  485. if (encoded_len < 0) {
  486. log_warn(LD_OR, "Unable to pre-encode ESTABLISH_INTRO cell.");
  487. goto err;
  488. }
  489. /* sanity check */
  490. tor_assert(encoded_len > ED25519_SIG_LEN + 2 + TRUNNEL_SHA3_256_LEN);
  491. /* Calculate MAC of all fields before HANDSHAKE_AUTH */
  492. crypto_mac_sha3_256(mac, sizeof(mac),
  493. circuit_key_material, circuit_key_material_len,
  494. cell_bytes_tmp,
  495. encoded_len -
  496. (ED25519_SIG_LEN + 2 + TRUNNEL_SHA3_256_LEN));
  497. /* Write the MAC to the cell */
  498. uint8_t *handshake_ptr =
  499. trn_cell_establish_intro_getarray_handshake_mac(cell);
  500. memcpy(handshake_ptr, mac, sizeof(mac));
  501. }
  502. /* Calculate the cell signature */
  503. {
  504. /* To calculate the sig we follow the same procedure as above. We first
  505. dump the cell up to the sig, and then calculate the sig */
  506. uint8_t cell_bytes_tmp[RELAY_PAYLOAD_SIZE] = {0};
  507. ed25519_signature_t sig;
  508. encoded_len = trn_cell_establish_intro_encode(cell_bytes_tmp,
  509. sizeof(cell_bytes_tmp),
  510. cell);
  511. if (encoded_len < 0) {
  512. log_warn(LD_OR, "Unable to pre-encode ESTABLISH_INTRO cell (2).");
  513. goto err;
  514. }
  515. tor_assert(encoded_len > ED25519_SIG_LEN);
  516. if (ed25519_sign_prefixed(&sig,
  517. cell_bytes_tmp,
  518. encoded_len -
  519. (ED25519_SIG_LEN + sizeof(cell->sig_len)),
  520. ESTABLISH_INTRO_SIG_PREFIX,
  521. &key_struct)) {
  522. log_warn(LD_BUG, "Unable to gen signature for ESTABLISH_INTRO cell.");
  523. goto err;
  524. }
  525. /* And write the signature to the cell */
  526. uint8_t *sig_ptr = trn_cell_establish_intro_getarray_sig(cell);
  527. memcpy(sig_ptr, sig.sig, sig_len);
  528. }
  529. /* We are done! Return the cell! */
  530. return cell;
  531. err:
  532. trn_cell_establish_intro_free(cell);
  533. return NULL;
  534. }