mirror of https://github.com/Dreamacro/clash.git
Improve: add tls, sni options to socks5 outbound adapter
This commit is contained in:
parent
19cbe52456
commit
bcba14e05e
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue