Bug #75643 [Opn->Fbk]: openssl_public_encrypt generates openssl errors

From: Date: Tue, 22 May 2018 13:50:56 +0000
Subject: Bug #75643 [Opn->Fbk]: openssl_public_encrypt generates openssl errors
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-215331@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75643&edit=1 ID: 75643 Updated by: bukka@php.net Reported by: ross dot mitchell at gmail dot com Summary: openssl_public_encrypt generates openssl errors -Status: Open +Status: Feedback Type: Bug Package: OpenSSL related Operating System: Linux Arch PHP Version: 7.1.12 -Assigned To: +Assigned To: bukka Block user comment: N Private report: N New Comment: The error in the queue is expected. If you supply string as a PEM (string not prefixed by "file://" which would be a file path), then certificate is tried first (using PEM_ASN1_read_bio). It means that it fails and the error is saved to the queue. However this queue is just a copy of the OpenSSL which is emptied. After that the key is loaded using PEM_read_bio_PUBKEY which is successful in your case so you get back the result. To sum it up openssl_error_string does not mean that the operation failed but just that some error was emitted. Also it is moved to the internal queue in the extension and the OpenSSL errors are cleared so I don't think this particular code is causing drop of the connection. Are you able to provide a script including the connection part where the issue is visible and the connection fails due to an error in the queue? Just to be clear, I debugged your test script to be sure and the OpenSSL queue is emptied correctly so I'm quite sure that this is not the issue... Previous Comments: ------------------------------------------------------------------------ [2017-12-06 22:31:20] ross dot mitchell at gmail dot com Description: ------------ Calling openssl_public_encrypt causes an "error:0906D06C:PEM routines:PEM_read_bio:no start line" to be returned from openssl_error_string, even though the function passes and returns an encrypted string This has become apparent when using PDO with SSL, as the openssl_error_string drops the connection. I think some work was done on the in Bug #69524, however the issue still appears to be in place, at least for the openssl_public_encrypt function Test script: --------------- <?php $key = "-----BEGIN PUBLIC KEY----- MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDLXp6PkCtbpV+P1gwFQWH6Ez0U 83uEmS8IGnpeI8Fk8rY/vHOZzZZaxRCw+loyc342qCDIQheMOCNm5Fkevz06q757 /oooiLR3yryYGKiKG1IZIiplmtsC95oKrzUSKk60wuI1mbgpMUP5LKi/Tvxes5Pm kUtXfimz2qgkeUcPpQIDAQAB -----END PUBLIC KEY-----"; $message = '123'; $passed = openssl_public_encrypt($message, $response, $key); echo (($passed) ? "Function Passed" : "Function Failed") . PHP_EOL; echo ((is_null($response)) ? "No Result Returned" : "Result Returned Successfully") . PHP_EOL; if ($error = openssl_error_string()) { echo "Error Returned: "; echo $error; } Expected result: ---------------- The script should either display Function Passed Result Returned or it should display Function Failed No Result Returned Error Returned: ${an openssl error string} Actual result: -------------- Function Passed Result Returned Successfully Error Returned: error:0906D06C:PEM routines:PEM_read_bio:no start line ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75643&edit=1

« previous php.bugs (#215331) next »