php.net |  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
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (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
Have you experienced this issue?
Rate the importance of this bug to you:

 [2017-12-06 22:31 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-05-22 13:50 UTC] bukka@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: bukka
 [2018-05-22 13:50 UTC] bukka@php.net
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-2021 The PHP Group
All rights reserved.
Last updated: Sun Mar 07 02:01:25 2021 UTC