aboutsummaryrefslogtreecommitdiffstats
path: root/ext/openssl/ossl_pkey_rsa.c
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2019-06-03 20:45:20 -0700
committerJeremy Evans <code@jeremyevans.net>2019-07-03 16:11:24 -0700
commite30b9a27f00338b065e90c6172d1c4509edc2853 (patch)
tree93755ea113df156e9ab0e1df7bc4457ea164b384 /ext/openssl/ossl_pkey_rsa.c
parent5c4391f767b5db55ffa73531ff6449a87b6c1154 (diff)
downloadruby-openssl-e30b9a27f00338b065e90c6172d1c4509edc2853.tar.gz
Fix segfaults in OpenSSL::PKey::RSA#private_{en,de}crypt when private exp not set
The public exp not set would trigger this for #public_{en,de}crypt, but OpenSSL::PKey::RSA#set_key does not allow setting a NULL public exp.
Diffstat (limited to 'ext/openssl/ossl_pkey_rsa.c')
-rw-r--r--ext/openssl/ossl_pkey_rsa.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/ext/openssl/ossl_pkey_rsa.c b/ext/openssl/ossl_pkey_rsa.c
index 761866c6..e09813a4 100644
--- a/ext/openssl/ossl_pkey_rsa.c
+++ b/ext/openssl/ossl_pkey_rsa.c
@@ -488,13 +488,13 @@ static VALUE
ossl_rsa_private_encrypt(int argc, VALUE *argv, VALUE self)
{
RSA *rsa;
- const BIGNUM *rsa_n;
+ const BIGNUM *rsa_n, *rsa_d;
int buf_len, pad;
VALUE str, buffer, padding;
GetRSA(self, rsa);
- RSA_get0_key(rsa, &rsa_n, NULL, NULL);
- if (!rsa_n)
+ RSA_get0_key(rsa, &rsa_n, NULL, &rsa_d);
+ if (!rsa_n || !rsa_d)
ossl_raise(eRSAError, "incomplete RSA");
if (!RSA_PRIVATE(self, rsa))
ossl_raise(eRSAError, "private key needed.");
@@ -522,13 +522,13 @@ static VALUE
ossl_rsa_private_decrypt(int argc, VALUE *argv, VALUE self)
{
RSA *rsa;
- const BIGNUM *rsa_n;
+ const BIGNUM *rsa_n, *rsa_d;
int buf_len, pad;
VALUE str, buffer, padding;
GetRSA(self, rsa);
- RSA_get0_key(rsa, &rsa_n, NULL, NULL);
- if (!rsa_n)
+ RSA_get0_key(rsa, &rsa_n, NULL, &rsa_d);
+ if (!rsa_n || !rsa_d)
ossl_raise(eRSAError, "incomplete RSA");
if (!RSA_PRIVATE(self, rsa))
ossl_raise(eRSAError, "private key needed.");