Commit 4ed8cfb
Implement and harden DTLS 1.2 Connection ID (RFC 9146)
Adds DTLS 1.2 Connection ID (RFC 9146) with record-layer hardening and
adjacent DTLS 1.3 (RFC 9147) / RFC 5246 / RFC 8446 extension-handling
gaps closed.
Record-layer hardening (RFC 9146 / RFC 6347 §4.1.2):
- Wire CID constant-time compared and threaded into AAD (not the cached
copy); wire version bytes likewise threaded through the AAD.
- Malformed record boundaries, too-short AEAD records, and the 2^14
inner-plaintext ceiling all silent-drop per §4.1.2.7, symmetric with
the send-side guard.
- Epoch-0 `tls12_cid` rejected at DTLSRecord::parse; legacy-framed
epoch-1 records rejected when inbound CID is expected.
- Pre-CCS CID records cleartext-filtered against the negotiated inbound
CID before entering queue_rx, closing a spray DoS vector.
- Replay window updates only after AEAD success AND CID inner-type
unwrap succeeds — peer-bug inner types no longer consume sequence
slots.
CID state model:
- Single private `CidState` enum replaces separate `our_cid`/`peer_cid`
fields so valid combinations are unrepresentable outside the module.
- Per-direction activation: outbound armed at negotiation, inbound
flipped live only after the peer's ChangeCipherSpec.
Extension parser and HVR cookie:
- Duplicate extensions (supported and unknown) rejected fail-closed via
a 64-codepoint tracker with `try_push(...).map_err(...)?`, including
a defense-in-depth ExtensionVec dedup pass.
- HVR cookie HMAC binds the raw offered-CID extension bytes with a
0x00/0x01 marker, catching CH1/CH2 CID swap attempts.
- Stateful `offered_cid` flag on dtls13::Client replaces the earlier
config-based proxy so the direct `Dtls::new_13` path still rejects
unsolicited `0x0036` echoes per RFC 8446 §4.2.
Outbound sizing and lifetimes:
- Shared `Engine::outbound_record_overhead` keeps create_handshake
fragmentation in sync with CID + AEAD overhead.
- New errors: `Error::Oversized`, `Error::MtuTooSmall`,
`Error::SequenceNumberExhausted`; 2^14 plaintext ceiling enforced
both sides; 48-bit sequence wrap surfaced distinctly from payload
size failures.
Auto-mode:
- Hybrid ClientHello now emits `connection_id(0x0036)` when configured,
so CH1/CH2 carry identical CID bytes and the stateless cookie binds
once.
- DTLS 1.3 client silent-accepts a server echo only when its own
ClientHello on the wire solicited `0x0036`.
- DTLS 1.3 server and client explicitly log-ignore `0x0036` per RFC.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 83e913f commit 4ed8cfb
36 files changed
Lines changed: 5746 additions & 250 deletions
File tree
- src
- crypto
- validation
- dtls12
- message
- extensions
- dtls13
- tests
- auto
- dtls12
- dtls13
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
50 | 69 | | |
51 | 70 | | |
52 | 71 | | |
| |||
188 | 207 | | |
189 | 208 | | |
190 | 209 | | |
| 210 | + | |
| 211 | + | |
191 | 212 | | |
192 | 213 | | |
193 | 214 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| |||
189 | 190 | | |
190 | 191 | | |
191 | 192 | | |
192 | | - | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
193 | 207 | | |
194 | 208 | | |
195 | 209 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
81 | 86 | | |
82 | 87 | | |
83 | 88 | | |
| |||
0 commit comments