From: Wez Furlong Date: Tue, 23 Sep 2003 16:05:52 +0000 (+0000) Subject: MFB 25614 "fix" X-Git-Tag: RELEASE_1_3b2~87 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fce7b92891293a9bdbed304bc733166d1bd22426;p=php MFB 25614 "fix" --- diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c index b01e78aea6..acb11ea0e5 100644 --- a/ext/openssl/openssl.c +++ b/ext/openssl/openssl.c @@ -1738,14 +1738,23 @@ static EVP_PKEY * php_openssl_evp_from_zval(zval ** val, int public_key, char * cert = (X509*)what; free_cert = 0; } else if (type == le_key) { + int is_priv; + + is_priv = php_openssl_is_private_key((EVP_PKEY*)what TSRMLS_CC); + /* check whether it is actually a private key if requested */ - if (!public_key && !php_openssl_is_private_key((EVP_PKEY*)what TSRMLS_CC)) { + if (!public_key && !ispriv) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "supplied key param is a public key"); return NULL; } - - /* got the key - return it */ - return (EVP_PKEY*)what; + + if (public_key && is_priv) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Don't know how to get public key from this private key"); + return NULL; + } else { + /* got the key - return it */ + return (EVP_PKEY*)what; + } } /* other types could be used here - eg: file pointers and read in the data from them */ diff --git a/ext/openssl/tests/bug25614.phpt b/ext/openssl/tests/bug25614.phpt new file mode 100644 index 0000000000..ce57ea772d --- /dev/null +++ b/ext/openssl/tests/bug25614.phpt @@ -0,0 +1,11 @@ +--TEST-- +openssl: get public key from generated private key +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +Warning: openssl_pkey_get_public(): Don't know how to get public key from this private key (the documentation lied) %s