Skip to content

Commit 222c06b

Browse files
committed
feat: use the nss-rs blapi feature
1 parent 7c2a6a3 commit 222c06b

17 files changed

Lines changed: 140 additions & 70 deletions

File tree

.github/workflows/clippy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
# and linted for each combination. Excluded features are either empty
6565
# (ci, test-fixture, gecko), benchmarking-only (bench), or have their
6666
# own dedicated workflow (build-fuzzing-corpus).
67-
- run: cargo hack clippy --locked --feature-powerset --all-targets --exclude-features gecko,ci,bench,build-fuzzing-corpus,test-fixture -- -D warnings
67+
- run: cargo hack clippy --locked --feature-powerset --all-targets --exclude-features gecko,ci,bench,build-fuzzing-corpus,test-fixture --mutually-exclusive-features blapi,disable-encryption -- -D warnings
6868
- run: cargo doc --locked --workspace --no-deps --document-private-items
6969
env:
7070
RUSTDOCFLAGS: "--deny rustdoc::broken_intra_doc_links --deny warnings"

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ hex = { version = "0.4", default-features = false }
3636
http = { version = "1", default-features = false, features = ["std"] }
3737
libc = { version = "0.2", default-features = false }
3838
log = { version = "0.4", default-features = false }
39-
nss = { rev = "0.10.0", package = "nss-rs", git = "https://github.com/mozilla/nss-rs" }
39+
nss = { rev = "167920ccec86c23a1f7e51c570baf82a28a966c6", package = "nss-rs", git = "https://github.com/mozilla/nss-rs" }
4040
qlog = { version = "0.16.0", default-features = false }
4141
quinn-udp = { version = "0.6", default-features = false, features = ["log", "fast-apple-datapath"] }
4242
rustc-hash = { version = "2.1", default-features = false, features = [ "std" ]}

fuzz/fuzz_targets/client_initial.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fuzz_target!(|data: &[u8]| {
1919
let Some((header, d_cid, s_cid, payload)) = decode_initial_header(&ci, Role::Client) else {
2020
return;
2121
};
22-
let (aead, hp) = initial_aead_and_hp(d_cid, Role::Client);
22+
let (aead, _, hp) = initial_aead_and_hp(d_cid, Role::Client);
2323
let (_, pn) = header_protection::remove(&hp, header, payload);
2424

2525
let mut payload_enc = Encoder::with_capacity(MIN_INITIAL_PACKET_SIZE);

fuzz/fuzz_targets/server_initial.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fuzz_target!(|data: &[u8]| {
2525
let Some((header, d_cid, s_cid, payload)) = decode_initial_header(&si, Role::Server) else {
2626
return;
2727
};
28-
let (aead, hp) = initial_aead_and_hp(d_cid, Role::Server);
28+
let (aead, _, hp) = initial_aead_and_hp(d_cid, Role::Server);
2929
let (_, pn) = header_protection::remove(&hp, header, payload);
3030

3131
let mut payload_enc = Encoder::with_capacity(MIN_INITIAL_PACKET_SIZE);

neqo-http3/Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ enumset = { workspace = true }
2323
http = { workspace = true }
2424
log = { workspace = true }
2525
neqo-common = { path = "./../neqo-common" }
26-
neqo-qpack = { path = "./../neqo-qpack" }
27-
neqo-transport = { path = "./../neqo-transport" }
26+
neqo-qpack = { path = "./../neqo-qpack", default-features = false }
27+
neqo-transport = { path = "./../neqo-transport", default-features = false }
2828
nss = { workspace = true }
2929
qlog = { workspace = true }
3030
rustc-hash = { workspace = true }
@@ -34,7 +34,7 @@ thiserror = { workspace = true }
3434

3535
[dev-dependencies]
3636
criterion = { version = "4", package = "codspeed-criterion-compat", default-features = false }
37-
neqo-http3 = { path = ".", features = ["draft-29"] }
37+
neqo-http3 = { path = ".", default-features = false, features = ["draft-29"] }
3838
test-fixture = { path = "../test-fixture" }
3939

4040
[features]
@@ -45,6 +45,8 @@ bench = [
4545
"test-fixture/bench",
4646
"log/release_max_level_info",
4747
]
48+
blapi = ["neqo-transport/blapi"]
49+
default = ["blapi"]
4850
build-fuzzing-corpus = [
4951
"neqo-common/build-fuzzing-corpus",
5052
"neqo-transport/disable-encryption",

neqo-qpack/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ workspace = true
1818
[dependencies]
1919
log = { workspace = true }
2020
neqo-common = { path = "./../neqo-common" }
21-
neqo-transport = { path = "./../neqo-transport" }
21+
neqo-transport = { path = "./../neqo-transport", default-features = false }
2222
qlog = { workspace = true }
2323
rustc-hash = { workspace = true }
2424
static_assertions = { workspace = true }
@@ -32,6 +32,8 @@ ignored = ["log"]
3232

3333
[features]
3434
bench = ["neqo-common/bench", "neqo-transport/bench", "log/release_max_level_info"]
35+
blapi = ["neqo-transport/blapi"]
36+
default = ["blapi"]
3537
build-fuzzing-corpus = [
3638
"neqo-common/build-fuzzing-corpus",
3739
"neqo-transport/build-fuzzing-corpus",

neqo-transport/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ thiserror = { workspace = true }
3434

3535
[dev-dependencies]
3636
criterion = { version = "4", package = "codspeed-criterion-compat", default-features = false }
37-
neqo-transport = { path = ".", features = ["draft-29"] }
37+
neqo-transport = { path = ".", default-features = false, features = ["draft-29"] }
3838
test-fixture = { path = "../test-fixture" }
3939

4040
[features]
4141
bench = ["neqo-common/bench", "nss/bench", "test-fixture/bench", "log/release_max_level_info"]
42+
blapi = ["nss/blapi"]
43+
default = ["blapi"]
4244
build-fuzzing-corpus = [
4345
"neqo-common/build-fuzzing-corpus",
4446
"nss/disable-encryption",

neqo-transport/src/connection/tests/resumption.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ fn ticket_rtt(rtt: Duration) -> Duration {
108108
decode_initial_header(&server_initial, Role::Server).unwrap();
109109

110110
// Now decrypt the packet.
111-
let (aead, hp) = initial_aead_and_hp(&client_dcid, Role::Server);
111+
let (aead_enc, aead_dec, hp) = initial_aead_and_hp(&client_dcid, Role::Server);
112112
let (header, pn) = header_protection::remove(&hp, protected_header, payload);
113113
let pn_len = header.len() - protected_header.len();
114114
let mut buf = vec![0; payload.len()];
115-
let mut plaintext = aead
115+
let mut plaintext = aead_dec
116116
.decrypt(pn, &header, &payload[pn_len..], &mut buf)
117117
.unwrap()
118118
.to_owned();
@@ -130,7 +130,8 @@ fn ticket_rtt(rtt: Duration) -> Duration {
130130
// And rebuild a packet.
131131
let mut packet = header.clone();
132132
packet.resize(MIN_INITIAL_PACKET_SIZE, 0);
133-
aead.encrypt(pn, &header, &plaintext, &mut packet[header.len()..])
133+
aead_enc
134+
.encrypt(pn, &header, &plaintext, &mut packet[header.len()..])
134135
.unwrap();
135136
header_protection::apply(&hp, &mut packet, protected_header.len()..header.len());
136137
let si = Datagram::new(

neqo-transport/src/crypto.rs

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use enum_map::EnumMap;
1818
use neqo_common::{Buffer, Encoder, Role, hex, hex_snip_middle, qdebug, qinfo, qtrace};
1919
pub use nss::Epoch;
2020
use nss::{
21-
Agent, AntiReplay, Cipher, Error as CryptoError, HandshakeState, PrivateKey, PublicKey, Record,
22-
RecordList, RecordProtection as Aead, ResumptionToken, SymKey, TLS_AES_128_GCM_SHA256,
21+
Agent, AntiReplay, Cipher, Error as CryptoError, HandshakeState, Mode, PrivateKey, PublicKey,
22+
Record, RecordList, RecordProtection as Aead, ResumptionToken, SymKey, TLS_AES_128_GCM_SHA256,
2323
TLS_AES_256_GCM_SHA384, TLS_CHACHA20_POLY1305_SHA256, TLS_CT_HANDSHAKE, TLS_GRP_EC_SECP256R1,
2424
TLS_GRP_EC_SECP384R1, TLS_GRP_EC_SECP521R1, TLS_GRP_EC_X25519, TLS_GRP_KEM_MLKEM768X25519,
2525
TLS_VERSION_1_3, ZeroRttChecker, hkdf, hp, random,
@@ -444,6 +444,15 @@ pub enum CryptoDxDirection {
444444
Write,
445445
}
446446

447+
impl From<CryptoDxDirection> for Mode {
448+
fn from(dir: CryptoDxDirection) -> Self {
449+
match dir {
450+
CryptoDxDirection::Read => Self::Decrypt,
451+
CryptoDxDirection::Write => Self::Encrypt,
452+
}
453+
}
454+
}
455+
447456
#[derive(Debug)]
448457
pub struct CryptoDxState {
449458
/// The QUIC version.
@@ -489,7 +498,13 @@ impl CryptoDxState {
489498
version,
490499
direction,
491500
epoch: usize::from(epoch),
492-
aead: Aead::new(TLS_VERSION_1_3, cipher, secret, version.label_prefix())?,
501+
aead: Aead::new(
502+
TLS_VERSION_1_3,
503+
cipher,
504+
secret,
505+
version.label_prefix(),
506+
direction.into(),
507+
)?,
493508
hpkey: hp::Key::extract(TLS_VERSION_1_3, cipher, secret, &hplabel)?,
494509
used_pn: min_pn..min_pn,
495510
min_pn,
@@ -581,6 +596,7 @@ impl CryptoDxState {
581596
cipher,
582597
next_secret,
583598
self.version.label_prefix(),
599+
self.direction.into(),
584600
)?,
585601
hpkey: self.hpkey.try_clone()?,
586602
used_pn: pn..pn,
@@ -708,6 +724,13 @@ impl CryptoDxState {
708724
}
709725

710726
#[must_use]
727+
#[cfg(not(feature = "disable-encryption"))]
728+
pub const fn expansion(&self) -> usize {
729+
self.aead.expansion()
730+
}
731+
732+
#[must_use]
733+
#[cfg(feature = "disable-encryption")]
711734
pub fn expansion(&self) -> usize {
712735
self.aead.expansion()
713736
}
@@ -734,21 +757,35 @@ impl CryptoDxState {
734757
#[cfg(not(feature = "disable-encryption"))]
735758
#[cfg(test)]
736759
pub(crate) fn test_default() -> Self {
760+
Self::test_default_with_direction(CryptoDxDirection::Write)
761+
}
762+
763+
#[cfg(not(feature = "disable-encryption"))]
764+
#[cfg(test)]
765+
pub(crate) fn test_default_read() -> Self {
766+
Self::test_default_with_direction(CryptoDxDirection::Read)
767+
}
768+
769+
#[cfg(not(feature = "disable-encryption"))]
770+
#[cfg(test)]
771+
fn test_default_with_direction(direction: CryptoDxDirection) -> Self {
737772
// This matches the value in packet.rs
738773
const CLIENT_CID: &[u8] = &[0x83, 0x94, 0xc8, 0xf0, 0x3e, 0x51, 0x57, 0x08];
739-
Self::new_initial(
740-
Version::default(),
741-
CryptoDxDirection::Write,
742-
"server in",
743-
CLIENT_CID,
744-
0,
745-
)
746-
.unwrap()
774+
Self::new_initial(Version::default(), direction, "server in", CLIENT_CID, 0).unwrap()
775+
}
776+
777+
/// Get the amount of extra padding packets protected with this profile need.
778+
/// This is the difference between the size of the header protection sample
779+
/// and the AEAD expansion.
780+
#[cfg(not(feature = "disable-encryption"))]
781+
pub const fn extra_padding(&self) -> usize {
782+
hp::Key::SAMPLE_SIZE.saturating_sub(self.expansion())
747783
}
748784

749785
/// Get the amount of extra padding packets protected with this profile need.
750786
/// This is the difference between the size of the header protection sample
751787
/// and the AEAD expansion.
788+
#[cfg(feature = "disable-encryption")]
752789
pub fn extra_padding(&self) -> usize {
753790
hp::Key::SAMPLE_SIZE.saturating_sub(self.expansion())
754791
}
@@ -1340,8 +1377,7 @@ impl CryptoStates {
13401377
#[cfg(test)]
13411378
pub(crate) fn test_default() -> Self {
13421379
let read = |epoch| {
1343-
let mut dx = CryptoDxState::test_default();
1344-
dx.direction = CryptoDxDirection::Read;
1380+
let mut dx = CryptoDxState::test_default_read();
13451381
dx.epoch = epoch;
13461382
dx
13471383
};
@@ -1390,6 +1426,7 @@ impl CryptoStates {
13901426
TLS_CHACHA20_POLY1305_SHA256,
13911427
&secret,
13921428
"quic ", // This is a v1 test so hard-code the label.
1429+
Mode::Decrypt,
13931430
)
13941431
.unwrap(),
13951432
hpkey: hp::Key::extract(

0 commit comments

Comments
 (0)