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
- Variables
- func AlertName(d uint8) string
- func MarshalSSLv2ClientHello(rnd io.Reader, kinds []uint32) ([]byte, error)
- func SSLv2CipherKinds() []uint32
- func SSLv2CipherName(kind uint32) string
- type Alert
- type ClientHello
- type Extension
- func ALPN(protocols ...string) Extension
- func ECPointFormats() Extension
- func ExtendedMasterSecret() Extension
- func Heartbeat() Extension
- func KeyShare(entries ...KeyShareEntry) Extension
- func KeyShareEmpty() Extension
- func PSKKeyExchangeModes() Extension
- func RenegotiationInfo() Extension
- func SNI(host string) Extension
- func SessionTicket() Extension
- func SignatureAlgorithms(schemes []uint16) Extension
- func StatusRequest() Extension
- func SupportedGroups(groups []uint16) Extension
- func SupportedVersions(versions ...Version) Extension
- type Flight
- type KeyExchange
- type KeyShareEntry
- type NotTLSError
- type SSLv2Error
- type SSLv2ServerHello
- type ServerHello
- type Version
Constants ¶
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.
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 ExtRenegotiationInfo uint16 = 0xFF01 )
Extension types (IANA TLS ExtensionType registry).
Variables ¶
var ErrNoResponse = errors.New("wire: connection closed without a response")
ErrNoResponse is returned when the peer closed the connection without sending anything.
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.
var ErrShort = errors.New("wire: truncated message")
ErrShort is returned when a message is shorter than its own length fields say.
Functions ¶
func MarshalSSLv2ClientHello ¶
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 ¶
SSLv2CipherName names an SSLv2 cipher kind.
Types ¶
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 ¶
Extension is one hello extension, in the order it is sent.
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 SessionTicket ¶
func SessionTicket() Extension
SessionTicket offers session tickets with an empty ticket.
func SignatureAlgorithms ¶
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 ¶
SupportedGroups is the supported_groups extension.
func SupportedVersions ¶
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 ¶
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 {
}
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 ¶
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).
}
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.