Add support for SOCKS 5 proxies.
This only covers outgoing TCP connections, and supports only username/password authentication or no authentication.
This commit is contained in:
parent
b58d95eb29
commit
fb5588856f
2 changed files with 48 additions and 2 deletions
|
@ -422,7 +422,7 @@ static bool setup_myself(void) {
|
||||||
if(proxyuser && *proxyuser)
|
if(proxyuser && *proxyuser)
|
||||||
proxyuser = xstrdup(proxyuser);
|
proxyuser = xstrdup(proxyuser);
|
||||||
if(proxypass && *proxypass)
|
if(proxypass && *proxypass)
|
||||||
proxyuser = xstrdup(proxypass);
|
proxypass = xstrdup(proxypass);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -67,8 +67,54 @@ static bool send_proxyrequest(connection_t *c) {
|
||||||
c->tcplen = 8;
|
c->tcplen = 8;
|
||||||
return send_meta(c, s4req, sizeof s4req);
|
return send_meta(c, s4req, sizeof s4req);
|
||||||
}
|
}
|
||||||
|
case PROXY_SOCKS5: {
|
||||||
|
int len = 3 + 6 + (c->address.sa.sa_family == AF_INET ? 4 : 16);
|
||||||
|
c->tcplen = 2;
|
||||||
|
if(proxypass)
|
||||||
|
len += 3 + strlen(proxyuser) + strlen(proxypass);
|
||||||
|
char s5req[len];
|
||||||
|
int i = 0;
|
||||||
|
s5req[i++] = 5;
|
||||||
|
s5req[i++] = 1;
|
||||||
|
if(proxypass) {
|
||||||
|
s5req[i++] = 2;
|
||||||
|
s5req[i++] = 1;
|
||||||
|
s5req[i++] = strlen(proxyuser);
|
||||||
|
strcpy(s5req + i, proxyuser);
|
||||||
|
i += strlen(proxyuser);
|
||||||
|
s5req[i++] = strlen(proxypass);
|
||||||
|
strcpy(s5req + i, proxypass);
|
||||||
|
i += strlen(proxypass);
|
||||||
|
c->tcplen += 2;
|
||||||
|
} else {
|
||||||
|
s5req[i++] = 0;
|
||||||
|
}
|
||||||
|
s5req[i++] = 5;
|
||||||
|
s5req[i++] = 1;
|
||||||
|
s5req[i++] = 0;
|
||||||
|
if(c->address.sa.sa_family == AF_INET) {
|
||||||
|
s5req[i++] = 1;
|
||||||
|
memcpy(s5req + i, &c->address.in.sin_addr, 4);
|
||||||
|
i += 4;
|
||||||
|
memcpy(s5req + i, &c->address.in.sin_port, 2);
|
||||||
|
i += 2;
|
||||||
|
c->tcplen += 10;
|
||||||
|
} else if(c->address.sa.sa_family == AF_INET6) {
|
||||||
|
s5req[i++] = 3;
|
||||||
|
memcpy(s5req + i, &c->address.in6.sin6_addr, 16);
|
||||||
|
i += 16;
|
||||||
|
memcpy(s5req + i, &c->address.in6.sin6_port, 2);
|
||||||
|
i += 2;
|
||||||
|
c->tcplen += 22;
|
||||||
|
} else {
|
||||||
|
logger(LOG_ERR, "Address family %hx not supported for SOCKS 5 proxies!", c->address.sa.sa_family);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(i > len)
|
||||||
|
abort();
|
||||||
|
return send_meta(c, s5req, sizeof s5req);
|
||||||
|
}
|
||||||
case PROXY_SOCKS4A:
|
case PROXY_SOCKS4A:
|
||||||
case PROXY_SOCKS5:
|
|
||||||
logger(LOG_ERR, "Proxy type not implemented yet");
|
logger(LOG_ERR, "Proxy type not implemented yet");
|
||||||
return false;
|
return false;
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in a new issue