Skip to content

Stdlib: openssl_x509_export()/openssl_x509_export_to_file() missing (ext/openssl/openssl.c) #20273

Closed

Description

@PurHur

Category

stdlib · php-src-strict · ext/openssl X.509 PEM export (extends #6274)

Problem

Certificates can be created via openssl_csr_sign(), and fingerprint/verify exist, but Zend’s openssl_x509_export() / openssl_x509_export_to_file() are not registered — apps cannot round-trip a certificate object back to PEM/file.

Repro Zend 8.2+ VM (2026-07-17)
function_exists('openssl_x509_export') 1 0
function_exists('openssl_x509_export_to_file') 1 0
$out=''; openssl_x509_export($cert, $out); strlen($out)>0 true / PEM fatal undefined function

Minimal setup that works on Zend: openssl_pkey_new → openssl_csr_new → openssl_csr_sign → openssl_x509_export.

php-src reference

PHP implementation target

  • ext/openssl/openssl_x509_export.php + openssl_x509_export_to_file.php Internals
  • Reuse PEM helpers in ext/openssl/VmOpensslX509Native.php / VmOpenssl.php (PHP-in-PHP; thin OpenSSL ABI only if already present for fingerprint)
  • Register in ext/openssl/Module.php
  • Prefer PHP lowering; no new hand-written C logic beyond existing native helpers

Repro

./script/docker-exec.sh -- bash -lc 'php bin/vm.php -r "var_export(function_exists(\"openssl_x509_export\")); echo PHP_EOL; var_export(function_exists(\"openssl_x509_export_to_file\")); echo PHP_EOL;"'

Expected: both true. Today: both false.

Done when (php-src-strict)

  • Both functions registered; export fills by-ref PEM matching Zend structure (BEGIN CERTIFICATE)
  • export_to_file writes readable PEM; false + warning on I/O failure like Zend
  • TypeError texts match openssl.stub.php argument names
  • Compliance .phpt under test/compliance/cases/; VM required, JIT/AOT as available
  • php-src-strict; no php-compiler-strict shortcut

Related

Activity

  1. added
    enhancementNew feature or request
    phase-4:stdlibPhase 4 – stdlib for web apps
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jul 17, 2026
  2. PurHur commented on Jul 17, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler Ext — I/O & Crypto — starting this run

    Implementing openssl_x509_export() / openssl_x509_export_to_file() (PHP-in-PHP; reuse VmOpenssl X.509 helpers).

  3. PurHur commented on Jul 17, 2026

    @PurHur
    OwnerAuthor

    Sibling gaps filed: #20285 (check_private_key), #20286 (checkpurpose), #20287 (pkey_export_to_file). Export (#20273) unblocks richer check_private_key compliance fixtures.

  4. PurHur commented on Jul 17, 2026

    @PurHur
    OwnerAuthor

    Merged via #20296

    Verification (Docker):

    • function_exists(openssl_x509_export|export_to_file) → true
    • php bin/vm.php test/repro/openssl_x509_export_20273.php → ok
    • phpunit --filter openssl_x509_export → OK (2)
    • inventory/spine → 5525/5525

    php-src-strict PEM (+ optional text) via VmOpensslX509Native::exportCertificatePem; no new C.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web appsstdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions