-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkey: track whether pkey is private key or not
There are multiple places where it's necessary to know whether a pkey is a private key, a public key, or just key parameters. This is due to two reasons: 1. It's currently a responsibility of the caller to give a properly populated pkey instance to _some_ OpenSSL functions. For example, calling EVP_PKEY_sign() with an RSA pkey instance without the necessary components is known to cause a segfault. 2. OpenSSL::PKey::{RSA,DSA,EC}#to_der behaves differently depending on it: they use the X.509 SubjectPublicKeyInfo structure instead of private key structures if the receiver pkey is a public key. Currently, whenever this is necessary, we check the backing object, such as RSA, and see if the fields are set or not. This approach won't always work on OpenSSL 3.0 because of the architecture change. Unfortunately, OpenSSL doesn't expose an API for this purpose (even though it has one for its internal use). As a workaround, let's manually track this information in an instance variable. This has been partly done for ENGINE-backed pkeys. Now all pkeys get this flag. This is straightforward on OpenSSL 3.0 as pkeys are immutable once instantiated. On OpenSSL 1.1 or before (and current versions of LibreSSL), it must be updated whenever a modification is made to the object. This commit comes with a slight behavior change. Pkeys returned by following method will be explicitly marked as "public", even if it happens to point at an EVP_PKEY struct containing private key components. I expect the effect is minimum since these methods explicitly say "public key". - OpenSSL::X509::Certificate#public_key - OpenSSL::X509::Request#public_key - OpenSSL::Netscape::SPKI#public_key
- Loading branch information
Showing
13 changed files
with
288 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.