Separate uTLS random fingerprint

This commit is contained in:
世界 2023-02-28 21:10:11 +08:00
parent 3b4e811907
commit 49f568abbd
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
3 changed files with 26 additions and 1 deletions

View file

@ -5,6 +5,7 @@ package tls
import ( import (
"crypto/tls" "crypto/tls"
"crypto/x509" "crypto/x509"
"math/rand"
"net" "net"
"net/netip" "net/netip"
"os" "os"
@ -159,6 +160,20 @@ func NewUTLSClient(router adapter.Router, serverAddress string, options option.O
return &UTLSClientConfig{&tlsConfig, id}, nil return &UTLSClientConfig{&tlsConfig, id}, nil
} }
var randomFingerprint utls.ClientHelloID
func init() {
modernFingerprints := []utls.ClientHelloID{
utls.HelloChrome_Auto,
utls.HelloFirefox_Auto,
utls.HelloEdge_Auto,
utls.HelloSafari_Auto,
utls.HelloIOS_Auto,
utls.HelloAndroid_11_OkHttp,
}
randomFingerprint = modernFingerprints[rand.Intn(len(modernFingerprints))]
}
func uTLSClientHelloID(name string) (utls.ClientHelloID, error) { func uTLSClientHelloID(name string) (utls.ClientHelloID, error) {
switch name { switch name {
case "chrome", "": case "chrome", "":
@ -178,7 +193,15 @@ func uTLSClientHelloID(name string) (utls.ClientHelloID, error) {
case "android": case "android":
return utls.HelloAndroid_11_OkHttp, nil return utls.HelloAndroid_11_OkHttp, nil
case "random": case "random":
return utls.HelloRandomized, nil return randomFingerprint, nil
case "randomized":
weights := utls.DefaultWeights
weights.TLSVersMax_Set_VersionTLS13 = 1
weights.FirstKeyShare_Set_CurveP256 = 0
randomized := utls.HelloRandomized
randomized.Seed, _ = utls.NewPRNGSeed()
randomized.Weights = &weights
return randomized, nil
default: default:
return utls.ClientHelloID{}, E.New("unknown uTLS fingerprint: ", name) return utls.ClientHelloID{}, E.New("unknown uTLS fingerprint: ", name)
} }

View file

@ -218,6 +218,7 @@ Available fingerprint values:
* ios * ios
* android * android
* random * random
* randomized
Chrome fingerprint will be used if empty. Chrome fingerprint will be used if empty.

View file

@ -218,6 +218,7 @@ uTLS 是 "crypto/tls" 的一个分支,它提供了 ClientHello 指纹识别阻
* ios * ios
* android * android
* random * random
* randomized
默认使用 chrome 指纹。 默认使用 chrome 指纹。