Skip to content

Commit 4b3ca1c

Browse files
Add QUIC test
1 parent 350e0f2 commit 4b3ca1c

File tree

11 files changed

+2883
-37
lines changed

11 files changed

+2883
-37
lines changed

.github/workflows/rustls-real-socket-test.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
name: Rustls Real Socket Test
1+
name: Rustls Real World Test
22

33
on:
44
push:
55
branches: [ master ]
66
paths:
77
- 'validation/rustls-real-socket-test/**'
8+
- 'validation/quic-test/**'
89
- '.github/workflows/rustls-real-socket-test.yml'
910
pull_request:
1011
paths:
1112
- 'validation/rustls-real-socket-test/**'
13+
- 'validation/quic-test/**'
1214
- '.github/workflows/rustls-real-socket-test.yml'
1315

1416
permissions:
@@ -31,9 +33,18 @@ jobs:
3133
- name: Cache Cargo
3234
uses: Swatinem/rust-cache@v2
3335
with:
34-
workspaces: "validation/rustls-real-socket-test"
36+
workspaces: |
37+
validation/rustls-real-socket-test
38+
validation/quic-test
3539
36-
- name: Run in release mode
40+
- name: Run in real socket test release mode
41+
working-directory: validation/rustls-real-socket-test
42+
run: cargo run --release
43+
env:
44+
SCCACHE_GHA_ENABLED: "true"
45+
RUSTC_WRAPPER: "sccache"
46+
47+
- name: Run in QUIC test release mode
3748
working-directory: validation/rustls-real-socket-test
3849
run: cargo run --release
3950
env:

src/aead.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use aead::Buffer;
22
use rustls::crypto::cipher::{BorrowedPayload, PrefixedPayload};
33

4-
#[cfg(feature = "tinyvec")]
5-
use tinyvec::SliceVec;
4+
#[cfg(feature = "alloc")]
5+
use alloc::vec::Vec;
66

77
#[cfg(feature = "gcm")]
88
pub mod gcm;
@@ -13,18 +13,21 @@ pub mod ccm;
1313
#[macro_use]
1414
pub(crate) mod common;
1515

16+
#[cfg(feature = "tinyvec")]
17+
use tinyvec::SliceVec;
18+
1619
pub(crate) enum EncryptBufferAdapter<'a> {
1720
PrefixedPayload(&'a mut PrefixedPayload),
18-
#[cfg(feature = "tinyvec")]
19-
Slice(SliceVec<'a, u8>),
21+
#[cfg(feature = "quic")]
22+
Vec(Vec<u8>),
2023
}
2124

2225
impl AsRef<[u8]> for EncryptBufferAdapter<'_> {
2326
fn as_ref(&self) -> &[u8] {
2427
match self {
2528
EncryptBufferAdapter::PrefixedPayload(payload) => payload.as_ref(),
26-
#[cfg(feature = "tinyvec")]
27-
EncryptBufferAdapter::Slice(payload) => payload.as_ref(),
29+
#[cfg(feature = "quic")]
30+
EncryptBufferAdapter::Vec(payload) => payload.as_ref(),
2831
}
2932
}
3033
}
@@ -33,8 +36,8 @@ impl AsMut<[u8]> for EncryptBufferAdapter<'_> {
3336
fn as_mut(&mut self) -> &mut [u8] {
3437
match self {
3538
EncryptBufferAdapter::PrefixedPayload(payload) => payload.as_mut(),
36-
#[cfg(feature = "tinyvec")]
37-
EncryptBufferAdapter::Slice(payload) => payload.as_mut(),
39+
#[cfg(feature = "quic")]
40+
EncryptBufferAdapter::Vec(payload) => payload.as_mut(),
3841
}
3942
}
4043
}
@@ -43,17 +46,17 @@ impl Buffer for EncryptBufferAdapter<'_> {
4346
fn extend_from_slice(&mut self, other: &[u8]) -> aead::Result<()> {
4447
match self {
4548
EncryptBufferAdapter::PrefixedPayload(payload) => payload.extend_from_slice(other),
46-
#[cfg(feature = "tinyvec")]
47-
EncryptBufferAdapter::Slice(payload) => payload.extend_from_slice(other),
49+
#[cfg(feature = "quic")]
50+
EncryptBufferAdapter::Vec(payload) => payload.extend_from_slice(other),
4851
}
4952
Ok(())
5053
}
5154

5255
fn truncate(&mut self, len: usize) {
5356
match self {
5457
EncryptBufferAdapter::PrefixedPayload(payload) => payload.truncate(len),
55-
#[cfg(feature = "tinyvec")]
56-
EncryptBufferAdapter::Slice(payload) => payload.truncate(len),
58+
#[cfg(feature = "quic")]
59+
EncryptBufferAdapter::Vec(payload) => payload.truncate(len),
5760
}
5861
}
5962
}

src/quic.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
use alloc::{boxed::Box, vec};
1+
use alloc::boxed::Box;
22

33
use aead::{AeadCore, AeadInOut, KeyInit};
44
use enum_dispatch::enum_dispatch;
55
use rustls::Error;
66
use rustls::crypto::cipher::{AeadKey, Iv, Nonce};
77
use rustls::quic;
8-
use tinyvec::SliceVec;
98
use typenum::Unsigned;
109

1110
use crate::aead::{DecryptBufferAdapter, EncryptBufferAdapter};
@@ -267,18 +266,15 @@ where
267266
let nonce_aead = aead::Nonce::<A>::try_from(&Nonce::new(&self.iv, packet_number).0[..])
268267
.map_err(|_| Error::EncryptError)?;
269268

270-
// Create a buffer with payload + space for tag
271-
let mut buffer = vec![0u8; payload.len() + A::TagSize::USIZE];
272-
buffer[..payload.len()].copy_from_slice(payload);
269+
// Create a buffer with the payload
270+
let mut buffer = EncryptBufferAdapter::Vec(payload.to_vec());
273271

274272
self.key
275-
.encrypt_in_place(
276-
&nonce_aead,
277-
header,
278-
&mut EncryptBufferAdapter::Slice(SliceVec::from(&mut buffer)),
279-
)
273+
.encrypt_in_place(&nonce_aead, header, &mut buffer)
280274
.map_err(|_| Error::EncryptError)?;
281275

276+
let buffer = buffer.as_ref();
277+
282278
// Copy the encrypted payload back
283279
payload.copy_from_slice(&buffer[..payload.len()]);
284280

src/tls13/suites/aes.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
#[cfg(feature = "quic")]
2-
use crate::aead::aes::{Aes128Gcm, Aes256Gcm};
31
use crate::const_concat_slices;
42
use crate::feature_eval_expr;
53
use crate::feature_slice;
4+
use crate::tls13_cipher_suite;
5+
use crate::{hash, hmac};
6+
use rustls::crypto::{CipherSuiteCommon, tls13::HkdfUsingHmac};
7+
use rustls::{CipherSuite, SupportedCipherSuite, Tls13CipherSuite};
8+
9+
#[cfg(all(feature = "gcm", feature = "hash-sha256", feature = "quic"))]
10+
use crate::aead::aes::Aes128Gcm;
11+
#[cfg(all(feature = "gcm", feature = "hash-sha384", feature = "quic"))]
12+
use crate::aead::aes::Aes256Gcm;
613
#[cfg(all(feature = "ccm", feature = "hash-sha256"))]
714
use crate::tls13::aead::ccm::{AES_128_CCM, AES_128_CCM_8};
815
#[cfg(all(feature = "gcm", feature = "hash-sha256"))]
916
use crate::tls13::aead::gcm::AES_128_GCM;
1017
#[cfg(all(feature = "gcm", feature = "hash-sha384"))]
1118
use crate::tls13::aead::gcm::AES_256_GCM;
12-
use crate::tls13_cipher_suite;
13-
use crate::{hash, hmac};
14-
use rustls::crypto::{CipherSuiteCommon, tls13::HkdfUsingHmac};
15-
use rustls::{CipherSuite, SupportedCipherSuite, Tls13CipherSuite};
1619

1720
#[cfg(all(feature = "gcm", feature = "hash-sha256"))]
1821
tls13_cipher_suite!(

validation/README.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,45 +14,54 @@ These validation crates serve multiple critical purposes:
1414

1515
## Validation Crates
1616

17-
| Crate | Description | Target Environment |
18-
| :--- | :--- | :--- |
19-
| consumer-no_std | Basic consumer library for no_std environments | no_std |
20-
| local_ping_pong_openssl | Local tests against OpenSSL reference | Standard Rust |
21-
| esp32-test | Test for ESP32 microcontroller target using real sockets | ESP32 |
22-
| rustls-real-socket-test | Test using real sockets for TLS integration | Standard Rust |
17+
| Crate | Description | Target Environment |
18+
| :---------------------- | :------------------------------------------------------- | :----------------- |
19+
| consumer-no_std | Basic consumer library for no_std environments | no_std |
20+
| local_ping_pong_openssl | Local tests against OpenSSL reference | Standard Rust |
21+
| esp32-test | Test for ESP32 microcontroller target using real sockets | ESP32 |
22+
| rustls-real-socket-test | Test using real sockets for TLS integration | Standard Rust |
23+
| quic-test | Battle-test using QUIC to do roundtrip calls | Standard Rust |
2324

2425
### Detailed Crate Descriptions
2526

2627
#### consumer-no_std
28+
2729
A minimal self-testing crate that validates the no_std build capability of rustls-rustcrypto. This crate ensures that the provider can be compiled and used in environments without the standard library, which is crucial for embedded systems and constrained environments.
2830

2931
**Key Features:**
32+
3033
- Validates no_std compilation
3134
- Minimal dependencies
3235
- Self-contained testing
3336

3437
#### local_ping_pong_openssl
38+
3539
This crate performs comprehensive compatibility testing between rustls-rustcrypto and OpenSSL. It includes tests with OpenSSL-generated certificates and keys to ensure interoperability and correct TLS handshake behavior.
3640

3741
**Key Features:**
42+
3843
- OpenSSL compatibility testing
3944
- Certificate and key validation
4045
- TLS handshake verification
4146
- Cross-implementation validation
4247

4348
#### esp32-test
49+
4450
A specialized test crate for the ESP32 microcontroller platform. It performs end-to-end TLS testing using real network sockets, validating the rustcrypto provider's functionality in an embedded environment.
4551

4652
**Key Features:**
53+
4754
- ESP32-specific testing
4855
- Real socket communication
4956
- TLS client/server implementation
5057
- Embedded target validation
5158

5259
#### rustls-real-socket-test
60+
5361
Similar to esp32-test but designed for standard Rust environments. This crate tests TLS functionality using actual network sockets, providing realistic validation of the provider's capabilities.
5462

5563
**Key Features:**
64+
5665
- Real socket testing
5766
- TLS client/server implementation
5867
- Network communication validation
@@ -122,16 +131,19 @@ cargo run -p esp32-test
122131
## Dependencies
123132

124133
### Common Dependencies
134+
125135
- `rustls` 0.23.x
126136
- `rustls-rustcrypto` (workspace)
127137
- `anyhow` for error handling
128138
- `log` for logging
129139

130140
### ESP32-Specific
141+
131142
- `esp-idf-svc` for ESP32 services
132143
- `esp-idf-hal` for hardware abstraction
133144

134145
### OpenSSL-Specific
146+
135147
- OpenSSL development libraries
136148
- Custom certificate generation tools
137149

0 commit comments

Comments
 (0)