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 ¶
- func Client(ctx context.Context, conn net.Conn, hello fingerprint.Hello, cfg Config) (net.Conn, string, error)
- func ConnState(conn net.Conn) *tls.ConnectionState
- func Spec(h fingerprint.Hello) (*utls.ClientHelloSpec, error)
- func State(cs utls.ConnectionState) *tls.ConnectionState
- func TLSConfig(cfg Config) *utls.Config
- type Config
- type Ticket
- type Tickets
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 ¶
func Spec(h fingerprint.Hello) (*utls.ClientHelloSpec, error)
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 ¶
func State(cs utls.ConnectionState) *tls.ConnectionState
State is cs as crypto/tls describes it. ExportKeyingMaterial is not carried over: it fails on the result.
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
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).
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 ¶
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.