-
Notifications
You must be signed in to change notification settings - Fork 581
feat(x25519-dalek): add PKCS#8 and PEM private key support #847
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
base: main
Are you sure you want to change the base?
Conversation
|
Hi @tarcieri. This is a implementation for #846. I've written tests, however it seems the current CI setup doesn't seem to test all feature combinations (especially |
Introduce support for encoding and decoding X25519 private keys using the PKCS#8 standard (both DER and PEM formats). This enables interoperability with OpenSSL, TLS stacks, and other crypto systems. Changes: - Add `pkcs8` crate as optional dependency - Implement `EncodePrivateKey` and `TryFrom<PrivateKeyInfoRef>` - Handle nested OCTET STRING structure required by RFC - Add tests for DER/PEM encoding round-trips - Wire up `pem` feature behind feature gate Signed-off-by: Kun Lai <laikun@linux.alibaba.com>
Signed-off-by: Kun Lai <laikun@linux.alibaba.com>
|
Just pushed a fix to keep Clippy happy. Thanks for catching that! @tarcieri |
|
Thank you! Just two things:
|
|
It’s standard PKCS#8, more specifically https://datatracker.ietf.org/doc/html/rfc5958 |
|
Ah, I see the answer to question 2 is that it's specified in RFC 8410 §7. Could you write that in a comment somewhere? It looks like the PEM is not from the RFC, though. Is that right? Could you change the PEM to the PEM found in the RFC? Also make the DER equal to the translated PEM (and write the command you used for the translation)? |
|
@imlk0 can you fix the conflicts? |
|
|
||
| #[cfg(all(feature = "alloc", feature = "pkcs8"))] | ||
| impl EncodePrivateKey for EphemeralSecret { | ||
| fn to_pkcs8_der(&self) -> Result<SecretDocument, pkcs8::Error> { |
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.
This should not be exported out as it violates perfect forward secrecy.
We made a point not to add any impls that allows serialization out.
| impl TryFrom<PrivateKeyInfoRef<'_>> for EphemeralSecret { | ||
| type Error = pkcs8::Error; | ||
|
|
||
| fn try_from(private_key: PrivateKeyInfoRef<'_>) -> Result<Self, pkcs8::Error> { |
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.
EphemeralSecret is supposed to be random generated always.
This should not be extended to it.
|
Adding any type of serialization to it will break this property and also breaks the property of ensuring randomized keys for it. It's fine for See documentation for
|
Introduce support for encoding and decoding X25519 private keys using the PKCS#8 standard (both DER and PEM formats). This enables interoperability with OpenSSL, TLS stacks, and other crypto systems.
Changes:
pkcs8crate as optional dependencyEncodePrivateKeyandTryFrom<PrivateKeyInfoRef>pemfeature behind feature gate