Skip to content

Make only_server_initial more robust - #2865

Merged
martinthomson merged 2 commits into
mozilla:mainfrom
martinthomson:robust-only-server-initial
Aug 18, 2025
Merged

martinthomson merged 2 commits into
mozilla:mainfrom
martinthomson:robust-only-server-initial

Conversation

@martinthomson

Copy link
Copy Markdown
Member

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

This uses `split_datagram` again to ensure that our counting is accurate
in case we can't coalesce sometimes.
@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 (aa593ce) to head (d9c032e).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2865      +/-   ##
==========================================
+ Coverage   94.90%   94.93%   +0.02%     
==========================================
  Files         115      115              
  Lines       34492    34492              
  Branches    34492    34492              
==========================================
+ Hits        32735    32744       +9     
+ Misses       1750     1741       -9     
  Partials        7        7              
Components Coverage Δ
neqo-common 97.48% <ø> (ø)
neqo-crypto 89.91% <ø> (ø)
neqo-http3 93.73% <ø> (ø)
neqo-qpack 95.45% <ø> (ø)
neqo-transport 95.96% <ø> (+0.05%) ⬆️
neqo-udp 89.37% <ø> (-0.49%) ⬇️

@github-actions

github-actions Bot commented Aug 18, 2025 •

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

github-actions Bot commented Aug 18, 2025 •

Copy link
Copy Markdown
Contributor

Benchmark results

Performance differences relative to b01d966.

1-conn/1-100mb-resp/mtu-1504 (aka. Download)/client: 💔 Performance has regressed.
       time:   [201.10 ms 201.49 ms 201.93 ms]
       thrpt:  [495.23 MiB/s 496.31 MiB/s 497.27 MiB/s]
change:
       time:   [+1.2216% +1.4940% +1.7899%] (p = 0.00 < 0.05)
       thrpt:  [−1.7584% −1.4720% −1.2069%]

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

1-conn/10_000-parallel-1b-resp/mtu-1504 (aka. RPS)/client: No change in performance detected.
       time:   [303.25 ms 304.93 ms 306.60 ms]
       thrpt:  [32.616 Kelem/s 32.794 Kelem/s 32.976 Kelem/s]
change:
       time:   [−1.3062% −0.5910% +0.1491%] (p = 0.11 > 0.05)
       thrpt:  [−0.1489% +0.5945% +1.3235%]
1-conn/1-1b-resp/mtu-1504 (aka. HPS)/client: No change in performance detected.
       time:   [27.870 ms 27.963 ms 28.057 ms]
       thrpt:  [35.642   B/s 35.762   B/s 35.881   B/s]
change:
       time:   [−0.8237% −0.2628% +0.2952%] (p = 0.37 > 0.05)
       thrpt:  [−0.2943% +0.2635% +0.8305%]
1-conn/1-100mb-req/mtu-1504 (aka. Upload)/client: 💔 Performance has regressed.
       time:   [207.85 ms 208.16 ms 208.52 ms]
       thrpt:  [479.58 MiB/s 480.41 MiB/s 481.11 MiB/s]
change:
       time:   [+1.8429% +2.0942% +2.3205%] (p = 0.00 < 0.05)
       thrpt:  [−2.2679% −2.0513% −1.8096%]

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

decode 4096 bytes, mask ff: No change in performance detected.
       time:   [11.606 µs 11.649 µs 11.696 µs]
       change: [−1.7432% −0.7160% +0.0412%] (p = 0.12 > 0.05)

Found 17 outliers among 100 measurements (17.00%)
1 (1.00%) low severe
5 (5.00%) low mild
3 (3.00%) high mild
8 (8.00%) high severe

decode 1048576 bytes, mask ff: No change in performance detected.
       time:   [3.0620 ms 3.0796 ms 3.1051 ms]
       change: [−0.3707% +0.3249% +1.2404%] (p = 0.47 > 0.05)

Found 9 outliers among 100 measurements (9.00%)
9 (9.00%) high severe

decode 4096 bytes, mask 7f: No change in performance detected.
       time:   [19.377 µs 19.427 µs 19.481 µs]
       change: [−0.8199% −0.2220% +0.2481%] (p = 0.46 > 0.05)

Found 16 outliers among 100 measurements (16.00%)
2 (2.00%) low severe
2 (2.00%) low mild
12 (12.00%) high severe

decode 1048576 bytes, mask 7f: No change in performance detected.
       time:   [5.0840 ms 5.0958 ms 5.1088 ms]
       change: [−0.5035% −0.1354% +0.2141%] (p = 0.48 > 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.5173 µs 5.5350 µs 5.5618 µs]
       change: [−0.9809% −0.3906% +0.1016%] (p = 0.18 > 0.05)

Found 13 outliers among 100 measurements (13.00%)
3 (3.00%) low mild
7 (7.00%) high mild
3 (3.00%) high severe

decode 1048576 bytes, mask 3f: Change within noise threshold.
       time:   [1.7742 ms 1.7872 ms 1.8037 ms]
       change: [+0.6421% +1.5021% +2.4954%] (p = 0.00 < 0.05)

Found 18 outliers among 100 measurements (18.00%)
18 (18.00%) high severe

coalesce_acked_from_zero 1+1 entries: No change in performance detected.
       time:   [88.015 ns 88.322 ns 88.644 ns]
       change: [−2.7194% −1.0360% +0.1136%] (p = 0.18 > 0.05)

Found 7 outliers among 100 measurements (7.00%)
4 (4.00%) high mild
3 (3.00%) high severe

coalesce_acked_from_zero 3+1 entries: No change in performance detected.
       time:   [106.30 ns 106.68 ns 107.07 ns]
       change: [−0.3886% +0.1398% +0.6906%] (p = 0.61 > 0.05)

Found 17 outliers among 100 measurements (17.00%)
17 (17.00%) high severe

coalesce_acked_from_zero 10+1 entries: Change within noise threshold.
       time:   [105.31 ns 105.53 ns 105.86 ns]
       change: [−2.8843% −1.4282% −0.2578%] (p = 0.02 < 0.05)

Found 22 outliers among 100 measurements (22.00%)
8 (8.00%) low severe
3 (3.00%) low mild
5 (5.00%) high mild
6 (6.00%) high severe

coalesce_acked_from_zero 1000+1 entries: No change in performance detected.
       time:   [88.916 ns 93.550 ns 103.71 ns]
       change: [−1.6915% +1.4824% +6.3694%] (p = 0.59 > 0.05)

Found 10 outliers among 100 measurements (10.00%)
3 (3.00%) high mild
7 (7.00%) high severe

RxStreamOrderer::inbound_frame(): Change within noise threshold.
       time:   [106.43 ms 106.58 ms 106.84 ms]
       change: [−1.0715% −0.9018% −0.6558%] (p = 0.00 < 0.05)

Found 25 outliers among 100 measurements (25.00%)
3 (3.00%) low severe
10 (10.00%) low mild
10 (10.00%) high mild
2 (2.00%) high severe

sent::Packets::take_ranges: :green_heart: Performance has improved.
       time:   [5.0913 µs 5.1646 µs 5.2315 µs]
       change: [−41.714% −36.361% −24.051%] (p = 0.00 < 0.05)

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

transfer/pacing-false/varying-seeds: Change within noise threshold.
       time:   [36.322 ms 36.405 ms 36.487 ms]
       change: [−3.2208% −2.8717% −2.5439%] (p = 0.00 < 0.05)

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

transfer/pacing-true/varying-seeds: 💚 Performance has improved.
       time:   [37.156 ms 37.258 ms 37.360 ms]
       change: [−3.9320% −3.5624% −3.1625%] (p = 0.00 < 0.05)
transfer/pacing-false/same-seed: Change within noise threshold.
       time:   [36.331 ms 36.404 ms 36.478 ms]
       change: [−2.9705% −2.7088% −2.4391%] (p = 0.00 < 0.05)
transfer/pacing-true/same-seed: Change within noise threshold.
       time:   [38.110 ms 38.191 ms 38.272 ms]
       change: [−2.9930% −2.6687% −2.3493%] (p = 0.00 < 0.05)

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

@github-actions

github-actions Bot commented Aug 18, 2025 •

Copy link
Copy Markdown
Contributor

Client/server transfer results

Performance differences relative to b01d966.

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 454.9 ± 4.0 449.5 469.0 70.3 ± 8.0
google vs. neqo (cubic, paced) 272.1 ± 4.0 265.3 280.8 117.6 ± 8.0 💚 -2.0 -0.7%
msquic vs. msquic 133.5 ± 41.6 110.9 403.0 239.7 ± 0.8
msquic vs. neqo (cubic, paced) 147.7 ± 33.8 121.3 341.4 216.7 ± 0.9 -2.3 -1.5%
neqo vs. google (cubic, paced) 758.9 ± 5.0 751.7 774.8 42.2 ± 6.4 💔 2.7 0.4%
neqo vs. msquic (cubic, paced) 156.0 ± 4.4 149.9 166.2 205.2 ± 7.3 -0.9 -0.6%
neqo vs. neqo (cubic) 92.2 ± 4.3 85.6 105.5 347.1 ± 7.4 -1.1 -1.2%
neqo vs. neqo (cubic, paced) 92.1 ± 5.5 82.5 114.6 347.5 ± 5.8 -0.7 -0.8%
neqo vs. neqo (reno) 92.9 ± 4.5 84.7 105.3 344.5 ± 7.1 -0.1 -0.1%
neqo vs. neqo (reno, paced) 92.5 ± 4.5 83.9 110.3 346.1 ± 7.1 💚 -1.7 -1.8%
neqo vs. quiche (cubic, paced) 191.2 ± 2.6 187.2 203.1 167.3 ± 12.3 💚 -2.1 -1.1%
neqo vs. s2n (cubic, paced) 220.6 ± 5.0 212.3 232.8 145.1 ± 6.4 0.5 0.2%
quiche vs. neqo (cubic, paced) 147.7 ± 6.1 138.8 181.7 216.7 ± 5.2 -0.9 -0.6%
quiche vs. quiche 145.5 ± 4.9 137.7 156.9 220.0 ± 6.5
s2n vs. neqo (cubic, paced) 171.1 ± 4.8 161.6 184.9 187.0 ± 6.7 -0.5 -0.3%
s2n vs. s2n 247.9 ± 23.0 233.6 348.0 129.1 ± 1.4

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 failed status checks Aug 18, 2025
Signed-off-by: Martin Thomson <mt@lowentropy.net>
@martinthomson
martinthomson added this pull request to the merge queue Aug 18, 2025
Merged via the queue into mozilla:main with commit ea3f7a5 Aug 18, 2025
@martinthomson
martinthomson deleted the robust-only-server-initial branch August 18, 2025 07:43
martinthomson added a commit to martinthomson/neqo that referenced this pull request Aug 21, 2025
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>
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