Improve: add tls, sni options to socks5 outbound adapter
This commit is contained in:
parent
009b985c49
commit
3042a47f9d
1 changed files with 16 additions and 0 deletions
|
@ -2,6 +2,7 @@ package adapters
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"crypto/tls"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
@ -29,12 +30,16 @@ func (ss *Socks5Adapter) Conn() net.Conn {
|
||||||
type Socks5 struct {
|
type Socks5 struct {
|
||||||
addr string
|
addr string
|
||||||
name string
|
name string
|
||||||
|
tls bool
|
||||||
|
sni bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type Socks5Option struct {
|
type Socks5Option struct {
|
||||||
Name string `proxy:"name"`
|
Name string `proxy:"name"`
|
||||||
Server string `proxy:"server"`
|
Server string `proxy:"server"`
|
||||||
Port int `proxy:"port"`
|
Port int `proxy:"port"`
|
||||||
|
TLS bool `proxy:"tls"`
|
||||||
|
SNI bool `proxy:"sni"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ss *Socks5) Name() string {
|
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) {
|
func (ss *Socks5) Generator(metadata *C.Metadata) (adapter C.ProxyAdapter, err error) {
|
||||||
c, err := net.DialTimeout("tcp", ss.addr, tcpTimeout)
|
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 {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%s connect error", ss.addr)
|
return nil, fmt.Errorf("%s connect error", ss.addr)
|
||||||
}
|
}
|
||||||
|
@ -92,5 +106,7 @@ func NewSocks5(option Socks5Option) *Socks5 {
|
||||||
return &Socks5{
|
return &Socks5{
|
||||||
addr: fmt.Sprintf("%s:%d", option.Server, option.Port),
|
addr: fmt.Sprintf("%s:%d", option.Server, option.Port),
|
||||||
name: option.Name,
|
name: option.Name,
|
||||||
|
tls: option.TLS,
|
||||||
|
sni: option.SNI,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue