test_extorport.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. /* Copyright (c) 2013, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. #define CONNECTION_PRIVATE
  4. #define EXT_ORPORT_PRIVATE
  5. #define MAIN_PRIVATE
  6. #include "or.h"
  7. #include "buffers.h"
  8. #include "connection.h"
  9. #include "connection_or.h"
  10. #include "config.h"
  11. #include "control.h"
  12. #include "ext_orport.h"
  13. #include "main.h"
  14. #include "test.h"
  15. /* Test connection_or_remove_from_ext_or_id_map and
  16. * connection_or_set_ext_or_identifier */
  17. static void
  18. test_ext_or_id_map(void *arg)
  19. {
  20. or_connection_t *c1 = NULL, *c2 = NULL, *c3 = NULL;
  21. char *idp = NULL, *idp2 = NULL;
  22. (void)arg;
  23. /* pre-initialization */
  24. tt_ptr_op(NULL, ==, connection_or_get_by_ext_or_id("xxxxxxxxxxxxxxxxxxxx"));
  25. c1 = or_connection_new(CONN_TYPE_EXT_OR, AF_INET);
  26. c2 = or_connection_new(CONN_TYPE_EXT_OR, AF_INET);
  27. c3 = or_connection_new(CONN_TYPE_OR, AF_INET);
  28. tt_ptr_op(c1->ext_or_conn_id, !=, NULL);
  29. tt_ptr_op(c2->ext_or_conn_id, !=, NULL);
  30. tt_ptr_op(c3->ext_or_conn_id, ==, NULL);
  31. tt_ptr_op(c1, ==, connection_or_get_by_ext_or_id(c1->ext_or_conn_id));
  32. tt_ptr_op(c2, ==, connection_or_get_by_ext_or_id(c2->ext_or_conn_id));
  33. tt_ptr_op(NULL, ==, connection_or_get_by_ext_or_id("xxxxxxxxxxxxxxxxxxxx"));
  34. idp = tor_memdup(c2->ext_or_conn_id, EXT_OR_CONN_ID_LEN);
  35. /* Give c2 a new ID. */
  36. connection_or_set_ext_or_identifier(c2);
  37. test_mem_op(idp, !=, c2->ext_or_conn_id, EXT_OR_CONN_ID_LEN);
  38. idp2 = tor_memdup(c2->ext_or_conn_id, EXT_OR_CONN_ID_LEN);
  39. tt_assert(!tor_digest_is_zero(idp2));
  40. tt_ptr_op(NULL, ==, connection_or_get_by_ext_or_id(idp));
  41. tt_ptr_op(c2, ==, connection_or_get_by_ext_or_id(idp2));
  42. /* Now remove it. */
  43. connection_or_remove_from_ext_or_id_map(c2);
  44. tt_ptr_op(NULL, ==, connection_or_get_by_ext_or_id(idp));
  45. tt_ptr_op(NULL, ==, connection_or_get_by_ext_or_id(idp2));
  46. done:
  47. if (c1)
  48. connection_free_(TO_CONN(c1));
  49. if (c2)
  50. connection_free_(TO_CONN(c2));
  51. if (c3)
  52. connection_free_(TO_CONN(c3));
  53. tor_free(idp);
  54. tor_free(idp2);
  55. connection_or_clear_ext_or_id_map();
  56. }
  57. /* Simple connection_write_to_buf_impl_ replacement that unconditionally
  58. * writes to outbuf. */
  59. static void
  60. connection_write_to_buf_impl_replacement(const char *string, size_t len,
  61. connection_t *conn, int zlib)
  62. {
  63. (void) zlib;
  64. tor_assert(string);
  65. tor_assert(conn);
  66. write_to_buf(string, len, conn->outbuf);
  67. }
  68. static char *
  69. buf_get_contents(buf_t *buf, size_t *sz_out)
  70. {
  71. char *out;
  72. *sz_out = buf_datalen(buf);
  73. if (*sz_out >= ULONG_MAX)
  74. return NULL; /* C'mon, really? */
  75. out = tor_malloc(*sz_out + 1);
  76. if (fetch_from_buf(out, (unsigned long)*sz_out, buf) != 0) {
  77. tor_free(out);
  78. return NULL;
  79. }
  80. out[*sz_out] = '\0'; /* Hopefully gratuitous. */
  81. return out;
  82. }
  83. static void
  84. test_ext_or_write_command(void *arg)
  85. {
  86. or_connection_t *c1;
  87. char *cp = NULL;
  88. char *buf = NULL;
  89. size_t sz;
  90. (void) arg;
  91. MOCK(connection_write_to_buf_impl_,
  92. connection_write_to_buf_impl_replacement);
  93. c1 = or_connection_new(CONN_TYPE_EXT_OR, AF_INET);
  94. tt_assert(c1);
  95. /* Length too long */
  96. tt_int_op(connection_write_ext_or_command(TO_CONN(c1), 100, "X", 100000),
  97. <, 0);
  98. /* Empty command */
  99. tt_int_op(connection_write_ext_or_command(TO_CONN(c1), 0x99, NULL, 0),
  100. ==, 0);
  101. cp = buf_get_contents(TO_CONN(c1)->outbuf, &sz);
  102. tt_int_op(sz, ==, 4);
  103. test_mem_op(cp, ==, "\x00\x99\x00\x00", 4);
  104. tor_free(cp);
  105. /* Medium command. */
  106. tt_int_op(connection_write_ext_or_command(TO_CONN(c1), 0x99,
  107. "Wai\0Hello", 9), ==, 0);
  108. cp = buf_get_contents(TO_CONN(c1)->outbuf, &sz);
  109. tt_int_op(sz, ==, 13);
  110. test_mem_op(cp, ==, "\x00\x99\x00\x09Wai\x00Hello", 13);
  111. tor_free(cp);
  112. /* Long command */
  113. buf = tor_malloc(65535);
  114. memset(buf, 'x', 65535);
  115. tt_int_op(connection_write_ext_or_command(TO_CONN(c1), 0xf00d,
  116. buf, 65535), ==, 0);
  117. cp = buf_get_contents(TO_CONN(c1)->outbuf, &sz);
  118. tt_int_op(sz, ==, 65539);
  119. test_mem_op(cp, ==, "\xf0\x0d\xff\xff", 4);
  120. test_mem_op(cp+4, ==, buf, 65535);
  121. tor_free(cp);
  122. done:
  123. if (c1)
  124. connection_free_(TO_CONN(c1));
  125. tor_free(cp);
  126. tor_free(buf);
  127. UNMOCK(connection_write_to_buf_impl_);
  128. }
  129. static void
  130. test_ext_or_init_auth(void *arg)
  131. {
  132. or_options_t *options = get_options_mutable();
  133. const char *fn;
  134. char *cp = NULL;
  135. struct stat st;
  136. char cookie0[32];
  137. (void)arg;
  138. /* Check default filename location */
  139. options->DataDirectory = tor_strdup("foo");
  140. cp = get_ext_or_auth_cookie_file_name();
  141. tt_str_op(cp, ==, "foo"PATH_SEPARATOR"extended_orport_auth_cookie");
  142. tor_free(cp);
  143. /* Shouldn't be initialized already, or our tests will be a bit
  144. * meaningless */
  145. test_assert(tor_mem_is_zero(ext_or_auth_cookie, 32));
  146. /* Now make sure we use a temporary file */
  147. fn = get_fname("ext_cookie_file");
  148. options->ExtORPortCookieAuthFile = tor_strdup(fn);
  149. cp = get_ext_or_auth_cookie_file_name();
  150. tt_str_op(cp, ==, fn);
  151. tor_free(cp);
  152. tt_int_op(0, ==, init_ext_or_cookie_authentication(1));
  153. tt_int_op(ext_or_auth_cookie_is_set, ==, 1);
  154. cp = read_file_to_str(fn, RFTS_BIN, &st);
  155. tt_ptr_op(cp, !=, NULL);
  156. tt_int_op(st.st_size, ==, 64);
  157. test_memeq(cp, "! Extended ORPort Auth Cookie !\x0a", 32);
  158. test_memeq(cp+32, ext_or_auth_cookie, 32);
  159. memcpy(cookie0, ext_or_auth_cookie, 32);
  160. test_assert(!tor_mem_is_zero(ext_or_auth_cookie, 32));
  161. /* Operation should be idempotent. */
  162. tt_int_op(0, ==, init_ext_or_cookie_authentication(1));
  163. test_memeq(cookie0, ext_or_auth_cookie, 32);
  164. done:
  165. tor_free(cp);
  166. }
  167. static void
  168. test_ext_or_cookie_auth(void *arg)
  169. {
  170. char *reply=NULL, *reply2=NULL, *client_hash=NULL, *client_hash2=NULL;
  171. size_t reply_len=0;
  172. char hmac1[32], hmac2[32];
  173. const char client_nonce[32] =
  174. "Who is the third who walks alway";
  175. char server_hash_input[] =
  176. "ExtORPort authentication server-to-client hash"
  177. "Who is the third who walks alway"
  178. "................................";
  179. char client_hash_input[] =
  180. "ExtORPort authentication client-to-server hash"
  181. "Who is the third who walks alway"
  182. "................................";
  183. (void)arg;
  184. tt_int_op(strlen(client_hash_input), ==, 46+32+32);
  185. tt_int_op(strlen(server_hash_input), ==, 46+32+32);
  186. memcpy(ext_or_auth_cookie, "s beside you? When I count, ther", 32);
  187. ext_or_auth_cookie_is_set = 1;
  188. /* For this authentication, the client sends 32 random bytes (ClientNonce)
  189. * The server replies with 32 byte ServerHash and 32 byte ServerNonce,
  190. * where ServerHash is:
  191. * HMAC-SHA256(CookieString,
  192. * "ExtORPort authentication server-to-client hash" | ClientNonce |
  193. * ServerNonce)"
  194. * The client must reply with 32-byte ClientHash, which we compute as:
  195. * ClientHash is computed as:
  196. * HMAC-SHA256(CookieString,
  197. * "ExtORPort authentication client-to-server hash" | ClientNonce |
  198. * ServerNonce)
  199. */
  200. /* Wrong length */
  201. tt_int_op(-1, ==,
  202. handle_client_auth_nonce(client_nonce, 33, &client_hash, &reply,
  203. &reply_len));
  204. tt_int_op(-1, ==,
  205. handle_client_auth_nonce(client_nonce, 31, &client_hash, &reply,
  206. &reply_len));
  207. /* Now let's try this for real! */
  208. tt_int_op(0, ==,
  209. handle_client_auth_nonce(client_nonce, 32, &client_hash, &reply,
  210. &reply_len));
  211. tt_int_op(reply_len, ==, 64);
  212. tt_ptr_op(reply, !=, NULL);
  213. tt_ptr_op(client_hash, !=, NULL);
  214. /* Fill in the server nonce into the hash inputs... */
  215. memcpy(server_hash_input+46+32, reply+32, 32);
  216. memcpy(client_hash_input+46+32, reply+32, 32);
  217. /* Check the HMACs are correct... */
  218. crypto_hmac_sha256(hmac1, ext_or_auth_cookie, 32, server_hash_input,
  219. 46+32+32);
  220. crypto_hmac_sha256(hmac2, ext_or_auth_cookie, 32, client_hash_input,
  221. 46+32+32);
  222. test_memeq(hmac1, reply, 32);
  223. test_memeq(hmac2, client_hash, 32);
  224. /* Now do it again and make sure that the results are *different* */
  225. tt_int_op(0, ==,
  226. handle_client_auth_nonce(client_nonce, 32, &client_hash2, &reply2,
  227. &reply_len));
  228. test_memneq(reply2, reply, reply_len);
  229. test_memneq(client_hash2, client_hash, 32);
  230. /* But that this one checks out too. */
  231. memcpy(server_hash_input+46+32, reply2+32, 32);
  232. memcpy(client_hash_input+46+32, reply2+32, 32);
  233. /* Check the HMACs are correct... */
  234. crypto_hmac_sha256(hmac1, ext_or_auth_cookie, 32, server_hash_input,
  235. 46+32+32);
  236. crypto_hmac_sha256(hmac2, ext_or_auth_cookie, 32, client_hash_input,
  237. 46+32+32);
  238. test_memeq(hmac1, reply2, 32);
  239. test_memeq(hmac2, client_hash2, 32);
  240. done:
  241. tor_free(reply);
  242. tor_free(client_hash);
  243. tor_free(reply2);
  244. tor_free(client_hash2);
  245. }
  246. static int
  247. crypto_rand_return_tse_str(char *to, size_t n)
  248. {
  249. if (n != 32) {
  250. TT_FAIL(("Asked for %d bytes, not 32", (int)n));
  251. return -1;
  252. }
  253. memcpy(to, "te road There is always another ", 32);
  254. return 0;
  255. }
  256. static void
  257. test_ext_or_cookie_auth_testvec(void *arg)
  258. {
  259. char *reply=NULL, *client_hash=NULL;
  260. size_t reply_len;
  261. char *mem_op_hex_tmp=NULL;
  262. const char client_nonce[] = "But when I look ahead up the whi";
  263. (void)arg;
  264. memcpy(ext_or_auth_cookie, "Gliding wrapt in a brown mantle," , 32);
  265. ext_or_auth_cookie_is_set = 1;
  266. MOCK(crypto_rand, crypto_rand_return_tse_str);
  267. tt_int_op(0, ==,
  268. handle_client_auth_nonce(client_nonce, 32, &client_hash, &reply,
  269. &reply_len));
  270. tt_ptr_op(reply, !=, NULL );
  271. tt_ptr_op(reply_len, ==, 64);
  272. test_memeq(reply+32, "te road There is always another ", 32);
  273. /* HMACSHA256("Gliding wrapt in a brown mantle,"
  274. * "ExtORPort authentication server-to-client hash"
  275. * "But when I look ahead up the write road There is always another ");
  276. */
  277. test_memeq_hex(reply,
  278. "ec80ed6e546d3b36fdfc22fe1315416b"
  279. "029f1ade7610d910878b62eeb7403821");
  280. /* HMACSHA256("Gliding wrapt in a brown mantle,"
  281. * "ExtORPort authentication client-to-server hash"
  282. * "But when I look ahead up the write road There is always another ");
  283. * (Both values computed using Python CLI.)
  284. */
  285. test_memeq_hex(client_hash,
  286. "ab391732dd2ed968cd40c087d1b1f25b"
  287. "33b3cd77ff79bd80c2074bbf438119a2");
  288. done:
  289. UNMOCK(crypto_rand);
  290. tor_free(reply);
  291. tor_free(client_hash);
  292. tor_free(mem_op_hex_tmp);
  293. }
  294. static void
  295. ignore_bootstrap_problem(const char *warn, int reason)
  296. {
  297. (void)warn;
  298. (void)reason;
  299. }
  300. static int is_reading = 1;
  301. static int handshake_start_called = 0;
  302. static void
  303. note_read_stopped(connection_t *conn)
  304. {
  305. (void)conn;
  306. is_reading=0;
  307. }
  308. static void
  309. note_read_started(connection_t *conn)
  310. {
  311. (void)conn;
  312. is_reading=1;
  313. }
  314. static int
  315. handshake_start(or_connection_t *conn, int receiving)
  316. {
  317. if (!conn || !receiving)
  318. TT_FAIL(("Bad arguments to handshake_start"));
  319. handshake_start_called = 1;
  320. return 0;
  321. }
  322. static void
  323. test_ext_or_handshake(void *arg)
  324. {
  325. or_connection_t *conn=NULL;
  326. char b[256];
  327. #define WRITE(s,n) \
  328. do { \
  329. write_to_buf((s), (n), TO_CONN(conn)->inbuf); \
  330. } while (0)
  331. #define CONTAINS(s,n) \
  332. do { \
  333. tt_int_op((n), <=, sizeof(b)); \
  334. tt_int_op(buf_datalen(TO_CONN(conn)->outbuf), ==, (n)); \
  335. if ((n)) { \
  336. fetch_from_buf(b, (n), TO_CONN(conn)->outbuf); \
  337. test_memeq(b, (s), (n)); \
  338. } \
  339. } while (0)
  340. (void) arg;
  341. MOCK(connection_write_to_buf_impl_,
  342. connection_write_to_buf_impl_replacement);
  343. /* Use same authenticators as for test_ext_or_cookie_auth_testvec */
  344. memcpy(ext_or_auth_cookie, "Gliding wrapt in a brown mantle," , 32);
  345. ext_or_auth_cookie_is_set = 1;
  346. init_connection_lists();
  347. conn = or_connection_new(CONN_TYPE_EXT_OR, AF_INET);
  348. tt_int_op(0, ==, connection_ext_or_start_auth(conn));
  349. /* The server starts by telling us about the one supported authtype. */
  350. CONTAINS("\x01\x00", 2);
  351. /* Say the client hasn't responded yet. */
  352. tt_int_op(0, ==, connection_ext_or_process_inbuf(conn));
  353. /* Let's say the client replies badly. */
  354. WRITE("\x99", 1);
  355. tt_int_op(-1, ==, connection_ext_or_process_inbuf(conn));
  356. CONTAINS("", 0);
  357. tt_assert(TO_CONN(conn)->marked_for_close);
  358. close_closeable_connections();
  359. conn = NULL;
  360. /* Okay, try again. */
  361. conn = or_connection_new(CONN_TYPE_EXT_OR, AF_INET);
  362. tt_int_op(0, ==, connection_ext_or_start_auth(conn));
  363. CONTAINS("\x01\x00", 2);
  364. /* Let's say the client replies sensibly this time. "Yes, AUTHTYPE_COOKIE
  365. * sounds delicious. Let's have some of that!" */
  366. WRITE("\x01", 1);
  367. /* Let's say that the client also sends part of a nonce. */
  368. WRITE("But when I look ", 16);
  369. tt_int_op(0, ==, connection_ext_or_process_inbuf(conn));
  370. CONTAINS("", 0);
  371. tt_int_op(TO_CONN(conn)->state, ==,
  372. EXT_OR_CONN_STATE_AUTH_WAIT_CLIENT_NONCE);
  373. /* Pump it again. Nothing should happen. */
  374. tt_int_op(0, ==, connection_ext_or_process_inbuf(conn));
  375. /* send the rest of the nonce. */
  376. WRITE("ahead up the whi", 16);
  377. MOCK(crypto_rand, crypto_rand_return_tse_str);
  378. tt_int_op(0, ==, connection_ext_or_process_inbuf(conn));
  379. UNMOCK(crypto_rand);
  380. /* We should get the right reply from the server. */
  381. CONTAINS("\xec\x80\xed\x6e\x54\x6d\x3b\x36\xfd\xfc\x22\xfe\x13\x15\x41\x6b"
  382. "\x02\x9f\x1a\xde\x76\x10\xd9\x10\x87\x8b\x62\xee\xb7\x40\x38\x21"
  383. "te road There is always another ", 64);
  384. /* Send the wrong response. */
  385. WRITE("not with a bang but a whimper...", 32);
  386. MOCK(control_event_bootstrap_problem, ignore_bootstrap_problem);
  387. tt_int_op(-1, ==, connection_ext_or_process_inbuf(conn));
  388. CONTAINS("\x00", 1);
  389. tt_assert(TO_CONN(conn)->marked_for_close);
  390. /* XXXX Hold-open-until-flushed. */
  391. close_closeable_connections();
  392. conn = NULL;
  393. UNMOCK(control_event_bootstrap_problem);
  394. MOCK(connection_start_reading, note_read_started);
  395. MOCK(connection_stop_reading, note_read_stopped);
  396. MOCK(connection_tls_start_handshake, handshake_start);
  397. /* Okay, this time let's succeed. */
  398. conn = or_connection_new(CONN_TYPE_EXT_OR, AF_INET);
  399. tt_int_op(0, ==, connection_ext_or_start_auth(conn));
  400. CONTAINS("\x01\x00", 2);
  401. WRITE("\x01", 1);
  402. WRITE("But when I look ahead up the whi", 32);
  403. MOCK(crypto_rand, crypto_rand_return_tse_str);
  404. tt_int_op(0, ==, connection_ext_or_process_inbuf(conn));
  405. UNMOCK(crypto_rand);
  406. tt_int_op(TO_CONN(conn)->state, ==, EXT_OR_CONN_STATE_AUTH_WAIT_CLIENT_HASH);
  407. CONTAINS("\xec\x80\xed\x6e\x54\x6d\x3b\x36\xfd\xfc\x22\xfe\x13\x15\x41\x6b"
  408. "\x02\x9f\x1a\xde\x76\x10\xd9\x10\x87\x8b\x62\xee\xb7\x40\x38\x21"
  409. "te road There is always another ", 64);
  410. /* Send the right response this time. */
  411. WRITE("\xab\x39\x17\x32\xdd\x2e\xd9\x68\xcd\x40\xc0\x87\xd1\xb1\xf2\x5b"
  412. "\x33\xb3\xcd\x77\xff\x79\xbd\x80\xc2\x07\x4b\xbf\x43\x81\x19\xa2",
  413. 32);
  414. tt_int_op(0, ==, connection_ext_or_process_inbuf(conn));
  415. CONTAINS("\x01", 1);
  416. tt_assert(! TO_CONN(conn)->marked_for_close);
  417. tt_int_op(TO_CONN(conn)->state, ==, EXT_OR_CONN_STATE_OPEN);
  418. /* Now let's run through some messages. */
  419. /* First let's send some junk and make sure it's ignored. */
  420. WRITE("\xff\xf0\x00\x03""ABC", 7);
  421. tt_int_op(0, ==, connection_ext_or_process_inbuf(conn));
  422. CONTAINS("", 0);
  423. /* Now let's send a USERADDR command. */
  424. WRITE("\x00\x01\x00\x0c""1.2.3.4:5678", 16);
  425. tt_int_op(0, ==, connection_ext_or_process_inbuf(conn));
  426. tt_int_op(TO_CONN(conn)->port, ==, 5678);
  427. tt_int_op(tor_addr_to_ipv4h(&TO_CONN(conn)->addr), ==, 0x01020304);
  428. /* Now let's send a TRANSPORT command. */
  429. WRITE("\x00\x02\x00\x07""rfc1149", 11);
  430. tt_int_op(0, ==, connection_ext_or_process_inbuf(conn));
  431. tt_ptr_op(NULL, !=, conn->ext_or_transport);
  432. tt_str_op("rfc1149", ==, conn->ext_or_transport);
  433. tt_int_op(is_reading,==,1);
  434. tt_int_op(TO_CONN(conn)->state, ==, EXT_OR_CONN_STATE_OPEN);
  435. /* DONE */
  436. WRITE("\x00\x00\x00\x00", 4);
  437. tt_int_op(0, ==, connection_ext_or_process_inbuf(conn));
  438. tt_int_op(TO_CONN(conn)->state, ==, EXT_OR_CONN_STATE_FLUSHING);
  439. tt_int_op(is_reading,==,0);
  440. CONTAINS("\x10\x00\x00\x00", 4);
  441. tt_int_op(handshake_start_called,==,0);
  442. tt_int_op(0, ==, connection_ext_or_finished_flushing(conn));
  443. tt_int_op(is_reading,==,1);
  444. tt_int_op(handshake_start_called,==,1);
  445. tt_int_op(TO_CONN(conn)->type, ==, CONN_TYPE_OR);
  446. /* XXXXX the state is now nonsensical! It should be set to something
  447. * neutral (zero?) before we connection_or_change_state; right now
  448. * it's EXT_OR_CONN_STATE_FLUSHING */
  449. /* tt_int_op(TO_CONN(conn)->state, ==, 0); XXXX */
  450. done:
  451. UNMOCK(connection_write_to_buf_impl_);
  452. UNMOCK(crypto_rand);
  453. if (conn)
  454. connection_free_(TO_CONN(conn));
  455. #undef WRITE
  456. }
  457. struct testcase_t extorport_tests[] = {
  458. { "id_map", test_ext_or_id_map, TT_FORK, NULL, NULL },
  459. { "write_command", test_ext_or_write_command, TT_FORK, NULL, NULL },
  460. { "init_auth", test_ext_or_init_auth, TT_FORK, NULL, NULL },
  461. { "cookie_auth", test_ext_or_cookie_auth, TT_FORK, NULL, NULL },
  462. { "cookie_auth_testvec", test_ext_or_cookie_auth_testvec, TT_FORK,
  463. NULL, NULL },
  464. { "handshake", test_ext_or_handshake, TT_FORK, NULL, NULL },
  465. END_OF_TESTCASES
  466. };