test_extorport.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  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. ext_or_auth_cookie = tor_malloc_zero(32);
  146. test_assert(tor_mem_is_zero((char*)ext_or_auth_cookie, 32));
  147. /* Now make sure we use a temporary file */
  148. fn = get_fname("ext_cookie_file");
  149. options->ExtORPortCookieAuthFile = tor_strdup(fn);
  150. cp = get_ext_or_auth_cookie_file_name();
  151. tt_str_op(cp, ==, fn);
  152. tor_free(cp);
  153. tt_int_op(0, ==, init_ext_or_cookie_authentication(1));
  154. tt_int_op(ext_or_auth_cookie_is_set, ==, 1);
  155. cp = read_file_to_str(fn, RFTS_BIN, &st);
  156. tt_ptr_op(cp, !=, NULL);
  157. tt_int_op(st.st_size, ==, 64);
  158. test_memeq(cp, "! Extended ORPort Auth Cookie !\x0a", 32);
  159. test_memeq(cp+32, ext_or_auth_cookie, 32);
  160. memcpy(cookie0, ext_or_auth_cookie, 32);
  161. test_assert(!tor_mem_is_zero((char*)ext_or_auth_cookie, 32));
  162. /* Operation should be idempotent. */
  163. tt_int_op(0, ==, init_ext_or_cookie_authentication(1));
  164. test_memeq(cookie0, ext_or_auth_cookie, 32);
  165. done:
  166. tor_free(cp);
  167. }
  168. static void
  169. test_ext_or_cookie_auth(void *arg)
  170. {
  171. char *reply=NULL, *reply2=NULL, *client_hash=NULL, *client_hash2=NULL;
  172. size_t reply_len=0;
  173. char hmac1[32], hmac2[32];
  174. const char client_nonce[32] =
  175. "Who is the third who walks alway";
  176. char server_hash_input[] =
  177. "ExtORPort authentication server-to-client hash"
  178. "Who is the third who walks alway"
  179. "................................";
  180. char client_hash_input[] =
  181. "ExtORPort authentication client-to-server hash"
  182. "Who is the third who walks alway"
  183. "................................";
  184. (void)arg;
  185. tt_int_op(strlen(client_hash_input), ==, 46+32+32);
  186. tt_int_op(strlen(server_hash_input), ==, 46+32+32);
  187. ext_or_auth_cookie = tor_malloc_zero(32);
  188. memcpy(ext_or_auth_cookie, "s beside you? When I count, ther", 32);
  189. ext_or_auth_cookie_is_set = 1;
  190. /* For this authentication, the client sends 32 random bytes (ClientNonce)
  191. * The server replies with 32 byte ServerHash and 32 byte ServerNonce,
  192. * where ServerHash is:
  193. * HMAC-SHA256(CookieString,
  194. * "ExtORPort authentication server-to-client hash" | ClientNonce |
  195. * ServerNonce)"
  196. * The client must reply with 32-byte ClientHash, which we compute as:
  197. * ClientHash is computed as:
  198. * HMAC-SHA256(CookieString,
  199. * "ExtORPort authentication client-to-server hash" | ClientNonce |
  200. * ServerNonce)
  201. */
  202. /* Wrong length */
  203. tt_int_op(-1, ==,
  204. handle_client_auth_nonce(client_nonce, 33, &client_hash, &reply,
  205. &reply_len));
  206. tt_int_op(-1, ==,
  207. handle_client_auth_nonce(client_nonce, 31, &client_hash, &reply,
  208. &reply_len));
  209. /* Now let's try this for real! */
  210. tt_int_op(0, ==,
  211. handle_client_auth_nonce(client_nonce, 32, &client_hash, &reply,
  212. &reply_len));
  213. tt_int_op(reply_len, ==, 64);
  214. tt_ptr_op(reply, !=, NULL);
  215. tt_ptr_op(client_hash, !=, NULL);
  216. /* Fill in the server nonce into the hash inputs... */
  217. memcpy(server_hash_input+46+32, reply+32, 32);
  218. memcpy(client_hash_input+46+32, reply+32, 32);
  219. /* Check the HMACs are correct... */
  220. crypto_hmac_sha256(hmac1, (char*)ext_or_auth_cookie, 32, server_hash_input,
  221. 46+32+32);
  222. crypto_hmac_sha256(hmac2, (char*)ext_or_auth_cookie, 32, client_hash_input,
  223. 46+32+32);
  224. test_memeq(hmac1, reply, 32);
  225. test_memeq(hmac2, client_hash, 32);
  226. /* Now do it again and make sure that the results are *different* */
  227. tt_int_op(0, ==,
  228. handle_client_auth_nonce(client_nonce, 32, &client_hash2, &reply2,
  229. &reply_len));
  230. test_memneq(reply2, reply, reply_len);
  231. test_memneq(client_hash2, client_hash, 32);
  232. /* But that this one checks out too. */
  233. memcpy(server_hash_input+46+32, reply2+32, 32);
  234. memcpy(client_hash_input+46+32, reply2+32, 32);
  235. /* Check the HMACs are correct... */
  236. crypto_hmac_sha256(hmac1, (char*)ext_or_auth_cookie, 32, server_hash_input,
  237. 46+32+32);
  238. crypto_hmac_sha256(hmac2, (char*)ext_or_auth_cookie, 32, client_hash_input,
  239. 46+32+32);
  240. test_memeq(hmac1, reply2, 32);
  241. test_memeq(hmac2, client_hash2, 32);
  242. done:
  243. tor_free(reply);
  244. tor_free(client_hash);
  245. tor_free(reply2);
  246. tor_free(client_hash2);
  247. }
  248. static int
  249. crypto_rand_return_tse_str(char *to, size_t n)
  250. {
  251. if (n != 32) {
  252. TT_FAIL(("Asked for %d bytes, not 32", (int)n));
  253. return -1;
  254. }
  255. memcpy(to, "te road There is always another ", 32);
  256. return 0;
  257. }
  258. static void
  259. test_ext_or_cookie_auth_testvec(void *arg)
  260. {
  261. char *reply=NULL, *client_hash=NULL;
  262. size_t reply_len;
  263. char *mem_op_hex_tmp=NULL;
  264. const char client_nonce[] = "But when I look ahead up the whi";
  265. (void)arg;
  266. ext_or_auth_cookie = tor_malloc_zero(32);
  267. memcpy(ext_or_auth_cookie, "Gliding wrapt in a brown mantle," , 32);
  268. ext_or_auth_cookie_is_set = 1;
  269. MOCK(crypto_rand, crypto_rand_return_tse_str);
  270. tt_int_op(0, ==,
  271. handle_client_auth_nonce(client_nonce, 32, &client_hash, &reply,
  272. &reply_len));
  273. tt_ptr_op(reply, !=, NULL );
  274. tt_ptr_op(reply_len, ==, 64);
  275. test_memeq(reply+32, "te road There is always another ", 32);
  276. /* HMACSHA256("Gliding wrapt in a brown mantle,"
  277. * "ExtORPort authentication server-to-client hash"
  278. * "But when I look ahead up the write road There is always another ");
  279. */
  280. test_memeq_hex(reply,
  281. "ec80ed6e546d3b36fdfc22fe1315416b"
  282. "029f1ade7610d910878b62eeb7403821");
  283. /* HMACSHA256("Gliding wrapt in a brown mantle,"
  284. * "ExtORPort authentication client-to-server hash"
  285. * "But when I look ahead up the write road There is always another ");
  286. * (Both values computed using Python CLI.)
  287. */
  288. test_memeq_hex(client_hash,
  289. "ab391732dd2ed968cd40c087d1b1f25b"
  290. "33b3cd77ff79bd80c2074bbf438119a2");
  291. done:
  292. UNMOCK(crypto_rand);
  293. tor_free(reply);
  294. tor_free(client_hash);
  295. tor_free(mem_op_hex_tmp);
  296. }
  297. static void
  298. ignore_bootstrap_problem(const char *warn, int reason)
  299. {
  300. (void)warn;
  301. (void)reason;
  302. }
  303. static int is_reading = 1;
  304. static int handshake_start_called = 0;
  305. static void
  306. note_read_stopped(connection_t *conn)
  307. {
  308. (void)conn;
  309. is_reading=0;
  310. }
  311. static void
  312. note_read_started(connection_t *conn)
  313. {
  314. (void)conn;
  315. is_reading=1;
  316. }
  317. static int
  318. handshake_start(or_connection_t *conn, int receiving)
  319. {
  320. if (!conn || !receiving)
  321. TT_FAIL(("Bad arguments to handshake_start"));
  322. handshake_start_called = 1;
  323. return 0;
  324. }
  325. static void
  326. test_ext_or_handshake(void *arg)
  327. {
  328. or_connection_t *conn=NULL;
  329. char b[256];
  330. #define WRITE(s,n) \
  331. do { \
  332. write_to_buf((s), (n), TO_CONN(conn)->inbuf); \
  333. } while (0)
  334. #define CONTAINS(s,n) \
  335. do { \
  336. tt_int_op((n), <=, sizeof(b)); \
  337. tt_int_op(buf_datalen(TO_CONN(conn)->outbuf), ==, (n)); \
  338. if ((n)) { \
  339. fetch_from_buf(b, (n), TO_CONN(conn)->outbuf); \
  340. test_memeq(b, (s), (n)); \
  341. } \
  342. } while (0)
  343. (void) arg;
  344. MOCK(connection_write_to_buf_impl_,
  345. connection_write_to_buf_impl_replacement);
  346. /* Use same authenticators as for test_ext_or_cookie_auth_testvec */
  347. ext_or_auth_cookie = tor_malloc_zero(32);
  348. memcpy(ext_or_auth_cookie, "Gliding wrapt in a brown mantle," , 32);
  349. ext_or_auth_cookie_is_set = 1;
  350. init_connection_lists();
  351. conn = or_connection_new(CONN_TYPE_EXT_OR, AF_INET);
  352. tt_int_op(0, ==, connection_ext_or_start_auth(conn));
  353. /* The server starts by telling us about the one supported authtype. */
  354. CONTAINS("\x01\x00", 2);
  355. /* Say the client hasn't responded yet. */
  356. tt_int_op(0, ==, connection_ext_or_process_inbuf(conn));
  357. /* Let's say the client replies badly. */
  358. WRITE("\x99", 1);
  359. tt_int_op(-1, ==, connection_ext_or_process_inbuf(conn));
  360. CONTAINS("", 0);
  361. tt_assert(TO_CONN(conn)->marked_for_close);
  362. close_closeable_connections();
  363. conn = NULL;
  364. /* Okay, try again. */
  365. conn = or_connection_new(CONN_TYPE_EXT_OR, AF_INET);
  366. tt_int_op(0, ==, connection_ext_or_start_auth(conn));
  367. CONTAINS("\x01\x00", 2);
  368. /* Let's say the client replies sensibly this time. "Yes, AUTHTYPE_COOKIE
  369. * sounds delicious. Let's have some of that!" */
  370. WRITE("\x01", 1);
  371. /* Let's say that the client also sends part of a nonce. */
  372. WRITE("But when I look ", 16);
  373. tt_int_op(0, ==, connection_ext_or_process_inbuf(conn));
  374. CONTAINS("", 0);
  375. tt_int_op(TO_CONN(conn)->state, ==,
  376. EXT_OR_CONN_STATE_AUTH_WAIT_CLIENT_NONCE);
  377. /* Pump it again. Nothing should happen. */
  378. tt_int_op(0, ==, connection_ext_or_process_inbuf(conn));
  379. /* send the rest of the nonce. */
  380. WRITE("ahead up the whi", 16);
  381. MOCK(crypto_rand, crypto_rand_return_tse_str);
  382. tt_int_op(0, ==, connection_ext_or_process_inbuf(conn));
  383. UNMOCK(crypto_rand);
  384. /* We should get the right reply from the server. */
  385. CONTAINS("\xec\x80\xed\x6e\x54\x6d\x3b\x36\xfd\xfc\x22\xfe\x13\x15\x41\x6b"
  386. "\x02\x9f\x1a\xde\x76\x10\xd9\x10\x87\x8b\x62\xee\xb7\x40\x38\x21"
  387. "te road There is always another ", 64);
  388. /* Send the wrong response. */
  389. WRITE("not with a bang but a whimper...", 32);
  390. MOCK(control_event_bootstrap_problem, ignore_bootstrap_problem);
  391. tt_int_op(-1, ==, connection_ext_or_process_inbuf(conn));
  392. CONTAINS("\x00", 1);
  393. tt_assert(TO_CONN(conn)->marked_for_close);
  394. /* XXXX Hold-open-until-flushed. */
  395. close_closeable_connections();
  396. conn = NULL;
  397. UNMOCK(control_event_bootstrap_problem);
  398. MOCK(connection_start_reading, note_read_started);
  399. MOCK(connection_stop_reading, note_read_stopped);
  400. MOCK(connection_tls_start_handshake, handshake_start);
  401. /* Okay, this time let's succeed. */
  402. conn = or_connection_new(CONN_TYPE_EXT_OR, AF_INET);
  403. tt_int_op(0, ==, connection_ext_or_start_auth(conn));
  404. CONTAINS("\x01\x00", 2);
  405. WRITE("\x01", 1);
  406. WRITE("But when I look ahead up the whi", 32);
  407. MOCK(crypto_rand, crypto_rand_return_tse_str);
  408. tt_int_op(0, ==, connection_ext_or_process_inbuf(conn));
  409. UNMOCK(crypto_rand);
  410. tt_int_op(TO_CONN(conn)->state, ==, EXT_OR_CONN_STATE_AUTH_WAIT_CLIENT_HASH);
  411. CONTAINS("\xec\x80\xed\x6e\x54\x6d\x3b\x36\xfd\xfc\x22\xfe\x13\x15\x41\x6b"
  412. "\x02\x9f\x1a\xde\x76\x10\xd9\x10\x87\x8b\x62\xee\xb7\x40\x38\x21"
  413. "te road There is always another ", 64);
  414. /* Send the right response this time. */
  415. WRITE("\xab\x39\x17\x32\xdd\x2e\xd9\x68\xcd\x40\xc0\x87\xd1\xb1\xf2\x5b"
  416. "\x33\xb3\xcd\x77\xff\x79\xbd\x80\xc2\x07\x4b\xbf\x43\x81\x19\xa2",
  417. 32);
  418. tt_int_op(0, ==, connection_ext_or_process_inbuf(conn));
  419. CONTAINS("\x01", 1);
  420. tt_assert(! TO_CONN(conn)->marked_for_close);
  421. tt_int_op(TO_CONN(conn)->state, ==, EXT_OR_CONN_STATE_OPEN);
  422. /* Now let's run through some messages. */
  423. /* First let's send some junk and make sure it's ignored. */
  424. WRITE("\xff\xf0\x00\x03""ABC", 7);
  425. tt_int_op(0, ==, connection_ext_or_process_inbuf(conn));
  426. CONTAINS("", 0);
  427. /* Now let's send a USERADDR command. */
  428. WRITE("\x00\x01\x00\x0c""1.2.3.4:5678", 16);
  429. tt_int_op(0, ==, connection_ext_or_process_inbuf(conn));
  430. tt_int_op(TO_CONN(conn)->port, ==, 5678);
  431. tt_int_op(tor_addr_to_ipv4h(&TO_CONN(conn)->addr), ==, 0x01020304);
  432. /* Now let's send a TRANSPORT command. */
  433. WRITE("\x00\x02\x00\x07""rfc1149", 11);
  434. tt_int_op(0, ==, connection_ext_or_process_inbuf(conn));
  435. tt_ptr_op(NULL, !=, conn->ext_or_transport);
  436. tt_str_op("rfc1149", ==, conn->ext_or_transport);
  437. tt_int_op(is_reading,==,1);
  438. tt_int_op(TO_CONN(conn)->state, ==, EXT_OR_CONN_STATE_OPEN);
  439. /* DONE */
  440. WRITE("\x00\x00\x00\x00", 4);
  441. tt_int_op(0, ==, connection_ext_or_process_inbuf(conn));
  442. tt_int_op(TO_CONN(conn)->state, ==, EXT_OR_CONN_STATE_FLUSHING);
  443. tt_int_op(is_reading,==,0);
  444. CONTAINS("\x10\x00\x00\x00", 4);
  445. tt_int_op(handshake_start_called,==,0);
  446. tt_int_op(0, ==, connection_ext_or_finished_flushing(conn));
  447. tt_int_op(is_reading,==,1);
  448. tt_int_op(handshake_start_called,==,1);
  449. tt_int_op(TO_CONN(conn)->type, ==, CONN_TYPE_OR);
  450. tt_int_op(TO_CONN(conn)->state, ==, 0);
  451. done:
  452. UNMOCK(connection_write_to_buf_impl_);
  453. UNMOCK(crypto_rand);
  454. if (conn)
  455. connection_free_(TO_CONN(conn));
  456. #undef WRITE
  457. }
  458. struct testcase_t extorport_tests[] = {
  459. { "id_map", test_ext_or_id_map, TT_FORK, NULL, NULL },
  460. { "write_command", test_ext_or_write_command, TT_FORK, NULL, NULL },
  461. { "init_auth", test_ext_or_init_auth, TT_FORK, NULL, NULL },
  462. { "cookie_auth", test_ext_or_cookie_auth, TT_FORK, NULL, NULL },
  463. { "cookie_auth_testvec", test_ext_or_cookie_auth_testvec, TT_FORK,
  464. NULL, NULL },
  465. { "handshake", test_ext_or_handshake, TT_FORK, NULL, NULL },
  466. END_OF_TESTCASES
  467. };