test_socks.c 17 KB

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