socks_request_st.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* Copyright (c) 2001 Matej Pfajfar.
  2. * Copyright (c) 2001-2004, Roger Dingledine.
  3. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  4. * Copyright (c) 2007-2018, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. #ifndef SOCKS_REQUEST_ST_H
  7. #define SOCKS_REQUEST_ST_H
  8. #define MAX_SOCKS_REPLY_LEN 1024
  9. #define SOCKS_NO_AUTH 0x00
  10. #define SOCKS_USER_PASS 0x02
  11. /** Please open a TCP connection to this addr:port. */
  12. #define SOCKS_COMMAND_CONNECT 0x01
  13. /** Please turn this FQDN into an IP address, privately. */
  14. #define SOCKS_COMMAND_RESOLVE 0xF0
  15. /** Please turn this IP address into an FQDN, privately. */
  16. #define SOCKS_COMMAND_RESOLVE_PTR 0xF1
  17. /* || 0 is for -Wparentheses-equality (-Wall?) appeasement under clang */
  18. #define SOCKS_COMMAND_IS_CONNECT(c) (((c)==SOCKS_COMMAND_CONNECT) || 0)
  19. #define SOCKS_COMMAND_IS_RESOLVE(c) ((c)==SOCKS_COMMAND_RESOLVE || \
  20. (c)==SOCKS_COMMAND_RESOLVE_PTR)
  21. /** State of a SOCKS request from a user to an OP. Also used to encode other
  22. * information for non-socks user request (such as those on TransPort and
  23. * DNSPort) */
  24. struct socks_request_t {
  25. /** Which version of SOCKS did the client use? One of "0, 4, 5" -- where
  26. * 0 means that no socks handshake ever took place, and this is just a
  27. * stub connection (e.g. see connection_ap_make_link()). */
  28. uint8_t socks_version;
  29. /** If using socks5 authentication, which authentication type did we
  30. * negotiate? currently we support 0 (no authentication) and 2
  31. * (username/password). */
  32. uint8_t auth_type;
  33. /** What is this stream's goal? One of the SOCKS_COMMAND_* values */
  34. uint8_t command;
  35. /** Which kind of listener created this stream? */
  36. uint8_t listener_type;
  37. size_t replylen; /**< Length of <b>reply</b>. */
  38. uint8_t reply[MAX_SOCKS_REPLY_LEN]; /**< Write an entry into this string if
  39. * we want to specify our own socks reply,
  40. * rather than using the default socks4 or
  41. * socks5 socks reply. We use this for the
  42. * two-stage socks5 handshake.
  43. */
  44. char address[MAX_SOCKS_ADDR_LEN]; /**< What address did the client ask to
  45. connect to/resolve? */
  46. uint16_t port; /**< What port did the client ask to connect to? */
  47. unsigned int has_finished : 1; /**< Has the SOCKS handshake finished? Used to
  48. * make sure we send back a socks reply for
  49. * every connection. */
  50. unsigned int got_auth : 1; /**< Have we received any authentication data? */
  51. /** If this is set, we will choose "no authentication" instead of
  52. * "username/password" authentication if both are offered. Used as input to
  53. * parse_socks. */
  54. unsigned int socks_prefer_no_auth : 1;
  55. /** Number of bytes in username; 0 if username is NULL */
  56. size_t usernamelen;
  57. /** Number of bytes in password; 0 if password is NULL */
  58. uint8_t passwordlen;
  59. /** The negotiated username value if any (for socks5), or the entire
  60. * authentication string (for socks4). This value is NOT nul-terminated;
  61. * see usernamelen for its length. */
  62. char *username;
  63. /** The negotiated password value if any (for socks5). This value is NOT
  64. * nul-terminated; see passwordlen for its length. */
  65. char *password;
  66. uint8_t socks5_atyp; /* SOCKS5 address type */
  67. };
  68. #endif