From: Wez Furlong Date: Tue, 23 Sep 2003 14:52:28 +0000 (+0000) Subject: "Fix" for bug #25614. X-Git-Tag: php-4.3.4RC1~34 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=872948f21a1cdd25d3eccb4948820e49e2470235;p=php "Fix" for bug #25614. The openssl_pkey_get_public() doesn't work as advertized in the docs; it can't get a public key from a private key (because a key is a key), but would return the private key anyway. The function was originally designed to get the public key from a certificate. --- diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c index 0487344eb3..1964ea5933 100644 --- a/ext/openssl/openssl.c +++ b/ext/openssl/openssl.c @@ -1689,15 +1689,21 @@ static EVP_PKEY * php_openssl_evp_from_zval(zval ** val, int public_key, char * 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 && !is_priv) { 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 (the documentation lied)"); + 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