Skip to content

Start handshake clocks at ClientHello and honor timing settings consistently - #162

Draft
xnorpx wants to merge 7 commits into
mainfrom
dev/161
Draft

Start handshake clocks at ClientHello and honor timing settings consistently#162
xnorpx wants to merge 7 commits into
mainfrom
dev/161

Conversation

@xnorpx

@xnorpx xnorpx commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator

TL;DR

Unify handshake and retransmission timing across DTLS 1.2, DTLS 1.3, and Auto.

The overall handshake budget now starts only at the observable first ClientHello boundary: packet emission for clients and accepted-fragment reception for servers. That absolute deadline survives cookie exchanges, HelloRetryRequest, retransmissions, and Auto version transitions, then shuts off after connection. Every flight uses the configured RTO and retry policy with proportional jitter and overflow-safe deadline arithmetic.

Fixes #161.

Timing model

flowchart LR
    A["Constructed / idle"] -->|"No budget consumed"| B{"First ClientHello boundary"}
    B -->|"Client emits packet"| C["Arm absolute handshake deadline"]
    B -->|"Server accepts fragment"| C
    C --> D["Cookie, HRR, Auto transition, later flights"]
    D -->|"Preserve the same deadline"| E["Handshake complete"]
    E -->|"Disable overall deadline"| F["Application data / KeyUpdate"]
    D -. "Each new flight" .-> G["Reset configured RTO and retry budget"]
    G -->|"x2 backoff with +/-25% jitter"| D
Loading

Issues fixed

  1. Client handshake clocks started during timeout handling instead of when the first ClientHello packet was emitted.
  2. Passive servers could spend handshake budget before receiving a peer; servers now start at the first accepted ClientHello fragment while malformed, rejected, and unrelated input stays idle.
  3. Queued or undersized output could consume handshake or retry budget before any packet was emitted; BufferTooSmall now leaves both clocks untouched.
  4. The pending Auto client ignored handshake_timeout and flight_start_rto and used a separate hard-coded retransmission schedule.
  5. Auto client version selection and Auto server DTLS 1.3-to-1.2 fallback could lose the original absolute deadline or outstanding retry state.
  6. Cookie exchanges, HelloRetryRequest, later fragments, duplicates, and fresh flights could inconsistently refresh or obscure the whole-handshake deadline.
  7. Idle, unarmed, and active timers could schedule the wrong wake-up; polling now returns the earliest relevant absolute or flight deadline without idle spin.
  8. Timer-driven and duplicate-triggered retransmissions now share the configured per-flight budget, with flight_retries = 0 meaning no retransmissions after the initial send.
  9. Successful handshakes disable the overall deadline while DTLS 1.3 KeyUpdate continues to use the configured per-flight retry policy.
  10. Jitter now matches the documented proportional +/-25% policy, including sub-second RTOs; zero and unsupported extreme durations are rejected, and deadline/backoff arithmetic is overflow-safe.
  11. A DTLS 1.3 completion ACK now receives a fresh duplicate-only resend budget instead of inheriting an exhausted preceding server-flight budget.

Added lines

Category Added lines
Production code 552
Test code 2,027
Top-level documentation 16

Counts use git diff --numstat main...HEAD; additions inside in-source #[cfg(test)] blocks are counted as test code rather than production code.

Validation

  • cargo test --all-features
  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • Focused red-green regression for an exhausted server flight followed by a lost DTLS 1.3 completion ACK

Comment thread src/auto.rs Fixed
Comment thread src/dtls13/engine.rs
}

pub fn handle_timeout(&mut self, now: Instant) -> Result<(), Error> {
if self.connect_timeout == Timeout::Unarmed {
Comment thread tests/timing.rs Fixed
@xnorpx

xnorpx commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator Author

@copilot fix snowflake ci and codeql

Copilot AI and others added 3 commits September 5, 2026 20:32
Co-authored-by: xnorpx <302709+xnorpx@users.noreply.github.com>
Co-authored-by: xnorpx <302709+xnorpx@users.noreply.github.com>
Co-authored-by: xnorpx <302709+xnorpx@users.noreply.github.com>

Copilot AI commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

@copilot fix snowflake ci and codeql

Fixed in e1d91cf, 2ef48c6, and 05185c8. Snowflake’s DTLS 1.2 import violation is corrected, and the CodeQL-sensitive debug/logging paths now avoid formatting potentially sensitive output while retaining safe diagnostics. Local validation passed: cargo fmt --all -- --check, cargo test --all-features --test timing, focused auto timing test, cargo clippy --workspace --all-targets --all-features -- -D warnings, and secret scanning.

Comment thread src/auto.rs Fixed
Comment thread src/dtls13/engine.rs Fixed
Comment thread src/dtls13/engine.rs Fixed
Comment thread src/dtls13/engine.rs Fixed
@xnorpx

xnorpx commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator Author

@copilot we are still failing CodeQL CI check

Copilot AI and others added 3 commits September 5, 2026 21:22
Co-authored-by: xnorpx <302709+xnorpx@users.noreply.github.com>
Co-authored-by: xnorpx <302709+xnorpx@users.noreply.github.com>
Co-authored-by: xnorpx <302709+xnorpx@users.noreply.github.com>

Copilot AI commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

@copilot we are still failing CodeQL CI check

Fixed in fa00010 and 26b6fe8. The CodeQL-flagged sinks now avoid logging dynamic data entirely: DTLS 1.3 queue-full warnings are static, timing panic paths no longer format output fields, and the auto timing match remains exhaustive with static per-variant messages. Local validation passed: cargo fmt --all -- --check, focused auto timing test, cargo test --all-features --test timing, cargo clippy --workspace --all-targets --all-features -- -D warnings, and secret scanning. The final CodeQL validation reported 0 Rust alerts before the last diagnostic-only follow-up; the GitHub workflow created for 26b6fe8 is currently action_required with no jobs started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Start handshake clocks at ClientHello and honor timing settings consistently

3 participants