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

pkey/ec: check private key validity with OpenSSL 3 #565

Closed
wants to merge 1 commit into from

Conversation

bannable
Copy link
Contributor

The behavior of EVP_PKEY_public_check changed between OpenSSL 1.1.1 and 3.0 so that it no longer validates the private key. Instead, private keys can be validated through EVP_PKEY_private_check and EVP_PKEY_pairwise_check.

This addresses #563

The behavior of EVP_PKEY_public_check changed between OpenSSL 1.1.1
and 3.0 so that it no longer validates the private key. Instead, private
keys can be validated through EVP_PKEY_private_check and
EVP_PKEY_pairwise_check.
@rhenium
Copy link
Member

rhenium commented Dec 22, 2022

Thank you for the report. This affects openssl gem v3.0.x. Let me change the target branch to maint-3.0 (which will be merged to master).

#if (defined(OPENSSL_VERSION_MAJOR) && OPENSSL_VERSION_MAJOR >= 3)
GetEC(self, ec);
if (EC_KEY_get0_private_key(ec) == NULL)
goto skip_priv_key;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hoping for a workaround without using the deprecated EC_KEY, which we eventually have to get rid of, but this looks necessary at the moment.


key5 = Fixtures.pkey("p384_invalid")
assert_raise(OpenSSL::PKey::ECError) { key5.check_key }
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally and these assertions pass on OpenSSL 1.1 too (as expected).

@rhenium
Copy link
Member

rhenium commented Dec 22, 2022

The manpage gave me the impression what EVP_PKEY_pairwise_check() does is a superset of both EVP_PKEY_public_check() and EVP_PKEY_private_check(). EVP_PKEY_pairwise_check() is apparently an alias of EVP_PKEY_check() and the latter name is already available in OpenSSL 1.1.1.

Could a shorter version like the below work, regardless of the OpenSSL version?

if (EC_KEY_get0_private_key(ec) != NULL) {
  if (EVP_PKEY_check()...
}
else {
  if (EVP_PKEY_public_check()...
}

@rhenium
Copy link
Member

rhenium commented Dec 22, 2022

I believe it is: all end up calling this function with a different selection in OpenSSL 3.0. https://github.com/openssl/openssl/blob/98663afce7a909be1518921a9995540308a52462/providers/implementations/keymgmt/ec_kmgmt.c#L936

@rhenium
Copy link
Member

rhenium commented Dec 22, 2022

I have applied those changes in #580. Thank you!

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.

2 participants