Bug #76676 [NEW]: OPENSSL_KEYTYPE_EC (and others) not supported by openssl_public_encrypt()

From: Date: Sat, 28 Jul 2018 13:47:55 +0000
Subject: Bug #76676 [NEW]: OPENSSL_KEYTYPE_EC (and others) not supported by openssl_public_encrypt()
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-216512@lists.php.net to get a copy of this message
From: kaplan Operating system: PHP version: 7.1.20 Package: OpenSSL related Bug Type: Bug Bug description:OPENSSL_KEYTYPE_EC (and others) not supported by openssl_public_encrypt() Description: ------------ Comparing key types supported by php_openssl_is_private_key() to the ones supported by openssl_public_key() shows many are missing. php_openssl_is_private_key recognizes: EVP_PKEY_RSA / EVP_PKEY_RSA2 EVP_PKEY_DSA / EVP_PKEY_DSA1 / EVP_PKEY_DSA2 / EVP_PKEY_DSA3 / EVP_PKEY_DSA4 EVP_PKEY_DH EVP_PKEY_EC openssl_private_encrypt supports EVP_PKEY_RSA / EVP_PKEY_RSA2 openssl_private_decrypt supports EVP_PKEY_RSA / EVP_PKEY_RSA2 openssl_public_decrypt supports EVP_PKEY_RSA / EVP_PKEY_RSA2 Maybe also use EVP_PKEY_base_id() as in openssl_pkey_get_details() which does support all the keys as php_openssl_is_private_key(). Tested in 7.1.14, 7.2.6 and master (July 26th, 2018). Test script: --------------- <?php $pair = generateKeyPair(true); $public = $pair['public']; $ciphertext = "111-11-1111"; $res = openssl_public_encrypt($ciphertext, $enc, $public, OPENSSL_PKCS1_OAEP_PADDING); if($res){ var_dump(bin2hex($enc)); } else { echo "Failed to encrypt :("; } function generateKeyPair(bool $ec){ $params = $ec ? [ 'private_key_bits' => 384, 'private_key_type' => OPENSSL_KEYTYPE_EC, 'curve_name' => 'secp384r1' ] : [ 'private_key_bits' => 3072, 'private_key_type' => OPENSSL_KEYTYPE_RSA ]; $res = openssl_pkey_new($params); openssl_pkey_export($res, $privKey); $pubKey = openssl_pkey_get_details($res); $pubKey = $pubKey["key"]; openssl_free_key($res); return ['private'=>$privKey, 'public'=>$pubKey]; } ?> Expected result: ---------------- 1. for OPENSSL_KEYTYPE_EC to be suppprted. 2. for missing keytype be part of the error message. Actual result: -------------- Warning: openssl_public_encrypt(): key type not supported in this PHP build! -- Edit bug report at https://bugs.php.net/bug.php?id=76676&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=76676&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=76676&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=76676&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=76676&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=76676&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=76676&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=76676&r=needscript Try newer version: https://bugs.php.net/fix.php?id=76676&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=76676&r=support Expected behavior: https://bugs.php.net/fix.php?id=76676&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=76676&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=76676&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=76676&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76676&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=76676&r=dst IIS Stability: https://bugs.php.net/fix.php?id=76676&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=76676&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=76676&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=76676&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=76676&r=mysqlcfg

« previous php.bugs (#216512) next »