]> git.meshlink.io Git - meshlink/commitdiff
Add support for SOCKS 5 proxies.
authorGuus Sliepen <guus@tinc-vpn.org>
Thu, 19 Apr 2012 12:10:54 +0000 (14:10 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Thu, 19 Apr 2012 12:10:54 +0000 (14:10 +0200)
This only covers outgoing TCP connections, and supports only
username/password authentication or no authentication.

src/net_setup.c
src/protocol_auth.c

index 2eff09f3f6d7a1370269c462e55ee63c908844df..eec438a80879831b1a2416fbdeefa0a9cebf6328 100644 (file)
@@ -422,7 +422,7 @@ static bool setup_myself(void) {
                                if(proxyuser && *proxyuser)
                                        proxyuser = xstrdup(proxyuser);
                                if(proxypass && *proxypass)
-                                       proxyuser = xstrdup(proxypass);
+                                       proxypass = xstrdup(proxypass);
                                break;
                }
 
index e5c4c1663d70ad5baff2d845de82e3b773da4d4f..81189332495ccd7b1a0618ada156a5358d31ca74 100644 (file)
@@ -67,8 +67,54 @@ static bool send_proxyrequest(connection_t *c) {
                        c->tcplen = 8;
                        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_SOCKS5:
                        logger(LOG_ERR, "Proxy type not implemented yet");
                        return false;
                default: