Skip to content

Commit 7c61113

Browse files
committed
dh: use EVP API for loading DH params/keys
Calling d2i_DHparams_bio() is not needed on OpenSSL 3.0 since the generic PKey routine supports it. It is also marked as deprecated on OpenSSL 3.0 and prevents EVP_PKEY_todata() from working.
1 parent 0acff8e commit 7c61113

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

ext/openssl/ossl_pkey_dh.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ ossl_dh_initialize(int argc, VALUE *argv, VALUE self)
7474
{
7575
EVP_PKEY *pkey;
7676
int type;
77+
#ifndef OSSL_HAVE_PROVIDER
7778
DH *dh;
79+
#endif
7880
BIO *in = NULL;
7981
VALUE arg;
8082

@@ -84,15 +86,20 @@ ossl_dh_initialize(int argc, VALUE *argv, VALUE self)
8486

8587
/* The DH.new(size, generator) form is handled by lib/openssl/pkey.rb */
8688
if (rb_scan_args(argc, argv, "01", &arg) == 0) {
89+
#ifdef OSSL_HAVE_PROVIDER
90+
rb_raise(eDHError, "empty DH cannot be created");
91+
#else
8792
dh = DH_new();
8893
if (!dh)
8994
ossl_raise(eDHError, "DH_new");
9095
goto legacy;
96+
#endif
9197
}
9298

9399
arg = ossl_to_der_if_possible(arg);
94100
in = ossl_obj2bio(&arg);
95101

102+
#ifndef OSSL_HAVE_PROVIDER
96103
/*
97104
* On OpenSSL <= 1.1.1 and current versions of LibreSSL, the generic
98105
* routine does not support DER-encoded parameters
@@ -101,6 +108,7 @@ ossl_dh_initialize(int argc, VALUE *argv, VALUE self)
101108
if (dh)
102109
goto legacy;
103110
OSSL_BIO_reset(in);
111+
#endif
104112

105113
pkey = ossl_pkey_read_generic(in, Qnil);
106114
BIO_free(in);
@@ -115,6 +123,7 @@ ossl_dh_initialize(int argc, VALUE *argv, VALUE self)
115123
RTYPEDDATA_DATA(self) = pkey;
116124
return self;
117125

126+
#ifndef OSSL_HAVE_PROVIDER
118127
legacy:
119128
BIO_free(in);
120129
pkey = EVP_PKEY_new();
@@ -125,6 +134,7 @@ ossl_dh_initialize(int argc, VALUE *argv, VALUE self)
125134
}
126135
RTYPEDDATA_DATA(self) = pkey;
127136
return self;
137+
#endif
128138
}
129139

130140
#ifndef HAVE_EVP_PKEY_DUP

0 commit comments

Comments
 (0)