|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #77761 openssl_text_parse does not create entries for public key type and size
Submitted: 2019-03-18 11:10 UTC Modified: -
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: stefan dot winter at restena dot lu Assigned:
Status: Open Package: OpenSSL related
PHP Version: 7.3.3 OS: Linux
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: stefan dot winter at restena dot lu
New email:
PHP Version: OS:


 [2019-03-18 11:10 UTC] stefan dot winter at restena dot lu
Now that PHP supports ECDSA keys, its parsing function for certificates should also report on the public key type (RSA/ECDSA) and bit length/curve.

The test script below first prints the output of openssl_x509_parse, which does not contain this information, and then extracts the info out of the text output of openssl_x509_export() instead.

From manual page:

Test script:
const CERT = "-----BEGIN CERTIFICATE-----
const ALGORITHMS = [0 => "rsaEncryption", 1 => "id-ecPublicKey"];

// prints lots of certificate properties, but not key type nor length


// needs to be parsed out of textual representation instead

$myca = openssl_x509_read(CERT);
$output = "";
$algoMatch = [];
$keyLengthMatch = [];

openssl_x509_export($myca, $output, FALSE);

if (preg_match('/^\s+Public Key Algorithm:\s*(.*)\s*$/m', $output, $algoMatch) && in_array($algoMatch[1], ALGORITHMS)) {
            echo "public_key_algorithm = $algoMatch[1]\n";
if ((preg_match('/^\s+Public-Key:\s*\((.*) bit\)\s*$/m', $output, $keyLengthMatch)) && is_numeric($keyLengthMatch[1])) {
            echo "public_key_length = $keyLengthMatch[1]\n";

Expected result:
The output array of openssl_x509_parse should contain two new keys for the properties of public key type and size.

Actual result:
The output array of openssl_x509_parse does not contain any keys related to the public key type and size.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-01-09 09:20 UTC] berestnevao27 at gmail dot com
This article is really amazing. Thanks for the sharing.
 [2021-05-19 18:21 UTC] ghdsportsfun at gmail dot com
Thank you very much for the great informative article about the bug
 [2021-08-27 19:59 UTC] crediblebhblog at gmail dot com
EHR or Electronic Health Records is the crucial aspect for health professionals and clinicians. Managing client’s data, appointments, schedules, and clinical assessments in an electronic form is quite possible only with the help of a contemporary cloud-based portal system.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Oct 18 11:04:16 2021 UTC