Skip to content

Commit e99ab75

Browse files
authored
chore: fix RUSTSEC-2025-0009 in libp2p-tls and libp2p-websocket
This PR tries to fix [RUSTSEC-2025-0009](https://rustsec.org/advisories/RUSTSEC-2025-0009.html) in `libp2p-tls` and `libp2p-websocket` by bumping `rcgen`. Note: Upgrading `rcgen` in `libp2p-webrtc` is non-trival, so it's not included in this PR. Pull-Request: #5917.
1 parent 2d7ce54 commit e99ab75

File tree

8 files changed

+96
-78
lines changed

8 files changed

+96
-78
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ libp2p-swarm = { version = "0.47.0", path = "swarm" }
106106
libp2p-swarm-derive = { version = "=0.35.1", path = "swarm-derive" } # `libp2p-swarm-derive` may not be compatible with different `libp2p-swarm` non-breaking releases. E.g. `libp2p-swarm` might introduce a new enum variant `FromSwarm` (which is `#[non-exhaustive]`) in a non-breaking release. Older versions of `libp2p-swarm-derive` would not forward this enum variant within the `NetworkBehaviour` hierarchy. Thus the version pinning is required.
107107
libp2p-swarm-test = { version = "0.5.0", path = "swarm-test" }
108108
libp2p-tcp = { version = "0.43.0", path = "transports/tcp" }
109-
libp2p-tls = { version = "0.6.0", path = "transports/tls" }
109+
libp2p-tls = { version = "0.6.1", path = "transports/tls" }
110110
libp2p-uds = { version = "0.42.0", path = "transports/uds" }
111111
libp2p-upnp = { version = "0.4.0", path = "protocols/upnp" }
112112
libp2p-webrtc = { version = "0.9.0-alpha", path = "transports/webrtc" }
@@ -134,8 +134,8 @@ multistream-select = { version = "0.13.0", path = "misc/multistream-select" }
134134
prometheus-client = "0.22.2"
135135
quick-protobuf-codec = { version = "0.3.1", path = "misc/quick-protobuf-codec" }
136136
quickcheck = { package = "quickcheck-ext", path = "misc/quickcheck-ext" }
137-
rcgen = "0.11.3"
138-
ring = "0.17.8"
137+
rcgen = "0.13"
138+
ring = "0.17.12"
139139
rw-stream-sink = { version = "0.4.0", path = "misc/rw-stream-sink" }
140140
thiserror = "2"
141141
tokio = { version = "1.38", default-features = false }

transports/tls/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.6.1
2+
3+
- Upgrade `rcgen` to `v0.13`
4+
See [PR 5917](https://github.com/libp2p/rust-libp2p/pull/5917).
5+
16
## 0.6.0
27

38
<!-- Update to libp2p-core v0.43.0 -->

transports/tls/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "libp2p-tls"
3-
version = "0.6.0"
3+
version = "0.6.1"
44
edition.workspace = true
55
rust-version = { workspace = true }
66
description = "TLS configuration based on libp2p TLS specs."

transports/tls/src/certificate.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,26 +99,22 @@ pub fn generate(
9999
// Endpoints MAY generate a new key and certificate
100100
// for every connection attempt, or they MAY reuse the same key
101101
// and certificate for multiple connections.
102-
let certificate_keypair = rcgen::KeyPair::generate(P2P_SIGNATURE_ALGORITHM)?;
102+
let certificate_keypair = rcgen::KeyPair::generate_for(P2P_SIGNATURE_ALGORITHM)?;
103103
let rustls_key = rustls::pki_types::PrivateKeyDer::from(
104104
rustls::pki_types::PrivatePkcs8KeyDer::from(certificate_keypair.serialize_der()),
105105
);
106106

107107
let certificate = {
108-
let mut params = rcgen::CertificateParams::new(vec![]);
108+
let mut params = rcgen::CertificateParams::new(vec![])?;
109109
params.distinguished_name = rcgen::DistinguishedName::new();
110110
params.custom_extensions.push(make_libp2p_extension(
111111
identity_keypair,
112112
&certificate_keypair,
113113
)?);
114-
params.alg = P2P_SIGNATURE_ALGORITHM;
115-
params.key_pair = Some(certificate_keypair);
116-
rcgen::Certificate::from_params(params)?
114+
params.self_signed(&certificate_keypair)?
117115
};
118116

119-
let rustls_certificate = rustls::pki_types::CertificateDer::from(certificate.serialize_der()?);
120-
121-
Ok((rustls_certificate, rustls_key))
117+
Ok((certificate.into(), rustls_key))
122118
}
123119

124120
/// Attempts to parse the provided bytes as a [`P2pCertificate`].
@@ -158,7 +154,7 @@ pub struct P2pExtension {
158154

159155
#[derive(Debug, thiserror::Error)]
160156
#[error(transparent)]
161-
pub struct GenError(#[from] rcgen::RcgenError);
157+
pub struct GenError(#[from] rcgen::Error);
162158

163159
#[derive(Debug, thiserror::Error)]
164160
#[error(transparent)]
@@ -244,7 +240,7 @@ fn parse_unverified(der_input: &[u8]) -> Result<P2pCertificate, webpki::Error> {
244240
fn make_libp2p_extension(
245241
identity_keypair: &identity::Keypair,
246242
certificate_keypair: &rcgen::KeyPair,
247-
) -> Result<rcgen::CustomExtension, rcgen::RcgenError> {
243+
) -> Result<rcgen::CustomExtension, rcgen::Error> {
248244
// The peer signs the concatenation of the string `libp2p-tls-handshake:`
249245
// and the public key that it used to generate the certificate carrying
250246
// the libp2p Public Key Extension, using its private host key.
@@ -255,7 +251,7 @@ fn make_libp2p_extension(
255251

256252
identity_keypair
257253
.sign(&msg)
258-
.map_err(|_| rcgen::RcgenError::RingUnspecified)?
254+
.map_err(|_| rcgen::Error::RingUnspecified)?
259255
};
260256

261257
// The public host key and the signature are ANS.1-encoded

transports/webrtc/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ libp2p-identity = { workspace = true }
2222
libp2p-webrtc-utils = { workspace = true }
2323
multihash = { workspace = true }
2424
rand = "0.8"
25-
rcgen = { workspace = true }
25+
rcgen = "0.11"
2626
stun = "0.7"
2727
thiserror = { workspace = true }
2828
tokio = { workspace = true, features = ["net"], optional = true }

transports/websocket/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
- Rename types to match naming convention in [discussion 2174](https://github.com/libp2p/rust-libp2p/discussions/2174).
33
See [PR 5873](https://github.com/libp2p/rust-libp2p/pull/5873).
44

5+
- Upgrade `rcgen` to `v0.13`
6+
See [PR 5917](https://github.com/libp2p/rust-libp2p/pull/5917).
7+
58
## 0.45.0
69

710
- fix: Return `Error::InvalidMultiaddr` when dialed to a `/dnsaddr` address

transports/websocket/src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ use rw_stream_sink::RwStreamSink;
7070
/// # use libp2p_dns as dns;
7171
/// # use libp2p_tcp as tcp;
7272
/// # use libp2p_websocket as websocket;
73-
/// # use rcgen::generate_simple_self_signed;
7473
/// # use std::pin::Pin;
7574
/// #
7675
/// # #[async_std::main]
@@ -82,9 +81,12 @@ use rw_stream_sink::RwStreamSink;
8281
/// .unwrap(),
8382
/// );
8483
///
85-
/// let rcgen_cert = generate_simple_self_signed(vec!["localhost".to_string()]).unwrap();
86-
/// let priv_key = websocket::tls::PrivateKey::new(rcgen_cert.serialize_private_key_der());
87-
/// let cert = websocket::tls::Certificate::new(rcgen_cert.serialize_der().unwrap());
84+
/// let rcgen::CertifiedKey {
85+
/// cert: rcgen_cert,
86+
/// key_pair,
87+
/// } = rcgen::generate_simple_self_signed(vec!["localhost".to_string()]).unwrap();
88+
/// let priv_key = websocket::tls::PrivateKey::new(key_pair.serialize_der());
89+
/// let cert = websocket::tls::Certificate::new(rcgen_cert.der().to_vec());
8890
/// transport.set_tls_config(websocket::tls::Config::new(priv_key, vec![cert]).unwrap());
8991
///
9092
/// let id = transport

0 commit comments

Comments
 (0)