Replies: 5 comments 14 replies
-
You can use package main
import (
"context"
"crypto/tls"
"github.com/imroc/req/v3"
utls "github.com/refraction-networking/utls"
"net"
)
type TLSConn struct {
*utls.Conn
}
func (conn *TLSConn) ConnectionState() tls.ConnectionState {
cs := conn.Conn.ConnectionState()
return tls.ConnectionState{
Version: cs.Version,
HandshakeComplete: cs.HandshakeComplete,
DidResume: cs.DidResume,
CipherSuite: cs.CipherSuite,
NegotiatedProtocol: cs.NegotiatedProtocol,
NegotiatedProtocolIsMutual: cs.NegotiatedProtocolIsMutual,
ServerName: cs.ServerName,
PeerCertificates: cs.PeerCertificates,
VerifiedChains: cs.VerifiedChains,
SignedCertificateTimestamps: cs.SignedCertificateTimestamps,
OCSPResponse: cs.OCSPResponse,
TLSUnique: cs.TLSUnique,
}
}
func main() {
c := req.C().DevMode()
utlsConfig := &utls.Config{NextProtos: c.GetTLSClientConfig().NextProtos}
c.SetDialTLS(func(ctx context.Context, network, addr string) (net.Conn, error) {
conn, err := utls.Dial(network, addr, utlsConfig)
if err != nil {
return nil, err
}
return &TLSConn{conn}, nil
})
c.R().MustGet("https://httpbin.org/get")
} |
Beta Was this translation helpful? Give feedback.
-
I can add a document explaining how to use utls to support tls ClientHello fingerprinting resistance in req, but I don't want to integrate it into req, which introduces too many unnecessary dependencies for most users |
Beta Was this translation helpful? Give feedback.
-
@imroc, thanks for the example, but I can't get it work with SetProxyURL. If I add a proxy (http or socks5) via SetProxyURL function, the SetDialTLS function is not even called, so the fingerprint does not change. Can you give an example of how to use this with a proxy server? |
Beta Was this translation helpful? Give feedback.
-
Now |
Beta Was this translation helpful? Give feedback.
-
@imroc It is so good to hear that |
Beta Was this translation helpful? Give feedback.
-
utls is a fork of the Go standard TLS library, providing low-level access to the ClientHello. I am particularly interested in generating randomized fingerprints.
This would require to modify the
addTLS
method ofpersistConn
intransport.go
. For instance :However, I was unable to negotiate the TLS connection with only these modifications.
Beta Was this translation helpful? Give feedback.
All reactions