From c39336d1d866866de629695fbd9971fb48f27ea9 Mon Sep 17 00:00:00 2001 From: Jakub Zelenka Date: Tue, 25 Aug 2015 20:26:11 +0100 Subject: [PATCH] Fix bug #55259 (openssl extension does not get the DH parameters from DH key resource) --- ext/openssl/openssl.c | 11 ++++------- ext/openssl/tests/bug55259.phpt | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 ext/openssl/tests/bug55259.phpt diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c index ef5162283bb1c..0421524d64c8e 100644 --- a/ext/openssl/openssl.c +++ b/ext/openssl/openssl.c @@ -3597,13 +3597,10 @@ PHP_FUNCTION(openssl_pkey_new) OPENSSL_PKEY_SET_BN(Z_ARRVAL_PP(data), dh, g); OPENSSL_PKEY_SET_BN(Z_ARRVAL_PP(data), dh, priv_key); OPENSSL_PKEY_SET_BN(Z_ARRVAL_PP(data), dh, pub_key); - if (dh->p && dh->g) { - if (!dh->pub_key) { - DH_generate_key(dh); - } - if (EVP_PKEY_assign_DH(pkey, dh)) { - RETURN_RESOURCE(zend_list_insert(pkey, le_key TSRMLS_CC)); - } + if (dh->p && dh->g && + (dh->pub_key || DH_generate_key(dh)) && + EVP_PKEY_assign_DH(pkey, dh)) { + RETURN_RESOURCE(zend_list_insert(pkey, le_key TSRMLS_CC)); } DH_free(dh); } diff --git a/ext/openssl/tests/bug55259.phpt b/ext/openssl/tests/bug55259.phpt new file mode 100644 index 0000000000000..27ededdb185e6 --- /dev/null +++ b/ext/openssl/tests/bug55259.phpt @@ -0,0 +1,29 @@ +--TEST-- +Bug #55259 (openssl extension does not get the DH parameters from DH key resource) +--SKIPIF-- + +--FILE-- + $phex, 'g' => '2' ); +$dh = openssl_pkey_new(array( 'dh'=> array( 'p' => $phex, 'g' => '2' ))); +var_dump($dh); +$dh = openssl_pkey_new(array( 'dh'=> array( 'p' => hex2bin($phex), 'g' => '2' ))); +$details = openssl_pkey_get_details($dh); +var_dump(bin2hex($details['dh']['p'])); +var_dump($details['dh']['g']); +var_dump(strlen($details['dh']['pub_key'])); +var_dump(strlen($details['dh']['priv_key'])); +echo "Done"; +?> +--EXPECT-- +bool(false) +string(256) "dcf93a0b883972ec0e19989ac5a2ce310e1d37717e8d9571bb7623731866e61ef75a2e27898b057f9891c2e27a639c3f29b60814581cd3b2ca3986d2683705577d45c2e7e52dc81c7a171876e5cea74b1448bfdfaf18828efd2519f14e45e3826634af1949e5b535cc829a483b8a76223e5d490a257f05bdff16f2fb22c583ab" +string(1) "2" +int(128) +int(128) +Done