@@ -4,13 +4,16 @@ DTLS - Datagram Transport Layer Security
44.. module :: pcapkit.protocols.application.dtls
55
66:mod: `pcapkit.protocols.application.dtls ` contains
7- :class: `~pcapkit.protocols.application.dtls.DTLS ` only , which implements an
7+ :class: `~pcapkit.protocols.application.dtls.DTLS `, which implements an
88extractor for Datagram Transport Layer Security (DTLS) [*]_ -- DTLS 1.0
9- (:rfc: `4347 `), DTLS 1.2 (:rfc: `6347 `) and DTLS 1.3's legacy-format and
9+ (:rfc: `4347 `), DTLS 1.2 (:rfc: `6347 `) and its connection-ID records
10+ (:rfc: `9146 `), and DTLS 1.3's legacy-format and
1011unified-header records (:rfc: `9147 `) -- at the record layer, plus the epoch/sequence-number fields and
1112the handshake-message fragment header that set DTLS apart from
1213:class: `~pcapkit.protocols.application.tls.TLS `, whose reliable, ordered
13- transport needs neither.
14+ transport needs neither. It also contains
15+ :class: `~pcapkit.protocols.application.dtls.DTLSContext `, which holds the
16+ connection IDs those records carry.
1417
1518Version Identification
1619----------------------
@@ -46,6 +49,53 @@ A unified-header record has no legacy version to read. Its first octet's top
4649three bits are ``001 ``, which no legacy content type (20 through 27) sets, so
4750the two formats are told apart by that octet alone.
4851
52+ A ``tls12_cid `` record is ``DTLS 1.2 ``: :rfc: `9146#section-10.3 ` limits the
53+ content type to that version, so one with another legacy version is refused.
54+
55+ Connection IDs
56+ --------------
57+
58+ A ``tls12_cid `` record carries a connection ID between its sequence number
59+ and its length (:rfc: `9146#section-4 `), and the ID's length is negotiated
60+ rather than carried.
61+ :class: `~pcapkit.protocols.application.dtls.DTLSContext ` resolves it, in this
62+ order:
63+
64+ * a connection ID the record begins with that a ``ClientHello `` or
65+ ``ServerHello `` ``connection_id `` extension negotiated earlier in the
66+ capture, each peer naming the one it receives (:rfc: `9146#section-3 `);
67+ * the ``cid_length `` the caller gives
68+ :class: `~pcapkit.protocols.application.dtls.DTLSContext `.
69+
70+ Without either the record stays :class: `~pcapkit.protocols.misc.raw.Raw `.
71+ A dissected one reports its epoch, sequence number, connection ID and length,
72+ and keeps its encrypted content as octets. The context reaches DTLS through
73+ :mod: `pcapkit.corekit.context `:
74+
75+ .. code-block :: python
76+
77+ import pcapkit
78+ from pcapkit.protocols.application.dtls import DTLSContext
79+
80+ extraction = pcapkit.extract(' dtls.pcap' , context = DTLSContext(cid_length = 8 ))
81+
82+ The connection IDs a
83+ :class: `~pcapkit.protocols.application.dtls.DTLSContext ` learns belong to that
84+ instance. A new instance starts with none, and one the caller reuses keeps
85+ what it has learned. An extraction given none gets its own in its own
86+ registry, so it carries what its handshakes negotiate across its capture and
87+ no further. A registry passed as ``__context__ `` to several parses carries
88+ its instance across them.
89+
90+ Matching by value relies on IDs being self-delineating
91+ (:rfc: `9146#section-4 `): with ``c1c2c3c4 `` registered, a record whose ID is
92+ ``c1c2c3c400010203 `` reads as carrying ``c1c2c3c4 ``.
93+
94+ A rebuild parses each layer's octets again, so ``from_data `` takes the same
95+ ``__context__ ``. Without it the octets still rebuild exactly, and
96+ ``DTLS.from_data `` keeps its chain, but a ``tls12_cid `` record under a
97+ rebuilt UDP layer reads as :class: `~pcapkit.protocols.misc.raw.Raw `.
98+
4999Records in One Datagram
50100-----------------------
51101
@@ -61,8 +111,9 @@ exceptions:
61111 :class: `~pcapkit.protocols.misc.raw.Raw ` together with everything after it.
62112* Octets that open no whole record stay raw, with no error: an unsupported
63113 content type, a legacy version outside ``0xFExx ``, a header cut short, a
64- length past the end of the datagram, or a unified header with a connection
65- ID, which leaves the record's end unknown.
114+ length past the end of the datagram, a unified header with a connection
115+ ID, or a ``tls12_cid `` record whose connection ID is not known, either of
116+ which leaves the record's end unknown.
66117* A parse told to stop at DTLS (``protocol='DTLS' `` or ``layer='Application' ``)
67118 keeps the rest of the datagram raw.
68119* Each record is a layer, so :data: `~pcapkit.utilities.config.FRAME_LAYER_LIMIT `
@@ -81,8 +132,10 @@ with :meth:`~pcapkit.protocols.application.dtls.DTLS.read_handshake`.
81132
82133**A unified-header record with a connection ID is not decoded **
83134(:rfc: `9147#section-4.1 `, :issue: `2467 `). Its length is negotiated, not carried
84- in the record, so it degrades to :class: `~pcapkit.protocols.misc.raw.Raw `. The
85- same holds for ``tls12_cid `` records (:rfc: `9146 `).
135+ in the record, so it degrades to :class: `~pcapkit.protocols.misc.raw.Raw `.
136+
137+ **A connection ID negotiated in a fragmented hello is not learned **: the
138+ message is not decoded here, so its ``connection_id `` extension is not read.
86139
87140**A unified-header record carries only the low two bits of the epoch **, and
88141its sequence number is header-protected, so the values it reports are the
@@ -113,6 +166,17 @@ ones on the wire.
113166
114167 .. automethod :: _make_data
115168
169+ .. autoclass :: pcapkit.protocols.application.dtls.DTLSContext
170+ :no-members:
171+ :show-inheritance:
172+
173+ .. autoproperty :: connection_ids
174+ .. autoproperty :: cid_length
175+
176+ .. automethod :: protocol
177+ .. automethod :: register
178+ .. automethod :: match
179+
116180Header Schema
117181-------------
118182
@@ -126,6 +190,10 @@ Header Schema
126190 :members:
127191 :show-inheritance:
128192
193+ .. autoclass :: pcapkit.protocols.schema.application.dtls.DTLSCIDCiphertext
194+ :members:
195+ :show-inheritance:
196+
129197Data Models
130198-----------
131199
@@ -139,6 +207,10 @@ Data Models
139207 :members:
140208 :show-inheritance:
141209
210+ .. autoclass :: pcapkit.protocols.data.application.dtls.DTLSCIDCiphertext
211+ :members:
212+ :show-inheritance:
213+
142214.. autoclass :: pcapkit.protocols.data.application.dtls.DTLSHandshake
143215 :members:
144216 :show-inheritance:
0 commit comments