Skip to content

Commit 341d72b

Browse files
committed
pkey/rsa: do not create legacy RSA pkey
1 parent 9d0718c commit 341d72b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

ext/openssl/ossl_pkey_rsa.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ static VALUE
7777
ossl_rsa_initialize(int argc, VALUE *argv, VALUE self)
7878
{
7979
EVP_PKEY *pkey;
80+
#ifndef OSSL_HAVE_PROVIDER
8081
RSA *rsa;
82+
#endif
8183
BIO *in = NULL;
8284
VALUE arg, pass;
8385
int type;
@@ -89,16 +91,21 @@ ossl_rsa_initialize(int argc, VALUE *argv, VALUE self)
8991
/* The RSA.new(size, generator) form is handled by lib/openssl/pkey.rb */
9092
rb_scan_args(argc, argv, "02", &arg, &pass);
9193
if (argc == 0) {
94+
#ifdef OSSL_HAVE_PROVIDER
95+
rb_raise(eRSAError, "empty RSA cannot be created");
96+
#else
9297
rsa = RSA_new();
9398
if (!rsa)
9499
ossl_raise(eRSAError, "RSA_new");
95100
goto legacy;
101+
#endif
96102
}
97103

98104
pass = ossl_pem_passwd_value(pass);
99105
arg = ossl_to_der_if_possible(arg);
100106
in = ossl_obj2bio(&arg);
101107

108+
#ifndef OSSL_HAVE_PROVIDER
102109
/* First try RSAPublicKey format */
103110
rsa = d2i_RSAPublicKey_bio(in, NULL);
104111
if (rsa)
@@ -108,6 +115,7 @@ ossl_rsa_initialize(int argc, VALUE *argv, VALUE self)
108115
if (rsa)
109116
goto legacy;
110117
OSSL_BIO_reset(in);
118+
#endif
111119

112120
/* Use the generic routine */
113121
pkey = ossl_pkey_read_generic(in, pass);
@@ -123,6 +131,7 @@ ossl_rsa_initialize(int argc, VALUE *argv, VALUE self)
123131
RTYPEDDATA_DATA(self) = pkey;
124132
return self;
125133

134+
#ifndef OSSL_HAVE_PROVIDER
126135
legacy:
127136
BIO_free(in);
128137
pkey = EVP_PKEY_new();
@@ -133,6 +142,7 @@ ossl_rsa_initialize(int argc, VALUE *argv, VALUE self)
133142
}
134143
RTYPEDDATA_DATA(self) = pkey;
135144
return self;
145+
#endif
136146
}
137147

138148
#ifndef HAVE_EVP_PKEY_DUP

0 commit comments

Comments
 (0)