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

Better support for generic PKEYs #119

Closed
wants to merge 12 commits into from

Conversation

rhenium
Copy link
Member

@rhenium rhenium commented Mar 23, 2017

This PR includes following changes:

  • Add support for PKCS#8 format private keys
  • Add OpenSSL::PKey::PKey#derive
  • Add OpenSSL::PKey.generate_{parameters,key}

Will resolve #117.

rb_intern() with a string literal caches the result. This is unnecessary
for init functions.
The EVP interface cannot tell whether if a pkey contains the private
components or not. Assume it has, if the object does not respond to
'private?'.
ossl_{rsa,dsa,dh,ec}_new() called from this function are not used
anywhere else. Inline them into pkey_new0() and reduce code
duplication.
Merge the code into the callers. They are used only once or twice.

In fact, they are inconsistent and not useful - they are expected to
return Qfalse on failure, but actually also raise NoMemoryError if a
Ruby object allocation fails. This potentially causes memory leaks.
OpenSSL::PKey::PKey#private_to_der, #private_to_pem are added to the
generic PKey class. They serialize the private key to PKCS ruby#8
{Encrypted,}PrivateKeyInfo format, in DER- and PEM- encoding,
respectively. For symmetry, also add #public_to_der and #public_to_pem
that serialize the public key into X.509 SubjectPublicKeyInfo format.

OpenSSL::PKey.read now reads DER-encoded PKCS ruby#8 keys as well as the
"raw" private keys. PEM-encoded PKCS ruby#8 keys have been already handled
by PEM_read_bio_PrivateKey().
Try PEM_read_bio_Parameters() in OpenSSL::PKey.read.
Let each class' initialize method use the same code as
OpenSSL::PKey.read for loading a key from String.
Add OpenSSL::PKey::PKey#derive as the wrapper for EVP_PKEY_CTX_derive().
This is useful for pkey types that we don't have dedicated classes, such
as X25519.
Use the new OpenSSL::PKey::PKey#derive instead of the raw
{EC,}DH_compute_key(), mainly to reduce amount of the C code.
Add two methods to create a PKey using the EVP interface. This can be
useful for PKey types we don't have a dedicated class.
@rhenium rhenium mentioned this pull request Mar 23, 2017
@ioquatix
Copy link
Member

ioquatix commented Oct 7, 2019

Can you please rebase on master and advise whether this is still relevant? Thanks!

@rhenium
Copy link
Member Author

rhenium commented Feb 16, 2020

PKCS #8 formats support has been added by #297.

The other changes, code cleanup are in #328. Generic pkey operations (including X25519 and Ed25519 support) are in #329.

@rhenium rhenium closed this Feb 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Add suppot for X25519
2 participants