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 ¶
- Variables
- func Client(ctx context.Context, conn net.Conn, hello fingerprint.Hello, cfg Config) (net.Conn, string, error)
- func ClientIdentified(conn net.Conn) bool
- 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 ECHConfig
- type ECHRejectedError
- type Saved
- type Store
- type Ticket
- type Tickets
Constants ¶
This section is empty.
Variables ¶
var ErrMalformedECH = errors.New("handshake: an ECH config list that does not parse")
ErrMalformedECH is an ECH config list that does not parse (RFC 9849, section 4), from a server's DNS HTTPS record.
var ErrRestart = errors.New("handshake: connection dropped at the host's first CertificateRequest, to be made again")
ErrRestart reports a connection Client closed at its host's first CertificateRequest, sending nothing, as the profile's browser does (tls.clientAuth.restart): the request goes again on a new connection, which answers it.
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 ClientIdentified ¶ added in v0.5.0
ClientIdentified reports whether conn, a connection Client returned, carries a client certificate: it sent one, or resumed a session one was sent in. Such a connection serves its own host alone (no coalescing), as Chrome's and Firefox's do; false for any other connection.
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, a trailing dot kept, and verified
// against the certificate.
ServerName string
// OmitSNI sends no server_name; the certificate is still verified
// against ServerName (Safari, for a host ending in a dot).
OmitSNI bool
// 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
// KeyLogWriter, when set, receives the connection's TLS secrets in
// NSS key log format, TCP and QUIC alike (Config.KeyLogWriter).
KeyLogWriter io.Writer
// ClientCertificate, when set, answers a server's CertificateRequest
// (Config.GetClientCertificate, bound to the host); a nil certificate,
// or one with no chain, sends none. ClientAuth is the profile's: how
// the certificate is signed for, whether its session is kept, and
// whether the first request from a host drops its connection.
ClientCertificate func(*tls.CertificateRequestInfo) (*tls.Certificate, error)
ClientAuth *profile.ClientAuth
// FirstRequest reports whether this CertificateRequest is the first
// from the connection's host and port the client has met, and marks
// it met. With ClientCertificate set and tls.clientAuth.restart, Client
// then closes the connection with nothing sent and fails with
// ErrRestart, and ClientCertificate is not asked.
FirstRequest func() bool
// ECH, when set, is the config the hello's inner hello is encrypted to
// (fingerprint.Plan.ECHHello). A server that rejects it, proving
// itself the config's public name, fails the handshake with
// *ECHRejectedError.
ECH *ECHConfig
}
Config is what a handshake needs besides the ClientHello.
type ECHConfig ¶ added in v0.5.0
type ECHConfig struct {
// List is the config as an ECHConfigList of its own.
List []byte
// PublicName is the config's public name: the outer hello's
// server_name, and the name a rejecting server's certificate must
// be valid for.
PublicName string
}
ECHConfig is the ECH config a connection encrypts its inner hello to.
func SelectECH ¶ added in v0.5.0
SelectECH picks the ECH config of list, the ech SvcParam of a server's HTTPS record, that the browser of r encrypts its inner hello to (profile tls.realEch): the first, in the list's order, with a measured KEM, among those the handshake can use, which it picks as uTLS's pickECHConfig does: the version RFC 9849 defines, a public name that is a DNS name, no mandatory extension, a public key its KEM reads, and a suite whose KDF and AEAD it has (RFC 9849, section 6.1). It returns nil for a list with none the browser uses, which is then sent the ClientHello as to any server. A list that does not parse is ErrMalformedECH. A config the browser was never seen to use or pass over, ahead of the one picked, and a picked config whose first usable HPKE suite (the one the handshake takes) is not among r.CipherSuites, are ErrNotMeasured: what the browser would send is unknown.
type ECHRejectedError ¶ added in v0.5.0
type ECHRejectedError struct {
RetryConfigs []byte
}
ECHRejectedError is the error of a handshake whose server rejected ECH, having proved itself the config's public name: the request goes again on a new connection, with RetryConfigs (a list SelectECH reads) or, without, none.
func (*ECHRejectedError) Error ¶ added in v0.5.0
func (e *ECHRejectedError) Error() string
type Saved ¶ added in v0.5.0
Saved is a stored ticket as Export gives it and Import takes it: its key, when it stops being usable (zero: unknown), the session as uTLS encodes it (ClientSessionState.ResumptionState: the ticket, and the SessionState's Bytes, the secrets included), and whether a client certificate was sent in it.
type Store ¶ added in v0.5.0
type Store struct {
// contains filtered or unexported fields
}
Store keeps session tickets by key (host, port, partition, proxy; QUIC apart) for the Tickets views given it: one engine's, or every engine sharing a store (Config.Tickets). It belongs to one browser once Bind or Import names it. Safe for concurrent use.
func (*Store) Bind ¶ added in v0.5.0
Bind makes s browser's, unless it already belongs to another: a ticket links the connections that use it, so two browsers sharing a store would show as one identity.
func (*Store) Clear ¶ added in v0.5.0
func (s *Store) Clear()
Clear forgets every ticket. The store still belongs to its browser.
func (*Store) Import ¶ added in v0.5.0
Import adds the tickets of saved, which belong to browser (empty: unknown), still usable at now, replacing any under the same key. A session that does not parse or is neither TLS 1.2 nor 1.3, or a store belonging to another browser, fails it before anything is added.
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 is a view of a Store that uses its tickets 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 a view of a new store using TLS 1.2 tickets as tls12 (profile.TLS12Reuse, profile.TLS12SingleUse, or "" for not at all), with clock telling expired tickets.
func (*Tickets) Has ¶
Has reports whether Take would return a ticket for key, without taking it or dropping an expired one.