extension

package
v4.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package extension provides TLS extension framing and payload codecs.

Index

Constants

This section is empty.

Variables

View Source
var ErrALPNInvalidFormat = dtlserrors.ErrALPNInvalidFormat

ErrALPNInvalidFormat is raised when the ALPN format is invalid.

Functions

func ALPNProtocolSelection

func ALPNProtocolSelection(supportedProtocols, peerSupportedProtocols []string) (string, error)

ALPNProtocolSelection negotiates a shared protocol according to #3.2 of rfc7301.

func MarshalList

func MarshalList(values []Value) ([]byte, error)

MarshalList frames extension payloads as a uint16-length-prefixed list.

func MarshalListSize

func MarshalListSize(values []Value) int

MarshalListSize returns the size of a framed extension list without serializing extension payloads.

func MarshalListTo

func MarshalListTo(out []byte, values []Value) (int, error)

MarshalListTo frames extension payloads into out without retaining another encoded copy of the list.

func MarshalRawList

func MarshalRawList(values []Raw) ([]byte, error)

MarshalRawList frames raw extensions without decoding their payloads.

Types

type ALPNOffer

type ALPNOffer struct {
	Protocols []string
}

ALPNOffer is the ClientHello application_layer_protocol_negotiation payload.

func (ALPNOffer) ExtensionType

func (ALPNOffer) ExtensionType() Type

func (ALPNOffer) MarshalData

func (a ALPNOffer) MarshalData() ([]byte, error)

func (ALPNOffer) MarshalSize

func (a ALPNOffer) MarshalSize() int

func (*ALPNOffer) UnmarshalData

func (a *ALPNOffer) UnmarshalData(data []byte) error

type ALPNSelection

type ALPNSelection struct {
	Protocol string
}

ALPNSelection is the server's single selected ALPN protocol.

func (ALPNSelection) ExtensionType

func (ALPNSelection) ExtensionType() Type

func (ALPNSelection) MarshalData

func (a ALPNSelection) MarshalData() ([]byte, error)

func (ALPNSelection) MarshalSize

func (a ALPNSelection) MarshalSize() int

func (*ALPNSelection) UnmarshalData

func (a *ALPNSelection) UnmarshalData(data []byte) error

type CertificateSignatureAlgorithms

type CertificateSignatureAlgorithms struct {
	Schemes []uint16
}

CertificateSignatureAlgorithms is the signature_algorithms_cert payload.

func (CertificateSignatureAlgorithms) ExtensionType

func (CertificateSignatureAlgorithms) ExtensionType() Type

func (CertificateSignatureAlgorithms) MarshalData

func (s CertificateSignatureAlgorithms) MarshalData() ([]byte, error)

func (CertificateSignatureAlgorithms) MarshalSize

func (s CertificateSignatureAlgorithms) MarshalSize() int

func (*CertificateSignatureAlgorithms) UnmarshalData

func (s *CertificateSignatureAlgorithms) UnmarshalData(data []byte) error

type ConnectionID

type ConnectionID struct {
	// A zero-length connection ID indicates for a client or server that
	// negotiated connection IDs from the peer will be sent but there is no need
	// to respond with one
	CID []byte // variable length
}

ConnectionID is a DTLS extension that provides an alternative to IP address and port for session association.

https://tools.ietf.org/html/rfc9146

func (ConnectionID) ExtensionType

func (c ConnectionID) ExtensionType() Type

ExtensionType returns the IANA extension type for the payload-oriented API.

func (ConnectionID) MarshalData

func (c ConnectionID) MarshalData() ([]byte, error)

MarshalData encodes extension_data without the extension header.

func (ConnectionID) MarshalSize

func (c ConnectionID) MarshalSize() int

MarshalSize returns the encoded payload size without serializing it.

func (*ConnectionID) UnmarshalData

func (c *ConnectionID) UnmarshalData(data []byte) error

UnmarshalData decodes extension_data without the extension header.

type PayloadUnmarshaller

type PayloadUnmarshaller interface {
	UnmarshalData(data []byte) error
}

PayloadUnmarshaller decodes extension_data without the extension header.

type PreparedList

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

PreparedList contains validated extension payloads ready to be framed.

func PrepareList

func PrepareList(values []Value) (PreparedList, error)

PrepareList serializes and validates extension payloads without allocating the final list.

func (PreparedList) MarshalSize

func (p PreparedList) MarshalSize() int

MarshalSize returns the exact size of the prepared framed extension list.

func (PreparedList) MarshalTo

func (p PreparedList) MarshalTo(out []byte) (int, error)

MarshalTo writes a prepared framed extension list to out.

type Raw

type Raw struct {
	Type Type
	Data []byte
}

Raw is a lossless representation of an extension whose payload has not been decoded. Data does not include the type or length fields.

func ParseList

func ParseList(buf []byte) ([]Raw, error)

ParseList parses a complete uint16-length-prefixed extension list. It validates framing only and preserves unknown extensions, order, and duplicates for contextual processing by the caller.

func (Raw) ExtensionType

func (r Raw) ExtensionType() Type

ExtensionType returns the extension type.

func (Raw) MarshalData

func (r Raw) MarshalData() ([]byte, error)

MarshalData returns a copy of the undecoded payload.

func (Raw) MarshalSize

func (r Raw) MarshalSize() int

MarshalSize returns the encoded payload size without serializing it.

func (*Raw) UnmarshalData

func (r *Raw) UnmarshalData(data []byte) error

UnmarshalData replaces the undecoded payload with a copy of data.

type ReturnRoutabilityCheck

type ReturnRoutabilityCheck struct{}

ReturnRoutabilityCheck negotiates the RFC 9853 RRC subprotocol.

func (ReturnRoutabilityCheck) ExtensionType

func (ReturnRoutabilityCheck) ExtensionType() Type

ExtensionType returns the IANA extension type for RRC.

func (ReturnRoutabilityCheck) MarshalData

func (ReturnRoutabilityCheck) MarshalData() ([]byte, error)

MarshalData returns the empty RRC extension_data.

func (ReturnRoutabilityCheck) MarshalSize

func (ReturnRoutabilityCheck) MarshalSize() int

MarshalSize returns the encoded payload size.

func (*ReturnRoutabilityCheck) UnmarshalData

func (*ReturnRoutabilityCheck) UnmarshalData(data []byte) error

UnmarshalData validates the empty RRC extension_data.

type SRTPOffer

type SRTPOffer struct {
	ProtectionProfiles  []SRTPProtectionProfile
	MasterKeyIdentifier []byte
}

SRTPOffer is the ClientHello use_srtp payload.

func (SRTPOffer) ExtensionType

func (SRTPOffer) ExtensionType() Type

func (SRTPOffer) MarshalData

func (s SRTPOffer) MarshalData() ([]byte, error)

func (SRTPOffer) MarshalSize

func (s SRTPOffer) MarshalSize() int

func (*SRTPOffer) UnmarshalData

func (s *SRTPOffer) UnmarshalData(data []byte) error

type SRTPProtectionProfile

type SRTPProtectionProfile uint16

SRTPProtectionProfile defines the parameters and options that are in effect for the SRTP processing https://tools.ietf.org/html/rfc5764#section-4.1.2

const (
	SRTP_AES128_CM_HMAC_SHA1_80 SRTPProtectionProfile = 0x0001 // nolint
	SRTP_AES128_CM_HMAC_SHA1_32 SRTPProtectionProfile = 0x0002 // nolint
	SRTP_AES256_CM_SHA1_80      SRTPProtectionProfile = 0x0003 // nolint
	SRTP_AES256_CM_SHA1_32      SRTPProtectionProfile = 0x0004 // nolint
	SRTP_NULL_HMAC_SHA1_80      SRTPProtectionProfile = 0x0005 // nolint
	SRTP_NULL_HMAC_SHA1_32      SRTPProtectionProfile = 0x0006 // nolint
	SRTP_AEAD_AES_128_GCM       SRTPProtectionProfile = 0x0007 // nolint
	SRTP_AEAD_AES_256_GCM       SRTPProtectionProfile = 0x0008 // nolint
)

type SRTPSelection

type SRTPSelection struct {
	ProtectionProfile   SRTPProtectionProfile
	MasterKeyIdentifier []byte
}

SRTPSelection is the server's single selected SRTP profile.

func (SRTPSelection) ExtensionType

func (SRTPSelection) ExtensionType() Type

func (SRTPSelection) MarshalData

func (s SRTPSelection) MarshalData() ([]byte, error)

func (SRTPSelection) MarshalSize

func (s SRTPSelection) MarshalSize() int

func (*SRTPSelection) UnmarshalData

func (s *SRTPSelection) UnmarshalData(data []byte) error

type ServerNameAck

type ServerNameAck struct{}

ServerNameAck is the empty server acknowledgement payload.

func (ServerNameAck) ExtensionType

func (ServerNameAck) ExtensionType() Type

func (ServerNameAck) MarshalData

func (ServerNameAck) MarshalData() ([]byte, error)

func (ServerNameAck) MarshalSize

func (ServerNameAck) MarshalSize() int

func (*ServerNameAck) UnmarshalData

func (*ServerNameAck) UnmarshalData(data []byte) error

type ServerNameOffer

type ServerNameOffer struct {
	ServerName string
}

ServerNameOffer is the ClientHello server_name payload.

func (ServerNameOffer) ExtensionType

func (ServerNameOffer) ExtensionType() Type

func (ServerNameOffer) MarshalData

func (s ServerNameOffer) MarshalData() ([]byte, error)

func (ServerNameOffer) MarshalSize

func (s ServerNameOffer) MarshalSize() int

func (*ServerNameOffer) UnmarshalData

func (s *ServerNameOffer) UnmarshalData(data []byte) error

type SignatureAlgorithms

type SignatureAlgorithms struct {
	Schemes []uint16
}

SignatureAlgorithms is the signature_algorithms payload. Scheme values are kept as wire identifiers so unknown values are not discarded by framing.

func (SignatureAlgorithms) ExtensionType

func (SignatureAlgorithms) ExtensionType() Type

func (SignatureAlgorithms) MarshalData

func (s SignatureAlgorithms) MarshalData() ([]byte, error)

func (SignatureAlgorithms) MarshalSize

func (s SignatureAlgorithms) MarshalSize() int

func (*SignatureAlgorithms) UnmarshalData

func (s *SignatureAlgorithms) UnmarshalData(data []byte) error

type SupportedGroups

type SupportedGroups struct {
	Groups []elliptic.Curve
}

SupportedGroups is the supported_groups payload.

func (SupportedGroups) ExtensionType

func (SupportedGroups) ExtensionType() Type

func (SupportedGroups) MarshalData

func (s SupportedGroups) MarshalData() ([]byte, error)

func (SupportedGroups) MarshalSize

func (s SupportedGroups) MarshalSize() int

func (*SupportedGroups) UnmarshalData

func (s *SupportedGroups) UnmarshalData(data []byte) error

type Type

type Type uint16

Type is the two-byte value assigned to a TLS extension by IANA.

const (
	TypeServerName              Type = 0
	TypeSupportedGroups         Type = 10
	TypeSupportedPointFormats   Type = 11
	TypeSignatureAlgorithms     Type = 13
	TypeUseSRTP                 Type = 14
	TypeALPN                    Type = 16
	TypePadding                 Type = 21
	TypeExtendedMasterSecret    Type = 23
	TypePreSharedKey            Type = 41
	TypeEarlyData               Type = 42
	TypeSupportedVersions       Type = 43
	TypeCookie                  Type = 44
	TypePSKKeyExchangeModes     Type = 45
	TypeCertificateAuthorities  Type = 47
	TypeOIDFilters              Type = 48
	TypePostHandshakeAuth       Type = 49
	TypeSignatureAlgorithmsCert Type = 50
	TypeKeyShare                Type = 51
	TypeConnectionID            Type = 54
	TypeReturnRoutabilityCheck  Type = 61
	TypeECHOuterExtensions      Type = 64768
	TypeEncryptedClientHello    Type = 65037
	TypeRenegotiationInfo       Type = 65281
)

type Value

type Value interface {
	ExtensionType() Type
	MarshalSize() int
	MarshalData() ([]byte, error)
}

Value is an extension payload that can be framed in an extension list.

Directories

Path Synopsis
Package dtls12 implements extension payloads specific to DTLS 1.2.
Package dtls12 implements extension payloads specific to DTLS 1.2.
Package dtls13 implements extension payloads specific to DTLS 1.3.
Package dtls13 implements extension payloads specific to DTLS 1.3.

Jump to

Keyboard shortcuts

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