summaryrefslogtreecommitdiff
path: root/indra/llmessage/llsocks5.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llmessage/llsocks5.cpp')
-rw-r--r--indra/llmessage/llsocks5.cpp73
1 files changed, 35 insertions, 38 deletions
diff --git a/indra/llmessage/llsocks5.cpp b/indra/llmessage/llsocks5.cpp
index 7eac27d4bb..27a31e35b3 100644
--- a/indra/llmessage/llsocks5.cpp
+++ b/indra/llmessage/llsocks5.cpp
@@ -1,6 +1,6 @@
/**
* @file llsocks5.cpp
- * @brief Socks 5 implementation
+ * @brief SOCKS 5 implementation
*
* $LicenseInfo:firstyear=2011&license=viewerlgpl$
* Second Life Viewer Source Code
@@ -37,52 +37,51 @@
// We want this to be static to avoid excessive indirection on every
// incoming packet just to do a simple bool test. The getter for this
// member is also static
-bool LLSocks::sUdpProxyEnabled;
-bool LLSocks::sHttpProxyEnabled;
+bool LLSocks::sUDPProxyEnabled;
+bool LLSocks::sHTTPProxyEnabled;
LLSocks::LLSocks()
{
- sUdpProxyEnabled = false;
- sHttpProxyEnabled = false;
- mProxyControlChannel = 0;
+ sUDPProxyEnabled = false;
+ sHTTPProxyEnabled = false;
+ mProxyControlChannel.reset();
mProxyType = LLPROXY_SOCKS;
}
-// Perform a Socks5 authentication and UDP association to the proxy
+// Perform a SOCKS 5 authentication and UDP association to the proxy
// specified by proxy, and associate UDP port message_port
int LLSocks::proxyHandshake(LLHost proxy, U32 message_port)
{
int result;
- /* Socks 5 Auth request */
+ /* SOCKS 5 Auth request */
socks_auth_request_t socks_auth_request;
socks_auth_response_t socks_auth_response;
- socks_auth_request.version = SOCKS_VERSION; // Socks version 5
- socks_auth_request.num_methods = 1; // Sending 1 method
- socks_auth_request.methods = mAuthMethodSelected; // send only the selected method
+ socks_auth_request.version = SOCKS_VERSION; // SOCKS version 5
+ socks_auth_request.num_methods = 1; // Sending 1 method.
+ socks_auth_request.methods = mAuthMethodSelected; // Send only the selected method.
result = tcp_handshake(mProxyControlChannel, (char*)&socks_auth_request, sizeof(socks_auth_request_t), (char*)&socks_auth_response, sizeof(socks_auth_response_t));
if (result != 0)
{
- llwarns << "Socks authentication request failed, error on TCP control channel : " << result << llendl;
+ llwarns << "SOCKS authentication request failed, error on TCP control channel : " << result << llendl;
stopProxy();
return SOCKS_CONNECT_ERROR;
}
if (socks_auth_response.method == AUTH_NOT_ACCEPTABLE)
{
- llwarns << "Socks5 server refused all our authentication methods" << llendl;
+ llwarns << "SOCKS 5 server refused all our authentication methods" << llendl;
stopProxy();
return SOCKS_NOT_ACCEPTABLE;
}
- // SOCKS5 USERNAME/PASSWORD authentication
+ // SOCKS 5 USERNAME/PASSWORD authentication
if (socks_auth_response.method == METHOD_PASSWORD)
{
// The server has requested a username/password combination
U32 request_size = mSocksUsername.size() + mSocksPassword.size() + 3;
- // char * password_auth = (char *)malloc(request_size);
char * password_auth = new char[request_size];
password_auth[0] = 0x01;
password_auth[1] = mSocksUsername.size();
@@ -97,14 +96,14 @@ int LLSocks::proxyHandshake(LLHost proxy, U32 message_port)
if (result != 0)
{
- llwarns << "Socks authentication failed, error on TCP control channel : " << result << llendl;
+ llwarns << "SOCKS authentication failed, error on TCP control channel : " << result << llendl;
stopProxy();
return SOCKS_CONNECT_ERROR;
}
if (password_reply.status != AUTH_SUCCESS)
{
- llwarns << "Socks authentication failed" << llendl;
+ llwarns << "SOCKS authentication failed" << llendl;
stopProxy();
return SOCKS_AUTH_FAIL;
}
@@ -115,18 +114,19 @@ int LLSocks::proxyHandshake(LLHost proxy, U32 message_port)
socks_command_request_t connect_request;
socks_command_response_t connect_reply;
- connect_request.version = SOCKS_VERSION; //Socks V5
- connect_request.command = COMMAND_UDP_ASSOCIATE; // Associate UDP
- connect_request.flag = FIELD_RESERVED;
- connect_request.atype = ADDRESS_IPV4;
- connect_request.address = 0; // 0.0.0.0 We are not fussy about address
- // UDP is promiscuous receive for our protocol
- connect_request.port = 0; // Port must be 0 if you ever want to connect via NAT and your router does port rewrite for you
+ connect_request.version = SOCKS_VERSION; // SOCKS V5
+ connect_request.command = COMMAND_UDP_ASSOCIATE; // Associate UDP
+ connect_request.reserved = FIELD_RESERVED;
+ connect_request.atype = ADDRESS_IPV4;
+ connect_request.address = htonl(0); // 0.0.0.0
+ connect_request.port = htons(0); // 0
+ // "If the client is not in possesion of the information at the time of the UDP ASSOCIATE,
+ // the client MUST use a port number and address of all zeros. RFC 1928"
result = tcp_handshake(mProxyControlChannel, (char*)&connect_request, sizeof(socks_command_request_t), (char*)&connect_reply, sizeof(socks_command_response_t));
if (result != 0)
{
- llwarns << "Socks connect request failed, error on TCP control channel : " << result << llendl;
+ llwarns << "SOCKS connect request failed, error on TCP control channel : " << result << llendl;
stopProxy();
return SOCKS_CONNECT_ERROR;
}
@@ -134,7 +134,7 @@ int LLSocks::proxyHandshake(LLHost proxy, U32 message_port)
if (connect_reply.reply != REPLY_REQUEST_GRANTED)
{
//Something went wrong
- llwarns << "Connection to SOCKS5 server failed, UDP forward request not granted" << llendl;
+ llwarns << "Connection to SOCKS 5 server failed, UDP forward request not granted" << llendl;
stopProxy();
return SOCKS_UDP_FWD_NOT_GRANTED;
}
@@ -142,7 +142,7 @@ int LLSocks::proxyHandshake(LLHost proxy, U32 message_port)
mUDPProxy.setPort(ntohs(connect_reply.port)); // reply port is in network byte order
mUDPProxy.setAddress(proxy.getAddress());
// All good now we have been given the UDP port to send requests that need forwarding.
- llinfos << "Socks 5 UDP proxy connected on " << mUDPProxy << llendl;
+ llinfos << "SOCKS 5 UDP proxy connected on " << mUDPProxy << llendl;
return SOCKS_OK;
}
@@ -155,19 +155,17 @@ int LLSocks::startProxy(LLHost proxy, U32 message_port)
if (mProxyControlChannel)
{
tcp_close_channel(mProxyControlChannel);
- mProxyControlChannel = 0;
}
- mProxyControlChannel = tcp_open_channel(proxy);
- if (mProxyControlChannel == -1)
+ mProxyControlChannel = tcp_open_channel(mTCPProxy);
+ if (!mProxyControlChannel)
{
return SOCKS_HOST_CONNECT_FAILED;
}
-
status = proxyHandshake(proxy, message_port);
if (status == SOCKS_OK)
{
- sUdpProxyEnabled = true;
+ sUDPProxyEnabled = true;
}
return status;
}
@@ -181,21 +179,20 @@ int LLSocks::startProxy(std::string host, U32 port)
void LLSocks::stopProxy()
{
- sUdpProxyEnabled = false;
+ sUDPProxyEnabled = false;
- // If the Socks proxy is requested to stop and we are using that for http as well
+ // If the SOCKS proxy is requested to stop and we are using that for http as well
// then we must shut down any http proxy operations. But it is allowable if web
// proxy is being used to continue proxying http.
if(LLPROXY_SOCKS == mProxyType)
{
- sHttpProxyEnabled = false;
+ sHTTPProxyEnabled = false;
}
if (mProxyControlChannel)
{
tcp_close_channel(mProxyControlChannel);
- mProxyControlChannel = 0;
}
}
@@ -211,9 +208,9 @@ void LLSocks::setAuthPassword(std::string username, std::string password)
mSocksPassword = password;
}
-void LLSocks::enableHttpProxy(LLHost httpHost, LLHttpProxyType type)
+void LLSocks::enableHTTPProxy(LLHost httpHost, LLHttpProxyType type)
{
- sHttpProxyEnabled = true;
+ sHTTPProxyEnabled = true;
mHTTPProxy = httpHost;
mProxyType = type;
}