-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Keypair::to_protobuf_encoding #2142
Conversation
740317d
to
66d5837
Compare
I now also notice that |
66d5837
to
8ba0b8c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Agree with PublicKey::into_protobuf_encoding
-> PublicKey::to_protobuf_encoding
Do I put that in here, or shall I make a separate PR? EDIT: and while we're at it, |
Can we do it in separate without having dependencies to this code? I think so right? Speaking of changes, can you add a changelog entry please?
I think that was because |
8ba0b8c
to
fe43968
Compare
Definitely.
I mean, we can leave both in, but it's really only deleting two characters :-)
Done
Hmm, |
They are, but if a type is not For encoding to protobuf, we need to allocate anyway so there is no point in offering |
@@ -116,6 +116,33 @@ impl Keypair { | |||
} | |||
} | |||
|
|||
/// Encode a private key as protobuf structure. | |||
pub fn to_protobuf_encoding(&self) -> Result<Vec<u8>, DecodingError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you expand on your use-case for encoding private keys?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is a usecase: https://github.com/comit-network/rendezvous-server/blob/c5dedb5119569ff523da981f5bb3b02d3e3cb903/src/main.rs#L143-L151
We want the server to always have the same identity, which is why we store the secret key in a file. Using normal unix user ACLs, we can control which parts of the machine have access to this private key.
Our design was inspired by: https://smallstep.com/blog/command-line-secrets/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same case here: a bootstrap server (set of bootstrap servers) with a fixed identity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be a bit paranoid, but I would really like to keep the extra safety measure of not being able to extract private key material once moved to a Keypar
.
Why not do something along the lines of GenerateNodeKeyCmd
and InspectNodeKeyCmd
?
I would even suggest that we alter our peer ID generator, enabling it to generate a random private key and saving it to a file, preferably in the IPFS format. The rendezvous-server or your bootstrap server can then read that file and load it as a Keypair
.
I am taking a similar approach with rust-libp2p-server and ipfs init.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I was confused that Keypair::generate_*()
was a thing, with seemingly no way to persist the private key. Maybe this is a documentation issue after all, if it's indeed possible to construct the private information, persist it, and then yield a key.
Would you agree if I say that it's strange to generate a Ed25519 keypair, persist the secret (somehow) and then read that as a Keypair? I wouldn't expect a struct to serialize, then deserialize to a different type.
It's not too paranoid IMO.
I would even suggest that we alter our peer ID generator, enabling it to generate a random private key and saving it to a file, preferably in the IPFS format. The rendezvous-server or your bootstrap server can then read that file and load it as a Keypair.
Note that saving to files is not a general solution; I imagine some people want to persist to a database, either in a file or in memory, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A patch to the docs would be very much appreciated, so others don't get confused too.
Making a lot of promises against rust-libp2p
lately, but since I'll have to revise my own stuff now (it's currently using this branch), I suppose it's not a lot of work to create some docs and example code with doctests on the Keypair
struct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be a bit paranoid, but I would really like to keep the extra safety measure of not being able to extract private key material once moved to a
Keypar
.
But that is already possible or am I missing something?
- Fields in enums are public, hence one can just match on the variant and get for example an
ed25519::Keypair
ed25519::Keypair
can be converted.into()
aned25519::SecretKey
.ed25519::SecretKey
implementsAsRef<[u8]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having a look at how to apply the approach you take in GenerateNodeKeyCmd
and InspectNodeKeyCmd
, but those seem not to use the protobuf encoding (which is what IPFS seems to use).
If the PeerID generator is altered to allow writing IPFS-style secret keys, I don't currently see how it can do without a patch like this one. Am I missing something here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦♂️ my bad, you are absolutely right @thomaseizinger! Sorry for the confusion.
If the PeerID generator is altered to allow writing IPFS-style secret keys, I don't currently see how it can do without a patch like this one. Am I missing something here?
Again, 100% correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, better to triple check and make sure! Thanks for having this :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for bearing with me! Looks good to me. Also thanks for changelog entry and test.
Current failure seems to be due to some incompatibility between #2142 and some new commit. This should fix it:
|
That is because CI runs on |
Right, I didn't realize it's code from this PR that messed that up. Too many things in parallel. Should work now :'-) |
Keypair was able to decode protobuf-encoded keys, but not to encode them yet afaik. This adds a method to encode
identity::Keypair
s.