diff --git a/adapters/outbound/socks5.go b/adapters/outbound/socks5.go index 4fe1cfe..a1495e9 100644 --- a/adapters/outbound/socks5.go +++ b/adapters/outbound/socks5.go @@ -2,6 +2,7 @@ package adapters import ( "bytes" + "crypto/tls" "errors" "fmt" "io" @@ -29,12 +30,16 @@ func (ss *Socks5Adapter) Conn() net.Conn { type Socks5 struct { addr string name string + tls bool + sni bool } type Socks5Option struct { Name string `proxy:"name"` Server string `proxy:"server"` Port int `proxy:"port"` + TLS bool `proxy:"tls"` + SNI bool `proxy:"sni"` } func (ss *Socks5) Name() string { @@ -47,6 +52,15 @@ func (ss *Socks5) Type() C.AdapterType { func (ss *Socks5) Generator(metadata *C.Metadata) (adapter C.ProxyAdapter, err error) { c, err := net.DialTimeout("tcp", ss.addr, tcpTimeout) + + if err == nil && ss.tls { + tlsConfig := tls.Config{ + InsecureSkipVerify: ss.sni, + MaxVersion: tls.VersionTLS12, + } + c = tls.Client(c, &tlsConfig) + } + if err != nil { return nil, fmt.Errorf("%s connect error", ss.addr) } @@ -92,5 +106,7 @@ func NewSocks5(option Socks5Option) *Socks5 { return &Socks5{ addr: fmt.Sprintf("%s:%d", option.Server, option.Port), name: option.Name, + tls: option.TLS, + sni: option.SNI, } }