Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core/: Introduce rsa feature flag to avoid ring dependency #2860

Merged
merged 11 commits into from
Sep 7, 2022
Merged
24 changes: 13 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ default = [
"relay",
"request-response",
"rendezvous",
"rsa",
"secp256k1",
"tcp-async-io",
"uds",
Expand Down Expand Up @@ -65,6 +66,7 @@ wasm-ext-websocket = ["wasm-ext", "libp2p-wasm-ext?/websocket"]
websocket = ["dep:libp2p-websocket"]
yamux = ["dep:libp2p-yamux"]
secp256k1 = ["libp2p-core/secp256k1"]
rsa = ["libp2p-core/rsa"]
serde = ["libp2p-core/serde", "libp2p-kad?/serde", "libp2p-gossipsub?/serde"]

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

libp2p-autonat = { version = "0.7.0", path = "protocols/autonat", optional = true }
libp2p-core = { version = "0.35.0", path = "core", default-features = false }
libp2p-core = { version = "0.36.0", path = "core", default-features = false }
libp2p-dcutr = { version = "0.6.0", path = "protocols/dcutr", optional = true }
libp2p-floodsub = { version = "0.39.0", path = "protocols/floodsub", optional = true }
libp2p-identify = { version = "0.39.0", path = "protocols/identify", optional = true }
libp2p-kad = { version = "0.40.0", path = "protocols/kad", optional = true }
libp2p-metrics = { version = "0.9.0", path = "misc/metrics", optional = true }
libp2p-mplex = { version = "0.35.0", path = "muxers/mplex", optional = true }
libp2p-noise = { version = "0.38.0", path = "transports/noise", optional = true }
libp2p-mplex = { version = "0.36.0", path = "muxers/mplex", optional = true }
libp2p-noise = { version = "0.39.0", path = "transports/noise", optional = true }
libp2p-ping = { version = "0.39.0", path = "protocols/ping", optional = true }
libp2p-plaintext = { version = "0.35.0", path = "transports/plaintext", optional = true }
libp2p-plaintext = { version = "0.36.0", path = "transports/plaintext", optional = true }
libp2p-pnet = { version = "0.22.0", path = "transports/pnet", optional = true }
libp2p-relay = { version = "0.12.0", path = "protocols/relay", optional = true }
libp2p-rendezvous = { version = "0.9.0", path = "protocols/rendezvous", optional = true }
libp2p-request-response = { version = "0.21.0", path = "protocols/request-response", optional = true }
libp2p-swarm = { version = "0.39.0", path = "swarm" }
libp2p-swarm-derive = { version = "0.30.0", path = "swarm-derive" }
libp2p-uds = { version = "0.34.0", path = "transports/uds", optional = true }
libp2p-wasm-ext = { version = "0.35.0", path = "transports/wasm-ext", default-features = false, optional = true }
libp2p-yamux = { version = "0.39.0", path = "muxers/yamux", optional = true }
libp2p-uds = { version = "0.35.0", path = "transports/uds", optional = true }
libp2p-wasm-ext = { version = "0.36.0", path = "transports/wasm-ext", default-features = false, optional = true }
libp2p-yamux = { version = "0.40.0", path = "muxers/yamux", optional = true }
multiaddr = { version = "0.14.0" }
parking_lot = "0.12.0"
pin-project = "1.0.0"
rand = "0.7.3" # Explicit dependency to be used in `wasm-bindgen` feature
smallvec = "1.6.1"

[target.'cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))'.dependencies]
libp2p-deflate = { version = "0.35.0", path = "transports/deflate", optional = true }
libp2p-dns = { version = "0.35.0", path = "transports/dns", optional = true, default-features = false }
libp2p-deflate = { version = "0.36.0", path = "transports/deflate", optional = true }
libp2p-dns = { version = "0.36.0", path = "transports/dns", optional = true, default-features = false }
libp2p-mdns = { version = "0.40.0", path = "protocols/mdns", optional = true, default-features = false }
libp2p-tcp = { version = "0.35.0", path = "transports/tcp", default-features = false, optional = true }
libp2p-websocket = { version = "0.37.0", path = "transports/websocket", optional = true }
libp2p-tcp = { version = "0.36.0", path = "transports/tcp", default-features = false, optional = true }
libp2p-websocket = { version = "0.38.0", path = "transports/websocket", optional = true }

[target.'cfg(not(target_os = "unknown"))'.dependencies]
libp2p-gossipsub = { version = "0.41.0", path = "protocols/gossipsub", optional = true }
Expand Down
7 changes: 7 additions & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 0.36.0 [unreleased]

- Make RSA keypair support optional. To enable RSA support, `rsa` feature should be enabled.
See [PR 2860].

[PR 2860]: https://github.com/libp2p/rust-libp2p/pull/2860/

# 0.35.1

- Update to `p256` `v0.11.0`. See [PR 2636].
Expand Down
5 changes: 3 additions & 2 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "libp2p-core"
edition = "2021"
rust-version = "1.56.1"
description = "Core traits and structs of libp2p"
version = "0.35.1"
version = "0.36.0"
authors = ["Parity Technologies <[email protected]>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand Down Expand Up @@ -40,7 +40,7 @@ zeroize = "1"
_serde = { package = "serde", version = "1", optional = true, features = ["derive"] }

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

[dev-dependencies]
async-std = { version = "1.6.2", features = ["attributes"] }
Expand All @@ -62,6 +62,7 @@ prost-build = "0.11"
default = [ "secp256k1", "ecdsa" ]
secp256k1 = [ "libsecp256k1" ]
ecdsa = [ "p256" ]
rsa = [ "dep:ring" ]
serde = ["multihash/serde-codec", "_serde"]

[[bench]]
Expand Down
22 changes: 11 additions & 11 deletions core/src/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#[cfg(feature = "ecdsa")]
pub mod ecdsa;
pub mod ed25519;
#[cfg(not(target_arch = "wasm32"))]
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
pub mod rsa;
#[cfg(feature = "secp256k1")]
pub mod secp256k1;
Expand Down Expand Up @@ -68,8 +68,8 @@ use std::convert::{TryFrom, TryInto};
pub enum Keypair {
/// An Ed25519 keypair.
Ed25519(ed25519::Keypair),
#[cfg(not(target_arch = "wasm32"))]
/// An RSA keypair.
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
Rsa(rsa::Keypair),
/// A Secp256k1 keypair.
#[cfg(feature = "secp256k1")]
Expand Down Expand Up @@ -101,7 +101,7 @@ impl Keypair {
/// format (i.e. unencrypted) as defined in [RFC5208].
///
/// [RFC5208]: https://tools.ietf.org/html/rfc5208#section-5
#[cfg(not(target_arch = "wasm32"))]
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
pub fn rsa_from_pkcs8(pkcs8_der: &mut [u8]) -> Result<Keypair, DecodingError> {
rsa::Keypair::from_pkcs8(pkcs8_der).map(Keypair::Rsa)
}
Expand All @@ -122,7 +122,7 @@ impl Keypair {
use Keypair::*;
match self {
Ed25519(ref pair) => Ok(pair.sign(msg)),
#[cfg(not(target_arch = "wasm32"))]
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
Rsa(ref pair) => pair.sign(msg),
#[cfg(feature = "secp256k1")]
Secp256k1(ref pair) => pair.secret().sign(msg),
Expand All @@ -136,7 +136,7 @@ impl Keypair {
use Keypair::*;
match self {
Ed25519(pair) => PublicKey::Ed25519(pair.public()),
#[cfg(not(target_arch = "wasm32"))]
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
Rsa(pair) => PublicKey::Rsa(pair.public()),
#[cfg(feature = "secp256k1")]
Secp256k1(pair) => PublicKey::Secp256k1(pair.public().clone()),
Expand All @@ -154,7 +154,7 @@ impl Keypair {
r#type: keys_proto::KeyType::Ed25519.into(),
data: data.encode().into(),
},
#[cfg(not(target_arch = "wasm32"))]
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
Self::Rsa(_) => {
return Err(DecodingError::new(
"Encoding RSA key into Protobuf is unsupported",
Expand Down Expand Up @@ -218,7 +218,7 @@ impl zeroize::Zeroize for keys_proto::PrivateKey {
pub enum PublicKey {
/// A public Ed25519 key.
Ed25519(ed25519::PublicKey),
#[cfg(not(target_arch = "wasm32"))]
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
/// A public RSA key.
Rsa(rsa::PublicKey),
#[cfg(feature = "secp256k1")]
Expand All @@ -239,7 +239,7 @@ impl PublicKey {
use PublicKey::*;
match self {
Ed25519(pk) => pk.verify(msg, sig),
#[cfg(not(target_arch = "wasm32"))]
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
Rsa(pk) => pk.verify(msg, sig),
#[cfg(feature = "secp256k1")]
Secp256k1(pk) => pk.verify(msg, sig),
Expand Down Expand Up @@ -286,7 +286,7 @@ impl From<&PublicKey> for keys_proto::PublicKey {
r#type: keys_proto::KeyType::Ed25519 as i32,
data: key.encode().to_vec(),
},
#[cfg(not(target_arch = "wasm32"))]
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
PublicKey::Rsa(key) => keys_proto::PublicKey {
r#type: keys_proto::KeyType::Rsa as i32,
data: key.encode_x509(),
Expand Down Expand Up @@ -316,11 +316,11 @@ impl TryFrom<keys_proto::PublicKey> for PublicKey {
keys_proto::KeyType::Ed25519 => {
ed25519::PublicKey::decode(&pubkey.data).map(PublicKey::Ed25519)
}
#[cfg(not(target_arch = "wasm32"))]
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
keys_proto::KeyType::Rsa => {
rsa::PublicKey::decode_x509(&pubkey.data).map(PublicKey::Rsa)
}
#[cfg(target_arch = "wasm32")]
#[cfg(any(not(feature = "rsa"), target_arch = "wasm32"))]
keys_proto::KeyType::Rsa => {
log::debug!("support for RSA was disabled at compile-time");
Err(DecodingError::new("Unsupported"))
Expand Down
2 changes: 2 additions & 0 deletions core/src/identity/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,15 @@ pub struct SigningError {

/// An error during encoding of key material.
impl SigningError {
#[cfg(any(feature = "secp256k1", feature = "rsa"))]
pub(crate) fn new<S: ToString>(msg: S) -> Self {
Self {
msg: msg.to_string(),
source: None,
}
}

#[cfg(feature = "rsa")]
pub(crate) fn source(self, source: impl Error + Send + Sync + 'static) -> Self {
Self {
source: Some(Box::new(source)),
Expand Down
2 changes: 1 addition & 1 deletion misc/keygen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ clap = {version = "3.1.6", features = ["derive"]}
zeroize = "1"
serde = { version = "1.0.136", features = ["derive"] }
serde_json = "1.0.79"
libp2p-core = { path = "../../core", default-features = false, version = "0.35.0"}
libp2p-core = { path = "../../core", default-features = false, version = "0.36.0"}
base64 = "0.13.0"
2 changes: 2 additions & 0 deletions misc/metrics/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

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

- Update to `libp2p-core` `v0.36.0`.

# 0.8.0

- Update to `libp2p-swarm` `v0.38.0`.
Expand Down
2 changes: 1 addition & 1 deletion misc/metrics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ relay = ["libp2p-relay"]
dcutr = ["libp2p-dcutr"]

[dependencies]
libp2p-core = { version = "0.35.0", path = "../../core", default-features = false }
libp2p-core = { version = "0.36.0", path = "../../core", default-features = false }
libp2p-dcutr = { version = "0.6.0", path = "../../protocols/dcutr", optional = true }
libp2p-identify = { version = "0.39.0", path = "../../protocols/identify", optional = true }
libp2p-kad = { version = "0.40.0", path = "../../protocols/kad", optional = true }
Expand Down
4 changes: 4 additions & 0 deletions muxers/mplex/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.36.0 [unreleased]

- Update to `libp2p-core` `v0.36.0`

# 0.35.0

- Update to `libp2p-core` `v0.35.0`
Expand Down
4 changes: 2 additions & 2 deletions muxers/mplex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "libp2p-mplex"
edition = "2021"
rust-version = "1.56.1"
description = "Mplex multiplexing protocol for libp2p"
version = "0.35.0"
version = "0.36.0"
authors = ["Parity Technologies <[email protected]>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand All @@ -14,7 +14,7 @@ categories = ["network-programming", "asynchronous"]
bytes = "1"
futures = "0.3.1"
asynchronous-codec = "0.6"
libp2p-core = { version = "0.35.0", path = "../../core", default-features = false }
libp2p-core = { version = "0.36.0", path = "../../core", default-features = false }
log = "0.4"
nohash-hasher = "0.2"
parking_lot = "0.12"
Expand Down
4 changes: 4 additions & 0 deletions muxers/yamux/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.40.0 [unreleased]

- Update to `libp2p-core` `v0.36.0`

# 0.39.0

- Update to `libp2p-core` `v0.35.0`
Expand Down
4 changes: 2 additions & 2 deletions muxers/yamux/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "libp2p-yamux"
edition = "2021"
rust-version = "1.56.1"
description = "Yamux multiplexing protocol for libp2p"
version = "0.39.0"
version = "0.40.0"
authors = ["Parity Technologies <[email protected]>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand All @@ -12,7 +12,7 @@ categories = ["network-programming", "asynchronous"]

[dependencies]
futures = "0.3.1"
libp2p-core = { version = "0.35.0", path = "../../core", default-features = false }
libp2p-core = { version = "0.36.0", path = "../../core", default-features = false }
parking_lot = "0.12"
thiserror = "1.0"
yamux = "0.10.0"
2 changes: 2 additions & 0 deletions protocols/autonat/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- Update to `libp2p-request-response` `v0.21.0`.

- Update to `libp2p-core` `v0.36.0`.

# 0.6.0

- Update prost requirement from 0.10 to 0.11 which no longer installs the protoc Protobuf compiler.
Expand Down
2 changes: 1 addition & 1 deletion protocols/autonat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async-trait = "0.1"
futures = "0.3"
futures-timer = "3.0"
instant = "0.1"
libp2p-core = { version = "0.35.0", path = "../../core", default-features = false }
libp2p-core = { version = "0.36.0", path = "../../core", default-features = false }
libp2p-swarm = { version = "0.39.0", path = "../../swarm" }
libp2p-request-response = { version = "0.21.0", path = "../request-response" }
log = "0.4"
Expand Down
2 changes: 2 additions & 0 deletions protocols/dcutr/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

- Update to `libp2p-swarm` `v0.39.0`.

- Update to `libp2p-core` `v0.36.0`.

# 0.5.1

- Make default features of `libp2p-core` optional. See [PR 2836].
Expand Down
2 changes: 1 addition & 1 deletion protocols/dcutr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ either = "1.6.0"
futures = "0.3.1"
futures-timer = "3.0"
instant = "0.1.11"
libp2p-core = { version = "0.35.0", path = "../../core", default-features = false }
libp2p-core = { version = "0.36.0", path = "../../core", default-features = false }
libp2p-swarm = { version = "0.39.0", path = "../../swarm" }
log = "0.4"
prost-codec = { version = "0.2", path = "../../misc/prost-codec" }
Expand Down
2 changes: 2 additions & 0 deletions protocols/floodsub/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

- Update to `libp2p-swarm` `v0.39.0`.

- Update to `libp2p-core` `v0.36.0`.

# 0.38.0

- Update prost requirement from 0.10 to 0.11 which no longer installs the protoc Protobuf compiler.
Expand Down
2 changes: 1 addition & 1 deletion protocols/floodsub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ categories = ["network-programming", "asynchronous"]
cuckoofilter = "0.5.0"
fnv = "1.0"
futures = "0.3.1"
libp2p-core = { version = "0.35.0", path = "../../core", default-features = false }
libp2p-core = { version = "0.36.0", path = "../../core", default-features = false }
libp2p-swarm = { version = "0.39.0", path = "../../swarm" }
log = "0.4"
prost = "0.11"
Expand Down
2 changes: 2 additions & 0 deletions protocols/gossipsub/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

- Update to `libp2p-swarm` `v0.39.0`.

- Update to `libp2p-core` `v0.36.0`.

- Allow publishing with any `impl Into<TopicHash>` as a topic. See [PR 2862].

[PR 2862]: https://github.com/libp2p/rust-libp2p/pull/2862
Expand Down
2 changes: 1 addition & 1 deletion protocols/gossipsub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ categories = ["network-programming", "asynchronous"]

[dependencies]
libp2p-swarm = { version = "0.39.0", path = "../../swarm" }
libp2p-core = { version = "0.35.0", path = "../../core", default-features = false }
libp2p-core = { version = "0.36.0", path = "../../core", default-features = false }
bytes = "1.0"
byteorder = "1.3.4"
fnv = "1.0.7"
Expand Down
7 changes: 7 additions & 0 deletions protocols/gossipsub/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ mod tests {
struct TestKeypair(Keypair);

impl Arbitrary for TestKeypair {
#[cfg(feature = "rsa")]
fn arbitrary<G: Gen>(g: &mut G) -> Self {
let keypair = if g.gen() {
// Small enough to be inlined.
Expand All @@ -624,6 +625,12 @@ mod tests {
};
TestKeypair(keypair)
}

#[cfg(not(feature = "rsa"))]
fn arbitrary<G: Gen>(_g: &mut G) -> Self {
// Small enough to be inlined.
TestKeypair(Keypair::generate_ed25519())
}
}

impl std::fmt::Debug for TestKeypair {
Expand Down
2 changes: 2 additions & 0 deletions protocols/identify/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

- Update to `libp2p-swarm` `v0.39.0`.

- Update to `libp2p-core` `v0.36.0`.

# 0.38.0

- Update prost requirement from 0.10 to 0.11 which no longer installs the protoc Protobuf compiler.
Expand Down
Loading