|  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
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
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Jul 25 15:01:23 2021 UTC