Skip to content

feat: Shuffle the client Initial crypto data - #2228

Merged
larseggert merged 28 commits into
mozilla:mainfrom
larseggert:feat-initial-mixer
Nov 29, 2024
Merged

larseggert merged 28 commits into
mozilla:mainfrom
larseggert:feat-initial-mixer

Conversation

@larseggert

@larseggert larseggert commented Nov 13, 2024 •

Copy link
Copy Markdown
Collaborator

Find the index range of the SNI extension in data, split data in half at the midpoint of the SNI extension, and return the two halves and their respective starting indexes in reverse order.

CC @martinthomson @dennisjackson

Look for ranges of `N` or more bytes of graphical ASCII data in `data`.
Create at least one split point for each range, multiple ones each `N`
bytes if the range is long enough. Create data chunks based on those
split points. Shuffle the chunks and return them.

CC @martinthomson @dennisjackson
@github-actions

github-actions Bot commented Nov 13, 2024 •

Copy link
Copy Markdown
Contributor

Failed Interop Tests

QUIC Interop Runner, client vs. server

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

@larseggert
larseggert marked this pull request as ready for review November 14, 2024 14:37
@codecov

codecov Bot commented Nov 15, 2024 •

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.39%. Comparing base (c6d5502) to head (d949b85).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2228      +/-   ##
==========================================
+ Coverage   95.38%   95.39%   +0.01%     
==========================================
  Files         112      113       +1     
  Lines       36593    36683      +90     
==========================================
+ Hits        34903    34994      +91     
+ Misses       1690     1689       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions

github-actions Bot commented Nov 15, 2024 •

Copy link
Copy Markdown
Contributor

Benchmark results

Performance differences relative to c6d5502.

coalesce_acked_from_zero 1+1 entries: Change within noise threshold.
       time:   [98.372 ns 98.696 ns 99.034 ns]
       change: [-1.3417% -0.7152% -0.2178%] (p = 0.01 < 0.05)

Found 12 outliers among 100 measurements (12.00%)
12 (12.00%) high severe

coalesce_acked_from_zero 3+1 entries: Change within noise threshold.
       time:   [116.67 ns 117.04 ns 117.44 ns]
       change: [-0.8933% -0.5158% -0.1757%] (p = 0.01 < 0.05)

Found 14 outliers among 100 measurements (14.00%)
1 (1.00%) low severe
1 (1.00%) low mild
12 (12.00%) high severe

coalesce_acked_from_zero 10+1 entries: Change within noise threshold.
       time:   [116.23 ns 116.58 ns 117.01 ns]
       change: [-0.9375% -0.4989% -0.0836%] (p = 0.02 < 0.05)

Found 12 outliers among 100 measurements (12.00%)
2 (2.00%) low severe
3 (3.00%) low mild
3 (3.00%) high mild
4 (4.00%) high severe

coalesce_acked_from_zero 1000+1 entries: No change in performance detected.
       time:   [97.661 ns 101.56 ns 110.40 ns]
       change: [+0.0832% +3.4703% +9.5705%] (p = 0.22 > 0.05)

Found 13 outliers among 100 measurements (13.00%)
5 (5.00%) high mild
8 (8.00%) high severe

RxStreamOrderer::inbound_frame(): 💔 Performance has regressed.
       time:   [114.39 ms 114.47 ms 114.54 ms]
       change: [+2.6355% +2.7211% +2.8008%] (p = 0.00 < 0.05)

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

SentPackets::take_ranges: No change in performance detected.
       time:   [5.5185 µs 5.6965 µs 5.8883 µs]
       change: [-2.6985% +0.4724% +3.6310%] (p = 0.77 > 0.05)

Found 7 outliers among 100 measurements (7.00%)
6 (6.00%) high mild
1 (1.00%) high severe

transfer/pacing-false/varying-seeds: No change in performance detected.
       time:   [26.085 ms 27.055 ms 28.019 ms]
       change: [-2.7087% +2.9087% +8.8336%] (p = 0.31 > 0.05)
transfer/pacing-true/varying-seeds: No change in performance detected.
       time:   [33.267 ms 34.933 ms 36.601 ms]
       change: [-4.7335% +1.6798% +8.9963%] (p = 0.64 > 0.05)
transfer/pacing-false/same-seed: No change in performance detected.
       time:   [24.999 ms 25.778 ms 26.554 ms]
       change: [-4.8756% -0.8536% +3.3036%] (p = 0.69 > 0.05)
transfer/pacing-true/same-seed: No change in performance detected.
       time:   [39.864 ms 41.951 ms 44.104 ms]
       change: [-5.8674% +1.1545% +8.7258%] (p = 0.74 > 0.05)
1-conn/1-100mb-resp/mtu-1504 (aka. Download)/client: No change in performance detected.
       time:   [899.71 ms 909.17 ms 918.77 ms]
       thrpt:  [108.84 MiB/s 109.99 MiB/s 111.15 MiB/s]
change:
       time:   [-1.0575% +0.4603% +1.9740%] (p = 0.56 > 0.05)
       thrpt:  [-1.9358% -0.4582% +1.0688%]
1-conn/10_000-parallel-1b-resp/mtu-1504 (aka. RPS)/client: Change within noise threshold.
       time:   [314.69 ms 317.96 ms 321.30 ms]
       thrpt:  [31.124 Kelem/s 31.450 Kelem/s 31.778 Kelem/s]
change:
       time:   [-3.4925% -2.1493% -0.7494%] (p = 0.00 < 0.05)
       thrpt:  [+0.7551% +2.1965% +3.6189%]
1-conn/1-1b-resp/mtu-1504 (aka. HPS)/client: No change in performance detected.
       time:   [33.531 ms 33.723 ms 33.925 ms]
       thrpt:  [29.477  elem/s 29.653  elem/s 29.823  elem/s]
change:
       time:   [-1.0394% -0.1718% +0.7032%] (p = 0.70 > 0.05)
       thrpt:  [-0.6983% +0.1721% +1.0503%]

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

1-conn/1-100mb-resp/mtu-1504 (aka. Upload)/client: Change within noise threshold.
       time:   [1.6757 s 1.6942 s 1.7129 s]
       thrpt:  [58.380 MiB/s 59.026 MiB/s 59.676 MiB/s]
change:
       time:   [+0.1173% +1.8842% +3.6179%] (p = 0.04 < 0.05)
       thrpt:  [-3.4916% -1.8494% -0.1172%]

Client/server transfer results

Transfer of 33554432 bytes over loopback.

Client Server CC Pacing MTU Mean [ms] Min [ms] Max [ms]
gquiche gquiche 1504 590.9 ± 82.2 520.2 754.2
neqo gquiche reno on 1504 794.6 ± 47.4 757.0 913.6
neqo gquiche reno 1504 775.2 ± 34.6 749.3 870.8
neqo gquiche cubic on 1504 779.6 ± 17.3 738.4 802.2
neqo gquiche cubic 1504 783.0 ± 41.5 754.6 896.5
msquic msquic 1504 172.1 ± 103.2 95.1 448.2
neqo msquic reno on 1504 255.3 ± 60.3 200.7 398.9
neqo msquic reno 1504 226.3 ± 13.8 201.3 250.2
neqo msquic cubic on 1504 263.5 ± 98.5 201.2 501.7
neqo msquic cubic 1504 297.9 ± 115.3 213.7 514.3
gquiche neqo reno on 1504 733.0 ± 101.5 571.9 855.8
gquiche neqo reno 1504 720.6 ± 93.0 609.7 869.7
gquiche neqo cubic on 1504 711.2 ± 83.8 587.7 836.4
gquiche neqo cubic 1504 749.1 ± 199.0 592.7 1271.8
msquic neqo reno on 1504 507.3 ± 30.0 486.8 587.4
msquic neqo reno 1504 547.7 ± 89.8 474.1 687.4
msquic neqo cubic on 1504 511.8 ± 62.9 471.3 636.2
msquic neqo cubic 1504 521.7 ± 49.0 475.4 598.5
neqo neqo reno on 1504 548.6 ± 23.3 512.3 578.8
neqo neqo reno 1504 558.9 ± 72.1 494.4 729.9
neqo neqo cubic on 1504 599.2 ± 48.0 571.2 694.1
neqo neqo cubic 1504 570.8 ± 22.5 550.5 625.9

⬇️ Download logs

@larseggert larseggert changed the title feat: Mix up the Initial crypto data a bit feat: Shuffle the client Initial crypto data Nov 15, 2024
Comment thread neqo-transport/src/crypto.rs Resolved
Comment thread neqo-transport/src/crypto.rs Resolved
Comment thread neqo-transport/src/crypto.rs Resolved
Comment thread neqo-transport/src/crypto.rs Resolved
Comment thread neqo-transport/src/crypto.rs Resolved
Comment thread neqo-transport/src/crypto.rs Resolved
Comment thread neqo-transport/src/crypto.rs Resolved
Comment thread neqo-transport/src/crypto.rs Resolved
Comment thread neqo-transport/src/crypto.rs Resolved
Comment thread neqo-transport/src/crypto.rs Resolved
Comment thread neqo-transport/src/crypto.rs Resolved

@martinthomson martinthomson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I spent a few minutes writing some code that might be a good replacement for this if you only care about splitting at a useful point. This would be used by drawing a random value in the range (r.start + 1..end - 1) to split on. It's a lot less code...

/// Finds the range where the SNI extension lives.
/// If this isn't a ClientHello, then return the whole message.
fn find_sni_split(mut buf: &[u8]) -> Range<usize> {
    fn read_len(buf: &[u8]) -> usize {
        let mut len = 0;
        for v in buf {
            len = len << 8 & usize::from(v);
        }
        len
    }
    fn skip_vec<const N: usize>(i: usize, buf: &[u8]) -> usize {
        i + N + read_len(&buf[i..i + N])
    }

    // ClientHello == 1
    if buf[0] == 1 {
        let mut i = 1 + 3 + 2 + 32; // msg_type, length, version, random
        i = skip_vec::<1>(i, buf); // session_id
        i = skip_vec::<2>(i, buf); // cipher_suites
        i = skip_vec::<1>(i, buf); // compression_methods
        i += 2; // extensions length
        while i < buf.len() {
            if buf[i] == 0 || buf[i + 1] == 0 {
                // SNI!
                return i..i + 4 + read_len(buf[i + 2..i + 4]);
            }
        }
    }
    0..buf.len()
}

Comment thread neqo-transport/src/shuffle.rs Resolved
@larseggert

Copy link
Copy Markdown
Collaborator Author

I spent a few minutes writing some code that might be a good replacement for this if you only care about splitting at a useful point.

Thanks for this, but I think it needs more work? I don't think this handles invalid crypto data well, skip_vec seems to easily read beyond the end of the buffer.

@martinthomson

Copy link
Copy Markdown
Member

Fair. It was only a few minutes of work. Adding bounds checks will complicate it a little, but not overmuch. Of course, you could take the attitude I did, which is that the TLS stack should not be producing invalid messages, so panicking in that case is justified.

@larseggert

Copy link
Copy Markdown
Collaborator Author

I am nervous about making assumptions about the input. But let me play with it and see how much complexity bounds checking adds.

@larseggert

larseggert commented Nov 27, 2024 •

Copy link
Copy Markdown
Collaborator Author

@martinthomson is your code taking SSL_ENABLE_CH_EXTENSION_PERMUTATION into account? Because the range it returns isn't the SNI...

Ah, it wasn't that; there were some minor nits that caused it to misbehave.

Comment thread neqo-transport/src/shuffle.rs Resolved
Comment thread neqo-transport/src/shuffle.rs Resolved
Comment thread neqo-transport/src/crypto.rs Resolved
Comment thread neqo-transport/src/crypto.rs Resolved
Comment thread neqo-transport/src/connection/mod.rs Resolved
Comment thread neqo-transport/src/crypto.rs Resolved
Comment thread neqo-transport/src/crypto.rs Resolved
larseggert and others added 2 commits November 29, 2024 08:38
Co-authored-by: Martin Thomson <mt@lowentropy.net>
Signed-off-by: Lars Eggert <lars@eggert.org>
@larseggert
larseggert added this pull request to the merge queue Nov 29, 2024
Merged via the queue into mozilla:main with commit 673d44d Nov 29, 2024
@larseggert
larseggert deleted the feat-initial-mixer branch November 29, 2024 07:35
@mxinden mxinden mentioned this pull request Jan 15, 2025
mxinden added a commit to mxinden/neqo that referenced this pull request Jan 16, 2025
`compatible_upgrade_large_initial` tests whether Neqo can handle an ACK using
QUIC version Y on a connection that ends up using QUIC version X.

mozilla#2228 changed the test, asserting that the
server will drop 2 instead of 1 packet. This spuriosly fails on CI:

https://github.com/mozilla/neqo/actions/runs/12796212878/job/35675377711?pr=2295

This commit allows both 1 and 2 packets dropped by the server.
github-merge-queue Bot pushed a commit that referenced this pull request Jan 26, 2025
`compatible_upgrade_large_initial` tests whether Neqo can handle an ACK using
QUIC version Y on a connection that ends up using QUIC version X.

#2228 changed the test, asserting that the
server will drop 2 instead of 1 packet. This spuriosly fails on CI:

https://github.com/mozilla/neqo/actions/runs/12796212878/job/35675377711?pr=2295

This commit allows both 1 and 2 packets dropped by the server.
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.

3 participants