NetBurner 3.5.6
PDF Version
Socks.h
1/*NB_REVISION*/
2
3/*NB_COPYRIGHT*/
4
16#ifndef _NB_SOCKS_H_
17#define _NB_SOCKS_H_
18
19#include <predef.h>
20#include <tcp.h>
21#include <nbstring.h>
22
23struct socket_struct;
24typedef socket_struct SOCKET;
25typedef SOCKET *PSOCKET;
26
33#define SOCKS_SUCCESS (0)
34#define SOCKS_ERR_TIMEOUT (-500)
35#define SOCKS_BAD_ADR_TYPE (-501)
36#define SOCKS_CONN_ABORTED (-502)
37#define SOCKS_BAD_AUTH_TYPE (-503)
38#define SOCKS_BAD_UN_PW (-504)
39#define SOCKS_UN_TOO_LONG (-505)
40#define SOCKS_PW_TOO_LONG (-506)
41#define SOCKS_BAD_REPLY (-507)
42#define SOCKS_BAD_DOMAIN (-508)
43#define SOCKS_CMD_NOT_SUPPORTED (-509)
44#define SOCKS_BAD_PARAM (-510)
47#define SOCKS_TIMEOUT (10 * TICKS_PER_SECOND)
48#define SOCKS_MAX_UNAME_SIZE 255
49#define SOCKS_MAX_PASSWD_SIZE 255
50
55enum SocksAuthType : unsigned char
56{
60};
61
62
72
76enum SocksAdrType : unsigned char
77{
81 eSocksAdrTypeIpv6 = 0x04
82};
83
84
85// Currently not used in code, but defined for future use if needed. Correspond to values returned in
86// SOCKS responses per RFC 1928.
87enum SocksReply : unsigned char
88{
89 eSocksReplySuc = 0,
90 eSocksReplyGeneral = 1,
91 eSocksReplyRuleset = 2,
92 eSocksReplyNetwork = 3,
93 eSocksReplyHost = 4,
94 eSocksReplyConRef = 5,
95 eSocksReplyTtlExp = 6,
96 eSocksReplyCmdNotSup = 7,
97 eSocksReplyAdrNotSup = 8,
98};
99
100class SocksProxy
101{
102 public:
103 SocksProxy(){};
104 SocksProxy( const NBString& adr, uint16_t port, SocksAdrType adrType, SocksAuthType authType, SocksClientCmd cmd, const char* username, const char* password, bool enable );
105 SocksProxy( const NBString& adr, uint16_t port, SocksAdrType adrType, SocksAuthType authType, SocksClientCmd cmd, bool enable );
106
107 void SetUsername( const NBString& username ){ m_username = username; }
108 void SetPassword( const NBString& password ){ m_password = password; }
109 void SetPort( uint16_t port ){ m_port = port; }
110 void SetAddressType( SocksAdrType adrType ){ m_adrType = adrType; }
111 void SetAddress( const NBString& adr ){ m_adr = adr; }
112 void SetAuthType( SocksAuthType authType ){ m_authType = authType; }
113 void SetClientCmd( SocksClientCmd cmd ){ m_cmd = cmd; }
114 void SetEnabled(bool enable){ m_enable = enable; }
115
116 NBString& GetUsername(){ return m_username; }
117 NBString& GetPassword(){ return m_password; }
118 uint16_t GetPort(){ return m_port; }
119 SocksAdrType GetAddressType(){ return m_adrType; }
120 NBString& GetAddress(){ return m_adr; }
121 SocksAuthType GetAuthType(){ return m_authType; }
122 SocksClientCmd GetClientCmd(){ return m_cmd; }
123 bool IsEnabled(){ return m_enable; }
124
128 void ClearProxyValues();
129
141 int SocksConnect( PSOCKET socket, uint16_t localPort, uint32_t timeout, const IPADDR &ifip, int ifn );
142
152 int SendAuthAndProcessReply( int tcpFd, const IPADDR& adr, int port );
153
154 private:
155
162 int SocksProcessReply( int tcpFd );
163
170 int SendAuthMethod( int tcpFd );
171
178 int AuthWithUsrNmPw( int tcpFd );
179
180 NBString m_adr;
181 NBString m_username;
182 NBString m_password;
183 uint16_t m_port = 1080;
187 bool m_enable = false;
188};
189
190extern SocksProxy* gSocksProxy;
191
192/*
193 * @brief Try to initiate a SOCKS5 connection with an IP address.
194 *
195 * @param auth The authorization type to use. No Authorization and plain text Username and Password are supported. The use of GSSAPI
196 * needs to be implemented by the developer by overriding AuthWithGssApi().
197 * @param cmd Which command to isssue. Currently only the Connect command is supported. See RFC 1928 for details on the other commands.
198 * @param adrType Which address type to use. This function supports IPv4 and IPv6.
199 * @param adr The host address to connect to.
200 * @param timeout The timeout value for the connection.
201 * @param username The username for the connection, if using the username and password authorization type.
202 * @param password The password for the connection, if using the username and password authorization type.
203 * @param socksPort The port to connect to. The default SOCKS port is 1080.
204 *
205 * @return int The FD of the connection if successful, or a TCP or SOCKS error code if unsuccessful.
206 */
207//int SocksConnect( PSOCKET socket, IPADDR adr, uint32_t timeout );
208
209/*
210 * @brief Try to initiate a SOCKS5 connection with a domain name or IP address.
211 *
212 * @param auth The authorization type to use. No Authorization and plain text Username and Password are supported. The use of GSSAPI
213 * needs to be implemented by the developer by overriding AuthWithGssApi().
214 * @param cmd Which command to isssue. Currently only the Connect command is supported. See RFC 1928 for details on the other commands.
215 * @param adrType Which address type to use. This function supports IPv4, IPv6, and domain names.
216 * @param adr The host address or domain name to connect to.
217 * @param timeout The timeout value for the connection.
218 * @param username The username for the connection, if using the username and password authorization type.
219 * @param password The password for the connection, if using the username and password authorization type.
220 * @param socksPort The port to connect to. The default SOCKS port is 1080.
221 *
222 * @return int The FD of the connection if successful, or a TCP or SOCKS error code if unsuccessful.
223 */
224//int SocksConnect( PSOCKET socket, SocksAuthType auth, SocksClientCmd cmd, SocksAdrType adrType, const NBString& adr, uint32_t timeout, const NBString& username, const NBString& password, uint16_t socksPort = 1080 );
225
226
233bool AuthWithGssApi();
234
241void SetSocksProxySettings( SocksProxy* socksProxy );
242
249
250#endif /* _NB_SOCKS_H_ */
251
Used to hold and manipulate IPv4 and IPv6 addresses in dual stack mode.
Definition ipv6_addr.h:41
Lightweight alternative to C++ CString class.
Definition nbstring.h:118
SocksProxy * GetSocksProxySettings()
Get a pointer to the currnetly set Socks proxy settings object.
SocksAuthType
SOCKS Autherization Types.
Definition Socks.h:56
SocksClientCmd
SOCKS Client Commands.
Definition Socks.h:67
void SetSocksProxySettings(SocksProxy *socksProxy)
Set the system level SOCKS proxy settings object to the one that is passed in. If this object is set ...
SocksAdrType
SOCKS Address Types.
Definition Socks.h:77
bool AuthWithGssApi()
A weak function that should be overriden by the developer in order to support GSSAPI authorization.
Definition Socks/src/main.cpp:26
@ eSocksAuthTypeGssApi
GSS API.
Definition Socks.h:57
@ eSocksAuthTypeNoAuth
Not as defined in RFC so that it could be propery tested against when being set by user.
Definition Socks.h:59
@ eSocksAuthTypeUnPw
User name and password.
Definition Socks.h:58
@ eSocksClientCmdBind
Not currently supported, see RFC 1928.
Definition Socks.h:69
@ eSocksClientCmdUdpAssoc
Not currently supported, see RFC 1928.
Definition Socks.h:70
@ eSocksClientCmdConnect
Connect.
Definition Socks.h:68
@ eSocksAdrTypeNone
None.
Definition Socks.h:78
@ eSocksAdrTypeIpv4
IPv4.
Definition Socks.h:79
@ eSocksAdrTypeDomain
Domain.
Definition Socks.h:80
@ eSocksAdrTypeIpv6
IPv6.
Definition Socks.h:81