Documentation
¶
Overview ¶
fastdialer is a dialer package containing a dns/tls cache layer
Index ¶
- Constants
- Variables
- func AsTLSConfig(ztlsConfig *ztls.Config) (*tls.Config, error)
- func AsZTLSConfig(tlsConfig *tls.Config) (*ztls.Config, error)
- func HandleResolverLine(raw string) (ip string)
- func IsTLS13(config interface{}) bool
- func WithResolveOverride(ctx context.Context, host, ip string) context.Context
- type CacheType
- type ContextOption
- type Dialer
- func (d *Dialer) Close()
- func (d *Dialer) Dial(ctx context.Context, network, address string) (conn net.Conn, err error)
- func (d *Dialer) DialTLS(ctx context.Context, network, address string) (conn net.Conn, err error)
- func (d *Dialer) DialTLSWithConfig(ctx context.Context, network, address string, config *tls.Config) (conn net.Conn, err error)
- func (d *Dialer) DialTLSWithConfigImpersonate(ctx context.Context, network, address string, config *tls.Config, ...) (conn net.Conn, err error)
- func (d *Dialer) DialZTLS(ctx context.Context, network, address string) (conn net.Conn, err error)
- func (d *Dialer) DialZTLSWithConfig(ctx context.Context, network, address string, config *ztls.Config) (conn net.Conn, err error)
- func (d *Dialer) GetDNSData(hostname string) (*retryabledns.DNSData, error)
- func (d *Dialer) GetDNSDataFromCache(hostname string) (*retryabledns.DNSData, error)
- func (d *Dialer) GetDialedIP(hostname string) string
- func (d *Dialer) GetTLSData(hostname string) (*cryptoutil.TLSData, error)
- func (d *Dialer) GetTimeout() time.Duration
- type DiskDBType
- type Options
- type ResolverConfig
Constants ¶
const ( // DefaultMaxResolverEntries is the default maximum number of resolver // entries to read from the resolvers file. DefaultMaxResolverEntries = 4096 // DefaultNdots is the default ndots value. DefaultNdots = 1 )
const ResolverFilePath = "/etc/resolv.conf"
ResolverFilePath in unix file os
Variables ¶
var ( MaxDNSCacheSize int64 MaxDNSItems = 1024 MaxDialCacheSize = 10000 )
option to disable ztls fallback in case of handshake error reads from env variable DISABLE_ZTLS_FALLBACK
var ( CouldNotConnectError = errkit.New("could not connect to any address found for host").SetKind(errkit.ErrKindNetworkPermanent) NoAddressFoundError = errkit.New("no address found for host").SetKind(errkit.ErrKindNetworkPermanent) NoAddressAllowedError = errkit.New("denied address found for host").SetKind(errkit.ErrKindNetworkPermanent) NoPortSpecifiedError = errkit.New("port was not specified").SetKind(errkit.ErrKindNetworkPermanent) MalformedIP6Error = errkit.New("malformed IPv6 address").SetKind(errkit.ErrKindNetworkPermanent) ResolveHostError = errkit.New("could not resolve host").SetKind(errkit.ErrKindNetworkPermanent) NoTLSHistoryError = errkit.New("no tls data history available") NoTLSDataError = errkit.New("no tls data found for the key") NoDNSDataError = errkit.New("no data found") AsciiConversionError = errkit.New("could not convert hostname to ASCII") ErrDialTimeout = errkit.New("dial timeout").SetKind(errkit.ErrKindNetworkTemporary) )
var DefaultOptions = Options{ BaseResolvers: DefaultResolvers, MaxRetries: 5, HostsFile: true, ResolversFile: true, CacheType: Memory, DialerTimeout: 10 * time.Second, DialerKeepAlive: 10 * time.Second, MaxTemporaryErrors: 30, MaxTemporaryToPermanentDuration: time.Minute, }
DefaultOptions of the cache
var DefaultResolvers = []string{
"1.1.1.1:53",
"1.0.0.1:53",
"8.8.8.8:53",
"8.8.4.4:53",
}
DefaultResolvers trusted
var DefaultTLSConfig = &tls.Config{ Renegotiation: tls.RenegotiateOnceAsClient, InsecureSkipVerify: true, MinVersion: tls.VersionTLS10, NextProtos: []string{"http/1.1"}, }
DefaultTLSConfig is a default TLS configuration that is used by the fastdialer. It offers the cipher suites of crypto/tls, and the ztls fallback reaches servers that only accept legacy ones.
var DefaultZTLSConfig = &ztls.Config{ InsecureSkipVerify: true, MinVersion: ztls.VersionTLS10, CipherSuites: getUnsafeCipherSuites(), }
DefaultZTLSConfig is a default ZTLS configuration that is used by the fastdialer.
var MaxDialerTimeout = time.Minute
var ( // MaxResolverEntries limits the number of resolver entries parsed from // resolver file. // // -1 means no limit. // // Deprecated: Use [DefaultMaxResolverEntries] instead. Adjust via [Options]. MaxResolverEntries = 4096 )
var MinDialerTimeout = time.Second
Functions ¶
func HandleResolverLine ¶ added in v0.0.9
HandleLine a resolver file line
func WithResolveOverride ¶ added in v0.6.0
WithResolveOverride returns a copy of ctx in which dials to host connect to ip instead of resolving host, like curl --resolve. host is compared with the hostname of the dialed address, case-insensitively and on any port, and the hostname is still used for SNI. Other hosts dialed with the same context, such as redirect targets or a proxy, are resolved as usual.
The IP context option and an ip given in the address (host:port:ip) take precedence over an override.
Types ¶
type ContextOption ¶ added in v0.0.16
type ContextOption string
const ( // SniName to use in tls connection SniName ContextOption = "sni-name" IP ContextOption = "ip" )
type Dialer ¶
type Dialer struct {
// contains filtered or unexported fields
}
Dialer structure containing data information
func (*Dialer) DialTLS ¶ added in v0.0.6
DialTLS with encrypted connection, using Options.TLSConfig, or Options.ZTLSConfig when Options.WithZTLS is set.
Note that the default configuration, used when those are nil, skips certificate verification and is not intended to be secure. Set Options.TLSConfig, or use the DialTLSWithConfig or DialTLSWithConfigImpersonate methods instead.
func (*Dialer) DialTLSWithConfig ¶ added in v0.0.13
func (d *Dialer) DialTLSWithConfig(ctx context.Context, network, address string, config *tls.Config) (conn net.Conn, err error)
DialTLS with encrypted connection
func (*Dialer) DialTLSWithConfigImpersonate ¶ added in v0.0.29
func (d *Dialer) DialTLSWithConfigImpersonate(ctx context.Context, network, address string, config *tls.Config, impersonate impersonate.Strategy, identity *impersonate.Identity) (conn net.Conn, err error)
DialTLSWithConfigImpersonate dials tls with impersonation
The config applies as in DialTLSWithConfig, except that the impersonated ClientHello decides what it offers, such as cipher suites and curves. Only TLS 1.3 sessions are stored in config.ClientSessionCache, and they resume only when the ClientHello has a pre_shared_key extension. utls can't resume a session when the server asks for another key share, so that dial fails and drops the session.
If config.NextProtos is set, it replaces the protocols in the ALPN extension of the impersonated ClientHello, which can change its JA4 fingerprint but not its JA3 one. A ClientHello without ALPN still sends none. If NextProtos is empty, the ClientHello keeps its own protocols.
config.MinVersion and config.MaxVersion limit the version that the server may select, but the ClientHello still offers its own versions, so the dial fails when the server selects one outside them. A zero MinVersion or MaxVersion leaves that limit to the ClientHello.
func (*Dialer) DialZTLS ¶ added in v0.0.15
DialZTLS with encrypted connection using ztls and Options.ZTLSConfig
Note that the default configuration, used when Options.ZTLSConfig is nil, is included for compatibility with the Go version <1.22, and is not intended to be secure. Set Options.ZTLSConfig, or use the DialZTLSWithConfig method instead.
func (*Dialer) DialZTLSWithConfig ¶ added in v0.0.15
func (d *Dialer) DialZTLSWithConfig(ctx context.Context, network, address string, config *ztls.Config) (conn net.Conn, err error)
DialZTLSWithConfig dials ztls with config
func (*Dialer) GetDNSData ¶
func (d *Dialer) GetDNSData(hostname string) (*retryabledns.DNSData, error)
GetDNSData for the given hostname
func (*Dialer) GetDNSDataFromCache ¶
func (d *Dialer) GetDNSDataFromCache(hostname string) (*retryabledns.DNSData, error)
GetDNSDataFromCache cached by the resolver
func (*Dialer) GetDialedIP ¶
GetDialedIP returns the ip dialed by the HTTP client
func (*Dialer) GetTLSData ¶ added in v0.0.13
func (d *Dialer) GetTLSData(hostname string) (*cryptoutil.TLSData, error)
GetTLSData returns the tls data for a hostname
func (*Dialer) GetTimeout ¶ added in v0.4.14
GetTimeout returns the maximum timeout allowed for dialer
type Options ¶
type Options struct {
BaseResolvers []string
MaxRetries int
HostsFile bool
ResolversFile bool
EnableFallback bool
Allow []string
Deny []string
// Deprecated: has no effect, the dialer validates hosts and IPs, not URLs.
AllowSchemeList []string
// Deprecated: has no effect, the dialer validates hosts and IPs, not URLs.
DenySchemeList []string
AllowPortList []int
DenyPortList []int
CacheType CacheType
CacheMemoryMaxItems int // used by Memory cache type
DiskDbType DiskDBType
WithDialerHistory bool
WithCleanup bool
WithTLSData bool
DialerTimeout time.Duration
DialerKeepAlive time.Duration
Dialer *net.Dialer
ProxyDialer *proxy.Dialer
WithZTLS bool
SNIName string
OnBeforeDial func(hostname, IP, port string)
// OnValidateTarget is called after network policy validation and before dialing.
// If it returns an error, the target is considered invalid.
OnValidateTarget func(hostname, IP, port string) error
OnInvalidTarget func(hostname, IP, port string)
OnDialCallback func(hostname, IP string)
DisableZtlsFallback bool
WithNetworkPolicyOptions *networkpolicy.Options
// optional network policy override for sharing
NetworkPolicy *networkpolicy.NetworkPolicy
// optional logger to log errors(like hostfile init error)
Logger *log.Logger
// optional max temporary errors to mark as permanent
MaxTemporaryErrors int
MaxTemporaryToPermanentDuration time.Duration
// ConnectionCacheExpiry is the duration after which a cached connection
// expires.
//
// Default is [DefaultConnExpiry].
ConnectionCacheExpiry time.Duration
// MaxResolverEntries limits the number of resolvers read from the resolvers
// file.
//
// Default is [DefaultMaxResolverEntries].
// Use -1 for unlimited entries.
MaxResolverEntries int
// Ndots enforces the resolv.conf(5) ndots: threshold for treating a name
// as absolute before search domains are appended (see
// https://man7.org/linux/man-pages/man5/resolv.conf.5.html).
//
// Default is [DefaultNdots].
Ndots int
// OnDialResult is called after each connection attempt with the caller's
// context and the error, nil on success. Targets that fail before a
// connection is attempted (resolution, policy) are not reported.
OnDialResult func(ctx context.Context, hostname, port string, err error)
// TLSConfig is the config of DialTLS. Default is [DefaultTLSConfig].
// Configs passed to the WithConfig dial methods are used as given.
TLSConfig *tls.Config
// ZTLSConfig is the config of DialZTLS, and of DialTLS when WithZTLS is
// set. Default is [DefaultZTLSConfig].
ZTLSConfig *ztls.Config
}
type ResolverConfig ¶ added in v0.5.3
type ResolverConfig struct {
// Resolvers are the list of nameservers.
Resolvers []string
// SearchDomains are the search domains.
SearchDomains []string
// Ndots enforces the resolv.conf(5) ndots: threshold for treating a name
// as absolute before search domains are appended (see
// https://man7.org/linux/man-pages/man5/resolv.conf.5.html).
Ndots int
}
ResolverConfig captures nameservers plus search-domain semantics from resolv.conf(5).
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
ja3 is a package for creating JA3 fingerprints from TLS clients.
|
ja3 is a package for creating JA3 fingerprints from TLS clients. |
|
impersonate
impersonate package contains strategy to impersonate a client and define an alias for the internal client tls spefications
|
impersonate package contains strategy to impersonate a client and define an alias for the internal client tls spefications |
|
metafiles are metadata files related to networking like /etc/hosts etc
|
metafiles are metadata files related to networking like /etc/hosts etc |