dns

package
v0.0.0-...-926f593 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NonceLen   = 12
	RetryCount = 10
)

DoH client constants.

Variables

View Source
var (
	// ErrorTimeout defines a timeout error.
	ErrorTimeout = errors.New("timeout")
)

Functions

func Decrypt

func Decrypt(key, data []byte) ([]byte, error)

Decrypt decrypts the data with the key.

func Encrypt

func Encrypt(key, data []byte) ([]byte, error)

Encrypt encrypts the data with the key.

func FlushCache

func FlushCache() error

FlushCache flushes DNS cache.

func GetServers

func GetServers() ([]string, error)

GetServers returns the list of system DNS servers.

func RestoreServers

func RestoreServers(servers []string) error

RestoreServers restores the system DNS servers.

func SetServers

func SetServers(servers []string) error

SetServers sets the system DNS servers.

Types

type Certificate

type Certificate struct {
	X509     *x509.Certificate
	LastSeen time.Time
}

Certificate defines a certificate.

func (*Certificate) Encrypt

func (cert *Certificate) Encrypt(data []byte) ([]byte, error)

Encrypt encrypts the data with the certificate.

func (*Certificate) ID

func (cert *Certificate) ID() string

ID returns the certificate ID as string.

type Client

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

Client implements DNS client.

func NewClient

func NewClient(server string) (*Client, error)

NewClient creates a new DNS client.

func (*Client) Resolve

func (client *Client) Resolve(name string) ([]ResolveResult, error)

Resolve resolves the DNS name.

type CreateSA

type CreateSA struct {
	SAs []*Envelope
}

CreateSA defines a create SA request.

type DoHClient

type DoHClient struct {
	URL string

	OAuth2  *auth.OAuth2Client
	Proxy   string
	Encrypt bool
	// contains filtered or unexported fields
}

DoHClient implements a DoH client.

func NewDoHClient

func NewDoHClient(server string, oauth2 *auth.OAuth2Client, proxy string) (
	*DoHClient, error)

NewDoHClient creates a new DoH client.

func (*DoHClient) AddCertificate

func (doh *DoHClient) AddCertificate(data []byte) (*Certificate, error)

AddCertificate adds certificates to the DoH client.

func (*DoHClient) AddPassthrough

func (doh *DoHClient) AddPassthrough(u string) error

AddPassthrough adds a passthrough name for the client.

func (*DoHClient) Certificate

func (doh *DoHClient) Certificate() ([]*Certificate, error)

Certificate returns certificates.

func (*DoHClient) CreateSA

func (doh *DoHClient) CreateSA(sa *SA) error

CreateSA creates a security association with the DoH server.

func (*DoHClient) Do

func (doh *DoHClient) Do(data []byte) ([]byte, error)

Do does an DoH operation.

func (*DoHClient) Passthrough

func (doh *DoHClient) Passthrough(host string) bool

Passthrough tests if the host is passed through to the system DNS resolver instead of using the DoH server.

func (*DoHClient) SA

func (doh *DoHClient) SA() (*SA, error)

SA returns a security association.

func (*DoHClient) Token

func (doh *DoHClient) Token() (string, error)

Token returns the OAuth2 authentication token.

type Envelope

type Envelope struct {
	Data  []byte `json:"data"`
	KeyID string `json:"key_id"`
}

Envelope implements an encrypted data with encryption key ID.

type Event

type Event struct {
	Type   EventType
	Labels Labels
}

Event defines proxy events.

type EventType

type EventType int

EventType defines proxy events.

const (
	EventQuery EventType = iota
	EventBlock
	EventConfig
)

Proxy event types.

func (EventType) String

func (t EventType) String() string

type Labels

type Labels []string

Labels define DNS labels.

func NewLabels

func NewLabels(name string) Labels

NewLabels creates new labels instance from the argument string.q

func ReadBlacklist

func ReadBlacklist(name string) ([]Labels, error)

ReadBlacklist reads the blacklist from the file.

func (Labels) Match

func (l Labels) Match(o Labels) bool

Match tests if the argument labels match this label instance.

func (Labels) String

func (l Labels) String() string

type Pending

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

Pending defines a pending DNS query.

type Proxy

type Proxy struct {
	Verbose   int
	Blacklist []Labels
	Events    chan Event
	DoH       *DoHClient
	NoPad     bool
	// contains filtered or unexported fields
}

Proxy defines a DNS proxy.

func NewProxy

func NewProxy(server string, out io.Writer) (*Proxy, error)

NewProxy creates a new DNS proxy.

func (*Proxy) Query

func (p *Proxy) Query(packet gopacket.Packet, dns *layers.DNS) error

Query starts a new DNS query.

func (*Proxy) SetServer

func (p *Proxy) SetServer(server string) error

SetServer sets the DNS server to use for the proxy queries.

type ResolveResult

type ResolveResult struct {
	Address  string
	NotAfter time.Time
}

ResolveResult provides DNS resolve results.

type SA

type SA struct {
	ID      string
	Key     []byte
	Created time.Time
}

SA implements a security association.

type UDPClient

type UDPClient struct {
	Server string
	Conn   net.Conn
	C      chan []byte
}

UDPClient implements an UDP client.

func NewUDPClient

func NewUDPClient(server string, c chan []byte) (*UDPClient, error)

NewUDPClient creates a new UDP client.

func (*UDPClient) Close

func (dns *UDPClient) Close() error

Close closes the UDP client.

func (*UDPClient) Write

func (dns *UDPClient) Write(data []byte) error

Jump to

Keyboard shortcuts

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