xref: /PHP-8.1/ext/openssl/tests/bug50293.phpt (revision 2f78c1f9)
1--TEST--
2Bug #50293 (Several openssl functions ignore the VCWD)
3--SKIPIF--
4<?php
5if (!extension_loaded("openssl")) die("skip openssl not loaded");
6?>
7--FILE--
8<?php
9$cert = "file://" . __DIR__ . "/cert.crt";
10$priv = "file://" . __DIR__ . "/private_rsa_1024.key";
11$config = __DIR__ . DIRECTORY_SEPARATOR . 'openssl.cnf';
12
13$dn = [
14    "countryName" => "GB",
15    "stateOrProvinceName" => "Berkshire",
16    "localityName" => "Newbury",
17    "organizationName" => "My Company Ltd",
18    "commonName" => "Demo Cert",
19];
20
21$args = array(
22    "digest_alg" => "sha256",
23    "private_key_bits" => 2048,
24    "private_key_type" => OPENSSL_KEYTYPE_RSA,
25    "encrypt_key" => true,
26    "config" => $config
27);
28
29mkdir(__DIR__ . "/bug50293");
30chdir(__DIR__ . "/bug50293");
31
32$privkey = openssl_pkey_get_private('file://' . __DIR__ . '/private_ec.key');
33$csr = openssl_csr_new($dn, $privkey, $args);
34$sscert = openssl_csr_sign($csr, null, $privkey, 365, $args);
35openssl_csr_export($csr, $csrout);;
36openssl_x509_export($sscert, $certout);
37openssl_x509_export_to_file($sscert , "bug50293.crt", false);
38openssl_pkey_export_to_file($privkey, "bug50293.pem", null, $args);
39
40var_dump(
41    file_exists("bug50293.crt"),
42    file_exists("bug50293.pem")
43);
44?>
45--CLEAN--
46<?php
47@unlink(__DIR__ . "/bug50293/bug50293.crt");
48@unlink(__DIR__ . "/bug50293/bug50293.pem");
49@rmdir(__DIR__ . "/bug50293");
50?>
51--EXPECT--
52bool(true)
53bool(true)
54