Bug #73478 [Com]: openssl_pkey_new() generates wrong pub/priv keys with Diffie Hellman
| From: | mhagstrand at gmail dot com | Date: | Fri, 11 Nov 2016 11:00:04 +0000 |
| Subject: | Bug #73478 [Com]: openssl_pkey_new() generates wrong pub/priv keys with Diffie Hellman | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-205303@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=73478&edit=1
ID: 73478
Comment by: mhagstrand at gmail dot com
Reported by: enrico at zimuel dot it
Summary: openssl_pkey_new() generates wrong pub/priv keys
with Diffie Hellman
Status: Open
Type: Bug
Package: OpenSSL related
Operating System: Ubuntu 16.04
PHP Version: 7.1.0RC5
Block user comment: N
Private report: N
New Comment:
I have put in a pull request to fix this issue.
https://github.com/php/php-src/pull/2197
Previous Comments:
------------------------------------------------------------------------
[2016-11-09 18:45:55] enrico at zimuel dot it
The error is reported also on Travis CI here:
https://travis-ci.org/ezimuel/zend-crypt/jobs/174568786#L329
------------------------------------------------------------------------
[2016-11-08 16:53:40] enrico at zimuel dot it
Description:
------------
I'm testing the zendframework/zend-crypt library using PHP7.1.0RC5 and I found an issue on
openssl_pkey_new() using the Diffie Hellman key generator. Using the same parameters the output
(public and private keys) is different for each execution.
I tested the test scripts on PHP 7.0.8, 7.0.4, 5.6.20 and it works fine.
I'm using OpenSSL 1.0.2g 1 Mar 2016.
Test script:
---------------
$details = [
'p' =>
base64_decode('3Pk6C4g5cuwOGZiaxaLOMQ4dN3F+jZVxu3Yjcxhm5h73Wi4niYsFf5iRwuJ6Y5w/KbYIFFgc07LKOYbSaDcFV31FwuflLcgcehcYduXOp0sUSL/frxiCjv0lGfFOReOCZjSvGUnltTXMgppIO4p2Ij5dSQolfwW9/xby+yLFg6s='),
'g' => base64_decode('Ag=='),
'priv_key' =>
base64_decode('jUdcV++P/m7oUodWiqKqKXZVenHRuj92Ig6Fmzs7QlqVdUc5mNBxmEWjug+ObffanPpOeab/LyXwjNMzevtBz3tW4oROau++9EIMJVVQr8fW9zdYBJcYieC5l4t8nRj5/Uu/Z0G2rWVLBleSi28mqqNEvnUs7uxYxrar69lwQYs=')
];
$opensslKeyResource = openssl_pkey_new(['dh' => $details]);
$data = openssl_pkey_get_details($opensslKeyResource);
printf("Private key:\n%s\n", base64_encode($data['dh']['priv_key']));
printf("Public key:\n%s\n", base64_encode($data['dh']['pub_key']));
Expected result:
----------------
Private key:
jUdcV++P/m7oUodWiqKqKXZVenHRuj92Ig6Fmzs7QlqVdUc5mNBxmEWjug+ObffanPpOeab/LyXwjNMzevtBz3tW4oROau++9EIMJVVQr8fW9zdYBJcYieC5l4t8nRj5/Uu/Z0G2rWVLBleSi28mqqNEvnUs7uxYxrar69lwQYs=
Public key:
0DmJUe9dr02pAtVoGyLHdC+rfBU3mDCelKGPXRDFHofx6mFfN2gcZCmp/ab4ezDXfpIBOatpVdbn2fTNUGo64DtKE2WGTsZCl90RgrGUv8XW/4WDPXeE7g5u7KWHBG/LCE5+XsilE5P5/GIyqr9gsiudTmk+H/hiYZl9Smar9k0=
Actual result:
--------------
The output is different for each execution, for instance this is one:
Private key:
fSv1nExIL8OaVzXIpKCw7YA3w9t5onYM9LR9glI2XEXttltLdfi2/l87iMsOeW+7aeNvGg97DtVC6xbiXmz7UrEyn1sLynauxTGF35xRCL2yCiYdbqcwDpzc2Xj31ggRjhZYTdf8BnM2kIUzTwt733+P0bDB0OhkAz07DvKahz4=
Public key:
S2/Lci8eLGt/ayV3faOJGb6daczG0z55VCoy9eHFhDqy6KHcPiPSnaF/GLyG5bhnlNgLeI9eU/yEIR6A8m+6Crd51A08itmmU2A6dhMtjbT8LYSHCQ1RlBcoasfEahhEltNZFErxl8whVPRXBrwDyZKwCmHu+AJYpoSTQFA6y4I=
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=73478&edit=1