Documentation
¶
Overview ¶
Package tls provides TLS connection utilities with browser fingerprint spoofing. It wraps the utls library to create TLS connections that mimic real browser TLS handshakes, including cipher suites, extensions, and other fingerprint elements.
Index ¶
- Constants
- func BuildChrome143Spec(serverName string) *utls.ClientHelloSpec
- func BuildFirefox146Spec(serverName string) *utls.ClientHelloSpec
- func BuildSafari261Spec(serverName string) *utls.ClientHelloSpec
- func GenerateGREASEBytes(length int) []byte
- func IsGREASE(v uint16) bool
- func RandomGREASE() uint16
- func RandomGREASEPair() (uint16, uint16)
- func RandomUint32() uint32
- type BrowserType
- type Dialer
- func (d *Dialer) Dial(network, addr string) (*utls.UConn, error)
- func (d *Dialer) DialContext(ctx context.Context, network, addr string) (*utls.UConn, error)
- func (d *Dialer) DialQUIC(ctx context.Context, addr string) (*quic.Conn, error)
- func (d *Dialer) SetDNSCache(cache *dns.Cache)
- func (d *Dialer) SetKeepAlive(keepAlive time.Duration)
- func (d *Dialer) SetTimeout(timeout time.Duration)
- type ProxyConfig
- type ProxyType
- type SpecBuilder
Constants ¶
const TCP_FASTOPEN_CONNECT = 30 // Linux 4.11+
TCP_FASTOPEN_CONNECT is the socket option for client-side TFO on Linux. This allows sending data in the SYN packet, eliminating 1 RTT.
Variables ¶
This section is empty.
Functions ¶
func BuildChrome143Spec ¶
func BuildChrome143Spec(serverName string) *utls.ClientHelloSpec
BuildChrome143Spec builds a Chrome 143 ClientHelloSpec for the given server.
func BuildFirefox146Spec ¶
func BuildFirefox146Spec(serverName string) *utls.ClientHelloSpec
BuildFirefox146Spec builds a Firefox 146 ClientHelloSpec for the given server.
func BuildSafari261Spec ¶
func BuildSafari261Spec(serverName string) *utls.ClientHelloSpec
BuildSafari261Spec builds a Safari 26.1 ClientHelloSpec for the given server.
func GenerateGREASEBytes ¶
GenerateGREASEBytes generates random bytes for GREASE extension data.
func RandomGREASEPair ¶
RandomGREASEPair returns two different random GREASE values.
func RandomUint32 ¶
func RandomUint32() uint32
RandomUint32 returns a random uint32 for session ID or other purposes.
Types ¶
type BrowserType ¶
type BrowserType int
BrowserType identifies the browser family for fingerprint generation.
const ( BrowserChrome BrowserType = iota BrowserFirefox BrowserSafari )
type Dialer ¶
type Dialer struct {
// UseBuiltinChrome uses uTLS built-in Chrome preset instead of custom spec.
// This is more reliable but gives less control over the exact fingerprint.
UseBuiltinChrome bool
// InsecureSkipVerify skips TLS certificate verification.
// WARNING: This should only be used for testing.
InsecureSkipVerify bool
// ForceHTTP1 forces HTTP/1.1 by only advertising http/1.1 in ALPN.
ForceHTTP1 bool
// contains filtered or unexported fields
}
Dialer creates uTLS connections with browser fingerprint spoofing.
func Chrome143Dialer ¶
func Chrome143Dialer() *Dialer
Chrome143Dialer returns a dialer configured for Chrome 143. Uses built-in Chrome preset by default for reliability.
func Firefox146Dialer ¶
func Firefox146Dialer() *Dialer
Firefox146Dialer returns a dialer configured for Firefox 146.
func NewCustomDialer ¶
func NewCustomDialer(p *profile.BrowserProfile) *Dialer
NewCustomDialer creates a TLS dialer that uses a custom ClientHelloSpec. This gives more control but may be less compatible with some servers.
func NewDialer ¶
func NewDialer(p *profile.BrowserProfile) *Dialer
NewDialer creates a new TLS dialer with the given profile. Uses custom ClientHelloSpec by default for maximum fingerprint control.
func NewDialerWithProxy ¶
func NewDialerWithProxy(p *profile.BrowserProfile, proxy *ProxyConfig) *Dialer
NewDialerWithProxy creates a new TLS dialer with the given profile and proxy.
func Safari261Dialer ¶
func Safari261Dialer() *Dialer
Safari261Dialer returns a dialer configured for Safari 26.1.
func (*Dialer) DialContext ¶
DialContext establishes a TLS connection with the configured fingerprint.
func (*Dialer) DialQUIC ¶
DialQUIC establishes a QUIC connection with browser-like transport parameters. The connection can be used to create an HTTP/3 transport. Note: TLS fingerprinting within QUIC uses standard crypto/tls. QUIC transport parameters are configured from the browser profile's HTTP3Profile.
func (*Dialer) SetDNSCache ¶
SetDNSCache enables DNS caching with the given cache. This reduces DNS lookup latency for repeated requests to the same hosts.
func (*Dialer) SetKeepAlive ¶
SetKeepAlive sets the TCP keep-alive period.
func (*Dialer) SetTimeout ¶
SetTimeout sets the dial timeout.
type ProxyConfig ¶
type ProxyConfig struct {
Type ProxyType
Host string
Port string
Username string // empty for IP-authenticated proxies
Password string
}
ProxyConfig holds proxy connection settings.
func ParseProxy ¶
func ParseProxy(s string, proxyType ProxyType) (*ProxyConfig, error)
ParseProxy parses a proxy string in "host:port:user:pass" or "host:port" format.
func (*ProxyConfig) Addr ¶
func (p *ProxyConfig) Addr() string
Addr returns the proxy address as host:port.
type SpecBuilder ¶
type SpecBuilder struct {
// contains filtered or unexported fields
}
SpecBuilder builds uTLS ClientHelloSpec from a BrowserProfile.
func NewSpecBuilder ¶
func NewSpecBuilder(p *profile.BrowserProfile) *SpecBuilder
NewSpecBuilder creates a new SpecBuilder for the given profile. By default, extensions are shuffled to mimic Chrome's behavior.
func (*SpecBuilder) Build ¶
func (b *SpecBuilder) Build(serverName string) *utls.ClientHelloSpec
Build creates a ClientHelloSpec for the given server name.
func (*SpecBuilder) WithShuffleExtensions ¶
func (b *SpecBuilder) WithShuffleExtensions(shuffle bool) *SpecBuilder
WithShuffleExtensions sets whether to shuffle extension order. Chrome randomizes extension order, so enabling this (default) produces more realistic fingerprints.