Skip to content

Commit

Permalink
1.1.16版本,JA3支持24的TokenBinding、41的PreSharedKey、57的QuicTransportParamet…
Browse files Browse the repository at this point in the history
…ers扩展
  • Loading branch information
wangluozhe committed Sep 1, 2023
1 parent fc4e4d7 commit 066d422
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 41 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# requests
[![Gitee link address](https://img.shields.io/badge/gitee-reference-red?logo=gitee&logoColor=red&labelColor=white)](https://gitee.com/leegene/requests)[![Github link address](https://img.shields.io/badge/github-reference-blue?logo=github&logoColor=black&labelColor=white&color=black)](https://github.com/wangluozhe/requests)[![Go Version](https://img.shields.io/badge/Go%20Version-1.20-blue?logo=go&logoColor=white&labelColor=gray)]()[![Release Version](https://img.shields.io/badge/release-v1.1.15-blue)]()[![go documentation](https://img.shields.io/badge/go-documentation-blue)](https://pkg.go.dev/github.com/wangluozhe/requests)[![license GPL-3.0](https://img.shields.io/badge/license-GPL3.0-orange)](https://github.com/wangluozhe/requests/blob/main/LICENSE)
[![Gitee link address](https://img.shields.io/badge/gitee-reference-red?logo=gitee&logoColor=red&labelColor=white)](https://gitee.com/leegene/requests)[![Github link address](https://img.shields.io/badge/github-reference-blue?logo=github&logoColor=black&labelColor=white&color=black)](https://github.com/wangluozhe/requests)[![Go Version](https://img.shields.io/badge/Go%20Version-1.20-blue?logo=go&logoColor=white&labelColor=gray)]()[![Release Version](https://img.shields.io/badge/release-v1.1.16-blue)]()[![go documentation](https://img.shields.io/badge/go-documentation-blue)](https://pkg.go.dev/github.com/wangluozhe/requests)[![license GPL-3.0](https://img.shields.io/badge/license-GPL3.0-orange)](https://github.com/wangluozhe/requests/blob/main/LICENSE)

requests支持以下新特性:

Expand Down Expand Up @@ -28,7 +28,7 @@ go get github.com/wangluozhe/requests
## 下载指定版

```bash
go get github.com/wangluozhe/requests@v1.1.15
go get github.com/wangluozhe/requests@v1.1.16
```


Expand Down
18 changes: 10 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ go 1.20
require (
github.com/andybalholm/brotli v1.0.5
github.com/bitly/go-simplejson v0.5.0
github.com/refraction-networking/utls v1.3.2
github.com/google/uuid v1.3.0
github.com/refraction-networking/utls v1.5.2
github.com/wangluozhe/fhttp v0.0.0-20230512135433-5c2ebfb4868a
golang.org/x/crypto v0.9.0
golang.org/x/net v0.10.0
golang.org/x/crypto v0.12.0
golang.org/x/net v0.14.0
)

require (
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
github.com/gaukas/godicttls v0.0.3 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/klauspost/compress v1.15.15 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/gaukas/godicttls v0.0.4 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/kr/pretty v0.3.1 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
github.com/quic-go/quic-go v0.37.4 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
)
42 changes: 26 additions & 16 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,41 @@ github.com/bitly/go-simplejson v0.5.0 h1:6IH+V8/tVMab511d5bn4M7EwGXZf9Hj6i2xSwkN
github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngEKAMDJEczWVA=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs=
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/gaukas/godicttls v0.0.3 h1:YNDIf0d9adcxOijiLrEzpfZGAkNwLRzPaG6OjU7EITk=
github.com/gaukas/godicttls v0.0.3/go.mod h1:l6EenT4TLWgTdwslVb4sEMOCf7Bv0JAK67deKr9/NCI=
github.com/gaukas/godicttls v0.0.4 h1:NlRaXb3J6hAnTmWdsEKb9bcSBD6BvcIjdGdeb0zfXbk=
github.com/gaukas/godicttls v0.0.4/go.mod h1:l6EenT4TLWgTdwslVb4sEMOCf7Bv0JAK67deKr9/NCI=
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 h1:yAJXTCF9TqKcTiHJAE8dj7HMvPfh66eeA2JYW7eFpSE=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/klauspost/compress v1.15.15 h1:EF27CXIuDsYJ6mmvtBRlEuB2UVOqHG1tAXgZ7yIO+lw=
github.com/klauspost/compress v1.15.15/go.mod h1:ZcK2JAFqKOpnBlxcLsJzYfrS9X1akm9fHZNnD9+Vo/4=
github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I=
github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/onsi/ginkgo/v2 v2.9.5 h1:+6Hr4uxzP4XIUyAkg61dWBw8lb/gc4/X5luuxN/EC+Q=
github.com/onsi/gomega v1.27.6 h1:ENqfyGeS5AX/rlXDd/ETokDz93u0YufY1Pgxuy/PvWE=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/refraction-networking/utls v1.3.2 h1:o+AkWB57mkcoW36ET7uJ002CpBWHu0KPxi6vzxvPnv8=
github.com/refraction-networking/utls v1.3.2/go.mod h1:fmoaOww2bxzzEpIKOebIsnBvjQpqP7L2vcm/9KUfm/E=
github.com/quic-go/quic-go v0.37.4 h1:ke8B73yMCWGq9MfrCCAw0Uzdm7GaViC3i39dsIdDlH4=
github.com/quic-go/quic-go v0.37.4/go.mod h1:YsbH1r4mSHPJcLF4k4zruUkLBqctEMBDR6VPvcYjIsU=
github.com/refraction-networking/utls v1.5.2 h1:l6diiLbEoRqdQ+/osPDO0z0lTc8O8VZV+p82N+Hi+ws=
github.com/refraction-networking/utls v1.5.2/go.mod h1:SPuDbBmgLGp8s+HLNc83FuavwZCFoMmExj+ltUHiHUw=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/wangluozhe/fhttp v0.0.0-20230512094319-9596880bdf8a h1:BNnudZ48Z56ASQix+6tKUhizpPF3rc/Q+wE7dc98hCM=
github.com/wangluozhe/fhttp v0.0.0-20230512094319-9596880bdf8a/go.mod h1:kAK+x1U0Wmy/htOSEeV31JyFBAVndp/orqVJZTq9FxM=
github.com/wangluozhe/fhttp v0.0.0-20230512135433-5c2ebfb4868a h1:nFqhBDkWfNrI5h8nAOv4orMHi0w3qMrd7GoBFXXZGmc=
github.com/wangluozhe/fhttp v0.0.0-20230512135433-5c2ebfb4868a/go.mod h1:kAK+x1U0Wmy/htOSEeV31JyFBAVndp/orqVJZTq9FxM=
golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g=
golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0=
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk=
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/tools v0.9.1 h1:8WMNJAz3zrtPmnYC7ISf5dEn3MT0gY7jBJfw27yrrLo=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Binary file modified imgs/wechat_group.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 15 additions & 4 deletions sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"errors"
"fmt"
"github.com/andybalholm/brotli"
tls "github.com/refraction-networking/utls"
utls "github.com/refraction-networking/utls"
"github.com/wangluozhe/fhttp"
"github.com/wangluozhe/fhttp/cookiejar"
"github.com/wangluozhe/fhttp/http2"
Expand Down Expand Up @@ -152,8 +152,9 @@ func NewSession() *Session {
cookies, _ := cookiejar.New(nil)
session.Cookies = cookies
session.transport = &http.Transport{
TLSClientConfig: &tls.Config{
TLSClientConfig: &utls.Config{
InsecureSkipVerify: session.Verify,
OmitEmptyPsk: true,
},
DisableKeepAlives: false, // 这里问题很严重
}
Expand Down Expand Up @@ -323,12 +324,22 @@ func (s *Session) Send(preq *models.PrepareRequest, req *url.Request) (*models.R
// 自定义TLS指纹信息
tlsExtensions := merge_setting(req.TLSExtensions, s.TLSExtensions).(*ja3.TLSExtensions)
http2Settings := merge_setting(req.HTTP2Settings, s.HTTP2Settings).(*http2.HTTP2Settings)
if strings.Index(strings.Split(browser.JA3, ",")[2], "-41") != -1 {
config := s.transport.TLSClientConfig.Clone()
if config.ClientSessionCache == nil {
config.SessionTicketKey = [32]byte{}
config.OmitEmptyPsk = true
config.ClientSessionCache = utls.NewLRUClientSessionCache(0)
s.transport.TLSClientConfig = config
}
}

options := &ja3.Options{
Browser: browser,
TLSExtensions: tlsExtensions,
HTTP2Settings: http2Settings,
ForceHTTP1: req.ForceHTTP1,
TLSConfig: s.transport.TLSClientConfig,
}

if proxies != "" {
Expand All @@ -350,7 +361,7 @@ func (s *Session) Send(preq *models.PrepareRequest, req *url.Request) (*models.R
cert := merge_setting(s.Cert, req.Cert).([]string)
if cert != nil {
var cert_byte []byte
certs, err := tls.LoadX509KeyPair(cert[0], cert[1])
certs, err := utls.LoadX509KeyPair(cert[0], cert[1])
if err != nil {
return nil, err
}
Expand All @@ -369,7 +380,7 @@ func (s *Session) Send(preq *models.PrepareRequest, req *url.Request) (*models.R
}
s.transport.TLSClientConfig.RootCAs = certPool
fmt.Println(certs)
s.transport.TLSClientConfig.Certificates = []tls.Certificate{certs}
s.transport.TLSClientConfig.Certificates = []utls.Certificate{certs}
}

// 设置超时时间
Expand Down
21 changes: 14 additions & 7 deletions transport/roundtripper.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,13 @@ func (rt *roundTripper) dialTLS(ctx context.Context, network, addr string) (net.
}

rt.config.ServerName = host
conn := utls.UClient(rawConn, rt.config,
// MinVersion: tls.VersionTLS10,
// MaxVersion: tls.VersionTLS13,

utls.HelloCustom)
conn := utls.UClient(rawConn, rt.config.Clone(), utls.HelloCustom)

if err := conn.ApplyPreset(spec); err != nil {
return nil, err
}

if err = conn.Handshake(); err != nil {
if err = conn.HandshakeContext(ctx); err != nil {
_ = conn.Close()

if err.Error() == "tls: CurvePreferences includes unsupported curve" {
Expand Down Expand Up @@ -159,7 +155,18 @@ func (rt *roundTripper) getDialTLSAddr(req *http.Request) string {

func newRoundTripper(browser Browser, config *utls.Config, tlsExtensions *TLSExtensions, http2Settings *http2.HTTP2Settings, forceHTTP1 bool, dialer ...proxy.ContextDialer) http.RoundTripper {
if config == nil {
config = &utls.Config{InsecureSkipVerify: true}
if strings.Index(strings.Split(browser.JA3, ",")[2], "-41") == -1 {
config = &utls.Config{
InsecureSkipVerify: true,
}
} else {
config = &utls.Config{
InsecureSkipVerify: true,
SessionTicketKey: [32]byte{},
ClientSessionCache: utls.NewLRUClientSessionCache(0),
OmitEmptyPsk: true,
}
}
}
if len(dialer) > 0 {

Expand Down
10 changes: 7 additions & 3 deletions transport/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ func StringToSpec(ja3 string, userAgent string, tlsExtensions *TLSExtensions, fo
extMap["50"] = ext.SignatureAlgorithmsCert
}
if ext.KeyShareCurves != nil {
extMap["51"] = ext.KeyShareCurves
if strings.Index(strings.Split(ja3, ",")[2], "-41") == -1 {
extMap["51"] = ext.KeyShareCurves
}
}
}

Expand Down Expand Up @@ -200,7 +202,8 @@ func genMap() (extMap map[string]utls.TLSExtension) {
"18": &utls.SCTExtension{},
"21": &utls.UtlsPaddingExtension{GetPaddingLen: utls.BoringPaddingStyle},
"22": &utls.GenericExtension{Id: 22}, // encrypt_then_mac
"23": &utls.UtlsExtendedMasterSecretExtension{},
"23": &utls.ExtendedMasterSecretExtension{},
"24": &utls.FakeTokenBindingExtension{},
"27": &utls.UtlsCompressCertExtension{
Algorithms: []utls.CertCompressionAlgo{utls.CertCompressionBrotli},
},
Expand All @@ -216,7 +219,7 @@ func genMap() (extMap map[string]utls.TLSExtension) {
},
},
"35": &utls.SessionTicketExtension{},
"41": &utls.FakePreSharedKeyExtension{}, //FIXME pre_shared_key, Currently not supported 41 extension
"41": &utls.UtlsPreSharedKeyExtension{}, //FIXME pre_shared_key
"43": &utls.SupportedVersionsExtension{Versions: []uint16{
utls.VersionTLS13,
utls.VersionTLS12,
Expand Down Expand Up @@ -246,6 +249,7 @@ func genMap() (extMap map[string]utls.TLSExtension) {

// {Group: utls.CurveP384}, known bug missing correct extensions for handshake
}},
"57": &utls.QUICTransportParametersExtension{},
"13172": &utls.NPNExtension{},
"17513": &utls.ApplicationSettingsExtension{
SupportedProtocols: []string{
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package requests

const (
NAME = "golang-requests" // 名称
VERSION = "1.1.15" // 当前版本
VERSION = "1.1.16" // 当前版本
USER_AGENT = NAME + VERSION // UA
)

0 comments on commit 066d422

Please sign in to comment.