Skip to content

Commit 8644c65

Browse files
authored
core/: Introduce rsa feature flag to avoid ring dependency (#2860)
- Introduce `rsa` feature flag to `libp2p-core`. - Expose `rsa` feature in `libp2p`. - Add `rsa` feature to `libp2p` `default`.
1 parent a40180c commit 8644c65

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+145
-58
lines changed

Cargo.toml

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ default = [
2828
"relay",
2929
"request-response",
3030
"rendezvous",
31+
"rsa",
3132
"secp256k1",
3233
"tcp-async-io",
3334
"uds",
@@ -65,6 +66,7 @@ wasm-ext-websocket = ["wasm-ext", "libp2p-wasm-ext?/websocket"]
6566
websocket = ["dep:libp2p-websocket"]
6667
yamux = ["dep:libp2p-yamux"]
6768
secp256k1 = ["libp2p-core/secp256k1"]
69+
rsa = ["libp2p-core/rsa"]
6870
serde = ["libp2p-core/serde", "libp2p-kad?/serde", "libp2p-gossipsub?/serde"]
6971

7072
[package.metadata.docs.rs]
@@ -79,37 +81,37 @@ instant = "0.1.11" # Explicit dependency to be used in `wasm-bindgen` feature
7981
lazy_static = "1.2"
8082

8183
libp2p-autonat = { version = "0.7.0", path = "protocols/autonat", optional = true }
82-
libp2p-core = { version = "0.35.0", path = "core", default-features = false }
84+
libp2p-core = { version = "0.36.0", path = "core", default-features = false }
8385
libp2p-dcutr = { version = "0.6.0", path = "protocols/dcutr", optional = true }
8486
libp2p-floodsub = { version = "0.39.0", path = "protocols/floodsub", optional = true }
8587
libp2p-identify = { version = "0.39.0", path = "protocols/identify", optional = true }
8688
libp2p-kad = { version = "0.40.0", path = "protocols/kad", optional = true }
8789
libp2p-metrics = { version = "0.9.0", path = "misc/metrics", optional = true }
88-
libp2p-mplex = { version = "0.35.0", path = "muxers/mplex", optional = true }
89-
libp2p-noise = { version = "0.38.0", path = "transports/noise", optional = true }
90+
libp2p-mplex = { version = "0.36.0", path = "muxers/mplex", optional = true }
91+
libp2p-noise = { version = "0.39.0", path = "transports/noise", optional = true }
9092
libp2p-ping = { version = "0.39.0", path = "protocols/ping", optional = true }
91-
libp2p-plaintext = { version = "0.35.0", path = "transports/plaintext", optional = true }
93+
libp2p-plaintext = { version = "0.36.0", path = "transports/plaintext", optional = true }
9294
libp2p-pnet = { version = "0.22.0", path = "transports/pnet", optional = true }
9395
libp2p-relay = { version = "0.12.0", path = "protocols/relay", optional = true }
9496
libp2p-rendezvous = { version = "0.9.0", path = "protocols/rendezvous", optional = true }
9597
libp2p-request-response = { version = "0.21.0", path = "protocols/request-response", optional = true }
9698
libp2p-swarm = { version = "0.39.0", path = "swarm" }
9799
libp2p-swarm-derive = { version = "0.30.0", path = "swarm-derive" }
98-
libp2p-uds = { version = "0.34.0", path = "transports/uds", optional = true }
99-
libp2p-wasm-ext = { version = "0.35.0", path = "transports/wasm-ext", default-features = false, optional = true }
100-
libp2p-yamux = { version = "0.39.0", path = "muxers/yamux", optional = true }
100+
libp2p-uds = { version = "0.35.0", path = "transports/uds", optional = true }
101+
libp2p-wasm-ext = { version = "0.36.0", path = "transports/wasm-ext", default-features = false, optional = true }
102+
libp2p-yamux = { version = "0.40.0", path = "muxers/yamux", optional = true }
101103
multiaddr = { version = "0.14.0" }
102104
parking_lot = "0.12.0"
103105
pin-project = "1.0.0"
104106
rand = "0.7.3" # Explicit dependency to be used in `wasm-bindgen` feature
105107
smallvec = "1.6.1"
106108

107109
[target.'cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))'.dependencies]
108-
libp2p-deflate = { version = "0.35.0", path = "transports/deflate", optional = true }
109-
libp2p-dns = { version = "0.35.0", path = "transports/dns", optional = true, default-features = false }
110+
libp2p-deflate = { version = "0.36.0", path = "transports/deflate", optional = true }
111+
libp2p-dns = { version = "0.36.0", path = "transports/dns", optional = true, default-features = false }
110112
libp2p-mdns = { version = "0.40.0", path = "protocols/mdns", optional = true, default-features = false }
111-
libp2p-tcp = { version = "0.35.0", path = "transports/tcp", default-features = false, optional = true }
112-
libp2p-websocket = { version = "0.37.0", path = "transports/websocket", optional = true }
113+
libp2p-tcp = { version = "0.36.0", path = "transports/tcp", default-features = false, optional = true }
114+
libp2p-websocket = { version = "0.38.0", path = "transports/websocket", optional = true }
113115

114116
[target.'cfg(not(target_os = "unknown"))'.dependencies]
115117
libp2p-gossipsub = { version = "0.41.0", path = "protocols/gossipsub", optional = true }

core/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# 0.36.0 [unreleased]
2+
3+
- Make RSA keypair support optional. To enable RSA support, `rsa` feature should be enabled.
4+
See [PR 2860].
5+
6+
[PR 2860]: https://github.com/libp2p/rust-libp2p/pull/2860/
7+
18
# 0.35.1
29

310
- Update to `p256` `v0.11.0`. See [PR 2636].

core/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "libp2p-core"
33
edition = "2021"
44
rust-version = "1.56.1"
55
description = "Core traits and structs of libp2p"
6-
version = "0.35.1"
6+
version = "0.36.0"
77
authors = ["Parity Technologies <[email protected]>"]
88
license = "MIT"
99
repository = "https://github.com/libp2p/rust-libp2p"
@@ -40,7 +40,7 @@ zeroize = "1"
4040
_serde = { package = "serde", version = "1", optional = true, features = ["derive"] }
4141

4242
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
43-
ring = { version = "0.16.9", features = ["alloc", "std"], default-features = false }
43+
ring = { version = "0.16.9", features = ["alloc", "std"], default-features = false, optional = true}
4444

4545
[dev-dependencies]
4646
async-std = { version = "1.6.2", features = ["attributes"] }
@@ -62,6 +62,7 @@ prost-build = "0.11"
6262
default = [ "secp256k1", "ecdsa" ]
6363
secp256k1 = [ "libsecp256k1" ]
6464
ecdsa = [ "p256" ]
65+
rsa = [ "dep:ring" ]
6566
serde = ["multihash/serde-codec", "_serde"]
6667

6768
[[bench]]

core/src/identity.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#[cfg(feature = "ecdsa")]
3636
pub mod ecdsa;
3737
pub mod ed25519;
38-
#[cfg(not(target_arch = "wasm32"))]
38+
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
3939
pub mod rsa;
4040
#[cfg(feature = "secp256k1")]
4141
pub mod secp256k1;
@@ -68,8 +68,8 @@ use std::convert::{TryFrom, TryInto};
6868
pub enum Keypair {
6969
/// An Ed25519 keypair.
7070
Ed25519(ed25519::Keypair),
71-
#[cfg(not(target_arch = "wasm32"))]
7271
/// An RSA keypair.
72+
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
7373
Rsa(rsa::Keypair),
7474
/// A Secp256k1 keypair.
7575
#[cfg(feature = "secp256k1")]
@@ -101,7 +101,7 @@ impl Keypair {
101101
/// format (i.e. unencrypted) as defined in [RFC5208].
102102
///
103103
/// [RFC5208]: https://tools.ietf.org/html/rfc5208#section-5
104-
#[cfg(not(target_arch = "wasm32"))]
104+
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
105105
pub fn rsa_from_pkcs8(pkcs8_der: &mut [u8]) -> Result<Keypair, DecodingError> {
106106
rsa::Keypair::from_pkcs8(pkcs8_der).map(Keypair::Rsa)
107107
}
@@ -122,7 +122,7 @@ impl Keypair {
122122
use Keypair::*;
123123
match self {
124124
Ed25519(ref pair) => Ok(pair.sign(msg)),
125-
#[cfg(not(target_arch = "wasm32"))]
125+
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
126126
Rsa(ref pair) => pair.sign(msg),
127127
#[cfg(feature = "secp256k1")]
128128
Secp256k1(ref pair) => pair.secret().sign(msg),
@@ -136,7 +136,7 @@ impl Keypair {
136136
use Keypair::*;
137137
match self {
138138
Ed25519(pair) => PublicKey::Ed25519(pair.public()),
139-
#[cfg(not(target_arch = "wasm32"))]
139+
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
140140
Rsa(pair) => PublicKey::Rsa(pair.public()),
141141
#[cfg(feature = "secp256k1")]
142142
Secp256k1(pair) => PublicKey::Secp256k1(pair.public().clone()),
@@ -154,7 +154,7 @@ impl Keypair {
154154
r#type: keys_proto::KeyType::Ed25519.into(),
155155
data: data.encode().into(),
156156
},
157-
#[cfg(not(target_arch = "wasm32"))]
157+
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
158158
Self::Rsa(_) => {
159159
return Err(DecodingError::new(
160160
"Encoding RSA key into Protobuf is unsupported",
@@ -218,7 +218,7 @@ impl zeroize::Zeroize for keys_proto::PrivateKey {
218218
pub enum PublicKey {
219219
/// A public Ed25519 key.
220220
Ed25519(ed25519::PublicKey),
221-
#[cfg(not(target_arch = "wasm32"))]
221+
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
222222
/// A public RSA key.
223223
Rsa(rsa::PublicKey),
224224
#[cfg(feature = "secp256k1")]
@@ -239,7 +239,7 @@ impl PublicKey {
239239
use PublicKey::*;
240240
match self {
241241
Ed25519(pk) => pk.verify(msg, sig),
242-
#[cfg(not(target_arch = "wasm32"))]
242+
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
243243
Rsa(pk) => pk.verify(msg, sig),
244244
#[cfg(feature = "secp256k1")]
245245
Secp256k1(pk) => pk.verify(msg, sig),
@@ -286,7 +286,7 @@ impl From<&PublicKey> for keys_proto::PublicKey {
286286
r#type: keys_proto::KeyType::Ed25519 as i32,
287287
data: key.encode().to_vec(),
288288
},
289-
#[cfg(not(target_arch = "wasm32"))]
289+
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
290290
PublicKey::Rsa(key) => keys_proto::PublicKey {
291291
r#type: keys_proto::KeyType::Rsa as i32,
292292
data: key.encode_x509(),
@@ -316,11 +316,11 @@ impl TryFrom<keys_proto::PublicKey> for PublicKey {
316316
keys_proto::KeyType::Ed25519 => {
317317
ed25519::PublicKey::decode(&pubkey.data).map(PublicKey::Ed25519)
318318
}
319-
#[cfg(not(target_arch = "wasm32"))]
319+
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
320320
keys_proto::KeyType::Rsa => {
321321
rsa::PublicKey::decode_x509(&pubkey.data).map(PublicKey::Rsa)
322322
}
323-
#[cfg(target_arch = "wasm32")]
323+
#[cfg(any(not(feature = "rsa"), target_arch = "wasm32"))]
324324
keys_proto::KeyType::Rsa => {
325325
log::debug!("support for RSA was disabled at compile-time");
326326
Err(DecodingError::new("Unsupported"))

core/src/identity/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,15 @@ pub struct SigningError {
6767

6868
/// An error during encoding of key material.
6969
impl SigningError {
70+
#[cfg(any(feature = "secp256k1", feature = "rsa"))]
7071
pub(crate) fn new<S: ToString>(msg: S) -> Self {
7172
Self {
7273
msg: msg.to_string(),
7374
source: None,
7475
}
7576
}
7677

78+
#[cfg(feature = "rsa")]
7779
pub(crate) fn source(self, source: impl Error + Send + Sync + 'static) -> Self {
7880
Self {
7981
source: Some(Box::new(source)),

misc/keygen/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ clap = {version = "3.1.6", features = ["derive"]}
1313
zeroize = "1"
1414
serde = { version = "1.0.136", features = ["derive"] }
1515
serde_json = "1.0.79"
16-
libp2p-core = { path = "../../core", default-features = false, version = "0.35.0"}
16+
libp2p-core = { path = "../../core", default-features = false, version = "0.36.0"}
1717
base64 = "0.13.0"

misc/metrics/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
- Update to `libp2p-kad` `v0.40.0`.
1414

15+
- Update to `libp2p-core` `v0.36.0`.
16+
1517
# 0.8.0
1618

1719
- Update to `libp2p-swarm` `v0.38.0`.

misc/metrics/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ relay = ["libp2p-relay"]
1919
dcutr = ["libp2p-dcutr"]
2020

2121
[dependencies]
22-
libp2p-core = { version = "0.35.0", path = "../../core", default-features = false }
22+
libp2p-core = { version = "0.36.0", path = "../../core", default-features = false }
2323
libp2p-dcutr = { version = "0.6.0", path = "../../protocols/dcutr", optional = true }
2424
libp2p-identify = { version = "0.39.0", path = "../../protocols/identify", optional = true }
2525
libp2p-kad = { version = "0.40.0", path = "../../protocols/kad", optional = true }

muxers/mplex/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 0.36.0 [unreleased]
2+
3+
- Update to `libp2p-core` `v0.36.0`
4+
15
# 0.35.0
26

37
- Update to `libp2p-core` `v0.35.0`

muxers/mplex/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "libp2p-mplex"
33
edition = "2021"
44
rust-version = "1.56.1"
55
description = "Mplex multiplexing protocol for libp2p"
6-
version = "0.35.0"
6+
version = "0.36.0"
77
authors = ["Parity Technologies <[email protected]>"]
88
license = "MIT"
99
repository = "https://github.com/libp2p/rust-libp2p"
@@ -14,7 +14,7 @@ categories = ["network-programming", "asynchronous"]
1414
bytes = "1"
1515
futures = "0.3.1"
1616
asynchronous-codec = "0.6"
17-
libp2p-core = { version = "0.35.0", path = "../../core", default-features = false }
17+
libp2p-core = { version = "0.36.0", path = "../../core", default-features = false }
1818
log = "0.4"
1919
nohash-hasher = "0.2"
2020
parking_lot = "0.12"

0 commit comments

Comments
 (0)