Skip to content

Improve resending of Initial on undecryptable - #2866

Merged
larseggert merged 2 commits into
mozilla:mainfrom
martinthomson:improve-initial-retransmission-on-save
Aug 18, 2025
Merged

larseggert merged 2 commits into
mozilla:mainfrom
martinthomson:improve-initial-retransmission-on-save

Conversation

@martinthomson

Copy link
Copy Markdown
Member

The goal here was to make the test more robust, but it turns out that the code could have been simpler as well. That is, rather than testing for a separate threshold, we can test instead for whether the saved datagram store is full. That was the same constant anyway.

The test is made more robust by having it disable MLKEM, which ensures that there is just one Initial packet in each flight. The undecryptable packet is constructed manually (by rewriting an Initial).

The goal here was to make the test more robust, but it turns out that
the code could have been simpler as well.  That is, rather than testing
for a separate threshold, we can test instead for whether the saved
datagram store is full.  That was the same constant anyway.

The test is made more robust by having it disable MLKEM, which ensures
that there is just one Initial packet in each flight.  The undecryptable
packet is constructed manually (by rewriting an Initial).
@codecov

codecov Bot commented Aug 18, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.93%. Comparing base (a20e4e9) to head (b0cdbf5).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2866   +/-   ##
=======================================
  Coverage   94.92%   94.93%           
=======================================
  Files         115      115           
  Lines       34484    34488    +4     
  Branches    34484    34488    +4     
=======================================
+ Hits        32733    32740    +7     
+ Misses       1742     1741    -1     
+ Partials        9        7    -2     
Components Coverage Δ
neqo-common 97.48% <ø> (ø)
neqo-crypto 89.91% <ø> (ø)
neqo-http3 93.73% <ø> (ø)
neqo-qpack 95.45% <ø> (ø)
neqo-transport 95.96% <100.00%> (+0.01%) ⬆️
neqo-udp 89.37% <ø> (ø)

@github-actions

Copy link
Copy Markdown
Contributor

Failed Interop Tests

QUIC Interop Runner, client vs. server, differences relative to a20e4e9.

neqo-latest as client

neqo-latest as server

All results

Succeeded Interop Tests

QUIC Interop Runner, client vs. server

neqo-latest as client

neqo-latest as server

Unsupported Interop Tests

QUIC Interop Runner, client vs. server

neqo-latest as client

neqo-latest as server

@github-actions

Copy link
Copy Markdown
Contributor

Benchmark results

Performance differences relative to a20e4e9.

1-conn/1-100mb-resp/mtu-1504 (aka. Download)/client: Change within noise threshold.
       time:   [200.24 ms 200.67 ms 201.20 ms]
       thrpt:  [497.02 MiB/s 498.33 MiB/s 499.39 MiB/s]
change:
       time:   [−1.2710% −0.9307% −0.6117%] (p = 0.00 < 0.05)
       thrpt:  [+0.6154% +0.9395% +1.2873%]

Found 2 outliers among 100 measurements (2.00%)
1 (1.00%) high mild
1 (1.00%) high severe

1-conn/10_000-parallel-1b-resp/mtu-1504 (aka. RPS)/client: No change in performance detected.
       time:   [303.63 ms 304.87 ms 306.14 ms]
       thrpt:  [32.665 Kelem/s 32.800 Kelem/s 32.935 Kelem/s]
change:
       time:   [−1.1425% −0.5125% +0.1136%] (p = 0.10 > 0.05)
       thrpt:  [−0.1135% +0.5151% +1.1557%]
1-conn/1-1b-resp/mtu-1504 (aka. HPS)/client: No change in performance detected.
       time:   [27.733 ms 27.880 ms 28.046 ms]
       thrpt:  [35.655   B/s 35.868   B/s 36.058   B/s]
change:
       time:   [−0.6278% +0.0713% +0.8681%] (p = 0.85 > 0.05)
       thrpt:  [−0.8606% −0.0712% +0.6318%]

Found 5 outliers among 100 measurements (5.00%)
5 (5.00%) high severe

1-conn/1-100mb-req/mtu-1504 (aka. Upload)/client: 💔 Performance has regressed.
       time:   [208.87 ms 209.21 ms 209.60 ms]
       thrpt:  [477.11 MiB/s 477.99 MiB/s 478.77 MiB/s]
change:
       time:   [+1.3794% +1.6220% +1.8562%] (p = 0.00 < 0.05)
       thrpt:  [−1.8224% −1.5961% −1.3606%]

Found 3 outliers among 100 measurements (3.00%)
1 (1.00%) high mild
2 (2.00%) high severe

decode 4096 bytes, mask ff: Change within noise threshold.
       time:   [11.638 µs 11.681 µs 11.731 µs]
       change: [+0.0196% +0.4467% +0.8930%] (p = 0.04 < 0.05)

Found 22 outliers among 100 measurements (22.00%)
1 (1.00%) low severe
8 (8.00%) low mild
1 (1.00%) high mild
12 (12.00%) high severe

decode 1048576 bytes, mask ff: No change in performance detected.
       time:   [3.0086 ms 3.0183 ms 3.0296 ms]
       change: [−0.4275% +0.0599% +0.5522%] (p = 0.82 > 0.05)

Found 10 outliers among 100 measurements (10.00%)
10 (10.00%) high severe

decode 4096 bytes, mask 7f: No change in performance detected.
       time:   [19.367 µs 19.419 µs 19.475 µs]
       change: [−0.8125% −0.3387% +0.0663%] (p = 0.14 > 0.05)

Found 19 outliers among 100 measurements (19.00%)
2 (2.00%) low severe
3 (3.00%) low mild
1 (1.00%) high mild
13 (13.00%) high severe

decode 1048576 bytes, mask 7f: No change in performance detected.
       time:   [5.0863 ms 5.0991 ms 5.1124 ms]
       change: [−0.3521% +0.0139% +0.3769%] (p = 0.93 > 0.05)

Found 15 outliers among 100 measurements (15.00%)
15 (15.00%) high severe

decode 4096 bytes, mask 3f: No change in performance detected.
       time:   [5.5160 µs 5.5428 µs 5.5747 µs]
       change: [−0.4126% −0.0375% +0.3248%] (p = 0.85 > 0.05)

Found 8 outliers among 100 measurements (8.00%)
2 (2.00%) high mild
6 (6.00%) high severe

decode 1048576 bytes, mask 3f: No change in performance detected.
       time:   [1.7578 ms 1.7579 ms 1.7581 ms]
       change: [−0.3878% −0.1267% +0.0094%] (p = 0.42 > 0.05)

Found 1 outliers among 100 measurements (1.00%)
1 (1.00%) high mild

coalesce_acked_from_zero 1+1 entries: No change in performance detected.
       time:   [88.216 ns 88.549 ns 88.905 ns]
       change: [−0.5687% −0.0528% +0.4873%] (p = 0.85 > 0.05)

Found 8 outliers among 100 measurements (8.00%)
6 (6.00%) high mild
2 (2.00%) high severe

coalesce_acked_from_zero 3+1 entries: No change in performance detected.
       time:   [105.60 ns 105.92 ns 106.26 ns]
       change: [−0.4587% −0.0325% +0.3818%] (p = 0.88 > 0.05)

Found 12 outliers among 100 measurements (12.00%)
1 (1.00%) high mild
11 (11.00%) high severe

coalesce_acked_from_zero 10+1 entries: No change in performance detected.
       time:   [105.00 ns 105.39 ns 105.86 ns]
       change: [−0.8257% −0.1794% +0.3734%] (p = 0.59 > 0.05)

Found 12 outliers among 100 measurements (12.00%)
3 (3.00%) high mild
9 (9.00%) high severe

coalesce_acked_from_zero 1000+1 entries: No change in performance detected.
       time:   [88.954 ns 89.075 ns 89.216 ns]
       change: [−8.0418% −2.4257% +1.1056%] (p = 0.52 > 0.05)

Found 11 outliers among 100 measurements (11.00%)
4 (4.00%) high mild
7 (7.00%) high severe

RxStreamOrderer::inbound_frame(): Change within noise threshold.
       time:   [108.27 ms 108.43 ms 108.66 ms]
       change: [+0.0428% +0.2175% +0.4361%] (p = 0.03 < 0.05)

Found 6 outliers among 100 measurements (6.00%)
5 (5.00%) high mild
1 (1.00%) high severe

sent::Packets::take_ranges: :green_heart: Performance has improved.
       time:   [5.1041 µs 5.2327 µs 5.3907 µs]
       change: [−41.665% −34.988% −20.486%] (p = 0.00 < 0.05)

Found 4 outliers among 100 measurements (4.00%)
2 (2.00%) high mild
2 (2.00%) high severe

transfer/pacing-false/varying-seeds: Change within noise threshold.
       time:   [37.471 ms 37.567 ms 37.671 ms]
       change: [+0.3615% +0.7567% +1.1354%] (p = 0.00 < 0.05)

Found 1 outliers among 100 measurements (1.00%)
1 (1.00%) high severe

transfer/pacing-true/varying-seeds: Change within noise threshold.
       time:   [38.365 ms 38.483 ms 38.600 ms]
       change: [+0.3742% +0.8222% +1.2808%] (p = 0.00 < 0.05)
transfer/pacing-false/same-seed: No change in performance detected.
       time:   [37.164 ms 37.232 ms 37.301 ms]
       change: [−0.0473% +0.2308% +0.4850%] (p = 0.09 > 0.05)

Found 2 outliers among 100 measurements (2.00%)
2 (2.00%) high mild

transfer/pacing-true/same-seed: Change within noise threshold.
       time:   [38.638 ms 38.741 ms 38.851 ms]
       change: [−1.2430% −0.9020% −0.5325%] (p = 0.00 < 0.05)

Found 4 outliers among 100 measurements (4.00%)
1 (1.00%) low mild
2 (2.00%) high mild
1 (1.00%) high severe

Download data for profiler.firefox.com or download performance comparison data.

@github-actions

Copy link
Copy Markdown
Contributor

Client/server transfer results

Performance differences relative to a20e4e9.

Transfer of 33554432 bytes over loopback, min. 100 runs. All unit-less numbers are in milliseconds.

Client vs. server (params) Mean ± σ Min Max MiB/s ± σ Δ main Δ main
google vs. google 452.4 ± 4.3 445.0 463.2 70.7 ± 7.4
google vs. neqo (cubic, paced) 273.3 ± 4.3 266.9 282.7 117.1 ± 7.4 -1.0 -0.4%
msquic vs. msquic 128.9 ± 15.2 111.2 203.9 248.2 ± 2.1
msquic vs. neqo (cubic, paced) 143.3 ± 14.2 120.0 208.6 223.4 ± 2.3 -3.2 -2.2%
neqo vs. google (cubic, paced) 753.0 ± 4.2 746.6 774.2 42.5 ± 7.6 -0.8 -0.1%
neqo vs. msquic (cubic, paced) 156.2 ± 5.4 149.7 182.6 204.9 ± 5.9 0.9 0.6%
neqo vs. neqo (cubic) 92.3 ± 5.0 82.6 110.1 346.6 ± 6.4 1.3 1.4%
neqo vs. neqo (cubic, paced) 92.5 ± 4.4 86.5 106.7 345.8 ± 7.3 -1.3 -1.4%
neqo vs. neqo (reno) 93.5 ± 4.3 82.5 102.9 342.1 ± 7.4 💔 3.3 3.7%
neqo vs. neqo (reno, paced) 93.1 ± 5.2 85.2 109.8 343.6 ± 6.2 0.5 0.6%
neqo vs. quiche (cubic, paced) 191.4 ± 4.9 182.9 216.3 167.2 ± 6.5 -0.8 -0.4%
neqo vs. s2n (cubic, paced) 218.9 ± 4.1 212.5 228.0 146.2 ± 7.8 0.0 0.0%
quiche vs. neqo (cubic, paced) 147.9 ± 5.3 136.7 161.9 216.4 ± 6.0 -0.4 -0.3%
quiche vs. quiche 146.4 ± 5.2 137.8 160.2 218.6 ± 6.2
s2n vs. neqo (cubic, paced) 169.5 ± 5.0 161.8 193.5 188.7 ± 6.4 0.3 0.2%
s2n vs. s2n 248.3 ± 29.1 232.1 346.5 128.9 ± 1.1

Download data for profiler.firefox.com or download performance comparison data.

@larseggert
larseggert added this pull request to the merge queue Aug 18, 2025
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Aug 18, 2025
@larseggert
larseggert added this pull request to the merge queue Aug 18, 2025
Merged via the queue into mozilla:main with commit 3f16554 Aug 18, 2025
martinthomson added a commit to martinthomson/neqo that referenced this pull request Aug 21, 2025
* Improve resending of Initial on undecryptable

The goal here was to make the test more robust, but it turns out that
the code could have been simpler as well.  That is, rather than testing
for a separate threshold, we can test instead for whether the saved
datagram store is full.  That was the same constant anyway.

The test is made more robust by having it disable MLKEM, which ensures
that there is just one Initial packet in each flight.  The undecryptable
packet is constructed manually (by rewriting an Initial).

* Rename the function
github-merge-queue Bot pushed a commit that referenced this pull request Mar 13, 2026
* Ignore all SCONE packets

* SCONE transport parameter

* Add SCONE indication

* Log SCONE value

* Add a connection-level test for SCONE

* Clippy, review comments

* Reduce log level for packet drops

* Conditionally error on other version packets

* Add a further test for Initial before docking two bytes

* Fix the indication reservation and test it

* chore(.github/check.yaml): remove obsolete run_benchmarks input (#2826)

#2773 removed the benchmark trigger from `check.yaml`. Thus the input is no longer needed.

Signed-off-by: Max Inden <mail@max-inden.de>

* ci: Create cache on `merge_group` trigger (#2824)

* ci: Create cache on `merge_group` trigger

* Fix comment

* refactor(http3): improve `FrameReader` `Debug` implementation (#2815)

`FrameReader` owns a 2048 byte `buffer`

``` rust
pub struct FrameReader {
    state: FrameReaderState,
    frame_type: HFrameType,
    frame_len: u64,
    buffer: [u8; MAX_READ_SIZE],
}
```

This buffer is only used when reading from a stream, then consecutively
decoding off the buffer. There is no need to print the entire buffer in
its `Debug` implementation. See sample logging output below.

```
0.036 DEBUG [RecvMessage stream_id:0] state=WaitingForResponseHeaders { frame_reader: FrameReader { state: GetLength { decoder: IncrementalDecoderUint { v: 0, remaining: None } }, frame_type: HFrameType(1), frame_len: 0, buffer: [0, 0, 0, 0, 0, ... ] } }
```

* chore(clippy): remove expect for needless_match (#2835)

* chore(clippy): update to latest lints (#2837)

* ci: Disable systemd unified cgroups on GCP (#2803)

* build(deps): bump github/codeql-action from 3.29.7 to 3.29.8 (#2845)

Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.29.7 to 3.29.8.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](github/codeql-action@51f7732...76621b6)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-version: 3.29.8
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* build(deps): bump actions/cache from 4.2.3 to 4.2.4 (#2844)

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Lars Eggert <lars@eggert.org>

* build(deps): bump docker/login-action from 3.4.0 to 3.5.0 (#2846)

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* build(deps): bump actions/download-artifact from 4.3.0 to 5.0.0 (#2841)

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Lars Eggert <lars@eggert.org>

* ci: Use an older kernel with `cpuset` support for benchers (#2840)

* fix(transport/frame): prevent potential overflow in padding decode (#2839)

* test(transport/frame): decode padding frame > u16::MAX

* fix(transport/frame): prevent potential overflow in padding decode

Previously `neqo-transport` would use a `u16` to count the number of
padding frames, i.e. `0`s. If an attacker sends more than `u16::MAX`
`0`s, the counter would overflow.

This commit returns a `Error::TooMuchData` instead.

Note that the maximum UDP size is `u16::MAX`, thus in the real world, an
attacker can not send more than `u16::MAX` padding frames.

* Update neqo-common/src/codec.rs

Co-authored-by: Martin Thomson <mt@lowentropy.net>
Signed-off-by: Max Inden <mail@max-inden.de>

---------

Signed-off-by: Max Inden <mail@max-inden.de>
Co-authored-by: Martin Thomson <mt@lowentropy.net>

* docs(transport/datagrams): remove outdated fn return docs (#2842)

Signed-off-by: Max Inden <mail@max-inden.de>

* refactor(crypto): improve `ResumptionToken` `Debug` impl (#2847)

* refactor(crypto): improve `ResumptionToken` `Debug` impl

Use `hex_snip_middle` to print token.

See similar change in #2815.

* test: debug impl

* docs(transport): extend preprocess_packet docs on State::Closing (#2848)

* ci: Use 6.11 kernel on GCP (#2849)

* ci: Use implicit `$HOME` home directory (#2850)

* feat: Optimize `neqo-qpack` (#2831)

* feat: Optimize `neqo-qpack`

 Similar to #2827

* Address @martinthomson's comments

* fix(http3): reduce visibility of internal functions (#2802)

Mark functions not used in Firefox as pub(crate). This enables us to
detect unused code and simplifies future refactorings.

* refactor: unify most exchange_packets impls (#2851)

This commit unifies various `exchange_packets` implementations across the
codebase.

* Make initial RTT configurable (#2825)

Co-authored-by: Max Inden <mail@max-inden.de>

* fix(bin): replace buggy `to_headers` with `FromStr` `impl` (#2833)

* refactor(webtransport): rename WebTransportEvent::Session to NewSession (#2853)

On a new WebTransport session a client emits
`neqo_http3::client_events::WebTransportEvent::Session` and a server
emits  `neqo_http3::server_events::WebTransportServerEvent::NewSession`.
For the sake of consistency, rename the former to `NewSession`. Also
consistent with `neqo_http3:client_event::WebTransportEvent::NewStream`.

* ci: No `mold` (#2857)

It takes longer to install the mold package then performing the link.

* docs(http3): remove partially outdated docs (#2859)

* chore: Bump `sfv` to 0.14 (#2856)

* Make the drop_handshake_packet_from_wrong_address robust (#2862)

This test assumes that the server Initial is smaller than a single
packet.  That doesn't hold, even if we increase the size of that packet
by a single byte.  This test is a little more complex, but more robust.

* Make discarded_initial_keys more robust (#2864)

* Make discarded_initial_keys more robust

Use split_datagram to make the dropping/dup counting more robust.
Rename some variables to make them more obvious.

* Fix import foul-up

* Improve resending of Initial on undecryptable (#2866)

* Improve resending of Initial on undecryptable

The goal here was to make the test more robust, but it turns out that
the code could have been simpler as well.  That is, rather than testing
for a separate threshold, we can test instead for whether the saved
datagram store is full.  That was the same constant anyway.

The test is made more robust by having it disable MLKEM, which ensures
that there is just one Initial packet in each flight.  The undecryptable
packet is constructed manually (by rewriting an Initial).

* Rename the function

* compatible_upgrade_large_initial robustness (#2863)

* compatible_upgrade_large_initial robustness

This strips padding from all the packets in the handshake.
That makes all the accounting a lot simpler and robust.

This is not generic, but if I find a use for it in other tests (which
seems likely), it should be easy enough to factor it out.  The padding
test is a little fragile, but it accounts for the possibility of adding
SCONE at some point.

* Move the strip_padding function out

* Make sure to strip padding

* Move connection parameter defaults to the type (#2869)

* Move connection parameter defaults to the type

This is just a bunch of renaming, but it makes it possible to
encapsulate better.

* Update doc link

* Move test_frame_writer use (#2870)

* Move test_frame_writer use

... to ensure that it can be used for handshake packet types.

Takes @larseggert's suggestion to assert that the packet isn't full.

* Factor out the overfill test for datagrams

* Improve the ALPN handling (#2871)

* Improve the ALPN handling

We went through and removed `unwrap()` calls and assertions from a lot
of the code.  This function gained a `Result` return value, but was
still doing some asserting.  Also, there are a few nice facilities in
the std library that can make this a bit smoother than before.

* Also take byte arrays, which is more general ( counts)

* Add a test for the ALPN to get coverage back

* Remove redundant &

* Make only_server_initial more robust (#2865)

This uses `split_datagram` again to ensure that our counting is accurate
in case we can't coalesce sometimes.

Signed-off-by: Martin Thomson <mt@lowentropy.net>

* coalesce_05rtt robustness improvements (#2867)

* compatible_upgrade_large_initial robustness

This strips padding from all the packets in the handshake.
That makes all the accounting a lot simpler and robust.

This is not generic, but if I find a use for it in other tests (which
seems likely), it should be easy enough to factor it out.  The padding
test is a little fragile, but it accounts for the possibility of adding
SCONE at some point.

* Move the strip_padding function out

* Make the coalesce_05rtt test robust

This was checking for dropped packets as if that made a significant
difference.  It does, because we want to make sure that no packet was
dropped because it couldn't be decrypted, but we need to ensure that the
packet padding wasn't masking real drops.  The way to fix that is to
strip padding where necessary.  Factors out the code from the previous
test.

---------

Signed-off-by: Martin Thomson <mt@lowentropy.net>

* A bunch of logging improvements (#2874)

* A bunch of logging improvements

There's a lot of places we were dumping Debug implementations to the
log, without considering that they were big buffers of data.  This fixes
that.  It also removes a few logging statements that were redundant and
enables logging for anything using the test-fixture crate.

* Get the imports right this time

* Completely rewrite dup_server_flight1 (#2868)

* compatible_upgrade_large_initial robustness

This strips padding from all the packets in the handshake.
That makes all the accounting a lot simpler and robust.

This is not generic, but if I find a use for it in other tests (which
seems likely), it should be easy enough to factor it out.  The padding
test is a little fragile, but it accounts for the possibility of adding
SCONE at some point.

* Move the strip_padding function out

* Completely rewrite dup_server_flight1

This was very old and it showed.  The new version is much more in line
with other tests we've written recently.  It also avoids a bunch of
unnecessary back and forth.  It covers all the cases properly as well.

---------

Signed-off-by: Martin Thomson <mt@lowentropy.net>

* Force coverage up by simplifying a test (#2872)

* Force coverage up by simplifying a test

* Even shorter

* Enable the client-side assertion as well.

* Fix packet_with_only_padding test (#2873)

This test was broken - it wasn't correctly encrypting the modified
packet.

* PTO across packet number spaces better (#2878)

This tweaks the change that @larseggert made to reduce the number of
pointless handshake packets (Initial and Handshake both).  Rather than
cap the number of probes we send on a PTO, this keeps the limit of two
packets, but disables the probing we do with PING frames once we have
sent a packet of the indicated type.

This merges the spaces that we probe when a PTO occurs.  So we don't
just probe the last space that fired the PTO timer.   Because we time
out Initial and Handshake packets at the same time often, that results
in only probing the Handshake space.  That's probably OK in most cases,
but it can mean stalling Handshake if there is stuff to send at that
level at a server.

Because this allows more than one packet to be sent in Initial and
Handshake packet number spaces, there are some tests that do precise
counting and need to be adjusted.

* fix: Don't call `finish` in `std::hash::Hash` implementations (#2881)

At least I understand from the docs that is not needed: https://doc.rust-lang.org/std/hash/trait.Hash.html#implementing-hash

* refactor(bin/server): simplify run() removing need for HttpServer::new (#2883)

#2734 introduced a trait parameter
into the `HTTPServer::process_multiple` trait function, thus making
`HttpServer` no longer object safe. That required a couple of minor
changes, solved via a new `HttpServer::new` function.

`HttpServer` is consumed by `neqo-bin`, but also `http3server` in
mozilla-firefox/firefox. The latter does not use `HttpServer::new`, but
the trait requires implementing it anyways.

This commit removes the need for `HttpServer::new`.

* Fix compatible upgrade (#2877)

* Fix compatible upgrade

This changeset should have zero obvious effect right now, but this is
preparatory for the change that will randomize the first packet number.

This makes the whole version negotiation thing far more robust.  It
ensures that we correctly track the received packet numbers across
multiple crypto states at both client and server.

It changes how we confirm a compatible version upgrade, using the
availability of Handshake keys as the definitive trigger.  At the
server, that means that the server has processed the ClientHello (which
contains the client transport parameters and that is what the server
needs.  At the client, that means that the client has received at least
one packet with the chosen value, which is what the client needs (any
packet that makes progress on the handshake is enough).

This fixes two bugs:

1. We previously committed a version when receiving any CRYPTO frame.
   If we received an Initial packet with a TLS HelloRetryRequest, that
   would have been wrong.  That can happen if the server hadn't
   processed the ClientHello, but we were previously assuming that the
   server would have done so.

2. There are cases where a peer can send a v2 packet with a
   truncated packet number.  They make the choice to truncate based on
   the largest acknowledged, which might be > 256 if they are doing
   first packet number randomization.  Because we track the largest
   received packet number in the cryptographic send/receive state AND
   there is separate state for that for each version that might be used,
   if that truncated packet number is the first v2 packet we see,
   we fail to decrypt.  That situation is not recoverable.

There are now tests for these bugs, which are a little convoluted to
setup, but not completely implausible.

I've retained the case for compatible upgrade if the packet version
in an Initial packet changes during the handshake.  This is consistent
with what the spec requires and it can avoid the need to do the fiddly
stuff that follows.

Fixing the packet number continuation thing was easy on the server: it
is the one that decides to use a new version, so it can commit before it
ever needs to decrypt anything.  On the client, we have to be a little
more careful.  There's a tiny performance hit for doing the update,
which entails looking at the crypto state for every version, but it
should be modest overall.

There was one other test that tests an error condition that becomes
State::Closed rather than State::Closing as a result of deferring the
version confirmation.

* Mention MSRV

Co-authored-by: Lars Eggert <lars@eggert.org>
Signed-off-by: Martin Thomson <mt@lowentropy.net>

* Capital idea

Co-authored-by: Lars Eggert <lars@eggert.org>
Signed-off-by: Martin Thomson <mt@lowentropy.net>

* Remove outdated comment.

Signed-off-by: Martin Thomson <mt@lowentropy.net>

---------

Signed-off-by: Martin Thomson <mt@lowentropy.net>
Co-authored-by: Lars Eggert <lars@eggert.org>

* Address test changes (more padding now means rearrangement of handshake)

* More tests with less flake

* Moar robust testing

* Finalize fixes for more tests

* dafmt

* Clippy

* Fix some comments

---------

Signed-off-by: Max Inden <mail@max-inden.de>
Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Martin Thomson <mt@lowentropy.net>
Co-authored-by: Lars Eggert <lars@eggert.org>
Co-authored-by: Max Inden <mail@max-inden.de>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Adolfo Ochagavía <github@adolfo.ochagavia.nl>
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.

2 participants