Skip to content

Unable to read the cert store when Using openssl_pkcs12_read with OpenSSL 3.x #12128

@JohnyRooke

Description

@JohnyRooke

Description

The following code:

<?php
    if (!$cert_store = file_get_contents("/certs/file.p12")) {
        echo "Error: Unable to read the cert file.";
        exit;
    }

    if (openssl_pkcs12_read($cert_store, $cert_info, "my_secret_pass")) {
        echo "Certificate Information:";
        print_r($cert_info);
    } else {
        echo "Error: Unable to read the cert store.";
        exit;
    }
?>

Resulted in this output:

Error: Unable to read the cert store.

But I expected this output instead:

Certificate Information:
Array
(
    [cert] => -----BEGIN CERTIFICATE-----
ICAL0wDQYJKoZIhvcNAQELBQAwgYkxCzAJBgNVBAYTAk
-----END CERTIFICATE-----,
    [pkey] => -----BEGIN PRIVATE KEY-----
LyaH3FnQfJkGmc0CgGAV72ecpf06CRrUYVl5sBUcKcT67O
 -----END PRIVATE KEY-----
)
// The values are only examples.

The error does not occur in earlier versions, such as PHP 8.2.6 and 8.2.7, which utilize OpenSSL version 1.x. Starting from PHP version 8.2.8 onwards, OpenSSL 3.x is employed, and the error occurs as previously mentioned.

PHP Version

PHP 8.2.8

Operating System

Ubuntu 20.04

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions