Skip to content

Commit 43f0141

Browse files
committed
Make OpenSSL tests less dependent on system config
It fixes dependencies on system config if running tests with OpenSSL 3.0
1 parent d4ea11d commit 43f0141

File tree

5 files changed

+17
-9
lines changed

5 files changed

+17
-9
lines changed

ext/openssl/tests/bug52093.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ $dn = array(
1515
"commonName" => "Henrique do N. Angelo",
1616
"emailAddress" => "hnangelo@php.net"
1717
);
18-
18+
$options = ['config' => __DIR__ . DIRECTORY_SEPARATOR . 'openssl.cnf'];
1919
$privkey = openssl_pkey_new();
20-
$csr = openssl_csr_new($dn, $privkey);
21-
$cert = openssl_csr_sign($csr, null, $privkey, 365, [], PHP_INT_MAX);
20+
$csr = openssl_csr_new($dn, $privkey, $options);
21+
$cert = openssl_csr_sign($csr, null, $privkey, 365, $options, PHP_INT_MAX);
2222
var_dump(openssl_x509_parse($cert)['serialNumber']);
2323
?>
2424
--EXPECT--

ext/openssl/tests/bug72165.phpt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ Bug #72165 Null pointer dereference - openssl_csr_new
44
openssl
55
--FILE--
66
<?php
7-
$var0 = array(0 => "hello", 1 => "world");
8-
$var2 = openssl_csr_new(array(0),$var0,null,array(0));
7+
$var0 = [0 => "hello", 1 => "world"];
8+
$options = ['config' => __DIR__ . DIRECTORY_SEPARATOR . 'openssl.cnf'];
9+
$var2 = openssl_csr_new([0], $var0, $options, [0]);
910
?>
1011
--EXPECTF--
1112
Warning: openssl_csr_new(): dn: numeric fild names are not supported in %sbug72165.php on line %d

ext/openssl/tests/bug73711.phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ Bug #73711: Segfault in openssl_pkey_new when generating DSA or DH key
44
openssl
55
--FILE--
66
<?php
7+
$config = __DIR__ . DIRECTORY_SEPARATOR . 'openssl.cnf';
78
var_dump(openssl_pkey_new([
89
"private_key_type" => OPENSSL_KEYTYPE_DSA,
910
"private_key_bits" => 1024,
11+
'config' => $config,
1012
]));
1113
var_dump(openssl_pkey_new([
1214
"private_key_type" => OPENSSL_KEYTYPE_DH,
1315
"private_key_bits" => 512,
16+
'config' => $config,
1417
]));
1518
echo "DONE";
1619
?>

ext/openssl/tests/ecc.phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ openssl
66
<?php if (!defined("OPENSSL_KEYTYPE_EC")) print "skip"; ?>
77
--FILE--
88
<?php
9+
$config = __DIR__ . DIRECTORY_SEPARATOR . 'openssl.cnf';
910
$args = array(
1011
"curve_name" => "secp384r1",
1112
"private_key_type" => OPENSSL_KEYTYPE_EC,
13+
"config" => $config,
1214
);
1315
echo "Testing openssl_pkey_new\n";
1416
$key1 = openssl_pkey_new($args);
@@ -17,6 +19,7 @@ var_dump($key1);
1719
$argsFailed = array(
1820
"curve_name" => "invalid_cuve_name",
1921
"private_key_type" => OPENSSL_KEYTYPE_EC,
22+
"config" => $config,
2023
);
2124

2225
$keyFailed = openssl_pkey_new($argsFailed);

ext/openssl/tests/openssl_error_string_basic_openssl3.phpt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,19 @@ echo "\n";
100100
$err_pem_no_start_line = '0480006C';
101101

102102
// PKEY
103+
$options = ['config' => __DIR__ . DIRECTORY_SEPARATOR . 'openssl.cnf'];
103104
echo "PKEY errors\n";
104105
// file for pkey (file:///) fails when opennig (BIO_new_file)
105-
@openssl_pkey_export_to_file("file://" . $invalid_file_for_read, $output_file);
106+
@openssl_pkey_export_to_file("file://" . $invalid_file_for_read, $output_file, null, $options);
106107
expect_openssl_errors('openssl_pkey_export_to_file opening', ['10000080']);
107108
// file or private pkey is not correct PEM - failing PEM_read_bio_PrivateKey
108-
@openssl_pkey_export_to_file($csr_file, $output_file);
109+
@openssl_pkey_export_to_file($csr_file, $output_file, null, $options);
109110
expect_openssl_errors('openssl_pkey_export_to_file pem', ['1E08010C']);
110111
// file to export cannot be written
111-
@openssl_pkey_export_to_file($private_key_file, $invalid_file_for_write);
112+
@openssl_pkey_export_to_file($private_key_file, $invalid_file_for_write, null, $options);
112113
expect_openssl_errors('openssl_pkey_export_to_file write', ['10080002']);
113114
// successful export
114-
@openssl_pkey_export($private_key_file_with_pass, $out, 'wrong pwd');
115+
@openssl_pkey_export($private_key_file_with_pass, $out, 'wrong pwd', $options);
115116
expect_openssl_errors('openssl_pkey_export', ['1C800064', '04800065']);
116117
// invalid x509 for getting public key
117118
@openssl_pkey_get_public($private_key_file);

0 commit comments

Comments
 (0)