test_socks.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. /* Copyright (c) 2001-2004, Roger Dingledine.
  2. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  3. * Copyright (c) 2007-2017, The Tor Project, Inc. */
  4. /* See LICENSE for licensing information */
  5. #include "or.h"
  6. #include "buffers.h"
  7. #include "config.h"
  8. #include "proto_socks.h"
  9. #include "test.h"
  10. typedef struct socks_test_data_t {
  11. socks_request_t *req;
  12. buf_t *buf;
  13. } socks_test_data_t;
  14. static void *
  15. socks_test_setup(const struct testcase_t *testcase)
  16. {
  17. socks_test_data_t *data = tor_malloc(sizeof(socks_test_data_t));
  18. (void)testcase;
  19. data->buf = buf_new_with_capacity(256);
  20. data->req = socks_request_new();
  21. config_register_addressmaps(get_options());
  22. return data;
  23. }
  24. static int
  25. socks_test_cleanup(const struct testcase_t *testcase, void *ptr)
  26. {
  27. socks_test_data_t *data = ptr;
  28. (void)testcase;
  29. buf_free(data->buf);
  30. socks_request_free(data->req);
  31. tor_free(data);
  32. return 1;
  33. }
  34. static const struct testcase_setup_t socks_setup = {
  35. socks_test_setup, socks_test_cleanup
  36. };
  37. #define SOCKS_TEST_INIT() \
  38. socks_test_data_t *testdata = ptr; \
  39. buf_t *buf = testdata->buf; \
  40. socks_request_t *socks = testdata->req;
  41. #define ADD_DATA(buf, s) \
  42. buf_add(buf, s, sizeof(s)-1)
  43. static void
  44. socks_request_clear(socks_request_t *socks)
  45. {
  46. tor_free(socks->username);
  47. tor_free(socks->password);
  48. memset(socks, 0, sizeof(socks_request_t));
  49. }
  50. /** Perform unsupported SOCKS 4 commands */
  51. static void
  52. test_socks_4_unsupported_commands(void *ptr)
  53. {
  54. SOCKS_TEST_INIT();
  55. /* SOCKS 4 Send BIND [02] to IP address 2.2.2.2:4369 */
  56. ADD_DATA(buf, "\x04\x02\x11\x11\x02\x02\x02\x02\x00");
  57. tt_int_op(fetch_from_buf_socks(buf, socks, get_options()->TestSocks,
  58. get_options()->SafeSocks),
  59. OP_EQ, -1);
  60. tt_int_op(4,OP_EQ, socks->socks_version);
  61. tt_int_op(0,OP_EQ, socks->replylen); /* XXX: shouldn't tor reply? */
  62. done:
  63. ;
  64. }
  65. /** Perform supported SOCKS 4 commands */
  66. static void
  67. test_socks_4_supported_commands(void *ptr)
  68. {
  69. SOCKS_TEST_INIT();
  70. tt_int_op(0,OP_EQ, buf_datalen(buf));
  71. /* SOCKS 4 Send CONNECT [01] to IP address 2.2.2.2:4370 */
  72. ADD_DATA(buf, "\x04\x01\x11\x12\x02\x02\x02\x03\x00");
  73. tt_int_op(fetch_from_buf_socks(buf, socks, get_options()->TestSocks,
  74. get_options()->SafeSocks),
  75. OP_EQ, 1);
  76. tt_int_op(4,OP_EQ, socks->socks_version);
  77. tt_int_op(0,OP_EQ, socks->replylen); /* XXX: shouldn't tor reply? */
  78. tt_int_op(SOCKS_COMMAND_CONNECT,OP_EQ, socks->command);
  79. tt_str_op("2.2.2.3",OP_EQ, socks->address);
  80. tt_int_op(4370,OP_EQ, socks->port);
  81. tt_assert(socks->got_auth == 0);
  82. tt_assert(! socks->username);
  83. tt_int_op(0,OP_EQ, buf_datalen(buf));
  84. socks_request_clear(socks);
  85. /* SOCKS 4 Send CONNECT [01] to IP address 2.2.2.2:4369 with userid*/
  86. ADD_DATA(buf, "\x04\x01\x11\x12\x02\x02\x02\x04me\x00");
  87. tt_int_op(fetch_from_buf_socks(buf, socks, get_options()->TestSocks,
  88. get_options()->SafeSocks),
  89. OP_EQ, 1);
  90. tt_int_op(4,OP_EQ, socks->socks_version);
  91. tt_int_op(0,OP_EQ, socks->replylen); /* XXX: shouldn't tor reply? */
  92. tt_int_op(SOCKS_COMMAND_CONNECT,OP_EQ, socks->command);
  93. tt_str_op("2.2.2.4",OP_EQ, socks->address);
  94. tt_int_op(4370,OP_EQ, socks->port);
  95. tt_assert(socks->got_auth == 1);
  96. tt_assert(socks->username);
  97. tt_int_op(2,OP_EQ, socks->usernamelen);
  98. tt_mem_op("me",OP_EQ, socks->username, 2);
  99. tt_int_op(0,OP_EQ, buf_datalen(buf));
  100. socks_request_clear(socks);
  101. /* SOCKS 4a Send RESOLVE [F0] request for torproject.org */
  102. ADD_DATA(buf, "\x04\xF0\x01\x01\x00\x00\x00\x02me\x00torproject.org\x00");
  103. tt_int_op(fetch_from_buf_socks(buf, socks, get_options()->TestSocks,
  104. get_options()->SafeSocks),
  105. OP_EQ, 1);
  106. tt_int_op(4,OP_EQ, socks->socks_version);
  107. tt_int_op(0,OP_EQ, socks->replylen); /* XXX: shouldn't tor reply? */
  108. tt_str_op("torproject.org",OP_EQ, socks->address);
  109. tt_int_op(0,OP_EQ, buf_datalen(buf));
  110. done:
  111. ;
  112. }
  113. /** Perform unsupported SOCKS 5 commands */
  114. static void
  115. test_socks_5_unsupported_commands(void *ptr)
  116. {
  117. SOCKS_TEST_INIT();
  118. /* SOCKS 5 Send unsupported BIND [02] command */
  119. ADD_DATA(buf, "\x05\x02\x00\x01");
  120. tt_int_op(fetch_from_buf_socks(buf, socks, get_options()->TestSocks,
  121. get_options()->SafeSocks),OP_EQ, 0);
  122. tt_int_op(0,OP_EQ, buf_datalen(buf));
  123. tt_int_op(5,OP_EQ, socks->socks_version);
  124. tt_int_op(2,OP_EQ, socks->replylen);
  125. tt_int_op(5,OP_EQ, socks->reply[0]);
  126. tt_int_op(0,OP_EQ, socks->reply[1]);
  127. ADD_DATA(buf, "\x05\x02\x00\x01\x02\x02\x02\x01\x01\x01");
  128. tt_int_op(fetch_from_buf_socks(buf, socks, get_options()->TestSocks,
  129. get_options()->SafeSocks),OP_EQ, -1);
  130. tt_int_op(5,OP_EQ,socks->socks_version);
  131. tt_int_op(10,OP_EQ,socks->replylen);
  132. tt_int_op(5,OP_EQ,socks->reply[0]);
  133. tt_int_op(SOCKS5_COMMAND_NOT_SUPPORTED,OP_EQ,socks->reply[1]);
  134. tt_int_op(1,OP_EQ,socks->reply[3]);
  135. buf_clear(buf);
  136. socks_request_clear(socks);
  137. /* SOCKS 5 Send unsupported UDP_ASSOCIATE [03] command */
  138. ADD_DATA(buf, "\x05\x02\x00\x01");
  139. tt_int_op(fetch_from_buf_socks(buf, socks, get_options()->TestSocks,
  140. get_options()->SafeSocks),OP_EQ, 0);
  141. tt_int_op(5,OP_EQ, socks->socks_version);
  142. tt_int_op(2,OP_EQ, socks->replylen);
  143. tt_int_op(5,OP_EQ, socks->reply[0]);
  144. tt_int_op(0,OP_EQ, socks->reply[1]);
  145. ADD_DATA(buf, "\x05\x03\x00\x01\x02\x02\x02\x01\x01\x01");
  146. tt_int_op(fetch_from_buf_socks(buf, socks, get_options()->TestSocks,
  147. get_options()->SafeSocks),OP_EQ, -1);
  148. tt_int_op(5,OP_EQ,socks->socks_version);
  149. tt_int_op(10,OP_EQ,socks->replylen);
  150. tt_int_op(5,OP_EQ,socks->reply[0]);
  151. tt_int_op(SOCKS5_COMMAND_NOT_SUPPORTED,OP_EQ,socks->reply[1]);
  152. tt_int_op(1,OP_EQ,socks->reply[3]);
  153. done:
  154. ;
  155. }
  156. /** Perform supported SOCKS 5 commands */
  157. static void
  158. test_socks_5_supported_commands(void *ptr)
  159. {
  160. SOCKS_TEST_INIT();
  161. /* SOCKS 5 Send CONNECT [01] to IP address 2.2.2.2:4369 */
  162. ADD_DATA(buf, "\x05\x01\x00");
  163. tt_int_op(fetch_from_buf_socks(buf, socks, get_options()->TestSocks,
  164. get_options()->SafeSocks),OP_EQ, 0);
  165. tt_int_op(5,OP_EQ, socks->socks_version);
  166. tt_int_op(2,OP_EQ, socks->replylen);
  167. tt_int_op(5,OP_EQ, socks->reply[0]);
  168. tt_int_op(0,OP_EQ, socks->reply[1]);
  169. ADD_DATA(buf, "\x05\x01\x00\x01\x02\x02\x02\x02\x11\x11");
  170. tt_int_op(fetch_from_buf_socks(buf, socks, get_options()->TestSocks,
  171. get_options()->SafeSocks),OP_EQ, 1);
  172. tt_str_op("2.2.2.2",OP_EQ, socks->address);
  173. tt_int_op(4369,OP_EQ, socks->port);
  174. tt_int_op(0,OP_EQ, buf_datalen(buf));
  175. socks_request_clear(socks);
  176. /* SOCKS 5 Send CONNECT [01] to FQDN torproject.org:4369 */
  177. ADD_DATA(buf, "\x05\x01\x00");
  178. ADD_DATA(buf, "\x05\x01\x00\x03\x0Etorproject.org\x11\x11");
  179. tt_int_op(fetch_from_buf_socks(buf, socks, get_options()->TestSocks,
  180. get_options()->SafeSocks),OP_EQ, 1);
  181. tt_int_op(5,OP_EQ, socks->socks_version);
  182. tt_int_op(2,OP_EQ, socks->replylen);
  183. tt_int_op(5,OP_EQ, socks->reply[0]);
  184. tt_int_op(0,OP_EQ, socks->reply[1]);
  185. tt_str_op("torproject.org",OP_EQ, socks->address);
  186. tt_int_op(4369,OP_EQ, socks->port);
  187. tt_int_op(0,OP_EQ, buf_datalen(buf));
  188. socks_request_clear(socks);
  189. /* SOCKS 5 Send RESOLVE [F0] request for torproject.org:4369 */
  190. ADD_DATA(buf, "\x05\x01\x00");
  191. ADD_DATA(buf, "\x05\xF0\x00\x03\x0Etorproject.org\x01\x02");
  192. tt_int_op(fetch_from_buf_socks(buf, socks, get_options()->TestSocks,
  193. get_options()->SafeSocks),
  194. OP_EQ, 1);
  195. tt_int_op(5,OP_EQ, socks->socks_version);
  196. tt_int_op(2,OP_EQ, socks->replylen);
  197. tt_int_op(5,OP_EQ, socks->reply[0]);
  198. tt_int_op(0,OP_EQ, socks->reply[1]);
  199. tt_str_op("torproject.org",OP_EQ, socks->address);
  200. tt_int_op(0,OP_EQ, buf_datalen(buf));
  201. socks_request_clear(socks);
  202. /* SOCKS 5 Should NOT reject RESOLVE [F0] request for IPv4 address
  203. * string if SafeSocks is enabled. */
  204. ADD_DATA(buf, "\x05\x01\x00");
  205. ADD_DATA(buf, "\x05\xF0\x00\x03\x07");
  206. ADD_DATA(buf, "8.8.8.8");
  207. ADD_DATA(buf, "\x11\x11");
  208. tt_int_op(fetch_from_buf_socks(buf, socks, get_options()->TestSocks, 1),
  209. OP_EQ, 1);
  210. tt_str_op("8.8.8.8", OP_EQ, socks->address);
  211. tt_int_op(4369, OP_EQ, socks->port);
  212. tt_int_op(0, OP_EQ, buf_datalen(buf));
  213. socks_request_clear(socks);
  214. /* SOCKS 5 should NOT reject RESOLVE [F0] reject for IPv6 address
  215. * string if SafeSocks is enabled. */
  216. ADD_DATA(buf, "\x05\x01\x00");
  217. ADD_DATA(buf, "\x05\xF0\x00\x03\x27");
  218. ADD_DATA(buf, "2001:0db8:85a3:0000:0000:8a2e:0370:7334");
  219. ADD_DATA(buf, "\x01\x02");
  220. tt_int_op(fetch_from_buf_socks(buf, socks, get_options()->TestSocks, 1),
  221. OP_EQ, -1);
  222. tt_str_op("2001:0db8:85a3:0000:0000:8a2e:0370:7334", OP_EQ, socks->address);
  223. tt_int_op(258, OP_EQ, socks->port);
  224. tt_int_op(0, OP_EQ, buf_datalen(buf));
  225. socks_request_clear(socks);
  226. /* SOCKS 5 Send RESOLVE_PTR [F1] for IP address 2.2.2.5 */
  227. ADD_DATA(buf, "\x05\x01\x00");
  228. ADD_DATA(buf, "\x05\xF1\x00\x01\x02\x02\x02\x05\x01\x03");
  229. tt_int_op(fetch_from_buf_socks(buf, socks, get_options()->TestSocks,
  230. get_options()->SafeSocks),
  231. OP_EQ, 1);
  232. tt_int_op(5,OP_EQ, socks->socks_version);
  233. tt_int_op(2,OP_EQ, socks->replylen);
  234. tt_int_op(5,OP_EQ, socks->reply[0]);
  235. tt_int_op(0,OP_EQ, socks->reply[1]);
  236. tt_str_op("2.2.2.5",OP_EQ, socks->address);
  237. tt_int_op(0,OP_EQ, buf_datalen(buf));
  238. done:
  239. ;
  240. }
  241. /** Perform SOCKS 5 authentication */
  242. static void
  243. test_socks_5_no_authenticate(void *ptr)
  244. {
  245. SOCKS_TEST_INIT();
  246. /*SOCKS 5 No Authentication */
  247. ADD_DATA(buf,"\x05\x01\x00");
  248. tt_assert(!fetch_from_buf_socks(buf, socks,
  249. get_options()->TestSocks,
  250. get_options()->SafeSocks));
  251. tt_int_op(2,OP_EQ, socks->replylen);
  252. tt_int_op(5,OP_EQ, socks->reply[0]);
  253. tt_int_op(SOCKS_NO_AUTH,OP_EQ, socks->reply[1]);
  254. tt_int_op(0,OP_EQ, buf_datalen(buf));
  255. /*SOCKS 5 Send username/password anyway - pretend to be broken */
  256. ADD_DATA(buf,"\x01\x02\x01\x01\x02\x01\x01");
  257. tt_assert(!fetch_from_buf_socks(buf, socks,
  258. get_options()->TestSocks,
  259. get_options()->SafeSocks));
  260. tt_int_op(5,OP_EQ, socks->socks_version);
  261. tt_int_op(2,OP_EQ, socks->replylen);
  262. tt_int_op(1,OP_EQ, socks->reply[0]);
  263. tt_int_op(0,OP_EQ, socks->reply[1]);
  264. tt_int_op(2,OP_EQ, socks->usernamelen);
  265. tt_int_op(2,OP_EQ, socks->passwordlen);
  266. tt_mem_op("\x01\x01",OP_EQ, socks->username, 2);
  267. tt_mem_op("\x01\x01",OP_EQ, socks->password, 2);
  268. done:
  269. ;
  270. }
  271. /** Perform SOCKS 5 authentication */
  272. static void
  273. test_socks_5_authenticate(void *ptr)
  274. {
  275. SOCKS_TEST_INIT();
  276. /* SOCKS 5 Negotiate username/password authentication */
  277. ADD_DATA(buf, "\x05\x01\x02");
  278. tt_assert(!fetch_from_buf_socks(buf, socks,
  279. get_options()->TestSocks,
  280. get_options()->SafeSocks));
  281. tt_int_op(2,OP_EQ, socks->replylen);
  282. tt_int_op(5,OP_EQ, socks->reply[0]);
  283. tt_int_op(SOCKS_USER_PASS,OP_EQ, socks->reply[1]);
  284. tt_int_op(5,OP_EQ, socks->socks_version);
  285. tt_int_op(0,OP_EQ, buf_datalen(buf));
  286. /* SOCKS 5 Send username/password */
  287. ADD_DATA(buf, "\x01\x02me\x08mypasswd");
  288. tt_assert(!fetch_from_buf_socks(buf, socks,
  289. get_options()->TestSocks,
  290. get_options()->SafeSocks));
  291. tt_int_op(5,OP_EQ, socks->socks_version);
  292. tt_int_op(2,OP_EQ, socks->replylen);
  293. tt_int_op(1,OP_EQ, socks->reply[0]);
  294. tt_int_op(0,OP_EQ, socks->reply[1]);
  295. tt_int_op(2,OP_EQ, socks->usernamelen);
  296. tt_int_op(8,OP_EQ, socks->passwordlen);
  297. tt_mem_op("me",OP_EQ, socks->username, 2);
  298. tt_mem_op("mypasswd",OP_EQ, socks->password, 8);
  299. done:
  300. ;
  301. }
  302. /** Perform SOCKS 5 authentication and send data all in one go */
  303. static void
  304. test_socks_5_authenticate_with_data(void *ptr)
  305. {
  306. SOCKS_TEST_INIT();
  307. /* SOCKS 5 Negotiate username/password authentication */
  308. ADD_DATA(buf, "\x05\x01\x02");
  309. tt_assert(!fetch_from_buf_socks(buf, socks,
  310. get_options()->TestSocks,
  311. get_options()->SafeSocks));
  312. tt_int_op(2,OP_EQ, socks->replylen);
  313. tt_int_op(5,OP_EQ, socks->reply[0]);
  314. tt_int_op(SOCKS_USER_PASS,OP_EQ, socks->reply[1]);
  315. tt_int_op(5,OP_EQ, socks->socks_version);
  316. tt_int_op(0,OP_EQ, buf_datalen(buf));
  317. /* SOCKS 5 Send username/password */
  318. /* SOCKS 5 Send CONNECT [01] to IP address 2.2.2.2:4369 */
  319. ADD_DATA(buf, "\x01\x02me\x03you\x05\x01\x00\x01\x02\x02\x02\x02\x11\x11");
  320. tt_int_op(fetch_from_buf_socks(buf, socks, get_options()->TestSocks,
  321. get_options()->SafeSocks),
  322. OP_EQ, 1);
  323. tt_int_op(5,OP_EQ, socks->socks_version);
  324. tt_int_op(2,OP_EQ, socks->replylen);
  325. tt_int_op(1,OP_EQ, socks->reply[0]);
  326. tt_int_op(0,OP_EQ, socks->reply[1]);
  327. tt_str_op("2.2.2.2",OP_EQ, socks->address);
  328. tt_int_op(4369,OP_EQ, socks->port);
  329. tt_int_op(2,OP_EQ, socks->usernamelen);
  330. tt_int_op(3,OP_EQ, socks->passwordlen);
  331. tt_mem_op("me",OP_EQ, socks->username, 2);
  332. tt_mem_op("you",OP_EQ, socks->password, 3);
  333. done:
  334. ;
  335. }
  336. /** Perform SOCKS 5 authentication before method negotiated */
  337. static void
  338. test_socks_5_auth_before_negotiation(void *ptr)
  339. {
  340. SOCKS_TEST_INIT();
  341. /* SOCKS 5 Send username/password */
  342. ADD_DATA(buf, "\x01\x02me\x02me");
  343. tt_int_op(fetch_from_buf_socks(buf, socks, get_options()->TestSocks,
  344. get_options()->SafeSocks),
  345. OP_EQ, -1);
  346. tt_int_op(0,OP_EQ, socks->socks_version);
  347. tt_int_op(0,OP_EQ, socks->replylen);
  348. tt_int_op(0,OP_EQ, socks->reply[0]);
  349. tt_int_op(0,OP_EQ, socks->reply[1]);
  350. done:
  351. ;
  352. }
  353. /** Perform malformed SOCKS 5 commands */
  354. static void
  355. test_socks_5_malformed_commands(void *ptr)
  356. {
  357. SOCKS_TEST_INIT();
  358. /* XXX: Stringified address length > MAX_SOCKS_ADDR_LEN will never happen */
  359. /** SOCKS 5 Send CONNECT [01] to IP address 2.2.2.2:4369, with SafeSocks set
  360. */
  361. ADD_DATA(buf, "\x05\x01\x00");
  362. ADD_DATA(buf, "\x05\x01\x00\x01\x02\x02\x02\x02\x11\x11");
  363. tt_int_op(fetch_from_buf_socks(buf, socks, get_options()->TestSocks, 1),
  364. OP_EQ, -1);
  365. tt_int_op(5,OP_EQ,socks->socks_version);
  366. tt_int_op(10,OP_EQ,socks->replylen);
  367. tt_int_op(5,OP_EQ,socks->reply[0]);
  368. tt_int_op(SOCKS5_NOT_ALLOWED,OP_EQ,socks->reply[1]);
  369. tt_int_op(1,OP_EQ,socks->reply[3]);
  370. buf_clear(buf);
  371. socks_request_clear(socks);
  372. /* SOCKS 5 Send RESOLVE_PTR [F1] for FQDN torproject.org */
  373. ADD_DATA(buf, "\x05\x01\x00");
  374. ADD_DATA(buf, "\x05\xF1\x00\x03\x0Etorproject.org\x11\x11");
  375. tt_int_op(fetch_from_buf_socks(buf, socks, get_options()->TestSocks,
  376. get_options()->SafeSocks),OP_EQ, -1);
  377. tt_int_op(5,OP_EQ,socks->socks_version);
  378. tt_int_op(10,OP_EQ,socks->replylen);
  379. tt_int_op(5,OP_EQ,socks->reply[0]);
  380. tt_int_op(SOCKS5_ADDRESS_TYPE_NOT_SUPPORTED,OP_EQ,socks->reply[1]);
  381. tt_int_op(1,OP_EQ,socks->reply[3]);
  382. buf_clear(buf);
  383. socks_request_clear(socks);
  384. /* XXX: len + 1 > MAX_SOCKS_ADDR_LEN (FQDN request) will never happen */
  385. /* SOCKS 5 Send CONNECT [01] to FQDN """"".com */
  386. ADD_DATA(buf, "\x05\x01\x00");
  387. ADD_DATA(buf, "\x05\x01\x00\x03\x09\"\"\"\"\".com\x11\x11");
  388. tt_int_op(fetch_from_buf_socks(buf, socks, get_options()->TestSocks,
  389. get_options()->SafeSocks),OP_EQ, -1);
  390. tt_int_op(5,OP_EQ,socks->socks_version);
  391. tt_int_op(10,OP_EQ,socks->replylen);
  392. tt_int_op(5,OP_EQ,socks->reply[0]);
  393. tt_int_op(SOCKS5_GENERAL_ERROR,OP_EQ,socks->reply[1]);
  394. tt_int_op(1,OP_EQ,socks->reply[3]);
  395. buf_clear(buf);
  396. socks_request_clear(socks);
  397. /* SOCKS 5 Send CONNECT [01] to address type 0x23 */
  398. ADD_DATA(buf, "\x05\x01\x00");
  399. ADD_DATA(buf, "\x05\x01\x00\x23\x02\x02\x02\x02\x11\x11");
  400. tt_int_op(fetch_from_buf_socks(buf, socks, get_options()->TestSocks,
  401. get_options()->SafeSocks),OP_EQ, -1);
  402. tt_int_op(5,OP_EQ,socks->socks_version);
  403. tt_int_op(10,OP_EQ,socks->replylen);
  404. tt_int_op(5,OP_EQ,socks->reply[0]);
  405. tt_int_op(SOCKS5_ADDRESS_TYPE_NOT_SUPPORTED,OP_EQ,socks->reply[1]);
  406. tt_int_op(1,OP_EQ,socks->reply[3]);
  407. done:
  408. ;
  409. }
  410. #define SOCKSENT(name) \
  411. { #name, test_socks_##name, TT_FORK, &socks_setup, NULL }
  412. struct testcase_t socks_tests[] = {
  413. SOCKSENT(4_unsupported_commands),
  414. SOCKSENT(4_supported_commands),
  415. SOCKSENT(5_unsupported_commands),
  416. SOCKSENT(5_supported_commands),
  417. SOCKSENT(5_no_authenticate),
  418. SOCKSENT(5_auth_before_negotiation),
  419. SOCKSENT(5_authenticate),
  420. SOCKSENT(5_authenticate_with_data),
  421. SOCKSENT(5_malformed_commands),
  422. END_OF_TESTCASES
  423. };