svcb

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2025 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package svcb deals with all the intricacies of the SVCB/HTTPS RR. All the sub-types ([Pairs]) used in the RR are defined here.

Index

Constants

View Source
const (
	KeyMandatory uint16 = iota
	KeyAlpn
	KeyNoDefaultALPN
	KeyPort
	KeyIPv4Hint
	KeyEchConfig
	KeyIPv6Hint
	KeyDohPath // See RFC 9461 Section 5.
	KeyOhttp   // See RFC 9540 Section 8.

	KeyReserved uint16 = 65535
)

Keys as defined in RFC 9460.

Variables

This section is empty.

Functions

func KeyToPair

func KeyToPair(k uint16) func() Pair

KeyToPair convert the key value to a Pair.

func KeyToString

func KeyToString(k uint16) string

KeyToString return the string representation for k. For KeyReserved the empty string is returned. For unknown keys "key"+value is returned, see section 2.1 of RFC 9460.

func Pack

func Pack(pairs []Pair, msg []byte, off int) (off1 int, err error)

func PairToKey

func PairToKey(p Pair) uint16

PairToKey is the reverse of KeyToPair.

func Parse

func Parse(p Pair, b, o string) error

func StringToKey

func StringToKey(s string) uint16

StringtoKey is the reverse of KeyToString and takes keyXXXX into account.

Types

type ALPN

type ALPN struct {
	Alpn []string
}

ALPN pair is used to list supported connection protocols. The user of this library must ensure that at least one protocol is listed when alpn is present. Protocol IDs can be found at: https://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml#alpn-protocol-ids Basic use pattern for creating an ALPN option, in a SVCB RR called s:

e := svcb.ALPN{Alpn: []string{"h2", "http/1.1"}}
s.Value = append(s.Value, e)

func (*ALPN) Clone added in v0.5.4

func (s *ALPN) Clone() Pair

func (*ALPN) Len

func (s *ALPN) Len() int

func (*ALPN) String

func (s *ALPN) String() string

type DOHPATH

type DOHPATH struct {
	Template string
}

DOHPATH pair is used to indicate the URI template that the clients may use to construct a DNS over HTTPS URI.

See RFC 9461 (https://datatracker.ietf.org/doc/html/rfc9461) and RFC 9462 (https://datatracker.ietf.org/doc/html/rfc9462).

A basic example of using the dohpath option together with the alpn option to indicate support for DNS over HTTPS on a certain path:

e := &svcb.ALPN{Alpn: []string{"h2", "h3"}}
p := &svcb.DOHPATH{Template: "/dns-query{?dns}"}
s.Value = append(s.Value, e, p)

The parsing currently doesn't validate that Template is a valid RFC 6570 URI template.

func (*DOHPATH) Clone added in v0.5.4

func (s *DOHPATH) Clone() Pair

func (*DOHPATH) Len

func (s *DOHPATH) Len() int

func (*DOHPATH) String

func (s *DOHPATH) String() string

type ECHCONFIG

type ECHCONFIG struct {
	ECH []byte // Specifically ECHConfigList including the redundant length prefix.
}

ECHCONFIG pair contains the ECHConfig structure defined in draft-ietf-tls-esni [RFC xxxx]. Basic use pattern for creating an ech option:

h := &dns.HTTPS{Hdr: dns.Header{Name: ".", Class: dns.ClassINET}}
e := &svcb.ECHCONFIG{ECH: []byte{0xfe, 0x08, ...}}
h.Value = append(h.Value, e)

func (*ECHCONFIG) Clone added in v0.5.4

func (s *ECHCONFIG) Clone() Pair

func (*ECHCONFIG) Len

func (s *ECHCONFIG) Len() int

func (*ECHCONFIG) String

func (s *ECHCONFIG) String() string

type IPV4HINT

type IPV4HINT struct {
	Hint []netip.Addr
}

IPV4HINT pair suggests an IPv4 address which may be used to open connections if A and AAAA record responses for SVCB's Target domain haven't been received. In that case, optionally, A and AAAA requests can be made, after which the connection to the hinted IP address may be terminated and a new connection may be opened. Basic use pattern for creating an ipv4hint option:

 h := &dns.HTTPS{Hdr: dns.Header{Name: ".", Class: dns.ClassINET}}
 e := &svcb.IPV4HINT{Hint: []netip.Addr{netip.MustParseAddr("1.1.1.1")}}

Or

 e.Hint = []netip.Addr{netip.MustParseAddr("1.1.1.1")}
 h.Value = append(h.Value, e)

func (*IPV4HINT) Clone added in v0.5.4

func (s *IPV4HINT) Clone() Pair

func (*IPV4HINT) Len

func (s *IPV4HINT) Len() int

func (*IPV4HINT) String

func (s *IPV4HINT) String() string

type IPV6HINT

type IPV6HINT struct {
	Hint []netip.Addr
}

IPV6HINT pair suggests an IPv6 address which may be used to open connections if A and AAAA record responses for SVCB's Target domain haven't been received. In that case, optionally, A and AAAA requests can be made, after which the connection to the hinted IP address may be terminated and a new connection may be opened. Basic use pattern for creating an ipv6hint option:

h := &dns.HTTPS{Hdr: dns.Header{Name: ".", Class: dns.ClassINET}}
e := &svcb.IPV6HINT{Hint: []netip.Addr{netip.MustParseAddr("2001:db8::1")}}
h.Value = append(h.Value, e)

func (*IPV6HINT) Clone added in v0.5.4

func (s *IPV6HINT) Clone() Pair

func (*IPV6HINT) Len

func (s *IPV6HINT) Len() int

func (*IPV6HINT) String

func (s *IPV6HINT) String() string

type LOCAL

type LOCAL struct {
	KeyCode uint16 // Just like as in RFC 5559.
	Data    []byte // All byte sequences are allowed.
}

LOCAL pair is intended for experimental/private use. The key is recommended to be in the range [SVCB_PRIVATE_LOWER, SVCB_PRIVATE_UPPER]. Basic use pattern for creating a keyNNNNN option:

h := &dns.HTTPS{Hdr: dns.Header{Name: ".", Class: dns.ClassINET}}
e := &svcb.LOCAL{KeyCode: 65400, Data: []byte("abc")}
h.Value = append(h.Value, e)

func (*LOCAL) Clone added in v0.5.4

func (s *LOCAL) Clone() Pair

func (*LOCAL) Len

func (s *LOCAL) Len() int

func (*LOCAL) String

func (s *LOCAL) String() string

type MANDATORY

type MANDATORY struct {
	Key []uint16
}

MANDATORY pair adds to required keys that must be interpreted for the RR to be functional. If ignored, the whole RRSet must be ignored. "port" and "no-default-alpn" are mandatory by default if present, so they shouldn't be included here.

It is incumbent upon the user of this library to reject the RRSet if or avoid constructing such an RRSet that:

  • "mandatory" is included as one of the keys of mandatory
  • no key is listed multiple times in mandatory
  • all keys listed in mandatory are present
  • escape sequences are not used in mandatory
  • mandatory, when present, lists at least one key

Basic use pattern for creating a mandatory option in a SVCB RR, called s:

s.Value = append(s.Value, &svcb.MANDATORY{})
t := &svcb.ALPN{Alpn: []string{"xmpp-client"}}
s.Value = append(s.Value, t)

func (*MANDATORY) Clone added in v0.5.4

func (s *MANDATORY) Clone() Pair

func (*MANDATORY) Len

func (s *MANDATORY) Len() int

func (*MANDATORY) String

func (s *MANDATORY) String() string

type NODEFAULTALPN

type NODEFAULTALPN struct{}

NODEFAULTALPN pair signifies no support for default connection protocols. Should be used in conjunction with alpn. Basic use pattern for creating a no-default-alpn option:

t := &svcb.ALPN{Alpn: []string{"xmpp-client"}}
s.Value = append(s.Value, t)
e := &svcb.NODEFAULTALPN{}
s.Value = append(s.Value, e)

func (*NODEFAULTALPN) Clone added in v0.5.4

func (*NODEFAULTALPN) Clone() Pair

func (*NODEFAULTALPN) Len

func (*NODEFAULTALPN) Len() int

func (*NODEFAULTALPN) String

func (*NODEFAULTALPN) String() string

type OHTTP

type OHTTP struct{}

The "ohttp" SvcParamKey is used to indicate that a service described in a SVCB RR can be accessed as a target using an associated gateway. Both the presentation and wire-format values for the "ohttp" parameter MUST be empty.

See RFC 9460 (https://datatracker.ietf.org/doc/html/rfc9460/) and RFC 9230 (https://datatracker.ietf.org/doc/html/rfc9230/)

A basic example of using the dohpath option together with the alpn option to indicate support for DNS over HTTPS on a certain path:

e := &dns.ALPN{Alpn: []string{"h2", "h3"}}
p := &svcb.OHTTP{}
s.Value = append(s.Value, e, p)

func (*OHTTP) Clone added in v0.5.4

func (*OHTTP) Clone() Pair

func (*OHTTP) Len

func (*OHTTP) Len() int

func (*OHTTP) String

func (*OHTTP) String() string

type PORT

type PORT struct {
	Port uint16
}

PORT pair defines the port for connection. Basic use pattern for creating a port option:

s.Value = append(s.Value, &svcb.PORT{Port: 80})

func (*PORT) Clone added in v0.5.4

func (s *PORT) Clone() Pair

func (*PORT) Len

func (*PORT) Len() int

func (*PORT) String

func (s *PORT) String() string

type Pair

type Pair interface {
	String() string // String returns the string representation of the value.
	Len() int       // Len returns the length of value in the wire format.
	Clone() Pair    // Clone returns a deep copy of the Pair.
}

Pair defines a key=value pair for the SVCB RR type. An SVCB RR can have multiple pairs appended to it. The numerical key code is derived from the type, see PairToKey.

func Unpack

func Unpack(s *cryptobyte.String) ([]Pair, error)

Jump to

Keyboard shortcuts

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