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: allow setting algorithm-specific options in #sign and #verify #374

Merged
merged 3 commits into from
Apr 4, 2021

Conversation

rhenium
Copy link
Member

@rhenium rhenium commented May 21, 2020

Similarly to OpenSSL::PKey.generate_key and .generate_parameters, add
an optional parameter to OpenSSL::PKey::PKey#sign and #verify to specify
strings for EVP_PKEY_CTX_ctrl_str().

@rhenium rhenium force-pushed the ky/pkey-sign-verify-options branch from 76db8a4 to 4c13c6a Compare June 29, 2020 05:44
@ioquatix
Copy link
Member

Do these behave like keyword options?

@rhenium
Copy link
Member Author

rhenium commented Jun 30, 2020

Technically, it takes Hash as the last (3rd) positional parameter, and the key-value pairs are passed to EVP_PKEY_CTX_ctrl_str(). The Hash can have String and Symbol keys (both converted to String later), so caller can use the keyword argument style as well. My understanding is that Ruby 3 is not going to change this.

pkey.sign("sha256", data, { rsa_padding_mode: "pss", ... })
pkey.sign("sha256", data, rsa_padding_mode: "pss", ...)

The drawback is that we won't be able to add real keyword arguments to #sign or #verify later. But at the moment I can't think of any.

@rhenium
Copy link
Member Author

rhenium commented Aug 21, 2020

CI is failing because the test depends on OpenSSL >= 1.0.2 feature (RSA-PSS).

@rhenium rhenium force-pushed the ky/pkey-sign-verify-options branch from e39e92c to 7f57273 Compare April 4, 2021 14:32
Fix potential leak of EVP_MD_CTX object in an error path. This path is
normally unreachable, since the size of a signature generated by any
supported algorithms would not be larger than LONG_MAX.
The routine to apply Hash to EVP_PKEY_CTX_ctrl_str() is currently used
by key generation, but it is useful for other operations too. Let's
change it to a slightly more generic name.
Similarly to OpenSSL::PKey.generate_key and .generate_parameters, let
OpenSSL::PKey::PKey#sign and #verify take an optional parameter for
specifying control strings for EVP_PKEY_CTX_ctrl_str().
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