Skip to content

Commit ef787ba

Browse files
committed
Switch dh_param handling to EVP_PKEY API
1 parent 2addab1 commit ef787ba

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

ext/openssl/xp_ssl.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,11 +1191,7 @@ static RSA *php_openssl_tmp_rsa_cb(SSL *s, int is_export, int keylength)
11911191

11921192
static int php_openssl_set_server_dh_param(php_stream * stream, SSL_CTX *ctx) /* {{{ */
11931193
{
1194-
DH *dh;
1195-
BIO* bio;
1196-
zval *zdhpath;
1197-
1198-
zdhpath = php_stream_context_get_option(PHP_STREAM_CONTEXT(stream), "ssl", "dh_param");
1194+
zval *zdhpath = php_stream_context_get_option(PHP_STREAM_CONTEXT(stream), "ssl", "dh_param");
11991195
if (zdhpath == NULL) {
12001196
#if 0
12011197
/* Coming in OpenSSL 1.1 ... eventually we'll want to enable this
@@ -1210,14 +1206,29 @@ static int php_openssl_set_server_dh_param(php_stream * stream, SSL_CTX *ctx) /*
12101206
return FAILURE;
12111207
}
12121208

1213-
bio = BIO_new_file(Z_STRVAL_P(zdhpath), PHP_OPENSSL_BIO_MODE_R(PKCS7_BINARY));
1209+
BIO *bio = BIO_new_file(Z_STRVAL_P(zdhpath), PHP_OPENSSL_BIO_MODE_R(PKCS7_BINARY));
12141210

12151211
if (bio == NULL) {
12161212
php_error_docref(NULL, E_WARNING, "Invalid dh_param");
12171213
return FAILURE;
12181214
}
12191215

1220-
dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
1216+
#if PHP_OPENSSL_API_VERSION >= 0x30000
1217+
EVP_PKEY *pkey = PEM_read_bio_Parameters(bio, NULL);
1218+
BIO_free(bio);
1219+
1220+
if (pkey == NULL) {
1221+
php_error_docref(NULL, E_WARNING, "Failed reading DH params");
1222+
return FAILURE;
1223+
}
1224+
1225+
if (SSL_CTX_set0_tmp_dh_pkey(ctx, pkey) < 0) {
1226+
php_error_docref(NULL, E_WARNING, "Failed assigning DH params");
1227+
EVP_PKEY_free(pkey);
1228+
return FAILURE;
1229+
}
1230+
#else
1231+
DH *dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
12211232
BIO_free(bio);
12221233

12231234
if (dh == NULL) {
@@ -1232,6 +1243,7 @@ static int php_openssl_set_server_dh_param(php_stream * stream, SSL_CTX *ctx) /*
12321243
}
12331244

12341245
DH_free(dh);
1246+
#endif
12351247

12361248
return SUCCESS;
12371249
}

0 commit comments

Comments
 (0)