feat: add fingerprint param

This commit is contained in:
Skyxim
2022-07-11 13:42:28 +08:00
parent ab8e9e7d7a
commit a8ce283727
16 changed files with 193 additions and 30 deletions

View File

@ -2,6 +2,7 @@ package obfs
import (
"crypto/tls"
tlsC "github.com/Dreamacro/clash/component/tls"
"net"
"net/http"
@ -16,6 +17,7 @@ type Option struct {
Headers map[string]string
TLS bool
SkipCertVerify bool
Fingerprint string
Mux bool
}
@ -35,11 +37,20 @@ func NewV2rayObfs(conn net.Conn, option *Option) (net.Conn, error) {
if option.TLS {
config.TLS = true
config.TLSConfig = &tls.Config{
tlsConfig := &tls.Config{
ServerName: option.Host,
InsecureSkipVerify: option.SkipCertVerify,
NextProtos: []string{"http/1.1"},
}
if len(option.Fingerprint) == 0 {
config.TLSConfig = tlsC.GetGlobalFingerprintTLCConfig(tlsConfig)
} else {
var err error
if config.TLSConfig, err = tlsC.GetSpecifiedFingerprintTLSConfig(tlsConfig, option.Fingerprint); err != nil {
return nil, err
}
}
if host := config.Headers.Get("Host"); host != "" {
config.TLSConfig.ServerName = host
}