recordlayer

package
v2.0.0-...-8205865 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package recordlayer implements the TLS Record Layer https://tools.ietf.org/html/rfc5246#section-6

Index

Constants

View Source
const (
	// FixedHeaderSize is the size of a DTLS record header when connection IDs
	// are not in use.
	FixedHeaderSize   = 13
	MaxSequenceNumber = 0x0000FFFFFFFFFFFF
)

RecordLayer enums

Variables

View Source
var (
	// ErrInvalidPacketLength is returned when the packet length too small or declared length do not match
	ErrInvalidPacketLength = &protocol.TemporaryError{Err: errors.New("packet length and declared length do not match")} //nolint:goerr113

)

Functions

func ContentAwareUnpackDatagram

func ContentAwareUnpackDatagram(buf []byte, cidLength int) ([][]byte, error)

ContentAwareUnpackDatagram is the same as UnpackDatagram but considers the presence of a connection identifier if the record is of content type tls12_cid.

func UnpackDatagram

func UnpackDatagram(buf []byte) ([][]byte, error)

UnpackDatagram extracts all RecordLayer messages from a single datagram. Note that as with TLS, multiple handshake messages may be placed in the same DTLS record, provided that there is room and that they are part of the same flight. Thus, there are two acceptable ways to pack two DTLS messages into the same datagram: in the same record or in separate records. https://tools.ietf.org/html/rfc6347#section-4.2.3

Types

type Header struct {
	ContentType    protocol.ContentType
	ContentLen     uint16
	Version        protocol.Version
	Epoch          uint16
	SequenceNumber uint64 // uint48 in spec

	// Optional Fields
	ConnectionID []byte
}

Header implements a TLS RecordLayer header

func (*Header) Marshal

func (h *Header) Marshal() ([]byte, error)

Marshal encodes a TLS RecordLayer Header to binary

func (*Header) Size

func (h *Header) Size() int

Size returns the total size of the header.

func (*Header) Unmarshal

func (h *Header) Unmarshal(data []byte) error

Unmarshal populates a TLS RecordLayer Header from binary

type InnerPlaintext

type InnerPlaintext struct {
	Content  []byte
	RealType protocol.ContentType
	Zeros    uint
}

InnerPlaintext implements DTLSInnerPlaintext

https://datatracker.ietf.org/doc/html/rfc9146#name-record-layer-extensions

func (*InnerPlaintext) Marshal

func (p *InnerPlaintext) Marshal() ([]byte, error)

Marshal encodes a DTLS InnerPlaintext to binary

func (*InnerPlaintext) Unmarshal

func (p *InnerPlaintext) Unmarshal(data []byte) error

Unmarshal populates a DTLS InnerPlaintext from binary

type RecordLayer

type RecordLayer struct {
	Header  Header
	Content protocol.Content
}

RecordLayer which handles all data transport. The record layer is assumed to sit directly on top of some reliable transport such as TCP. The record layer can carry four types of content:

1. Handshake messages—used for algorithm negotiation and key establishment. 2. ChangeCipherSpec messages—really part of the handshake but technically a separate kind of message. 3. Alert messages—used to signal that errors have occurred 4. Application layer data

The DTLS record layer is extremely similar to that of TLS 1.1. The only change is the inclusion of an explicit sequence number in the record. This sequence number allows the recipient to correctly verify the TLS MAC.

https://tools.ietf.org/html/rfc4347#section-4.1

func (*RecordLayer) Marshal

func (r *RecordLayer) Marshal() ([]byte, error)

Marshal encodes the RecordLayer to binary

func (*RecordLayer) Unmarshal

func (r *RecordLayer) Unmarshal(data []byte) error

Unmarshal populates the RecordLayer from binary

Jump to

Keyboard shortcuts

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