diff --git a/component/tls/utls.go b/component/tls/utls.go index ed35bd99..f965fc64 100644 --- a/component/tls/utls.go +++ b/component/tls/utls.go @@ -18,11 +18,11 @@ type UClientHelloID struct { *utls.ClientHelloID } -var initRandomFingerprint *utls.ClientHelloID +var initRandomFingerprint UClientHelloID var initUtlsClient string -func UClient(c net.Conn, config *tls.Config, fingerprint *UClientHelloID) net.Conn { - utlsConn := utls.UClient(c, CopyConfig(config), utls.ClientHelloID{ +func UClient(c net.Conn, config *tls.Config, fingerprint UClientHelloID) net.Conn { + utlsConn := utls.UClient(c, copyConfig(config), utls.ClientHelloID{ Client: fingerprint.Client, Version: fingerprint.Version, Seed: fingerprint.Seed, @@ -30,12 +30,12 @@ func UClient(c net.Conn, config *tls.Config, fingerprint *UClientHelloID) net.Co return &UConn{UConn: utlsConn} } -func GetFingerprint(ClientFingerprint string) (*utls.ClientHelloID, bool) { +func GetFingerprint(ClientFingerprint string) (UClientHelloID, bool) { if ClientFingerprint == "none" { - return nil, false + return UClientHelloID{}, false } - if initRandomFingerprint == nil { + if initRandomFingerprint.ClientHelloID == nil { initRandomFingerprint, _ = RollFingerprint() } @@ -49,7 +49,7 @@ func GetFingerprint(ClientFingerprint string) (*utls.ClientHelloID, bool) { return fingerprint, ok } -func RollFingerprint() (*utls.ClientHelloID, bool) { +func RollFingerprint() (UClientHelloID, bool) { chooser, _ := weightedrand.NewChooser( weightedrand.NewChoice("chrome", 6), weightedrand.NewChoice("safari", 3), @@ -62,15 +62,15 @@ func RollFingerprint() (*utls.ClientHelloID, bool) { return fingerprint, ok } -var Fingerprints = map[string]*utls.ClientHelloID{ - "chrome": &utls.HelloChrome_Auto, - "firefox": &utls.HelloFirefox_Auto, - "safari": &utls.HelloSafari_Auto, - "ios": &utls.HelloIOS_Auto, - "randomized": &utls.HelloRandomized, +var Fingerprints = map[string]UClientHelloID{ + "chrome": {&utls.HelloChrome_Auto}, + "firefox": {&utls.HelloFirefox_Auto}, + "safari": {&utls.HelloSafari_Auto}, + "ios": {&utls.HelloIOS_Auto}, + "randomized": {&utls.HelloRandomized}, } -func CopyConfig(c *tls.Config) *utls.Config { +func copyConfig(c *tls.Config) *utls.Config { return &utls.Config{ RootCAs: c.RootCAs, ServerName: c.ServerName, diff --git a/transport/gun/gun.go b/transport/gun/gun.go index 8c096861..920e7adc 100644 --- a/transport/gun/gun.go +++ b/transport/gun/gun.go @@ -202,9 +202,7 @@ func NewHTTP2Client(dialFn DialFn, tlsConfig *tls.Config, Fingerprint string) *T if len(Fingerprint) != 0 { if fingerprint, exists := tlsC.GetFingerprint(Fingerprint); exists { - utlsConn := tlsC.UClient(pconn, cfg, &tlsC.UClientHelloID{ - ClientHelloID: fingerprint, - }) + utlsConn := tlsC.UClient(pconn, cfg, fingerprint) if err := utlsConn.(*tlsC.UConn).HandshakeContext(ctx); err != nil { pconn.Close() return nil, err diff --git a/transport/vmess/tls.go b/transport/vmess/tls.go index 27924ccc..711c342d 100644 --- a/transport/vmess/tls.go +++ b/transport/vmess/tls.go @@ -55,9 +55,7 @@ func StreamTLSConn(conn net.Conn, cfg *TLSConfig) (net.Conn, error) { func GetUtlsConnWithClientFingerprint(conn net.Conn, ClientFingerprint string, tlsConfig *tls.Config) (net.Conn, bool) { if fingerprint, exists := tlsC.GetFingerprint(ClientFingerprint); exists { - utlsConn := tlsC.UClient(conn, tlsConfig, &tlsC.UClientHelloID{ - ClientHelloID: fingerprint, - }) + utlsConn := tlsC.UClient(conn, tlsConfig, fingerprint) return utlsConn, true } diff --git a/transport/vmess/websocket.go b/transport/vmess/websocket.go index d56cf07c..2487b93a 100644 --- a/transport/vmess/websocket.go +++ b/transport/vmess/websocket.go @@ -335,9 +335,7 @@ func streamWebsocketConn(conn net.Conn, c *WebsocketConfig, earlyData *bytes.Buf if len(c.ClientFingerprint) != 0 { if fingerprint, exists := tlsC.GetFingerprint(c.ClientFingerprint); exists { dialer.NetDialTLSContext = func(_ context.Context, _, addr string) (net.Conn, error) { - utlsConn := tlsC.UClient(conn, c.TLSConfig, &tlsC.UClientHelloID{ - ClientHelloID: fingerprint, - }) + utlsConn := tlsC.UClient(conn, c.TLSConfig, fingerprint) if err := utlsConn.(*tlsC.UConn).WebsocketHandshake(); err != nil { return nil, fmt.Errorf("parse url %s error: %w", c.Path, err)