libp2p / rust-libp2p

The Rust Implementation of the libp2p networking stack.
https://libp2p.io
MIT License
4.54k stars 945 forks source link

identity: Implement protobuf encoding for RSA, ECDSA and secp256k1 keypairs #3630

Open thomaseizinger opened 1 year ago

thomaseizinger commented 1 year ago

Description

The spec is here: https://github.com/libp2p/specs/blob/master/peer-ids/peer-ids.md#key-types

Related: https://github.com/libp2p/rust-libp2p/pull/3350#issuecomment-1474048757.

Motivation

Being feature-complete and compliant with libp2p specs.

Are you planning to do it yourself in a pull request?

No.

drHuangMHT commented 1 year ago

ring doesn't seem to provide a way to "serialize" RSA keys. Should we implement it ourselves?

thomaseizinger commented 1 year ago

ring doesn't seem to provide a way to "serialize" RSA keys. Should we implement it ourselves?

That is a bit unfortunate. There is only one way to construct the keypair, using from_pkcs8. We can store the original bytes next to the decoded key and use that when required. I don't see another solution unfortunately.

thomaseizinger commented 1 year ago

ring doesn't seem to provide a way to "serialize" RSA keys. Should we implement it ourselves?

That is a bit unfortunate. There is only one way to construct the keypair, using from_pkcs8. We can store the original bytes next to the decoded key and use that when required. I don't see another solution unfortunately.

We've discovered in https://github.com/libp2p/rust-libp2p/pull/3681 that our spec requires PKCS#1 and ring only supports decoding from PKCS#8.

If we were to use the rsa crate, this issue would go away.

@mxinden What is your opinion on switching to the rsa crate to finish this issue? One of the practical implications is that the function for encoding to protobuf cannot be infallible because we need to return an error if somebody attempts to serialize an RSA keypair.

mxinden commented 1 year ago

For others to follow along, past discussion: https://github.com/libp2p/rust-libp2p/issues/1133

I don't have an opinion on this issue. Overall I would deem anything RSA related low priority. That said, I see the advantages that the gained consistency would bring us (see comment by @thomaseizinger above).

Maybe @dignifiedquire since you are one of the main authors and since you know libp2p well, do you have an opinion?