|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #77761 openssl_x509_parse does not create entries for public key type and size
Submitted: 2019-03-18 11:10 UTC Modified: 2021-12-14 22:45 UTC
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-12-14 22:45 UTC]
-Summary: openssl_text_parse does not create entries for public key type and size +Summary: openssl_x509_parse does not create entries for public key type and size
 [2022-01-15 12:18 UTC] nancychandler340 at gmail dot com
Nice post, Thank you so much for sharing this information.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Mar 04 06:01:30 2024 UTC