query

package
v0.0.0-...-1b4ddf7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const DEFAULT_BACKOFF_TIME time.Duration = 5000 * time.Millisecond
View Source
const DEFAULT_DNS_PORT = 53
View Source
const DEFAULT_DOH_PARAM = "dns"
View Source
const DEFAULT_DOH_PATH = "/dns-query{?dns}"
View Source
const DEFAULT_DOH_PORT = 443
View Source
const DEFAULT_DOH_TIMEOUT = 10000 * time.Millisecond
View Source
const DEFAULT_DOQ_PORT = 853

see https://www.rfc-editor.org/rfc/rfc9250.html#section-4.1.1

View Source
const DEFAULT_DOQ_TIMEOUT time.Duration = 10000 * time.Millisecond
View Source
const DEFAULT_DOT_PORT = 853
View Source
const DEFAULT_DOT_TIMEOUT time.Duration = 10000 * time.Millisecond
View Source
const DEFAULT_RECURSIVE_RESOLVER = "8.8.8.8"
View Source
const DEFAULT_TCP_RETRIES = 1
View Source
const DEFAULT_TCP_TIMEOUT time.Duration = 5000 * time.Millisecond
View Source
const DEFAULT_TLS_PORT = 443
View Source
const DEFAULT_TLS_TIMEOUT time.Duration = 5000 * time.Millisecond
View Source
const DEFAULT_UDP_RETRIES = 3
View Source
const DEFAULT_UDP_TIMEOUT time.Duration = 5000 * time.Millisecond
View Source
const DNS_DOT_PROTOCOL = "tcp-tls"
View Source
const DNS_TCP = "tcp"
View Source
const DNS_UDP = "udp"
View Source
const DOH_MEDIA_TYPE = "application/dns-message"
View Source
const HTTP_GET = "GET"
View Source
const HTTP_POST = "POST"
View Source
const HTTP_VERSION_1 = "HTTP/1.1"
View Source
const HTTP_VERSION_2 = "HTTP2"
View Source
const HTTP_VERSION_3 = "HTTP3"
View Source
const MAX_DNS_FQDN_LENGTH = 255

see https://datatracker.ietf.org/doc/html/rfc1035#section-3.1 however, let's be slightly below the threshold

View Source
const MAX_SUBDOMAIN_LENGTH = 25
View Source
const MAX_URI_LENGTH = 2048
View Source
const QUERY_HOST = "measurement.raiun.de."
View Source
const SSH_PORT = 22
View Source
const SSH_TIMEOUT = 2500 * time.Millisecond
View Source
const TLS_PROTOCOL_TCP = "tcp"
View Source
const TLS_PROTOCOL_UDP = "udp"

Variables

View Source
var DOQ_TLS_PROTOCOLS = []string{"doq", "dq"}

see https://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml nolint: gochecknoglobals

Functions

func AddQuicPrefix

func AddQuicPrefix(b []byte) (m []byte)

AddQuicPrefix adds a 2-byte prefix with the DNS message length. see https://datatracker.ietf.org/doc/html/rfc9250#section-4.2-4

func GetDefaultQueryMsg

func GetDefaultQueryMsg() *dns.Msg

func GetPathParamFromDoHPath

func GetPathParamFromDoHPath(uri string) (path string, param string, err *custom_errors.DoEError)

func GetRandomizedQueryHost

func GetRandomizedQueryHost(host string) string

func ResolveHost

func ResolveHost(hostname string, resolver net.IP, qh ConventionalDNSQueryHandlerI) ([]*net.IP, error)

Types

type CertQueryHandler

type CertQueryHandler interface {
	Query(host string, port int, protocol string, timeout time.Duration, tlsConf *tls.Config) (*tls.ConnectionState, error)
}

type CertificateQuery

type CertificateQuery struct {
	// Host is the host for the dialer (required)
	Host string `json:"host"`
	// Port is the port for the dialer (default: 443)
	Port int `json:"port"`
	// Protocol is the protocol for the dialer (default: "tcp")
	Protocol string `json:"protocol"`
	// Timeout is the timeout in ms (default: 2500)
	Timeout time.Duration `json:"timeout"`
	// SNI
	SNI string `json:"sni"`
	// ALPN protocol
	ALPN []string `json:"alpn"`
}

func NewCertificateQuery

func NewCertificateQuery() (q *CertificateQuery)

func (*CertificateQuery) Check

func (cq *CertificateQuery) Check() (err custom_errors.DoEErrors)

type CertificateQueryHandler

type CertificateQueryHandler struct {
	QueryHandler CertQueryHandler
}

func NewCertificateQueryHandler

func NewCertificateQueryHandler(config *QueryConfig) (*CertificateQueryHandler, error)

func (*CertificateQueryHandler) Query

type CertificateResponse

type CertificateResponse struct {
	// Certificate is the certificate
	Certificates []*x509.Certificate `json:"certificates"`

	RetryWithoutCertificateVerification bool `json:"retry_without_certificate_verification"`
}

type Conn

type Conn interface {
	Close() error
	ConnectionState() tls.ConnectionState
}

type ConventionalDNSQuery

type ConventionalDNSQuery struct {
	DNSQuery

	// protocol to use (default: udp)
	Protocol string `json:"protocol"`
	// maximum number of UDP retries (default: 3)
	MaxUDPRetries int `json:"max_udp_retries"`
	// fallback to TCP if UDP fails (default: true)
	AutoFallbackTCP bool `json:"auto_fallback_tcp"`
	// maximum number of TCP retries (default: 1)
	MaxTCPRetries int `json:"max_tcp_retries"`
	// timeout in ms for UDP (default: 5000)
	//
	// if Timeout is set, it will overwrite this value
	TimeoutUDP time.Duration `json:"timeout_udp"`
	// timeout in ms for TCP (default: 5000)
	//
	// if Timeout is set, it will overwrite this value
	TimeoutTCP time.Duration `json:"timeout_tcp"`
	// maximum backoff time in ms (default: 5000)
	MaxBackoffTime time.Duration `json:"max_backoff_time"`
}

func NewCanaryQuery

func NewCanaryQuery(canaryDomain string, host string) *ConventionalDNSQuery

func NewConventionalQuery

func NewConventionalQuery() *ConventionalDNSQuery

func NewDDRDNSSECQuery

func NewDDRDNSSECQuery(targetName string) *ConventionalDNSQuery

func NewDDRQuery

func NewDDRQuery() *ConventionalDNSQuery

func NewEDSRQuery

func NewEDSRQuery(targetName string) *ConventionalDNSQuery

type ConventionalDNSQueryHandler

type ConventionalDNSQueryHandler struct {
	ConventionalDNSQueryHandlerI

	Sleeper      sleeper
	QueryHandler QueryHandlerDNS
}

func NewCanaryQueryHandler

func NewCanaryQueryHandler(config *QueryConfig) *ConventionalDNSQueryHandler

func NewConventionalDNSQueryHandler

func NewConventionalDNSQueryHandler(config *QueryConfig) *ConventionalDNSQueryHandler

func NewDDRDNSSECQueryHandler

func NewDDRDNSSECQueryHandler(config *QueryConfig) *ConventionalDNSQueryHandler

func NewDDRQueryHandler

func NewDDRQueryHandler(config *QueryConfig) *ConventionalDNSQueryHandler

func NewEDSRQueryHandler

func NewEDSRQueryHandler(config *QueryConfig) *ConventionalDNSQueryHandler

func NewPTRQueryHandler

func NewPTRQueryHandler(config *QueryConfig) (qh *ConventionalDNSQueryHandler)

func (*ConventionalDNSQueryHandler) Query

type ConventionalDNSQueryHandlerI

type ConventionalDNSQueryHandlerI interface {
	Query(query *ConventionalDNSQuery) (res *ConventionalDNSResponse, err custom_errors.DoEErrors)
}

type ConventionalDNSResponse

type ConventionalDNSResponse struct {
	Response      *DNSResponse `json:"response"`
	WasTruncated  bool         `json:"was_truncated"`
	UDPAttempts   int          `json:"udp_attempts"`
	TCPAttempts   int          `json:"tcp_attempts"`
	AttemptErrors []string     `json:"attempt_errors"`
}

type DNSQuery

type DNSQuery struct {
	// Host is the nameserver to query
	Host string `json:"host"`
	// QueryMsg is the DNS message to send
	QueryMsg *dns.Msg `json:"query_msg"`
	// Port is the port number (default: 443)
	Port int `json:"port"`
	// Timeout is the timeout in ms (default: 5000)
	Timeout time.Duration `json:"timeout"`
	// DNSSEC
	DNSSEC bool `json:"dnssec"`
}

func (*DNSQuery) Check

func (q *DNSQuery) Check(checkForTimeout bool) (err custom_errors.DoEErrors)

func (*DNSQuery) SetDNSSEC

func (q *DNSQuery) SetDNSSEC()

SetDNSSEC sets the DNSSEC flag in the query message Do not use this function before marshaling the query but before sending it as a DNS query

type DNSResponse

type DNSResponse struct {
	// Response is the DNS response
	ResponseMsg *dns.Msg `json:"responsemsg"`
	// RTT is the round-trip time
	RTT time.Duration `json:"rtt"`
}

type DefaultCertQueryHandler

type DefaultCertQueryHandler struct {
	// contains filtered or unexported fields
}

func (*DefaultCertQueryHandler) Query

func (d *DefaultCertQueryHandler) Query(host string, port int, protocol string, timeout time.Duration, tlsConf *tls.Config) (*tls.ConnectionState, error)

type DefaultDoTQueryHandler

type DefaultDoTQueryHandler struct {
	QueryHandler DoTQueryHandler
}

func NewDefaultDoTHandler

func NewDefaultDoTHandler(config *QueryConfig) *DefaultDoTQueryHandler

func (*DefaultDoTQueryHandler) Query

type DefaultQueryHandlerDNS

type DefaultQueryHandlerDNS struct {
	DialerUDP *net.Dialer
	DialerTCP *net.Dialer
}

func NewDefaultQueryHandler

func NewDefaultQueryHandler(config *QueryConfig) *DefaultQueryHandlerDNS

func (*DefaultQueryHandlerDNS) Query

func (df *DefaultQueryHandlerDNS) Query(host string, query *dns.Msg, protocol string, timeout time.Duration, tlsConfig *tls.Config) (*dns.Msg, time.Duration, error)

type DefaultQuicQueryHandler

type DefaultQuicQueryHandler struct {
	Conn net.PacketConn
}

func (*DefaultQuicQueryHandler) Query

func (d *DefaultQuicQueryHandler) Query(ctx context.Context, addr net.Addr, tlsConf *tls.Config, conf *quic.Config) (QuicConn, error)

type DoEQuery

type DoEQuery struct {
	DNSQuery

	SkipCertificateVerify bool   `json:"skip_certificate_verify"`
	SNI                   string `json:"sni"`
}

type DoEResponse

type DoEResponse struct {
	DNSResponse

	TLSVersion          string `json:"tls_version"`
	TLSCipherSuite      string `json:"tls_cipher_suite"`
	CertificateVerified bool   `json:"certificate_verified"`
	CertificateValid    bool   `json:"certificate_valid"`
}

type DoHQuery

type DoHQuery struct {
	DoEQuery

	// the URI path for the DoH query, usually /dns-query{?dns}
	URI string `json:"uri"`

	// HTTP method, either GET or POST
	Method string `json:"method"`

	// fallback to POST request if GET request is too long for URI (default: true)
	POSTFallback bool `json:"post_fallback"`

	// HTTP1, HTTP2 or HTTP3 support (default:HTTP2)
	HTTPVersion string `json:"http_version"`
}

func NewDoHQuery

func NewDoHQuery() (q *DoHQuery)

type DoHQueryHandler

type DoHQueryHandler struct {
	// QueryHandler is an interface to execute HTTP requests
	QueryHandler HttpQueryHandler
}

func NewDoHQueryHandler

func NewDoHQueryHandler(config *QueryConfig) (*DoHQueryHandler, error)

func (*DoHQueryHandler) Query

type DoHResponse

type DoHResponse struct {
	DoEResponse
}

type DoQQuery

type DoQQuery struct {
	DoEQuery
}

func NewDoQQuery

func NewDoQQuery() (q *DoQQuery)

type DoQQueryHandler

type DoQQueryHandler struct {
	// QueryHandler is the QUIC dial handler (defaults to quic.DialAddr)
	QueryHandler QuicQueryHandler
}

func NewDoQQueryHandler

func NewDoQQueryHandler(config *QueryConfig) (*DoQQueryHandler, error)

func (*DoQQueryHandler) Query

This DoQ implementation is inspired by the q library, see https://github.com/natesales/q/blob/main/transport/quic.go

type DoQResponse

type DoQResponse struct {
	DoEResponse
}

type DoTQuery

type DoTQuery struct {
	DoEQuery
}

func NewDoTQuery

func NewDoTQuery() (q *DoTQuery)

type DoTQueryHandler

type DoTQueryHandler interface {
	Query(host string, query *dns.Msg, timeout time.Duration, tlsConfig *tls.Config) (answer *dns.Msg, rtt time.Duration, tlsConnState *tls.ConnectionState, err error)
}

type DoTResponse

type DoTResponse struct {
	DoEResponse
}

type HttpQueryHandler

type HttpQueryHandler interface {
	Query(httpReq *http.Request, httpVersion string, timeout time.Duration, transport http.RoundTripper) (*dns.Msg, time.Duration, *tls.ConnectionState, error)
}

type PTRQuery

type PTRQuery struct {
	ConventionalDNSQuery
}

func NewPTRQuery

func NewPTRQuery() *PTRQuery

func (*PTRQuery) SetQueryMsg

func (p *PTRQuery) SetQueryMsg(resolveIp string) custom_errors.DoEErrors

type QueryConfig

type QueryConfig struct {
	LocalAddr net.IP
}

type QueryHandler

type QueryHandler interface {
	Query(query *DNSQuery) (res *QueryResponse, err error)
}

type QueryHandlerDNS

type QueryHandlerDNS interface {
	Query(host string, query *dns.Msg, protocol string, timeout time.Duration, tlsConfig *tls.Config) (answer *dns.Msg, rtt time.Duration, err error)
}

type QueryResponse

type QueryResponse struct {
	DNSResponse
}

type QuicConn

type QuicConn interface {
	CloseWithError(quic.ApplicationErrorCode, string) error
	OpenStream() (quic.Stream, error)
	ConnectionState() quic.ConnectionState
}

type QuicQueryHandler

type QuicQueryHandler interface {
	Query(ctx context.Context, addr net.Addr, tlsConf *tls.Config, conf *quic.Config) (QuicConn, error)
}

type SSHDialWrapper

type SSHDialWrapper struct{}

func (*SSHDialWrapper) NewClientConn

func (sc *SSHDialWrapper) NewClientConn(c net.Conn, addr string, config *ssh.ClientConfig) (ssh.Conn, <-chan ssh.NewChannel, <-chan *ssh.Request, error)

type SSHDialer

type SSHDialer interface {
	NewClientConn(c net.Conn, addr string, config *ssh.ClientConfig) (ssh.Conn, <-chan ssh.NewChannel, <-chan *ssh.Request, error)
}

type SSHQuery

type SSHQuery struct {
	Host     string `json:"host"`
	Port     int    `json:"port"`
	Timeout  time.Duration
	Username string `json:"username"`
}

func NewSSHQuery

func NewSSHQuery(host string) *SSHQuery

type SSHQueryHandler

type SSHQueryHandler struct {
	TCPDialer TCPDialer
	SSHDialer SSHDialer
}

func NewSSHQueryHandler

func NewSSHQueryHandler(config *QueryConfig) *SSHQueryHandler

func (*SSHQueryHandler) Query

type SSHResponse

type SSHResponse struct {
	SSHEnabled        bool                      `json:"ssh_enabled"`
	PubKeyType        string                    `json:"pub_key_type"`
	PubKeyFingerprint string                    `json:"pub_key_fingerprint"`
	OpenSSHServer     bool                      `json:"openssh_server"`
	Errors            []custom_errors.DoEErrors `json:"errors"`
}

type TCPDialer

type TCPDialer interface {
	Dial(network, address string) (net.Conn, error)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL