handshake

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package handshake performs the TLS handshake and ALPN from a fingerprint plan and keeps session tickets for resumption. Config.VerifyConnection runs in every handshake, resumed ones included.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Client

func Client(ctx context.Context, conn net.Conn, hello fingerprint.Hello, cfg Config) (net.Conn, string, error)

Client performs the TLS handshake on conn with hello and returns the TLS connection and the negotiated ALPN protocol. It honours ctx; on error conn is closed.

func ConnState

func ConnState(conn net.Conn) *tls.ConnectionState

ConnState is the TLS state of conn, a connection Client returned, as crypto/tls describes it; nil for any other connection.

func Spec

Spec turns a connection's ClientHello layout into a uTLS spec. GREASE placeholders, empty key shares and GREASE ECH's random fields are filled in by uTLS per connection, so a spec serves one connection.

func State

State is cs as crypto/tls describes it. ExportKeyingMaterial is not carried over: it fails on the result.

func TLSConfig

func TLSConfig(cfg Config) *utls.Config

TLSConfig is the uTLS configuration for cfg: its server name, roots and ticket cache, which QUIC uses for its 0-RTT tickets too. Both TCP and QUIC handshakes use it.

Types

type Config

type Config struct {
	// ServerName is sent in server_name and verified against the certificate.
	ServerName string
	// RootCAs verifies the server certificate; nil uses the system roots.
	RootCAs *x509.CertPool
	// Tickets, when set, keeps the server's TLS 1.3 tickets under
	// TicketKey for later connections. Nil: no resumption.
	Tickets   *Tickets
	TicketKey string
	// Ticket is the session this connection resumes; the hello must then
	// carry pre_shared_key (fingerprint.Plan.ResumedHello).
	Ticket *Ticket
	// VerifyConnection, when set, runs after certificate verification on
	// every handshake, resumed ones included, before any received ticket is
	// kept; an error fails the handshake.
	VerifyConnection func(tls.ConnectionState) error
}

Config is what a handshake needs besides the ClientHello.

type Ticket

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

Ticket is a session a connection resumes, taken from a Tickets.

func (*Ticket) EarlyData added in v0.3.0

func (t *Ticket) EarlyData() bool

EarlyData reports whether the ticket allows 0-RTT: its max_early_data_size is above 0. A browser offers early_data only then (fingerprint.Plan.ResumedQUICHello).

func (*Ticket) Extra

func (t *Ticket) Extra() [][]byte

Extra is the session's SessionState.Extra: what the connection that received the ticket stored with it (the QUIC version and transport parameters, quic.TicketVersion).

func (*Ticket) TLS13

func (t *Ticket) TLS13() bool

TLS13 reports a TLS 1.3 ticket, which the ClientHello offers in pre_shared_key (fingerprint.Plan.ResumedHello); a TLS 1.2 one goes in session_ticket of the full ClientHello.

type Tickets

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

Tickets keeps session tickets by key (host, port, partition) and uses them as the browser does: a TLS 1.3 ticket once, TLS 1.2 tickets by the profile's tls12 policy. A ticket uTLS would decline (expired lifetime or certificate) is never handed out, so a hello never looks resumed without resuming. Safe for concurrent use. See decision 0013.

func NewTickets

func NewTickets(tls12 string, clock clockwork.Clock) *Tickets

NewTickets returns an empty store using TLS 1.2 tickets as tls12 (profile.TLS12Reuse, profile.TLS12SingleUse, or "" for not at all), with clock telling expired tickets.

func (*Tickets) Drop added in v0.2.0

func (t *Tickets) Drop(key string)

Drop forgets key's ticket, if any.

func (*Tickets) Has

func (t *Tickets) Has(key string) bool

Has reports whether Take would return a ticket for key, without taking it or dropping an expired one.

func (*Tickets) Take

func (t *Tickets) Take(key string) *Ticket

Take returns the ticket a new connection for key offers, or nil. TLS 1.3 tickets, and TLS 1.2 ones under single use, leave the store: concurrent connections then resume one at a time. Expired tickets are dropped.

Jump to

Keyboard shortcuts

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