php.net |  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
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
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.
Password:
Status:
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-12-14 22:45 UTC] bukka@php.net
-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.
https://www.myfeedbackcard.com/
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 10:01:28 2024 UTC