From 8b180e941aa7ccf178a7e82c5a11d172c23d6331 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Sat, 9 May 2020 11:24:32 +0100 Subject: [PATCH] Add SOCKS proxy auth (closes #423) --- src/yggdrasil/link.go | 6 ++++++ src/yggdrasil/tcp.go | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/yggdrasil/link.go b/src/yggdrasil/link.go index 40d128e..5c4f0e6 100644 --- a/src/yggdrasil/link.go +++ b/src/yggdrasil/link.go @@ -17,6 +17,7 @@ import ( "github.com/yggdrasil-network/yggdrasil-go/src/address" "github.com/yggdrasil-network/yggdrasil-go/src/crypto" "github.com/yggdrasil-network/yggdrasil-go/src/util" + "golang.org/x/net/proxy" "github.com/Arceliar/phony" ) @@ -127,6 +128,11 @@ func (l *link) call(uri string, sintf string) error { l.tcp.call(u.Host, tcpOpts, sintf) case "socks": tcpOpts.socksProxyAddr = u.Host + if u.User != nil { + tcpOpts.socksProxyAuth = &proxy.Auth{} + tcpOpts.socksProxyAuth.User = u.User.Username() + tcpOpts.socksProxyAuth.Password, _ = u.User.Password() + } l.tcp.call(pathtokens[0], tcpOpts, sintf) case "tls": tcpOpts.upgrade = l.tcp.tls.forDialer diff --git a/src/yggdrasil/tcp.go b/src/yggdrasil/tcp.go index 6f97da8..e137391 100644 --- a/src/yggdrasil/tcp.go +++ b/src/yggdrasil/tcp.go @@ -61,6 +61,7 @@ type tcpOptions struct { linkOptions upgrade *TcpUpgrade socksProxyAddr string + socksProxyAuth *proxy.Auth socksPeerAddr string } @@ -282,7 +283,7 @@ func (t *tcp) call(saddr string, options tcpOptions, sintf string) { return } var dialer proxy.Dialer - dialer, err = proxy.SOCKS5("tcp", dialerdst.String(), nil, proxy.Direct) + dialer, err = proxy.SOCKS5("tcp", dialerdst.String(), options.socksProxyAuth, proxy.Direct) if err != nil { return }