php.net |  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: -
Votes:1
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
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
Description:
------------
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: https://php.net/function.openssl-x509-parse
---


Test script:
---------------
<?php
const CERT = "-----BEGIN CERTIFICATE-----
MIIDtzCCAp+gAwIBAgIQDOfg5RfYRv6P5WD8G/AwOTANBgkqhkiG9w0BAQUFADBlMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNlcnQuY29tMSQwIgYDVQQDExtEaWdpQ2VydCBBc3N1cmVkIElEIFJvb3QgQ0EwHhcNMDYxMTEwMDAwMDAwWhcNMzExMTEwMDAwMDAwWjBlMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNlcnQuY29tMSQwIgYDVQQDExtEaWdpQ2VydCBBc3N1cmVkIElEIFJvb3QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCtDhXO5EOAXLGH87dg+XESpa7cJpSIqvTO9SA5KFhgDPiA2qkVlTJhPLWxKISKityfCgyDF3qPkKyK53lTXDGEKvYPmDI2dsze3Tyoou9q+yHyUmHfnyDXH+Kx2f4YZNISW1/5WBg1vEfNoTb5a3/UsDg+wRvDjDPZ2C8Y/igPs6eD1sNuRMBhNZYW/lmci3Zt1/GiSw0r/wty2p5g0I6QNcZ4VYcgoc/lbQrISXwxmDNsIumH0DJaoroTghHtORedmTpyoeb6pNnVFzF1roV9Iq4/AUaG9ih5yLHa5FcXxH4cDrC0kqZWs72yl+2qp/C3xag/lRbQ/6GW6whfGHdPAgMBAAGjYzBhMA4GA1UdDwEB/wQEAwIBhjAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBRF66Kv9JLLgjEtUYunpyGd823IDzAfBgNVHSMEGDAWgBRF66Kv9JLLgjEtUYunpyGd823IDzANBgkqhkiG9w0BAQUFAAOCAQEAog683+Lt8ONyc3pklL/3cmbYMuRCdWKuh+vy1dneVrOfzM4UKLkNl2BcEkxY5NM9g0lFWJc1aRqoR+pWxnmrEthngYTffwk8lOa4JiwgvT2zKIn3X/8i4peEH+ll74fg38FnSbNd67IJKusm7Xi+fT8r87cmNW1fiQG2SVufAQWbqz0lwcy2f8Lxb4bG+mRo64EtlOtCt/qMHt1i8b5QZ7dsvfPxH2sMNgcWfzd8qVttevESRmCD1ycEvkvOl77DZypoEd+A5wwzZr8TDRRu838fYxAe+o0bJW1sj6W3YQGx0qMmoRBxna3iw/nDmVG3KwcIzi7mULKn+gpFL6Lw8g==
-----END CERTIFICATE-----";
const ALGORITHMS = [0 => "rsaEncryption", 1 => "id-ecPublicKey"];

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

print_r(openssl_x509_parse(CERT));

// 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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-01-09 09:20 UTC] berestnevao27 at gmail dot com
This article is really amazing. Thanks for the sharing.    

https://www.indigocard.one/
 [2021-05-19 18:21 UTC] ghdsportsfun at gmail dot com
Thank you very much for the great informative article about the bug
https://paynjmcdirect.com/
 [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. https://crediblebh.live/
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Oct 18 11:04:16 2021 UTC