wire

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 5 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 wire implements just enough of the TLS/SSL wire protocol to probe a server: it builds ClientHello messages the standard library will not send (SSLv3, arbitrary suite and group lists, empty key shares) and parses what a server answers, up to the point where the rest is encrypted.

It never completes a handshake and holds no key material. It is written defensively, because everything it parses comes from an untrusted peer: every read is bounds-checked, every length is capped, and the parsers are fuzzed.

Index

Constants

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

	HandshakeClientHello       uint8 = 1
	HandshakeServerHello       uint8 = 2
	HandshakeCertificate       uint8 = 11
	HandshakeServerKeyExchange uint8 = 12
	HandshakeCertRequest       uint8 = 13
	HandshakeServerHelloDone   uint8 = 14
	HandshakeCertStatus        uint8 = 22
)

Record and handshake message types.

View Source
const (
	ExtServerName           uint16 = 0
	ExtStatusRequest        uint16 = 5
	ExtSupportedGroups      uint16 = 10
	ExtECPointFormats       uint16 = 11
	ExtHeartbeat            uint16 = 15
	ExtSignatureAlgorithms  uint16 = 13
	ExtALPN                 uint16 = 16
	ExtEncryptThenMAC       uint16 = 22
	ExtExtendedMasterSecret uint16 = 23
	ExtSessionTicket        uint16 = 35
	ExtSupportedVersions    uint16 = 43
	ExtPSKKeyExchangeModes  uint16 = 45
	ExtKeyShare             uint16 = 51
	ExtRenegotiationInfo    uint16 = 0xFF01
)

Extension types (IANA TLS ExtensionType registry).

Variables

View Source
var ErrNoResponse = errors.New("wire: connection closed without a response")

ErrNoResponse is returned when the peer closed the connection without sending anything.

View Source
var ErrNotSSLv2 = errors.New("wire: peer did not answer in SSLv2")

ErrNotSSLv2 means the peer answered a SSLv2 hello with something that is not SSLv2, typically a TLS alert or a closed connection: the normal reply of a server with SSLv2 disabled.

View Source
var ErrShort = errors.New("wire: truncated message")

ErrShort is returned when a message is shorter than its own length fields say.

Functions

func AlertName

func AlertName(d uint8) string

AlertName returns the IANA name of an alert description.

func MarshalSSLv2ClientHello

func MarshalSSLv2ClientHello(rnd io.Reader, kinds []uint32) ([]byte, error)

MarshalSSLv2ClientHello builds an SSLv2 CLIENT-HELLO offering the given cipher kinds. SSLv2 uses its own record framing, not the TLS record layer.

func SSLv2CipherKinds

func SSLv2CipherKinds() []uint32

SSLv2CipherKinds returns the seven cipher kinds the SSLv2 specification defines, in specification order.

func SSLv2CipherName

func SSLv2CipherName(kind uint32) string

SSLv2CipherName names an SSLv2 cipher kind.

Types

type Alert

type Alert struct {
	Level       uint8 // 1 warning, 2 fatal
	Description uint8
}

Alert is a TLS alert.

func (Alert) String

func (a Alert) String() string

type ClientHello

type ClientHello struct {
	// RecordVersion is the version in the record header of the hello.
	RecordVersion Version
	// LegacyVersion is client_version. For a TLS 1.3 offer it stays TLS 1.2 and the
	// real versions go in the supported_versions extension.
	LegacyVersion Version
	Random        [32]byte
	SessionID     []byte
	Suites        []uint16
	Compression   []byte // nil means the null method only
	// Extensions are sent in order. If nil and NoExtensions is false, the hello
	// still carries an (empty) extensions block; set NoExtensions for SSLv3-style
	// hellos that omit the block entirely.
	Extensions   []Extension
	NoExtensions bool
}

ClientHello describes a ClientHello to send. It is a plain value: the probe decides every field, nothing is defaulted behind its back.

func NewClientHello

func NewClientHello(rnd io.Reader, legacy Version, suites []uint16, exts ...Extension) (*ClientHello, error)

NewClientHello returns a hello with a fresh random drawn from rnd.

func (*ClientHello) Marshal

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

Marshal encodes the hello as a single handshake record.

type Extension

type Extension struct {
	Type uint16
	Data []byte
	// contains filtered or unexported fields
}

Extension is one hello extension, in the order it is sent.

func ALPN

func ALPN(protocols ...string) Extension

ALPN offers application protocols.

func ECPointFormats

func ECPointFormats() Extension

ECPointFormats offers only the uncompressed format.

func ExtendedMasterSecret

func ExtendedMasterSecret() Extension

ExtendedMasterSecret asks for extended_master_secret.

func Heartbeat added in v0.4.0

func Heartbeat() Extension

Heartbeat offers the heartbeat extension (RFC 6520) in mode peer_allowed_to_send. The scan only reads whether the server echoes it: it never sends a heartbeat message.

func KeyShare

func KeyShare(entries ...KeyShareEntry) Extension

KeyShare is a key_share carrying real shares (RFC 8446 section 4.2.8). A server that supports one of the shared groups answers with a ServerHello rather than a HelloRetryRequest, so it must first choose a certificate it can sign with.

func KeyShareEmpty

func KeyShareEmpty() Extension

KeyShareEmpty is a key_share carrying no shares. A TLS 1.3 server that supports one of the offered groups must answer with a HelloRetryRequest naming it, which reveals its choice without the client generating any key material.

func PSKKeyExchangeModes

func PSKKeyExchangeModes() Extension

PSKKeyExchangeModes offers psk_dhe_ke, as a TLS 1.3 client normally does.

func RenegotiationInfo

func RenegotiationInfo() Extension

RenegotiationInfo is the initial (empty) renegotiation_info extension.

func SNI

func SNI(host string) Extension

SNI is the server_name extension for a DNS host name.

func SessionTicket

func SessionTicket() Extension

SessionTicket offers session tickets with an empty ticket.

func SignatureAlgorithms

func SignatureAlgorithms(schemes []uint16) Extension

SignatureAlgorithms is the signature_algorithms extension.

func StatusRequest

func StatusRequest() Extension

StatusRequest asks for an OCSP staple (status_request, type ocsp, empty lists).

func SupportedGroups

func SupportedGroups(groups []uint16) Extension

SupportedGroups is the supported_groups extension.

func SupportedVersions

func SupportedVersions(versions ...Version) Extension

SupportedVersions is the ClientHello form of supported_versions.

type Flight

type Flight struct {
	ServerHello *ServerHello
	// Certificates is the certificate chain, DER, leaf first. Only present for
	// TLS 1.2 and earlier: in TLS 1.3 the Certificate message is encrypted.
	Certificates [][]byte
	// ServerKeyExchange is the raw body of the message, when the server sent one.
	ServerKeyExchange []byte
	// CertificateStatus reports that the server sent a stapled OCSP response.
	CertificateStatus bool
	// CertificateRequest reports that the server asked for a client certificate.
	CertificateRequest bool
	Done               bool // ServerHelloDone seen (TLS 1.2 and earlier)
	Alert              *Alert
}

Flight is what a server sent in reply to a ClientHello, as far as it is readable.

func ReadFlight

func ReadFlight(r io.Reader) (*Flight, error)

ReadFlight reads the server's reply to a ClientHello. It returns as soon as the remainder is unreadable or absent: after a TLS 1.3 ServerHello or HelloRetryRequest (everything after is encrypted), after ServerHelloDone, or after an alert. An alert is a normal answer and is returned in Flight.Alert with a nil error; only I/O failures and malformed data are errors, and then whatever was parsed before the failure is still returned.

type KeyExchange

type KeyExchange struct {
	// Kind is "ECDHE" or "DHE".
	Kind string

	// ECDHE: the named curve (an IANA supported-group id). ExplicitCurve is set for
	// the long-deprecated explicit-parameter forms, where no name is sent.
	CurveID       uint16
	ExplicitCurve bool

	// DHE: the size in bits of the server's prime and generator and of its public
	// value, and the prime itself (big-endian, no leading zeros) so callers can
	// recognise well-known groups.
	PrimeBits     int
	GeneratorBits int
	PublicBits    int
	Prime         []byte
}

KeyExchange holds what a ServerKeyExchange message discloses about the server's ephemeral key exchange.

func ParseServerKeyExchange

func ParseServerKeyExchange(kind string, psk bool, body []byte) (*KeyExchange, error)

ParseServerKeyExchange parses the body of a ServerKeyExchange for an ephemeral exchange. kind is "ECDHE" or "DHE"; psk says the suite is a PSK variant, whose message starts with an identity hint. The signature that follows the parameters is not parsed.

type KeyShareEntry

type KeyShareEntry struct {
	Group uint16
	Key   []byte
}

KeyShareEntry is one client key share: a group and the client's public value for it.

type NotTLSError

type NotTLSError struct{ Prefix []byte }

NotTLSError means the peer's first bytes were not a TLS record, for example a plain HTTP server answering on a TLS port.

func (*NotTLSError) Error

func (e *NotTLSError) Error() string

type SSLv2Error

type SSLv2Error struct{ Code uint16 }

SSLv2Error is an SSLv2 ERROR message.

func (*SSLv2Error) Error

func (e *SSLv2Error) Error() string

type SSLv2ServerHello

type SSLv2ServerHello struct {
	Version     uint16
	CipherKinds []uint32
	CertLength  int
}

SSLv2ServerHello is a parsed SSLv2 SERVER-HELLO.

func ReadSSLv2ServerHello

func ReadSSLv2ServerHello(r io.Reader) (*SSLv2ServerHello, error)

ReadSSLv2ServerHello reads the reply to an SSLv2 CLIENT-HELLO. It returns ErrNotSSLv2 (wrapping the observed alert, if any) for a non-SSLv2 reply and an *SSLv2Error for an SSLv2 ERROR message.

type ServerHello

type ServerHello struct {
	Version     Version // the legacy_version field
	Random      [32]byte
	SessionID   []byte
	Suite       uint16
	Compression uint8
	Extensions  []Extension

	HelloRetryRequest bool
	// SelectedVersion is the negotiated version: supported_versions if the server
	// sent it (TLS 1.3), otherwise Version.
	SelectedVersion Version
	// KeyShareGroup is the group the server chose (TLS 1.3 only, HasKeyShare).
	KeyShareGroup uint16
	HasKeyShare   bool
}

ServerHello is a parsed ServerHello or, when HelloRetryRequest is set, a HelloRetryRequest (which shares the wire format).

func (*ServerHello) Ext

func (s *ServerHello) Ext(t uint16) ([]byte, bool)

Ext returns the data of the first extension of type t.

func (*ServerHello) HasExt

func (s *ServerHello) HasExt(t uint16) bool

HasExt reports whether the server sent extension t.

type Version

type Version uint16

Version is a protocol version as it appears on the wire.

const (
	VersionSSL20 Version = 0x0002 // SSLv2; carried in its own record format
	VersionSSL30 Version = 0x0300
	VersionTLS10 Version = 0x0301
	VersionTLS11 Version = 0x0302
	VersionTLS12 Version = 0x0303
	VersionTLS13 Version = 0x0304
)

The versions.

func (Version) String

func (v Version) String() string

Jump to

Keyboard shortcuts

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