Skip to content

Commit

Permalink
Merge branch 'libp2p/master' into as-listener
Browse files Browse the repository at this point in the history
  • Loading branch information
mxinden committed Dec 15, 2021
2 parents 1800084 + b6c82a4 commit a08d2f9
Show file tree
Hide file tree
Showing 42 changed files with 1,102 additions and 246 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
jobs:
test-desktop:
name: Build and test
runs-on: ubuntu-latest
runs-on: ubuntu-18.04
strategy:
matrix:
args: [
Expand All @@ -34,7 +34,7 @@ jobs:

test-wasm:
name: Build on WASM
runs-on: ubuntu-latest
runs-on: ubuntu-18.04
strategy:
matrix:
toolchain: [
Expand Down Expand Up @@ -83,7 +83,7 @@ jobs:

check-rustdoc-links:
name: Check rustdoc intra-doc links
runs-on: ubuntu-latest
runs-on: ubuntu-18.04
container:
image: rust
steps:
Expand All @@ -101,7 +101,7 @@ jobs:
run: RUSTDOCFLAGS="--deny broken_intra_doc_links" cargo doc --verbose --workspace --no-deps --document-private-items

check-clippy:
runs-on: ubuntu-latest
runs-on: ubuntu-18.04
steps:

- name: Cancel Previous Runs
Expand All @@ -127,7 +127,7 @@ jobs:

integration-test:
name: Integration tests
runs-on: ubuntu-latest
runs-on: ubuntu-18.04
container:
image: rust
steps:
Expand All @@ -145,7 +145,7 @@ jobs:
run: RUST_LOG=libp2p_swarm=debug,libp2p_kad=trace,libp2p_tcp=debug cargo run --example ipfs-kad

rustfmt:
runs-on: ubuntu-latest
runs-on: ubuntu-18.04
steps:

- name: Cancel Previous Runs
Expand Down
5 changes: 4 additions & 1 deletion core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@

- Migrate to Rust edition 2021 (see [PR 2339]).

- Add support for ECDSA identities (see [PR 2352]).

[PR 2339]: https://github.com/libp2p/rust-libp2p/pull/2339
[PR 2350]: https://github.com/libp2p/rust-libp2p/pull/2350/
[PR 2350]: https://github.com/libp2p/rust-libp2p/pull/2350
[PR 2352]: https://github.com/libp2p/rust-libp2p/pull/2352

# 0.30.1 [2021-11-16]

Expand Down
8 changes: 5 additions & 3 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ log = "0.4"
multiaddr = { version = "0.13.0" }
multihash = { version = "0.14", default-features = false, features = ["std", "multihash-impl", "identity", "sha2"] }
multistream-select = { version = "0.11", path = "../misc/multistream-select" }
p256 = { version = "0.10.0", default-features = false, features = ["ecdsa"], optional = true }
parking_lot = "0.11.0"
pin-project = "1.0.0"
prost = "0.9"
rand = "0.8"
rw-stream-sink = "0.2.0"
sha2 = "0.9.1"
sha2 = "0.10.0"
smallvec = "1.6.1"
thiserror = "1.0"
unsigned-varint = "0.7"
Expand All @@ -55,8 +56,9 @@ rand07 = { package = "rand", version = "0.7" }
prost-build = "0.9"

[features]
default = ["secp256k1"]
secp256k1 = ["libsecp256k1"]
default = [ "secp256k1", "ecdsa" ]
secp256k1 = [ "libsecp256k1" ]
ecdsa = [ "p256" ]

[[bench]]
name = "peer_id"
Expand Down
43 changes: 43 additions & 0 deletions core/src/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
//! (e.g. [ed25519 binary format](https://datatracker.ietf.org/doc/html/rfc8032#section-5.1.5)).
//! All key types have functions to enable conversion to/from their binary representations.
#[cfg(feature = "ecdsa")]
pub mod ecdsa;
pub mod ed25519;
#[cfg(not(target_arch = "wasm32"))]
pub mod rsa;
Expand Down Expand Up @@ -71,6 +73,9 @@ pub enum Keypair {
/// A Secp256k1 keypair.
#[cfg(feature = "secp256k1")]
Secp256k1(secp256k1::Keypair),
/// An ECDSA keypair.
#[cfg(feature = "ecdsa")]
Ecdsa(ecdsa::Keypair),
}

impl Keypair {
Expand All @@ -85,6 +90,12 @@ impl Keypair {
Keypair::Secp256k1(secp256k1::Keypair::generate())
}

/// Generate a new ECDSA keypair.
#[cfg(feature = "ecdsa")]
pub fn generate_ecdsa() -> Keypair {
Keypair::Ecdsa(ecdsa::Keypair::generate())
}

/// Decode an keypair from a DER-encoded secret key in PKCS#8 PrivateKeyInfo
/// format (i.e. unencrypted) as defined in [RFC5208].
///
Expand Down Expand Up @@ -114,6 +125,8 @@ impl Keypair {
Rsa(ref pair) => pair.sign(msg),
#[cfg(feature = "secp256k1")]
Secp256k1(ref pair) => pair.secret().sign(msg),
#[cfg(feature = "ecdsa")]
Ecdsa(ref pair) => Ok(pair.secret().sign(msg)),
}
}

Expand All @@ -126,6 +139,8 @@ impl Keypair {
Rsa(pair) => PublicKey::Rsa(pair.public()),
#[cfg(feature = "secp256k1")]
Secp256k1(pair) => PublicKey::Secp256k1(pair.public().clone()),
#[cfg(feature = "ecdsa")]
Ecdsa(pair) => PublicKey::Ecdsa(pair.public().clone()),
}
}

Expand All @@ -150,6 +165,12 @@ impl Keypair {
"Encoding Secp256k1 key into Protobuf is unsupported",
))
}
#[cfg(feature = "ecdsa")]
Self::Ecdsa(_) => {
return Err(DecodingError::new(
"Encoding ECDSA key into Protobuf is unsupported",
))
}
};

Ok(pk.encode_to_vec())
Expand Down Expand Up @@ -177,6 +198,9 @@ impl Keypair {
keys_proto::KeyType::Secp256k1 => Err(DecodingError::new(
"Decoding Secp256k1 key from Protobuf is unsupported.",
)),
keys_proto::KeyType::Ecdsa => Err(DecodingError::new(
"Decoding ECDSA key from Protobuf is unsupported.",
)),
}
}
}
Expand All @@ -199,6 +223,9 @@ pub enum PublicKey {
#[cfg(feature = "secp256k1")]
/// A public Secp256k1 key.
Secp256k1(secp256k1::PublicKey),
/// A public ECDSA key.
#[cfg(feature = "ecdsa")]
Ecdsa(ecdsa::PublicKey),
}

impl PublicKey {
Expand All @@ -215,6 +242,8 @@ impl PublicKey {
Rsa(pk) => pk.verify(msg, sig),
#[cfg(feature = "secp256k1")]
Secp256k1(pk) => pk.verify(msg, sig),
#[cfg(feature = "ecdsa")]
Ecdsa(pk) => pk.verify(msg, sig),
}
}

Expand Down Expand Up @@ -266,6 +295,11 @@ impl From<&PublicKey> for keys_proto::PublicKey {
r#type: keys_proto::KeyType::Secp256k1 as i32,
data: key.encode().to_vec(),
},
#[cfg(feature = "ecdsa")]
PublicKey::Ecdsa(key) => keys_proto::PublicKey {
r#type: keys_proto::KeyType::Ecdsa as i32,
data: key.encode_der(),
},
}
}
}
Expand Down Expand Up @@ -299,6 +333,15 @@ impl TryFrom<keys_proto::PublicKey> for PublicKey {
log::debug!("support for secp256k1 was disabled at compile-time");
Err(DecodingError::new("Unsupported"))
}
#[cfg(feature = "ecdsa")]
keys_proto::KeyType::Ecdsa => {
ecdsa::PublicKey::decode_der(&pubkey.data).map(PublicKey::Ecdsa)
}
#[cfg(not(feature = "ecdsa"))]
keys_proto::KeyType::Ecdsa => {
log::debug!("support for ECDSA was disabled at compile-time");
Err(DecodingError::new("Unsupported"))
}
}
}
}
Expand Down
Loading

0 comments on commit a08d2f9

Please sign in to comment.