Skip to content

Commit 3667c6c

Browse files
authored
feat: use AWS-LC crypto provider and support PQ key-exchange (#6568)
## Description go-libp2p's tls implementation advertises hybrid X25519MLKEM768 key exchange in client hello enabling quantum resistance against "harvest now, decrypt later" attacks. This PR brings the same functionality to rust-libp2p by introducing the following changes: * Use rustls's AWS-LC crypto provider instead of ring for TLS configurations to enable hybrid X25519MLKEM768 key-exchange while keeping interoperability with X25519. ## AI Assistance Disclosure **Tools used** OpenCode **Attestation** _(required)_: - [x] I have read every line of this diff, understand what it does, and can explain it in review. ## Notes & open questions Note, that `prefer-post-quantum` for rustls was enabled, to put X25519MLKEM768 in the first place of key exchanges advertised in client hello, which mimics go-libp2p's tls implementation and enable hybrid key exchange by default when both peers support it ## Change checklist - [x] I have performed a self-review of my own code - [x] I have made corresponding changes to the documentation - [x] I have added tests that prove my fix is effective or that my feature works - [x] A changelog entry has been made in the appropriate crates Approved-by: jxs <1204690+jxs@users.noreply.github.com>
1 parent a27ba10 commit 3667c6c

8 files changed

Lines changed: 31 additions & 10 deletions

File tree

Cargo.lock

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

transports/quic/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## 0.14.0
22

3+
- Prefer and advertise the X25519MLKEM768 key exchange group for QUIC.
4+
See [PR 6568](https://github.com/libp2p/rust-libp2p/pull/6568).
5+
36
- Raise MSRV to 1.88.0.
47
See [PR 6273](https://github.com/libp2p/rust-libp2p/pull/6273).
58

transports/quic/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ if-watch = { workspace = true }
1515
libp2p-core = { workspace = true }
1616
libp2p-tls = { workspace = true }
1717
libp2p-identity = { workspace = true }
18-
quinn = { version = "0.11", default-features = false, features = ["rustls", "futures-io"] }
19-
quinn-proto = { version = "0.11" }
18+
quinn = { version = "0.11", default-features = false, features = ["rustls-aws-lc-rs", "futures-io"] }
19+
quinn-proto = { version = "0.11", default-features = false, features = ["bloom", "log", "ring"] }
2020
rand = { workspace = true }
21-
rustls = { version = "0.23", default-features = false }
2221
thiserror = { workspace = true }
2322
tokio = { workspace = true, default-features = false, features = ["net", "rt", "time"], optional = true }
2423
tracing = { workspace = true }

transports/tls/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## 0.7.0
22

3+
- Use the AWS-LC crypto provider and prefer the X25519MLKEM768 key exchange group for TLS configurations.
4+
See [PR 6568](https://github.com/libp2p/rust-libp2p/pull/6568).
5+
36
- Replace deprecated `webpki::Error` variants with their new context-based equivalents.
47
See [PR 6355](https://github.com/libp2p/rust-libp2p/pull/6355).
58

transports/tls/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ yasna = "0.6"
2424
[dependencies.rustls]
2525
version = "0.23"
2626
default-features = false
27-
features = ["ring", "std"] # Must enable this to allow for custom verification code.
28-
27+
features = ["aws-lc-rs", "prefer-post-quantum", "std"] # Must enable this to allow for custom verification code.
2928

3029
[dev-dependencies]
3130
hex-literal = { workspace = true }

transports/tls/src/certificate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl AlwaysResolvesCert {
5454
) -> Result<Self, rustls::Error> {
5555
let certified_key = rustls::sign::CertifiedKey::new(
5656
vec![cert],
57-
rustls::crypto::ring::sign::any_ecdsa_type(key)?,
57+
rustls::crypto::aws_lc_rs::sign::any_ecdsa_type(key)?,
5858
);
5959
Ok(Self(Arc::new(certified_key)))
6060
}

transports/tls/src/lib.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub fn make_client_config(
4545
) -> Result<rustls::ClientConfig, certificate::GenError> {
4646
let (certificate, private_key) = certificate::generate(keypair)?;
4747

48-
let mut provider = rustls::crypto::ring::default_provider();
48+
let mut provider = rustls::crypto::aws_lc_rs::default_provider();
4949
provider.cipher_suites = verifier::CIPHERSUITES.to_vec();
5050

5151
let cert_resolver = Arc::new(
@@ -73,7 +73,7 @@ pub fn make_server_config(
7373
) -> Result<rustls::ServerConfig, certificate::GenError> {
7474
let (certificate, private_key) = certificate::generate(keypair)?;
7575

76-
let mut provider = rustls::crypto::ring::default_provider();
76+
let mut provider = rustls::crypto::aws_lc_rs::default_provider();
7777
provider.cipher_suites = verifier::CIPHERSUITES.to_vec();
7878

7979
let cert_resolver = Arc::new(
@@ -91,3 +91,21 @@ pub fn make_server_config(
9191

9292
Ok(crypto)
9393
}
94+
95+
#[cfg(test)]
96+
mod tests {
97+
use rustls::NamedGroup;
98+
99+
use super::*;
100+
101+
#[test]
102+
fn prefers_x25519_mlkem768() {
103+
let keypair = Keypair::generate_ed25519();
104+
let config = make_client_config(&keypair, None).unwrap();
105+
106+
assert_eq!(
107+
config.crypto_provider().kx_groups[0].name(),
108+
NamedGroup::X25519MLKEM768
109+
);
110+
}
111+
}

transports/tls/src/verifier.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use rustls::{
3030
CertificateError, DigitallySignedStruct, DistinguishedName, OtherError, SignatureScheme,
3131
SupportedCipherSuite, SupportedProtocolVersion,
3232
client::danger::{HandshakeSignatureValid, ServerCertVerified, ServerCertVerifier},
33-
crypto::ring::cipher_suite::{
33+
crypto::aws_lc_rs::cipher_suite::{
3434
TLS13_AES_128_GCM_SHA256, TLS13_AES_256_GCM_SHA384, TLS13_CHACHA20_POLY1305_SHA256,
3535
},
3636
pki_types::CertificateDer,

0 commit comments

Comments
 (0)