From 43f0141d74c1db6e792f3b625ea7f4ae57ff338f Mon Sep 17 00:00:00 2001 From: Jakub Zelenka Date: Sun, 12 Sep 2021 20:30:02 +0100 Subject: [PATCH] Make OpenSSL tests less dependent on system config It fixes dependencies on system config if running tests with OpenSSL 3.0 --- ext/openssl/tests/bug52093.phpt | 6 +++--- ext/openssl/tests/bug72165.phpt | 5 +++-- ext/openssl/tests/bug73711.phpt | 3 +++ ext/openssl/tests/ecc.phpt | 3 +++ .../tests/openssl_error_string_basic_openssl3.phpt | 9 +++++---- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/ext/openssl/tests/bug52093.phpt b/ext/openssl/tests/bug52093.phpt index 959aac0cdde..093baced4b6 100644 --- a/ext/openssl/tests/bug52093.phpt +++ b/ext/openssl/tests/bug52093.phpt @@ -15,10 +15,10 @@ $dn = array( "commonName" => "Henrique do N. Angelo", "emailAddress" => "hnangelo@php.net" ); - +$options = ['config' => __DIR__ . DIRECTORY_SEPARATOR . 'openssl.cnf']; $privkey = openssl_pkey_new(); -$csr = openssl_csr_new($dn, $privkey); -$cert = openssl_csr_sign($csr, null, $privkey, 365, [], PHP_INT_MAX); +$csr = openssl_csr_new($dn, $privkey, $options); +$cert = openssl_csr_sign($csr, null, $privkey, 365, $options, PHP_INT_MAX); var_dump(openssl_x509_parse($cert)['serialNumber']); ?> --EXPECT-- diff --git a/ext/openssl/tests/bug72165.phpt b/ext/openssl/tests/bug72165.phpt index c0bc8a23c4f..3bb818ceefa 100644 --- a/ext/openssl/tests/bug72165.phpt +++ b/ext/openssl/tests/bug72165.phpt @@ -4,8 +4,9 @@ Bug #72165 Null pointer dereference - openssl_csr_new openssl --FILE-- "hello", 1 => "world"); -$var2 = openssl_csr_new(array(0),$var0,null,array(0)); +$var0 = [0 => "hello", 1 => "world"]; +$options = ['config' => __DIR__ . DIRECTORY_SEPARATOR . 'openssl.cnf']; +$var2 = openssl_csr_new([0], $var0, $options, [0]); ?> --EXPECTF-- Warning: openssl_csr_new(): dn: numeric fild names are not supported in %sbug72165.php on line %d diff --git a/ext/openssl/tests/bug73711.phpt b/ext/openssl/tests/bug73711.phpt index 419e65a5bdd..b8fc1e3c599 100644 --- a/ext/openssl/tests/bug73711.phpt +++ b/ext/openssl/tests/bug73711.phpt @@ -4,13 +4,16 @@ Bug #73711: Segfault in openssl_pkey_new when generating DSA or DH key openssl --FILE-- OPENSSL_KEYTYPE_DSA, "private_key_bits" => 1024, + 'config' => $config, ])); var_dump(openssl_pkey_new([ "private_key_type" => OPENSSL_KEYTYPE_DH, "private_key_bits" => 512, + 'config' => $config, ])); echo "DONE"; ?> diff --git a/ext/openssl/tests/ecc.phpt b/ext/openssl/tests/ecc.phpt index 29be3a76423..a18651dc5e4 100644 --- a/ext/openssl/tests/ecc.phpt +++ b/ext/openssl/tests/ecc.phpt @@ -6,9 +6,11 @@ openssl --FILE-- "secp384r1", "private_key_type" => OPENSSL_KEYTYPE_EC, + "config" => $config, ); echo "Testing openssl_pkey_new\n"; $key1 = openssl_pkey_new($args); @@ -17,6 +19,7 @@ var_dump($key1); $argsFailed = array( "curve_name" => "invalid_cuve_name", "private_key_type" => OPENSSL_KEYTYPE_EC, + "config" => $config, ); $keyFailed = openssl_pkey_new($argsFailed); diff --git a/ext/openssl/tests/openssl_error_string_basic_openssl3.phpt b/ext/openssl/tests/openssl_error_string_basic_openssl3.phpt index b119346fe1f..d435a53e304 100644 --- a/ext/openssl/tests/openssl_error_string_basic_openssl3.phpt +++ b/ext/openssl/tests/openssl_error_string_basic_openssl3.phpt @@ -100,18 +100,19 @@ echo "\n"; $err_pem_no_start_line = '0480006C'; // PKEY +$options = ['config' => __DIR__ . DIRECTORY_SEPARATOR . 'openssl.cnf']; echo "PKEY errors\n"; // file for pkey (file:///) fails when opennig (BIO_new_file) -@openssl_pkey_export_to_file("file://" . $invalid_file_for_read, $output_file); +@openssl_pkey_export_to_file("file://" . $invalid_file_for_read, $output_file, null, $options); expect_openssl_errors('openssl_pkey_export_to_file opening', ['10000080']); // file or private pkey is not correct PEM - failing PEM_read_bio_PrivateKey -@openssl_pkey_export_to_file($csr_file, $output_file); +@openssl_pkey_export_to_file($csr_file, $output_file, null, $options); expect_openssl_errors('openssl_pkey_export_to_file pem', ['1E08010C']); // file to export cannot be written -@openssl_pkey_export_to_file($private_key_file, $invalid_file_for_write); +@openssl_pkey_export_to_file($private_key_file, $invalid_file_for_write, null, $options); expect_openssl_errors('openssl_pkey_export_to_file write', ['10080002']); // successful export -@openssl_pkey_export($private_key_file_with_pass, $out, 'wrong pwd'); +@openssl_pkey_export($private_key_file_with_pass, $out, 'wrong pwd', $options); expect_openssl_errors('openssl_pkey_export', ['1C800064', '04800065']); // invalid x509 for getting public key @openssl_pkey_get_public($private_key_file);