TLS/SSL - Transport Layer Security¶
pcapkit.protocols.application.tls contains
TLS only, which implements an
extractor for the TLS/SSLv3+ record-layer family [*] – SSLv3 (RFC 6101),
TLS 1.0 (RFC 2246), TLS 1.1 (RFC 4346), TLS 1.2 (RFC 5246) and TLS
1.3 (RFC 9846, which obsoletes RFC 5077, RFC 5246, RFC 6961,
RFC 7627, RFC 8422 and RFC 8446) – at the record layer, plus
handshake message framing and the bodies Decoded Fields lists.
Version Identification¶
The record layer is wire-identical across the family, so one
TLS class parses all of it and
reports the version it identified through
alias and
name, set by
read() – the same shape
ARP uses for RARP/DRARP/InARP.
id() stays ('TLS',)
whatever the version.
Legacy record version |
||
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
any other |
|
|
TLS 1.3 never puts its own 0x0304 on the record layer
(RFC 9846 Section 5.1), so it is told apart only by the
supported_versions peek. A version the table does not name keeps the
generic TLS alias rather than claiming a specific one.
Each record is branded by its own legacy version, not by the connection’s
negotiated one. So in a TLS 1.3 connection, every record after the hellos
carries 0x0303 and reads TLS 1.2; and a TLS 1.2 ClientHello sent
at record version 0x0301 reads TLS 1.0.
SSLv3 is for explicit
construction only, mirroring InARP: it
narrows id() to ('SSLv3',)
and inherits read() unchanged,
so the alias still follows the wire. Dispatch never constructs one.
Decoded Fields¶
The record header, always: it is never encrypted.
A cleartext
handshake,alertorchange_cipher_specrecord (SSL._tls_content_is_cleartextdecides which are):ClientHello/ServerHellodown to their cipher suites, compression methods and extensions, andEncryptedExtensionsdown to its extensions; an extension’s body decodes whereSSL.__extension__registers a decoder for its type.Every other handshake message at type and length only.
AlertandChangeCipherSpecin full.
Everything else – the same types once encrypted,
application_dataand every other content type – as opaquebytes.
Records in One Segment¶
A whole record after the first in a TCP segment is dissected as a further
TLS layer, the previous record’s
payload (#2517): a ServerHello followed by a ChangeCipherSpec
reads TCP:TLS 1.3:TLS 1.2. The exceptions:
A whole record that fails to decode becomes
Rawtogether with everything after it, with no SSLv2 trial.Octets that open no record – an unsupported content type, a legacy version outside
0x03xx, or a header cut short – stay raw, with no error.A parse told to stop at TLS (
protocol='TLS'orlayer='Application') keeps the rest of the segment raw.Each record is a layer, so
FRAME_LAYER_LIMITbounds how many are dissected.
Known Limitation¶
A record split across two TCP segments is not reassembled, and decodes as
Raw, as does the partial record a segment
ends inside. A record may be up to 16 KiB against a typical 1460-octet MSS, so
this is routine.
Added in version 1.6.0.
- class pcapkit.protocols.application.tls.TLS(file=None, length=None, **kwargs)[source]¶
-
This class implements all protocols in the TLS/SSLv3+ record-layer family.
Secure Sockets Layer version 3 (
SSLv3)Transport Layer Security 1.0 [RFC 2246]
Transport Layer Security 1.1 [RFC 4346]
Transport Layer Security 1.2 [RFC 5246]
Transport Layer Security 1.3 [RFC 9846]
Note
The subpackage does not track the dispatch tier: TLS is dispatched from
TCP.__proto__at port 443, thehttpsservice name IANA assigns there. Seepcapkit.foundation.registry.protocols.transport.register_tcp().- property name: Literal['Transport Layer Security', 'Secure Sockets Layer version 3']¶
Name of current protocol.
- property alias: Literal['TLS', 'SSLv3', 'TLS 1.0', 'TLS 1.1', 'TLS 1.2', 'TLS 1.3']¶
Acronym of current protocol – the concrete tier
read()identified.
- property length: int¶
Header length of current protocol – the fixed record header,
length’s fragment excluded; or, onceunpack()has adopted an SSLv2 record, that record’s own 2- or 3-octet header.
- make(content_type=ContentType.application_data, version=0x0303, content=b'', data=None, payload=b'', **kwargs)[source]¶
Make (construct) packet data, for every tier:
versionis written as is.- Parameters:
content_type (
ContentType|int) – Record content type.version (
int) – Legacy record version (major << 8 | minor), e.g.0x0303for TLS 1.2 and (the legacy value TLS 1.3 keeps here) TLS 1.3.content (
Any) – Record content: atupleofHandshakeforhandshake, anAlert, aChangeCipherSpec, or rawbytes, asread()would decode it.data (
bytes|None) – Pre-encoded record fragment. When given, it is used verbatim in place ofcontentandlengthis computed from it.payload (
bytes|ProtocolBase|Schema) – Octets after the record, e.g. a further record coalesced in the same buffer.**kwargs (
Any) – Arbitrary keyword arguments.
- Return type:
- Returns:
Constructed packet data.
- Raises:
ProtocolError – If
content_typeis a name, abool, or a member or code the 8-bit content type field cannot carry, or an extension ofcontentgiven as a(type, kwargs)pair has such a type for its 16-bit field.StructError – If
versionor the record length, or a field ofcontent, does not fit its width.
- unpack(length=None, *, chained=False, **kwargs)[source]¶
Unpack (parse) packet data: TLS, or the SSLv2 record port 443 may carry.
TLS is tried first: the record header and
read(). Only when that trial rejects the first record of a segment is the payload offered toSSLv2, whose own header checks are strict, so a genuine TLS record is never taken as SSLv2.- Parameters:
- Return type:
- Returns:
Parsed packet data.
- Raises:
ProtocolError – If the payload is neither a TLS record (see
_read_tls_record()) nor an SSLv2 record.
Note
The TLS trial’s warnings are dropped when SSLv2 parses the record (#2525), and the SSLv2 trial’s when it fails. When the record is not parsed, the TLS trial’s are dropped only under
beholder()(#2308).
- classmethod __index__()[source]¶
Numeral registry index of the protocol.
- Return type:
- Returns:
Numeral registry index of the protocol in IANA service names and port numbers: TCP port 443, the port of
TCP.https_443as anint, whichTCP.__proto__dispatches here (The Registry Index).SSLv3inherits it.
Header Schema¶
- class pcapkit.protocols.schema.application.tls.TLS(content_type=NO_VALUE, version=NO_VALUE, length=NO_VALUE, fragment=NO_VALUE, payload=NO_VALUE, *, __packet__=None, **kwargs)[source]¶
Bases:
SchemaHeader schema for TLS record layer packet.
The record header has
DTLS’s fields minus the epoch and sequence number (RFC 9846 Section 5.1).fragmentis decoded bySSL, which DTLS shares.- content_type: ContentType = <EnumField content_type>¶
Content type.
Data Model¶
- class pcapkit.protocols.data.application.tls.TLS(content_type, version, length, content)[source]¶
Bases:
ProtocolData model for TLS protocol.
- content_type: ContentType¶
Content type.
- content: Any¶
Decoded record content. For
handshake,alert, andchange_cipher_spec, this is a tuple ofHandshake, anAlert, or aChangeCipherSpecrespectively only when the record is cleartext (as decided bySSL._tls_content_is_cleartext) – an encrypted record of any of those three types, which is the common case for TLS 1.2 post-handshake traffic, stays rawbytesinstead, same as every other content type.
See SSL - Secure Sockets Layer for ClientHello, ServerHello, EncryptedExtensions,
Handshake, Extension and its decoded bodies, Alert and
ChangeCipherSpec, shared verbatim with
DTLS.
Footnotes