|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75643 openssl_public_encrypt generates openssl errors
Submitted: 2017-12-06 22:31 UTC Modified: 2018-06-24 04:25 UTC
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:2 (100.0%)
From: ross dot mitchell at gmail dot com Assigned: bukka (profile)
Status: No Feedback Package: OpenSSL related
PHP Version: 7.1.12 OS: Linux Arch
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: ross dot mitchell at gmail dot com
New email:
PHP Version: OS:


 [2017-12-06 22:31 UTC] ross dot mitchell at gmail dot com
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:

$key = "-----BEGIN PUBLIC KEY-----
-----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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-05-22 13:50 UTC]
-Status: Open +Status: Feedback -Assigned To: +Assigned To: bukka
 [2018-05-22 13:50 UTC]
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...
 [2018-06-24 04:25 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jul 21 03:01:29 2024 UTC