tlssynth

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package tlssynth builds synthetic TLS handshake bytes for tests and for generating sample captures.

It deliberately does not import tlsparse and defines its own codepoint constants. A test oracle that shares definitions with the code under test cannot catch a wrong constant: rename a value in the parser and a shared table follows it silently. Keeping the two independent means the builders encode what the RFCs say, and the parser has to agree with that.

Index

Constants

View Source
const (
	RecordHandshake        uint8 = 22
	RecordChangeCipherSpec uint8 = 20
	RecordApplicationData  uint8 = 23

	MsgClientHello       uint8 = 1
	MsgServerHello       uint8 = 2
	MsgCertificate       uint8 = 11
	MsgServerKeyExchange uint8 = 12
	MsgServerHelloDone   uint8 = 14
)

Codepoints used by the builders, written out independently of the parser.

View Source
const QUICVersion1 uint32 = 0x00000001

QUICVersion1 is the version generated packets carry.

Variables

View Source
var HelloRetryRequestRandom = []byte{
	0xcf, 0x21, 0xad, 0x74, 0xe5, 0x9a, 0x61, 0x11,
	0xbe, 0x1d, 0x8c, 0x02, 0x1e, 0x65, 0xb8, 0x91,
	0xc2, 0xa2, 0x11, 0x16, 0x7a, 0xbb, 0x8c, 0x5e,
	0x07, 0x9e, 0x09, 0xe2, 0xc8, 0xa8, 0x33, 0x9c,
}

HelloRetryRequestRandom is the fixed Random marking a HelloRetryRequest (RFC 8446 section 4.1.3): SHA-256 of "HelloRetryRequest".

Functions

func CertificateMsg

func CertificateMsg(chain [][]byte) []byte

CertificateMsg builds a TLS 1.2 Certificate message body from raw DER.

func ClientHello

func ClientHello(s ClientHelloSpec) []byte

ClientHello builds a ClientHello message body, without the handshake header.

func CryptoFrame

func CryptoFrame(offset uint64, data []byte) []byte

CryptoFrame wraps handshake bytes in a QUIC CRYPTO frame at an offset.

func HandshakeMsg

func HandshakeMsg(typ uint8, body []byte) []byte

HandshakeMsg prefixes a body with its four-byte handshake header.

func KeyShareLen

func KeyShareLen(group uint16) int

KeyShareLen returns a realistic public key length for a group. The post-quantum sizes are the reason a PQ ClientHello does not fit in one TCP segment: X25519MLKEM768 alone is 1216 bytes of client share.

func QUICInitial

func QUICInitial(dcid, scid []byte, server bool, packetNumber uint32, frames []byte, padTo int) []byte

QUICInitial builds one protected Initial packet carrying frames.

padTo pads the packet with PADDING frames, as a client's first Initial must be (RFC 9000 requires at least 1200 bytes); pass 0 for none.

func Records

func Records(contentType uint8, payload []byte, chunk int) []byte

Records wraps a byte stream in TLS records of at most chunk bytes each. A chunk smaller than the payload exercises handshake fragmentation.

func ServerHello

func ServerHello(s ServerHelloSpec) []byte

ServerHello builds a ServerHello message body, without the handshake header.

func ServerKeyExchangeECDHE

func ServerKeyExchangeECDHE(group uint16) []byte

ServerKeyExchangeECDHE builds a TLS 1.2 ECDHE ServerKeyExchange body. It is the only place a TLS 1.2 handshake names its key exchange group.

Types

type ClientHelloSpec

type ClientHelloSpec struct {
	LegacyVersion     uint16
	Ciphers           []uint16
	Compression       []uint8
	SNI               string
	ALPN              []string
	SupportedVersions []uint16
	Groups            []uint16
	KeyShares         []uint16
	SigAlgs           []uint16
	ECH               bool
	QUIC              bool
	OmitExtensions    bool
	// NoGREASE suppresses the injected GREASE values, for building a
	// non-browser client.
	NoGREASE bool
}

ClientHelloSpec describes a ClientHello to build. GREASE values are added automatically in the places a real BoringSSL client puts them.

type ServerHelloSpec

type ServerHelloSpec struct {
	LegacyVersion   uint16
	Cipher          uint16
	SelectedVersion uint16
	Group           uint16
	ALPN            string
	HelloRetry      bool
}

ServerHelloSpec describes a ServerHello to build.

Jump to

Keyboard shortcuts

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