socks proxy reply fix

This commit is contained in:
Jiri Sasek 2018-04-23 20:30:08 +02:00 committed by David Fort
parent b1c1549ad1
commit 1ba31551a6
3 changed files with 45 additions and 64 deletions

View File

@ -1836,13 +1836,13 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
{
settings->ProxyType = PROXY_TYPE_HTTP;
}
else if (!strcmp("socks", arg->Value))
else if (!strcmp("socks5", arg->Value))
{
settings->ProxyType = PROXY_TYPE_SOCKS;
}
else
{
WLog_ERR(TAG, "Only HTTP and SOCKS proxies supported by now");
WLog_ERR(TAG, "Only HTTP and SOCKS5 proxies supported by now");
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
}

View File

@ -137,7 +137,7 @@ static COMMAND_LINE_ARGUMENT_A args[] =
{ "port", COMMAND_LINE_VALUE_REQUIRED, "<number>", NULL, NULL, -1, NULL, "Server port" },
{ "print-reconnect-cookie", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "Print base64 reconnect cookie after connecting" },
{ "printer", COMMAND_LINE_VALUE_OPTIONAL, "<name>[,<driver>]", NULL, NULL, -1, NULL, "Redirect printer device" },
{ "proxy", COMMAND_LINE_VALUE_REQUIRED, "[<proto>://]<host>:<port>", NULL, NULL, -1, NULL, "Proxy settings: override env.var (see also environment variable below).\n\tProtocol \"socks\" should be given explicitly where \"http[s]\" is default.\n\tNote: socks proxy is not supported by env. variable" },
{ "proxy", COMMAND_LINE_VALUE_REQUIRED, "[<proto>://]<host>:<port>", NULL, NULL, -1, NULL, "Proxy settings: override env.var (see also environment variable below).\n\tProtocol \"socks5\" should be given explicitly where \"http\" is default.\n\tNote: socks proxy is not supported by env. variable" },
{ "pth", COMMAND_LINE_VALUE_REQUIRED, "<password-hash>", NULL, NULL, -1, "pass-the-hash", "Pass the hash (restricted admin mode)" },
{ "pwidth", COMMAND_LINE_VALUE_REQUIRED, "<width>", NULL, NULL, -1, NULL, "Physical width of display (in millimeters)" },
{ "reconnect-cookie", COMMAND_LINE_VALUE_REQUIRED, "<base64-cookie>", NULL, NULL, -1, NULL, "Pass base64 reconnect cookie to the connection" },

View File

@ -259,6 +259,43 @@ static BOOL http_proxy_connect(BIO* bufferedBio, const char* hostname, UINT16 po
return TRUE;
}
static int recv_socks_reply(BIO* bufferedBio, BYTE * buf, int len, char* reason)
{
int status;
ZeroMemory(buf, len);
for(;;) {
status = BIO_read(bufferedBio, buf, len);
if (status > 0) break;
else if (status < 0)
{
/* Error? */
if (BIO_should_retry(bufferedBio))
{
USleep(100);
continue;
}
WLog_ERR(TAG, "Failed reading %s reply from SOCKS proxy (Status %d)", reason, status);
return -1;
}
else if (status == 0)
{
/* Error? */
WLog_ERR(TAG, "Failed reading %s reply from SOCKS proxy (BIO_read returned zero)", reason);
return -1;
}
}
if (buf[0] != 5)
{
WLog_ERR(TAG, "SOCKS Proxy version is not 5 (%s)", reason);
return -1;
}
return status;
}
/* SOCKS Proxy auth methods by rfc1928 */
#define AUTH_M_NO_AUTH 0
#define AUTH_M_GSSAPI 1
@ -267,7 +304,7 @@ static BOOL http_proxy_connect(BIO* bufferedBio, const char* hostname, UINT16 po
static BOOL socks_proxy_connect(BIO* bufferedBio, const char* hostname, UINT16 port)
{
int status;
BYTE buf[280], hostnlen = 0xff & strlen(hostname);
BYTE buf[280], hostnlen = strlen(hostname) & 0xff;
/* CONN REQ replies in enum. order */
static const char *rplstat[] = {
"succeeded",
@ -293,36 +330,8 @@ static BOOL socks_proxy_connect(BIO* bufferedBio, const char* hostname, UINT16 p
return FALSE;
}
/* Read result SOCK reply */
memset(buf, '\0', sizeof(buf));
for(;;) {
status = BIO_read(bufferedBio, buf, sizeof(buf));
if (status > 0) break;
else if (status < 0)
{
/* Error? */
if (BIO_should_retry(bufferedBio))
{
USleep(100);
continue;
}
WLog_ERR(TAG, "Failed reading AUTH reply from SOCKS proxy (Status %d)", status);
return FALSE;
}
else if (status == 0)
{
/* Error? */
WLog_ERR(TAG, "Failed reading AUTH reply from SOCKS proxy (BIO_read returned zero)");
return FALSE;
}
}
if (buf[0] != 5)
{
WLog_ERR(TAG, "SOCKS Proxy version is not 5 (AUTH)");
return FALSE;
}
status = recv_socks_reply(bufferedBio, buf, sizeof(buf), "AUTH REQ");
if (status < 0) return FALSE;
if (buf[1] != AUTH_M_NO_AUTH)
{
@ -348,36 +357,8 @@ static BOOL socks_proxy_connect(BIO* bufferedBio, const char* hostname, UINT16 p
return FALSE;
}
/* Read result SOCK reply */
memset(buf, '\0', sizeof(buf));
for(;;) {
status = BIO_read(bufferedBio, buf, sizeof(buf));
if (status > 0) break;
else if (status < 0)
{
/* Error? */
if (BIO_should_retry(bufferedBio))
{
USleep(100);
continue;
}
WLog_ERR(TAG, "Failed reading reply from SOCKS proxy (Status %d)", status);
return FALSE;
}
else if (status == 0)
{
/* Error? */
WLog_ERR(TAG, "Failed reading reply from SOCKS proxy (BIO_read returned zero)");
return FALSE;
}
}
if (buf[0] != 5)
{
WLog_ERR(TAG, "SOCKS Proxy version is not 5 (CONN REQ)");
return FALSE;
}
status = recv_socks_reply(bufferedBio, buf, sizeof(buf), "CONN REQ");
if (status < 0) return FALSE;
if (buf[1] == 0)
{