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

feat(identity): implement protobuf encoding for all key types #3681

Closed
wants to merge 100 commits into from
Closed
Show file tree
Hide file tree
Changes from 96 commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
7d5e606
feat: make mdns::Event clone-able
drHuangMHT Mar 13, 2023
05ce438
Merge branch 'libp2p:master' into master
Mar 13, 2023
a72e5e2
docs: filling CHANGELOG for PR 3606
drHuangMHT Mar 13, 2023
09bef20
Merge branch 'master' of https://github.com/drHuangMHT/rust-libp2p
drHuangMHT Mar 13, 2023
926c7ca
Update protocols/mdns/CHANGELOG.md
thomaseizinger Mar 13, 2023
49d26c4
Update protocols/mdns/CHANGELOG.md
thomaseizinger Mar 13, 2023
4a35406
Merge branch 'master' into master
mergify[bot] Mar 13, 2023
a8ff1eb
feat: change 'mdns::Event' to hold 'SmallVec'
drHuangMHT Mar 16, 2023
4cec5fa
test: adapting test to 'mdns::Event' change
drHuangMHT Mar 16, 2023
a876f2f
Merge branch 'master' of https://github.com/drHuangMHT/rust-libp2p
drHuangMHT Mar 16, 2023
18811d2
feat(mdns): change 'mdns::Event' to hold 'Vec'
drHuangMHT Mar 16, 2023
abdce7e
doc: add entry for #3621
drHuangMHT Mar 16, 2023
d5c246c
Update protocols/mdns/CHANGELOG.md
Mar 16, 2023
ed128a7
Merge branch 'master' of https://github.com/drHuangMHT/rust-libp2p
drHuangMHT Mar 26, 2023
0d06f4c
Merge branch 'master' of https://github.com/drHuangMHT/rust-libp2p
drHuangMHT Mar 26, 2023
9d45cf3
Remove conflict marker to resolve conflicts
drHuangMHT Mar 26, 2023
947b368
add 'try' to method returning 'Result'
drHuangMHT Mar 27, 2023
e3e6355
implement protobuf encoding for RSA keys
drHuangMHT Mar 27, 2023
b91bcc7
fix: change 'encode_unsupported' to 'missing_feature' for branch lead…
drHuangMHT Mar 27, 2023
959b90f
fix: wrongly configured feature attributes when encoding to protobuf
drHuangMHT Mar 27, 2023
20134d1
fix: clippy and fmt
drHuangMHT Mar 27, 2023
d833904
doc: documentation for changed methods
drHuangMHT Mar 27, 2023
0896a61
feat: enforce naming rules
drHuangMHT Mar 27, 2023
593272c
Merge branch 'master' into identity-keypair
thomaseizinger Mar 29, 2023
f559cfe
hide 'proto::KeyType'
drHuangMHT Mar 29, 2023
672b9b9
make 'to_protobuf_encoding' for 'Keypair' infallible
drHuangMHT Mar 29, 2023
33c9b9b
make 'to_protobuf_encoding' for 'PublicKey' infallible
drHuangMHT Mar 29, 2023
f4a764d
revert renamed method and deprecate instead
drHuangMHT Mar 29, 2023
8b8bfc5
split 'rsa::Keypair::try_decode' into two separate method
drHuangMHT Mar 30, 2023
921fc4a
introduce 'ConversionError' for associated 'Error' type in 'TryInto'
drHuangMHT Mar 30, 2023
b555d7f
add 'try' prefix to 'into_[keytype]' for 'libp2p_identity::Keypair'
drHuangMHT Apr 4, 2023
d65ce3e
revert renaming of method in 'libp2p_identity::Keypair'
drHuangMHT Apr 4, 2023
c587b73
recommend key promotion for deprecated methods in 'libp2p_identity::K…
drHuangMHT Apr 4, 2023
2a77a26
revert renaming of method in 'libp2p_identity::secp256k1'
drHuangMHT Apr 4, 2023
7d0ceaa
renaming 'ConversionError' to 'OtherVariantError'
drHuangMHT Apr 4, 2023
c846a3d
revert wrongly renamed 'secp256k1::SecretKey::from_der'
drHuangMHT Apr 4, 2023
a3eae1c
formatting
drHuangMHT Apr 4, 2023
3adb27f
revert removal of methods in 'libp2p_identity::PublicKey' and rename …
drHuangMHT Apr 4, 2023
43a33ce
clippy
drHuangMHT Apr 4, 2023
9ae47cf
remove unnecessary libp2p_identity::PublicKey::try_to_protobuf_encoding
drHuangMHT Apr 4, 2023
b25a446
revert rename of 'libp2p_identity::PublicKey::from_protobuf_encoding'
drHuangMHT Apr 4, 2023
d936772
improve deprecation messages
drHuangMHT Apr 5, 2023
284736c
delegate deprecated methods to suggested ones
drHuangMHT Apr 5, 2023
2f02c04
enforce 'decode' rule for protobuf encoding
drHuangMHT Apr 5, 2023
b0a33fd
formatting
drHuangMHT Apr 5, 2023
cb40674
remove support for DER-encoded RSA key
drHuangMHT Apr 5, 2023
0321368
syncing 'keypair_dummy.rs' with 'keypair.rs'
drHuangMHT Apr 5, 2023
667fa77
remove unnecessary 'Error' trait impl for 'OtherVariantError'
drHuangMHT Apr 5, 2023
c97d661
revert renaming of 'into' methods on 'Keypair' and deprecate instead
drHuangMHT Apr 10, 2023
a04b17f
prepare keys for testing
drHuangMHT Apr 10, 2023
92f6914
Add roundtrip tests
thomaseizinger Apr 10, 2023
a3285d7
Undo mdns changes
thomaseizinger Apr 10, 2023
3762a20
Merge branch 'master' into identity-keypair
thomaseizinger Apr 10, 2023
896117c
Merge branch 'master' into identity-keypair
thomaseizinger Apr 10, 2023
f5cf834
Fix cargo.lock
thomaseizinger Apr 10, 2023
74e7cf3
repetitive 'encoding' method naming removed
drHuangMHT Apr 11, 2023
4285bda
use '.ok()' combinator to replace 'match' expression
drHuangMHT Apr 11, 2023
73d9e55
put link to libp2p spec in 'encode_protobuf' documentation
drHuangMHT Apr 11, 2023
6120997
remove roundtrip test for 'ecdsa::Keypair'
drHuangMHT Apr 11, 2023
785ca7c
remove 'Eq' impl for 'ecdsa::Keypair' and 'ecdsa::SecretKey'
drHuangMHT Apr 11, 2023
faa4d42
correct diff for 'ecdsa::from_bytes'
drHuangMHT Apr 11, 2023
9914eab
deprecation note correction for 'Keypair::rsa_from_pkcs8'
drHuangMHT Apr 11, 2023
1090f14
remove feature cfg for KeyType
drHuangMHT Apr 11, 2023
278f19e
add feature cfg to branches in 'TryInto' impl of 'Keypair'
drHuangMHT Apr 11, 2023
4b103bb
add feature cfg to branches in 'TryInto' impl of 'PublicKey'
drHuangMHT Apr 11, 2023
bd0284b
fix missing target exclusion on 'Keypair::into_rsa'
drHuangMHT Apr 11, 2023
bbf59d8
formatting
drHuangMHT Apr 11, 2023
1a442fa
remove duplicate 'to_protobuf_encoding' in 'keypair_dummy.rs'
drHuangMHT Apr 12, 2023
676b7e6
revert removal of 'into' implementation on 'PublicKey' and deprecate …
drHuangMHT Apr 12, 2023
85f3871
Merge branch 'libp2p:master' into identity-keypair
Apr 14, 2023
b83422c
Merge 'libp2p/master' into identity-keypair
drHuangMHT Apr 14, 2023
ffacd94
clippy fix
drHuangMHT Apr 14, 2023
6c8b5c7
refactor 'match' expression to '?' operator
drHuangMHT Apr 17, 2023
c231e1d
rename test keys
drHuangMHT Apr 17, 2023
4ecffb3
revert 'try_decode_x509' signature change
drHuangMHT Apr 17, 2023
c958c04
revert 'to_protobuf_encoding' signature change
drHuangMHT Apr 17, 2023
7c992fd
Merge remote-tracking branch 'upstream/master' into identity-keypair
drHuangMHT Apr 17, 2023
b613d1c
implement encoding to pkcs#8 for ecdsa keys
drHuangMHT Apr 17, 2023
24a5a86
formatting
drHuangMHT Apr 25, 2023
5e776b5
resolve conflict with upstream
drHuangMHT Apr 25, 2023
aeea24b
remove 'deprecation since'
drHuangMHT Apr 26, 2023
54e2fad
replace 'unwrap' with 'expect'
drHuangMHT Apr 26, 2023
2d244c7
remove redundant 'Deprecated,' message
drHuangMHT Apr 26, 2023
2c188ca
rename 'to_raw_bytes' to 'encode_pkcs8_der'
drHuangMHT Apr 26, 2023
ba9f4ed
fix uncaught deprecated method
drHuangMHT Apr 26, 2023
1b11e4a
downgrade 'p256' and remove 'ecdsa'
drHuangMHT Apr 27, 2023
3a330ac
Merge branch 'master' into identity-keypair
thomaseizinger May 5, 2023
01b4fd6
Undo ecdsa changes
thomaseizinger May 5, 2023
46700cf
Minimize diff
thomaseizinger May 5, 2023
ce9ba0d
Merge branch 'identity-keypair' of https://github.com/drHuangMHT/rust…
drHuangMHT May 5, 2023
7662073
lock file update
drHuangMHT May 5, 2023
e4b6ec7
fix: wrong dependency 'p256' version
drHuangMHT May 5, 2023
75ee978
delete unused test keys
drHuangMHT May 5, 2023
fd7a660
revert RSA changes
drHuangMHT May 5, 2023
96ab553
Merge branch 'master' into identity-keypair
drHuangMHT May 5, 2023
b23e111
remove feature flag on 'decoding_unsupported'
drHuangMHT May 5, 2023
4d7b516
fix: duplicated outdated test
drHuangMHT May 6, 2023
11748b5
upstream sync
drHuangMHT Dec 27, 2023
cffd763
Merge branch 'master' into identity-keypair
drHuangMHT Dec 27, 2023
07df6dc
fix errors introduced by merging manually
drHuangMHT Dec 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion examples/dcutr/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,5 +280,7 @@ fn generate_ed25519(secret_key_seed: u8) -> identity::Keypair {
let mut bytes = [0u8; 32];
bytes[0] = secret_key_seed;

identity::Keypair::ed25519_from_bytes(bytes).expect("only errors on wrong length")
identity::ed25519::Keypair::try_from_bytes(&mut bytes)
.expect("only errors on wrong length")
.into()
}
4 changes: 3 additions & 1 deletion examples/file-sharing/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ pub(crate) async fn new(
Some(seed) => {
let mut bytes = [0u8; 32];
bytes[0] = seed;
identity::Keypair::ed25519_from_bytes(bytes).unwrap()
identity::ed25519::Keypair::try_from_bytes(&mut bytes)
.unwrap()
.into()
}
None => identity::Keypair::generate_ed25519(),
};
Expand Down
5 changes: 3 additions & 2 deletions examples/relay-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ struct Behaviour {
fn generate_ed25519(secret_key_seed: u8) -> identity::Keypair {
let mut bytes = [0u8; 32];
bytes[0] = secret_key_seed;

identity::Keypair::ed25519_from_bytes(bytes).expect("only errors on wrong length")
identity::ed25519::Keypair::try_from_bytes(&mut bytes)
.expect("only errors on wrong length")
.into()
}

#[derive(Debug, Parser)]
Expand Down
4 changes: 2 additions & 2 deletions identity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ peerid = [ "dep:multihash", "dep:multiaddr", "dep:bs58", "dep:rand", "dep:thiser
[dev-dependencies]
quickcheck = { workspace = true }
base64 = "0.21.0"
serde_json = "1.0"
rmp-serde = "1.0"
criterion = "0.4"
hex-literal = "0.4.1"
rmp-serde = "1.0"
serde_json = "1.0"

[[bench]]
name = "peer_id"
Expand Down
3 changes: 0 additions & 3 deletions identity/src/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ impl SecretKey {

/// Decode a secret key from a byte buffer containing raw scalar of the key.
#[deprecated(
since = "0.2.0",
note = "This method name does not follow Rust naming conventions, use `SecretKey::try_from_bytes` instead"
)]
pub fn from_bytes(buf: &[u8]) -> Result<Self, DecodingError> {
Expand Down Expand Up @@ -168,7 +167,6 @@ impl PublicKey {

/// Decode a public key from a byte buffer containing raw components of a key with or without compression.
#[deprecated(
since = "0.2.0",
note = "This method name does not follow Rust naming conventions, use `PublicKey::try_from_bytes` instead."
)]
pub fn from_bytes(k: &[u8]) -> Result<PublicKey, DecodingError> {
Expand Down Expand Up @@ -198,7 +196,6 @@ impl PublicKey {

/// Decode a public key into a DER encoded byte buffer as defined by SEC1 standard.
#[deprecated(
since = "0.2.0",
note = "This method name does not follow Rust naming conventions, use `PublicKey::try_decode_der` instead."
)]
pub fn decode_der(k: &[u8]) -> Result<PublicKey, DecodingError> {
Expand Down
10 changes: 2 additions & 8 deletions identity/src/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl Keypair {
/// Encode the keypair into a byte array by concatenating the bytes
/// of the secret scalar and the compressed public point,
/// an informal standard for encoding Ed25519 keypairs.
#[deprecated(since = "0.2.0", note = "Renamed to `Keypair::to_bytes`")]
#[deprecated(note = "Renamed to `Keypair::to_bytes`")]
pub fn encode(&self) -> [u8; 64] {
self.to_bytes()
}
Expand All @@ -58,7 +58,6 @@ impl Keypair {
///
/// Note that this binary format is the same as `ed25519_dalek`'s and `ed25519_zebra`'s.
#[deprecated(
since = "0.2.0",
note = "This method name does not follow Rust naming conventions, use `Keypair::try_from_bytes` instead."
)]
pub fn decode(kp: &mut [u8]) -> Result<Keypair, DecodingError> {
Expand Down Expand Up @@ -184,10 +183,7 @@ impl PublicKey {

/// Encode the public key into a byte array in compressed form, i.e.
/// where one coordinate is represented by a single bit.
#[deprecated(
since = "0.2.0",
note = "Renamed to `PublicKey::to_bytes` to reflect actual behaviour."
)]
#[deprecated(note = "Renamed to `PublicKey::to_bytes` to reflect actual behaviour.")]
pub fn encode(&self) -> [u8; 32] {
self.to_bytes()
}
Expand All @@ -200,7 +196,6 @@ impl PublicKey {

/// Decode a public key from a byte array as produced by `to_bytes`.
#[deprecated(
since = "0.2.0",
note = "This method name does not follow Rust naming conventions, use `PublicKey::try_from_bytes` instead."
)]
pub fn decode(k: &[u8]) -> Result<PublicKey, DecodingError> {
Expand Down Expand Up @@ -255,7 +250,6 @@ impl SecretKey {
/// If the bytes do not constitute a valid Ed25519 secret key, an error is
/// returned.
#[deprecated(
since = "0.2.0",
note = "This method name does not follow Rust naming conventions, use `SecretKey::try_from_bytes` instead."
)]
#[allow(unused_mut)]
Expand Down
25 changes: 4 additions & 21 deletions identity/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ impl DecodingError {
feature = "ed25519",
feature = "rsa"
))]
/// Error occurred when parsing one type into another.
pub(crate) fn failed_to_parse<E, S>(what: &'static str, source: S) -> Self
where
E: Error + Send + Sync + 'static,
Expand Down Expand Up @@ -76,24 +77,14 @@ impl DecodingError {
}
}

#[cfg(any(
feature = "ecdsa",
feature = "secp256k1",
feature = "ed25519",
feature = "rsa"
))]
pub(crate) fn decoding_unsupported(key_type: &'static str) -> Self {
Self {
msg: format!("decoding {key_type} key from Protobuf is unsupported"),
source: None,
}
}

#[cfg(any(
all(feature = "rsa", not(target_arch = "wasm32")),
feature = "secp256k1",
feature = "ecdsa"
))]
#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
pub(crate) fn encoding_unsupported(key_type: &'static str) -> Self {
Self {
msg: format!("encoding {key_type} key to Protobuf is unsupported"),
Expand Down Expand Up @@ -124,18 +115,10 @@ 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 {
pub(crate) fn new<S: ToString>(msg: S, source: Option<Box<dyn Error + Send + Sync>>) -> 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)),
..self
source,
}
}
}
Expand Down
Loading