diff options
Diffstat (limited to 'ext/openssl/tests')
49 files changed, 584 insertions, 503 deletions
diff --git a/ext/openssl/tests/002.phpt b/ext/openssl/tests/002.phpt deleted file mode 100644 index dd4f04a25c..0000000000 --- a/ext/openssl/tests/002.phpt +++ /dev/null @@ -1,32 +0,0 @@ ---TEST-- -openssl_seal() tests ---SKIPIF-- -<?php if (!extension_loaded("openssl")) print "skip"; ?> ---FILE-- -<?php - -$a = 1; -$b = array(1); -$c = array(1); -$d = array(1); - -var_dump(openssl_seal($a, $b, $c, $d)); -var_dump(openssl_seal($a, $a, $a, array())); -var_dump(openssl_seal($c, $c, $c, 1)); -var_dump(openssl_seal($b, $b, $b, "")); - -echo "Done\n"; -?> ---EXPECTF-- -Warning: openssl_seal(): not a public key (1th member of pubkeys) in %s on line %d -bool(false) - -Warning: openssl_seal(): Fourth argument to openssl_seal() must be a non-empty array in %s on line %d -bool(false) - -Warning: openssl_seal() expects parameter 1 to be string, array given in %s on line %d -NULL - -Warning: openssl_seal() expects parameter 1 to be string, array given in %s on line %d -NULL -Done diff --git a/ext/openssl/tests/007.phpt b/ext/openssl/tests/007.phpt deleted file mode 100644 index 0a74bd3411..0000000000 --- a/ext/openssl/tests/007.phpt +++ /dev/null @@ -1,60 +0,0 @@ ---TEST-- -openssl_x509_read() and openssl_x509_free() tests ---SKIPIF-- -<?php if (!extension_loaded("openssl")) print "skip"; ?> ---FILE-- -<?php -$fp = fopen(dirname(__FILE__) . "/cert.crt","r"); -$a = fread($fp,8192); -fclose($fp); - -$b = "file://" . dirname(__FILE__) . "/cert.crt"; -$c = "invalid cert"; -$d = openssl_x509_read($a); -$e = array(); -$f = array($b); - -var_dump($res = openssl_x509_read($a)); // read cert as a string -openssl_x509_free($res); -var_dump($res); -var_dump($res = openssl_x509_read($b)); // read cert as a filename string -openssl_x509_free($res); -var_dump($res); -var_dump($res = openssl_x509_read($c)); // read an invalid cert, fails -openssl_x509_free($res); -var_dump($res); -var_dump($res = openssl_x509_read($d)); // read cert from a resource -openssl_x509_free($res); -var_dump($res); -var_dump($res = openssl_x509_read($e)); // read an array -openssl_x509_free($res); -var_dump($res); -var_dump($res = openssl_x509_read($f)); // read an array with the filename -openssl_x509_free($res); -var_dump($res); -?> ---EXPECTF-- -resource(%d) of type (OpenSSL X.509) -resource(%d) of type (Unknown) -resource(%d) of type (OpenSSL X.509) -resource(%d) of type (Unknown) - -Warning: openssl_x509_read(): supplied parameter cannot be coerced into an X509 certificate! in %s on line %d -bool(false) - -Warning: openssl_x509_free() expects parameter 1 to be resource, boolean given in %s on line %d -bool(false) -resource(%d) of type (OpenSSL X.509) -resource(%d) of type (Unknown) - -Warning: openssl_x509_read(): supplied parameter cannot be coerced into an X509 certificate! in %s on line %d -bool(false) - -Warning: openssl_x509_free() expects parameter 1 to be resource, boolean given in %s on line %d -bool(false) - -Warning: openssl_x509_read(): supplied parameter cannot be coerced into an X509 certificate! in %s on line %d -bool(false) - -Warning: openssl_x509_free() expects parameter 1 to be resource, boolean given in %s on line %d -bool(false) diff --git a/ext/openssl/tests/008.phpt b/ext/openssl/tests/008.phpt deleted file mode 100644 index 171ca27fba..0000000000 --- a/ext/openssl/tests/008.phpt +++ /dev/null @@ -1,79 +0,0 @@ ---TEST-- -openssl_x509_export() and openssl_x509_export_to_file() tests ---SKIPIF-- -<?php if (!extension_loaded("openssl")) print "skip"; ?> ---FILE-- -<?php -$fp = fopen(dirname(__FILE__) . "/cert.crt","r"); -$a = fread($fp,8192); -fclose($fp); - -$b = "file://" . dirname(__FILE__) . "/cert.crt"; -$c = "invalid cert"; -$d = openssl_x509_read($a); -$e = array(); - -var_dump(openssl_x509_export($a, $output)); // read cert as a binary string -var_dump(openssl_x509_export($b, $output2)); // read cert from a filename string -var_dump(openssl_x509_export($c, $output3)); // read an invalid cert, fails -var_dump(openssl_x509_export($d, $output4)); // read cert from a resource -var_dump(openssl_x509_export($e, $output5)); // read an array, fails - -$outfilename = tempnam("/tmp", "ssl"); -if ($outfilename === false) - die("failed to get a temporary filename!"); - -echo "---\n"; - -var_dump(openssl_x509_export_to_file($a, $outfilename)); // read cert as a binary string -var_dump(openssl_x509_export_to_file($b, $outfilename)); // read cert from a filename string -var_dump(openssl_x509_export_to_file($c, $outfilename)); // read an invalid cert, fails -var_dump(openssl_x509_export_to_file($d, $outfilename)); // read cert from a resource -var_dump(openssl_x509_export_to_file($e, $outfilename)); // read an array, fails -echo "---\n"; - -var_dump($exists = file_exists($outfilename)); -if ($exists) { - @unlink($outfilename); -} -echo "---\n"; - -if (PHP_EOL !== "\n") { - $a = str_replace(PHP_EOL, "\n", $a); -} - -var_dump(strcmp($output, $a)); -var_dump(strcmp($output, $output2)); -var_dump(strcmp($output, $output3)); -var_dump(strcmp($output, $output4)); // different -var_dump(strcmp($output, $output5)); // different - -?> ---EXPECTF-- -bool(true) -bool(true) - -Warning: openssl_x509_export(): cannot get cert from parameter 1 in %s on line %d -bool(false) -bool(true) - -Warning: openssl_x509_export(): cannot get cert from parameter 1 in %s on line %d -bool(false) ---- -bool(true) -bool(true) - -Warning: openssl_x509_export_to_file(): cannot get cert from parameter 1 in %s on line %d -bool(false) -bool(true) - -Warning: openssl_x509_export_to_file(): cannot get cert from parameter 1 in %s on line %d -bool(false) ---- -bool(true) ---- -int(0) -int(0) -int(%d) -int(0) -int(%d) diff --git a/ext/openssl/tests/012.phpt b/ext/openssl/tests/012.phpt deleted file mode 100644 index dbd03ac0af..0000000000 --- a/ext/openssl/tests/012.phpt +++ /dev/null @@ -1,27 +0,0 @@ ---TEST-- -openssl_seal() error tests ---SKIPIF-- -<?php if (!extension_loaded("openssl")) print "skip"; ?> ---FILE-- -<?php -$data = "openssl_open() test"; -$pub_key = "file://" . dirname(__FILE__) . "/public.key"; -$wrong = "wrong"; - -openssl_seal($data, $sealed, $ekeys, array($pub_key)); // no output -openssl_seal($data, $sealed, $ekeys, array($pub_key, $pub_key)); // no output -openssl_seal($data, $sealed, $ekeys, array($pub_key, $wrong)); -openssl_seal($data, $sealed, $ekeys, $pub_key); -openssl_seal($data, $sealed, $ekeys, array()); -openssl_seal($data, $sealed, $ekeys, array($wrong)); -?> ---EXPECTF-- - -Warning: openssl_seal(): not a public key (2th member of pubkeys) in %s on line %d - -Warning: openssl_seal() expects parameter 4 to be array, string given in %s on line %d - -Warning: openssl_seal(): Fourth argument to openssl_seal() must be a non-empty array in %s on line %d - -Warning: openssl_seal(): not a public key (1th member of pubkeys) in %s on line %d - diff --git a/ext/openssl/tests/026.phpt b/ext/openssl/tests/026.phpt deleted file mode 100644 index 38d626d742..0000000000 --- a/ext/openssl/tests/026.phpt +++ /dev/null @@ -1,12 +0,0 @@ ---TEST-- -Options type checks ---SKIPIF-- -<?php if (!extension_loaded("openssl")) print "skip"; ?> ---FILE-- -<?php -$x = openssl_pkey_new(); -$csr = openssl_csr_new(["countryName" => "DE"], $x, ["x509_extensions" => 0xDEADBEEF]); -?> -DONE ---EXPECT-- -DONE diff --git a/ext/openssl/tests/bug70438.phpt b/ext/openssl/tests/bug70438.phpt index de87a51a7a..937e9f3bd9 100644 --- a/ext/openssl/tests/bug70438.phpt +++ b/ext/openssl/tests/bug70438.phpt @@ -14,7 +14,7 @@ if (!in_array('AES-128-CBC', openssl_get_cipher_methods(true))) { $data = "openssl_seal() test"; $cipher = 'AES-128-CBC'; $pub_key = "file://" . dirname(__FILE__) . "/public.key"; -$priv_key = "file://" . dirname(__FILE__) . "/private.key"; +$priv_key = "file://" . dirname(__FILE__) . "/private_rsa_1024.key"; openssl_seal($data, $sealed, $ekeys, array($pub_key, $pub_key), $cipher); openssl_seal($data, $sealed, $ekeys, array($pub_key, $pub_key), 'sparkles', $iv); diff --git a/ext/openssl/tests/bug71475.phpt b/ext/openssl/tests/bug71475.phpt new file mode 100644 index 0000000000..e959371c4c --- /dev/null +++ b/ext/openssl/tests/bug71475.phpt @@ -0,0 +1,16 @@ +--TEST-- +Bug #71475: openssl_seal() uninitialized memory usage +--SKIPIF-- +<?php +if (!extension_loaded("openssl")) die("skip openssl not loaded"); +?> +--FILE-- +<?php +$_ = str_repeat("A", 512); +openssl_seal($_, $_, $_, array_fill(0,64,0)); +?> +DONE +--EXPECTF-- + +Warning: openssl_seal(): not a public key (1th member of pubkeys) in %s%ebug71475.php on line %d +DONE diff --git a/ext/openssl/tests/005_crt.txt b/ext/openssl/tests/cert.csr index 39084bce05..39084bce05 100644 --- a/ext/openssl/tests/005_crt.txt +++ b/ext/openssl/tests/cert.csr diff --git a/ext/openssl/tests/022.phpt b/ext/openssl/tests/openssl_csr_export_bacis.phpt index 1fa84d9f42..d3f8842e71 100644 --- a/ext/openssl/tests/022.phpt +++ b/ext/openssl/tests/openssl_csr_export_bacis.phpt @@ -14,7 +14,7 @@ $dn = array( "localityName" => "Porto Alegre", "commonName" => "Henrique do N. Angelo", "emailAddress" => "hnangelo@php.net" - ); +); $args = array( "digest_alg" => "sha1", @@ -22,7 +22,7 @@ $args = array( "private_key_type" => OPENSSL_KEYTYPE_DSA, "encrypt_key" => true, "config" => $config, - ); +); $privkey = openssl_pkey_new($config_arg); $csr = openssl_csr_new($dn, $privkey, $args); diff --git a/ext/openssl/tests/005.phpt b/ext/openssl/tests/openssl_csr_get_subject_basic.phpt index f7fa201561..895ed3695d 100644 --- a/ext/openssl/tests/005.phpt +++ b/ext/openssl/tests/openssl_csr_get_subject_basic.phpt @@ -8,7 +8,7 @@ if (!function_exists("utf8_decode")) die("skip"); --FILE-- <?php -$csr = file_get_contents(dirname(__FILE__) . '/005_crt.txt'); +$csr = file_get_contents(dirname(__FILE__) . '/cert.csr'); if ($out = openssl_csr_get_subject($csr, 1)) { var_dump($out); } diff --git a/ext/openssl/tests/004.phpt b/ext/openssl/tests/openssl_csr_new_basic.phpt index 508ccabc85..e0f52d739f 100644 --- a/ext/openssl/tests/004.phpt +++ b/ext/openssl/tests/openssl_csr_new_basic.phpt @@ -9,12 +9,18 @@ $a = 1; var_dump(openssl_csr_new(1,$a)); var_dump(openssl_csr_new(1,$a,1,1)); $a = array(); -var_dump(openssl_csr_new(array(), $a, array('config' => __DIR__ . DIRECTORY_SEPARATOR . 'openssl.cnf'), array())); -//this leaks +$conf = array('config' => dirname(__FILE__) . DIRECTORY_SEPARATOR . 'openssl.cnf'); +var_dump(openssl_csr_new(array(), $a, $conf, array())); + +// this leaks $a = array(1,2); $b = array(1,2); -var_dump(openssl_csr_new($a, $b, array('config' => __DIR__ . DIRECTORY_SEPARATOR . 'openssl.cnf'))); +var_dump(openssl_csr_new($a, $b, $conf)); + +// options type check +$x = openssl_pkey_new($conf); +var_dump(openssl_csr_new(["countryName" => "DE"], $x, $conf + ["x509_extensions" => 0xDEADBEEF])); echo "Done\n"; @@ -31,4 +37,5 @@ Warning: openssl_csr_new(): key array must be of the form array(0 => key, 1 => p Warning: openssl_csr_new(): add1_attr_by_txt challengePassword_min -> 4 (failed; check error queue and value of string_mask OpenSSL option if illegal characters are reported) in %s on line %d bool(false) resource(%d) of type (OpenSSL X.509 CSR) +resource(%d) of type (OpenSSL X.509 CSR) Done diff --git a/ext/openssl/tests/021.phpt b/ext/openssl/tests/openssl_csr_sign_basic.phpt index 9fdf8e4e65..34cf50a997 100644 --- a/ext/openssl/tests/021.phpt +++ b/ext/openssl/tests/openssl_csr_sign_basic.phpt @@ -5,7 +5,7 @@ openssl_csr_sign() tests --FILE-- <?php $cert = "file://" . dirname(__FILE__) . "/cert.crt"; -$priv = "file://" . dirname(__FILE__) . "/private.key"; +$priv = "file://" . dirname(__FILE__) . "/private_rsa_1024.key"; $wrong = "wrong"; $pub = "file://" . dirname(__FILE__) . "/public.key"; $config = __DIR__ . DIRECTORY_SEPARATOR . 'openssl.cnf'; diff --git a/ext/openssl/tests/011.phpt b/ext/openssl/tests/openssl_decrypt_basic.phpt index 118e952a51..1c29767cc5 100644 --- a/ext/openssl/tests/011.phpt +++ b/ext/openssl/tests/openssl_decrypt_basic.phpt @@ -1,5 +1,5 @@ --TEST-- -openssl_encrypt() and openssl_decrypt() tests +openssl_decrypt() tests dependent on openssl_encrypt --SKIPIF-- <?php if (!extension_loaded("openssl")) print "skip"; ?> --FILE-- diff --git a/ext/openssl/tests/013.phpt b/ext/openssl/tests/openssl_open_basic.phpt index 91bb73dab3..55bb9eb0e3 100644 --- a/ext/openssl/tests/013.phpt +++ b/ext/openssl/tests/openssl_open_basic.phpt @@ -6,7 +6,7 @@ openssl_open() tests <?php $data = "openssl_open() test"; $pub_key = "file://" . dirname(__FILE__) . "/public.key"; -$priv_key = "file://" . dirname(__FILE__) . "/private.key"; +$priv_key = "file://" . dirname(__FILE__) . "/private_rsa_1024.key"; $wrong = "wrong"; openssl_seal($data, $sealed, $ekeys, array($pub_key, $pub_key, $pub_key)); diff --git a/ext/openssl/tests/openssl_pbkdf2.phpt b/ext/openssl/tests/openssl_pbkdf2_basic.phpt index 3ec4dce236..3ec4dce236 100644 --- a/ext/openssl/tests/openssl_pbkdf2.phpt +++ b/ext/openssl/tests/openssl_pbkdf2_basic.phpt diff --git a/ext/openssl/tests/openssl_peer_fingerprint.phpt b/ext/openssl/tests/openssl_peer_fingerprint_basic.phpt index 743233579a..743233579a 100644 --- a/ext/openssl/tests/openssl_peer_fingerprint.phpt +++ b/ext/openssl/tests/openssl_peer_fingerprint_basic.phpt diff --git a/ext/openssl/tests/024.phpt b/ext/openssl/tests/openssl_pkcs7_decrypt_basic.phpt index 0a61840de3..5589abb039 100644 --- a/ext/openssl/tests/024.phpt +++ b/ext/openssl/tests/openssl_pkcs7_decrypt_basic.phpt @@ -5,7 +5,7 @@ openssl_pkcs7_decrypt() tests --FILE-- <?php $infile = dirname(__FILE__) . "/cert.crt"; -$privkey = "file://" . dirname(__FILE__) . "/private.key"; +$privkey = "file://" . dirname(__FILE__) . "/private_rsa_1024.key"; $encrypted = tempnam("/tmp", "ssl"); if ($encrypted === false) die("failed to get a temporary filename!"); diff --git a/ext/openssl/tests/003.phpt b/ext/openssl/tests/openssl_pkcs7_decrypt_error.phpt index 39363c4548..e8ba264550 100644 --- a/ext/openssl/tests/003.phpt +++ b/ext/openssl/tests/openssl_pkcs7_decrypt_error.phpt @@ -6,7 +6,7 @@ openssl_pkcs7_decrypt() and invalid parameters <?php function myErrorHandler($errno, $errstr, $errfile, $errline) { -var_dump($errstr); + var_dump($errstr); } set_error_handler("myErrorHandler"); diff --git a/ext/openssl/tests/023.phpt b/ext/openssl/tests/openssl_pkcs7_encrypt_basic.phpt index 1489613327..5f74f97b0c 100644 --- a/ext/openssl/tests/023.phpt +++ b/ext/openssl/tests/openssl_pkcs7_encrypt_basic.phpt @@ -13,7 +13,7 @@ if ($outfile2 === false) die("failed to get a temporary filename!"); $single_cert = "file://" . dirname(__FILE__) . "/cert.crt"; -$privkey = "file://" . dirname(__FILE__) . "/private.key"; +$privkey = "file://" . dirname(__FILE__) . "/private_rsa_1024.key"; $multi_certs = array($single_cert, $single_cert); $assoc_headers = array("To" => "test@test", "Subject" => "testing openssl_pkcs7_encrypt()"); $headers = array("test@test", "testing openssl_pkcs7_encrypt()"); diff --git a/ext/openssl/tests/025.phpt b/ext/openssl/tests/openssl_pkcs7_sign_basic.phpt index ac567a517a..ac8edf19a9 100644 --- a/ext/openssl/tests/025.phpt +++ b/ext/openssl/tests/openssl_pkcs7_sign_basic.phpt @@ -6,10 +6,11 @@ openssl_pkcs7_sign() tests <?php $infile = dirname(__FILE__) . "/cert.crt"; $outfile = tempnam("/tmp", "ssl"); -if ($outfile === false) +if ($outfile === false) { die("failed to get a temporary filename!"); +} -$privkey = "file://" . dirname(__FILE__) . "/private.key"; +$privkey = "file://" . dirname(__FILE__) . "/private_rsa_1024.key"; $single_cert = "file://" . dirname(__FILE__) . "/cert.crt"; $assoc_headers = array("To" => "test@test", "Subject" => "testing openssl_pkcs7_sign()"); $headers = array("test@test", "testing openssl_pkcs7_sign()"); diff --git a/ext/openssl/tests/027.phpt b/ext/openssl/tests/openssl_pkey_export_basic.phpt index d229d6b135..d229d6b135 100644 --- a/ext/openssl/tests/027.phpt +++ b/ext/openssl/tests/openssl_pkey_export_basic.phpt diff --git a/ext/openssl/tests/028.phpt b/ext/openssl/tests/openssl_pkey_get_details_basic.phpt index 8e0cef46c0..8e0cef46c0 100644 --- a/ext/openssl/tests/028.phpt +++ b/ext/openssl/tests/openssl_pkey_get_details_basic.phpt diff --git a/ext/openssl/tests/006.phpt b/ext/openssl/tests/openssl_pkey_new_basic.phpt index d6e41e496b..3c434978d2 100644 --- a/ext/openssl/tests/006.phpt +++ b/ext/openssl/tests/openssl_pkey_new_basic.phpt @@ -1,5 +1,5 @@ --TEST-- -openssl_pkey_new() with an empty sub-array arg generates a malformed resource +openssl_pkey_new() tests --SKIPIF-- <?php if (!extension_loaded("openssl")) print "skip"; ?> --FILE-- diff --git a/ext/openssl/tests/017.phpt b/ext/openssl/tests/openssl_private_decrypt_basic.phpt index 65a7cd1025..76a08b8d55 100644 --- a/ext/openssl/tests/017.phpt +++ b/ext/openssl/tests/openssl_private_decrypt_basic.phpt @@ -5,7 +5,7 @@ openssl_private_decrypt() tests --FILE-- <?php $data = "Testing openssl_public_decrypt()"; -$privkey = "file://" . dirname(__FILE__) . "/private.key"; +$privkey = "file://" . dirname(__FILE__) . "/private_rsa_1024.key"; $pubkey = "file://" . dirname(__FILE__) . "/public.key"; $wrong = "wrong"; diff --git a/ext/openssl/tests/014.phpt b/ext/openssl/tests/openssl_private_encrypt_basic.phpt index 6123964ee5..a2a5152158 100644 --- a/ext/openssl/tests/014.phpt +++ b/ext/openssl/tests/openssl_private_encrypt_basic.phpt @@ -5,13 +5,14 @@ openssl_private_encrypt() tests --FILE-- <?php $data = "Testing openssl_private_encrypt()"; -$privkey = "file://" . dirname(__FILE__) . "/private.key"; +$privkey = "file://" . dirname(__FILE__) . "/private_rsa_1024.key"; $pubkey = "file://" . dirname(__FILE__) . "/public.key"; $wrong = "wrong"; + class test { - function __toString() { - return "test"; - } + function __toString() { + return "test"; + } } $obj = new test; diff --git a/ext/openssl/tests/016.phpt b/ext/openssl/tests/openssl_public_decrypt_basic.phpt index 2d772e7a36..42d72b9cd4 100644 --- a/ext/openssl/tests/016.phpt +++ b/ext/openssl/tests/openssl_public_decrypt_basic.phpt @@ -5,7 +5,7 @@ openssl_public_decrypt() tests --FILE-- <?php $data = "Testing openssl_public_decrypt()"; -$privkey = "file://" . dirname(__FILE__) . "/private.key"; +$privkey = "file://" . dirname(__FILE__) . "/private_rsa_1024.key"; $pubkey = "file://" . dirname(__FILE__) . "/public.key"; $wrong = "wrong"; diff --git a/ext/openssl/tests/015.phpt b/ext/openssl/tests/openssl_public_encrypt_basic.phpt index a89121de10..a3c4c57539 100644 --- a/ext/openssl/tests/015.phpt +++ b/ext/openssl/tests/openssl_public_encrypt_basic.phpt @@ -5,13 +5,14 @@ openssl_public_encrypt() tests --FILE-- <?php $data = "Testing openssl_public_encrypt()"; -$privkey = "file://" . dirname(__FILE__) . "/private.key"; +$privkey = "file://" . dirname(__FILE__) . "/private_rsa_1024.key"; $pubkey = "file://" . dirname(__FILE__) . "/public.key"; $wrong = "wrong"; + class test { - function __toString() { - return "test"; - } + function __toString() { + return "test"; + } } $obj = new test; diff --git a/ext/openssl/tests/openssl_random_pseudo_bytes.phpt b/ext/openssl/tests/openssl_random_pseudo_bytes_basic.phpt index ac5a3079a1..ac5a3079a1 100644 --- a/ext/openssl/tests/openssl_random_pseudo_bytes.phpt +++ b/ext/openssl/tests/openssl_random_pseudo_bytes_basic.phpt diff --git a/ext/openssl/tests/openssl_seal_basic.phpt b/ext/openssl/tests/openssl_seal_basic.phpt new file mode 100644 index 0000000000..4f1958a365 --- /dev/null +++ b/ext/openssl/tests/openssl_seal_basic.phpt @@ -0,0 +1,58 @@ +--TEST-- +openssl_seal() tests +--SKIPIF-- +<?php if (!extension_loaded("openssl")) print "skip"; ?> +--FILE-- +<?php +// simple tests +$a = 1; +$b = array(1); +$c = array(1); +$d = array(1); + +var_dump(openssl_seal($a, $b, $c, $d)); +var_dump(openssl_seal($a, $a, $a, array())); +var_dump(openssl_seal($c, $c, $c, 1)); +var_dump(openssl_seal($b, $b, $b, "")); + +// tests with cert +$data = "openssl_open() test"; +$pub_key = "file://" . dirname(__FILE__) . "/public.key"; +$wrong = "wrong"; + +var_dump(openssl_seal($data, $sealed, $ekeys, array($pub_key))); // no output +var_dump(openssl_seal($data, $sealed, $ekeys, array($pub_key, $pub_key))); // no output +var_dump(openssl_seal($data, $sealed, $ekeys, array($pub_key, $wrong))); +var_dump(openssl_seal($data, $sealed, $ekeys, $pub_key)); +var_dump(openssl_seal($data, $sealed, $ekeys, array())); +var_dump(openssl_seal($data, $sealed, $ekeys, array($wrong))); + +echo "Done\n"; +?> +--EXPECTF-- +Warning: openssl_seal(): not a public key (1th member of pubkeys) in %s on line %d +bool(false) + +Warning: openssl_seal(): Fourth argument to openssl_seal() must be a non-empty array in %s on line %d +bool(false) + +Warning: openssl_seal() expects parameter 1 to be string, array given in %s on line %d +NULL + +Warning: openssl_seal() expects parameter 1 to be string, array given in %s on line %d +NULL +int(19) +int(19) + +Warning: openssl_seal(): not a public key (2th member of pubkeys) in %s on line %d +bool(false) + +Warning: openssl_seal() expects parameter 4 to be array, string given in %s on line %d +NULL + +Warning: openssl_seal(): Fourth argument to openssl_seal() must be a non-empty array in %s on line %d +bool(false) + +Warning: openssl_seal(): not a public key (1th member of pubkeys) in %s on line %d +bool(false) +Done diff --git a/ext/openssl/tests/018.phpt b/ext/openssl/tests/openssl_sign_basic.phpt index 230c0a89db..3d41ee1d34 100644 --- a/ext/openssl/tests/018.phpt +++ b/ext/openssl/tests/openssl_sign_basic.phpt @@ -5,7 +5,7 @@ openssl_sign() tests --FILE-- <?php $data = "Testing openssl_sign()"; -$privkey = "file://" . dirname(__FILE__) . "/private.key"; +$privkey = "file://" . dirname(__FILE__) . "/private_rsa_1024.key"; $wrong = "wrong"; var_dump(openssl_sign($data, $sign, $privkey)); // no output diff --git a/ext/openssl/tests/openssl_spki_export.phpt b/ext/openssl/tests/openssl_spki_export.phpt deleted file mode 100644 index 59332f70a5..0000000000 --- a/ext/openssl/tests/openssl_spki_export.phpt +++ /dev/null @@ -1,62 +0,0 @@ ---TEST-- -Testing openssl_spki_export() -Creates SPKAC for all available key sizes & signature algorithms and exports public key ---SKIPIF-- -<?php -if (!extension_loaded("openssl")) die("skip"); -if (!@openssl_pkey_new()) die("skip cannot create private key"); -?> ---FILE-- -<?php - -/* array of private key sizes to test */ -$ksize = array('1024'=>1024, - '2048'=>2048, - '4096'=>4096); - -/* array of available hashings to test */ -$algo = array('md4'=>OPENSSL_ALGO_MD4, - 'md5'=>OPENSSL_ALGO_MD5, - 'sha1'=>OPENSSL_ALGO_SHA1, - 'sha224'=>OPENSSL_ALGO_SHA224, - 'sha256'=>OPENSSL_ALGO_SHA256, - 'sha384'=>OPENSSL_ALGO_SHA384, - 'sha512'=>OPENSSL_ALGO_SHA512, - 'rmd160'=>OPENSSL_ALGO_RMD160); - -/* loop over key sizes for test */ -foreach($ksize as $k => $v) { - - /* generate new private key of specified size to use for tests */ - $pkey = openssl_pkey_new(array('digest_alg' => 'sha512', - 'private_key_type' => OPENSSL_KEYTYPE_RSA, - 'private_key_bits' => $v)); - openssl_pkey_export($pkey, $pass); - - /* loop to create and verify results */ - foreach($algo as $key => $value) { - $spkac = openssl_spki_new($pkey, _uuid(), $value); - echo openssl_spki_export(preg_replace('/SPKAC=/', '', $spkac)); - } - openssl_free_key($pkey); -} - -/* generate a random challenge */ -function _uuid() -{ - return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), - mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0x0fff) | 0x4000, - mt_rand(0, 0x3fff) | 0x8000, mt_rand(0, 0xffff), - mt_rand(0, 0xffff), mt_rand(0, 0xffff)); -} - -?> ---EXPECTREGEX-- -\-\-\-\-\-BEGIN PUBLIC KEY\-\-\-\-\-.*\-\-\-\-\-END PUBLIC KEY\-\-\-\-\- -\-\-\-\-\-BEGIN PUBLIC KEY\-\-\-\-\-.*\-\-\-\-\-END PUBLIC KEY\-\-\-\-\- -\-\-\-\-\-BEGIN PUBLIC KEY\-\-\-\-\-.*\-\-\-\-\-END PUBLIC KEY\-\-\-\-\- -\-\-\-\-\-BEGIN PUBLIC KEY\-\-\-\-\-.*\-\-\-\-\-END PUBLIC KEY\-\-\-\-\- -\-\-\-\-\-BEGIN PUBLIC KEY\-\-\-\-\-.*\-\-\-\-\-END PUBLIC KEY\-\-\-\-\- -\-\-\-\-\-BEGIN PUBLIC KEY\-\-\-\-\-.*\-\-\-\-\-END PUBLIC KEY\-\-\-\-\- -\-\-\-\-\-BEGIN PUBLIC KEY\-\-\-\-\-.*\-\-\-\-\-END PUBLIC KEY\-\-\-\-\- -\-\-\-\-\-BEGIN PUBLIC KEY\-\-\-\-\-.*\-\-\-\-\-END PUBLIC KEY\-\-\-\-\- diff --git a/ext/openssl/tests/openssl_spki_export_basic.phpt b/ext/openssl/tests/openssl_spki_export_basic.phpt new file mode 100644 index 0000000000..1e3bd1fd39 --- /dev/null +++ b/ext/openssl/tests/openssl_spki_export_basic.phpt @@ -0,0 +1,60 @@ +--TEST-- +openssl_spki_export() tests for exporting public key +--SKIPIF-- +<?php +if (!extension_loaded("openssl")) die("skip"); +if (!@openssl_pkey_new()) die("skip cannot create private key"); +?> +--FILE-- +<?php + +/* array of private key sizes to test */ +$key_sizes = array(1024, 2048, 4096); +$pkeys = array(); +foreach ($key_sizes as $key_size) { + $key_file = "file://" . dirname(__FILE__) . "/private_rsa_" . $key_size . ".key"; + $pkeys[] = openssl_pkey_get_private($key_file); +} + + +/* array of available hashings to test */ +$algo = array( + OPENSSL_ALGO_MD4, + OPENSSL_ALGO_MD5, + OPENSSL_ALGO_SHA1, + OPENSSL_ALGO_SHA224, + OPENSSL_ALGO_SHA256, + OPENSSL_ALGO_SHA384, + OPENSSL_ALGO_SHA512, + OPENSSL_ALGO_RMD160 +); + +/* loop over key sizes for test */ +foreach ($pkeys as $pkey) { + + /* loop to create and verify results */ + foreach ($algo as $value) { + $spkac = openssl_spki_new($pkey, _uuid(), $value); + echo openssl_spki_export(preg_replace('/SPKAC=/', '', $spkac)); + } +} + +/* generate a random challenge */ +function _uuid() { + return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), + mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0x0fff) | 0x4000, + mt_rand(0, 0x3fff) | 0x8000, mt_rand(0, 0xffff), + mt_rand(0, 0xffff), mt_rand(0, 0xffff)); +} + + +?> +--EXPECTREGEX-- +\-\-\-\-\-BEGIN PUBLIC KEY\-\-\-\-\-.*\-\-\-\-\-END PUBLIC KEY\-\-\-\-\- +\-\-\-\-\-BEGIN PUBLIC KEY\-\-\-\-\-.*\-\-\-\-\-END PUBLIC KEY\-\-\-\-\- +\-\-\-\-\-BEGIN PUBLIC KEY\-\-\-\-\-.*\-\-\-\-\-END PUBLIC KEY\-\-\-\-\- +\-\-\-\-\-BEGIN PUBLIC KEY\-\-\-\-\-.*\-\-\-\-\-END PUBLIC KEY\-\-\-\-\- +\-\-\-\-\-BEGIN PUBLIC KEY\-\-\-\-\-.*\-\-\-\-\-END PUBLIC KEY\-\-\-\-\- +\-\-\-\-\-BEGIN PUBLIC KEY\-\-\-\-\-.*\-\-\-\-\-END PUBLIC KEY\-\-\-\-\- +\-\-\-\-\-BEGIN PUBLIC KEY\-\-\-\-\-.*\-\-\-\-\-END PUBLIC KEY\-\-\-\-\- +\-\-\-\-\-BEGIN PUBLIC KEY\-\-\-\-\-.*\-\-\-\-\-END PUBLIC KEY\-\-\-\-\- diff --git a/ext/openssl/tests/openssl_spki_export_challenge.phpt b/ext/openssl/tests/openssl_spki_export_challenge_basic.phpt index 71ef62edd5..07a69d3b45 100644 --- a/ext/openssl/tests/openssl_spki_export_challenge.phpt +++ b/ext/openssl/tests/openssl_spki_export_challenge_basic.phpt @@ -1,6 +1,5 @@ --TEST-- -Testing openssl_spki_export_challenge() -Creates SPKAC for all available key sizes & signature algorithms and exports challenge +openssl_spki_export_challenge() tests for exporting challenge --INI-- error_reporting=0 --SKIPIF-- @@ -12,47 +11,46 @@ if (!@openssl_pkey_new()) die("skip cannot create private key"); <?php /* array of private key sizes to test */ -$ksize = array('1024'=>1024, - '2048'=>2048, - '4096'=>4096); +$key_sizes = array(1024, 2048, 4096); +$pkeys = array(); +foreach ($key_sizes as $key_size) { + $key_file = "file://" . dirname(__FILE__) . "/private_rsa_" . $key_size . ".key"; + $pkeys[] = openssl_pkey_get_private($key_file); +} + /* array of available hashings to test */ -$algo = array('md4'=>OPENSSL_ALGO_MD4, - 'md5'=>OPENSSL_ALGO_MD5, - 'sha1'=>OPENSSL_ALGO_SHA1, - 'sha224'=>OPENSSL_ALGO_SHA224, - 'sha256'=>OPENSSL_ALGO_SHA256, - 'sha384'=>OPENSSL_ALGO_SHA384, - 'sha512'=>OPENSSL_ALGO_SHA512, - 'rmd160'=>OPENSSL_ALGO_RMD160); +$algo = array( + OPENSSL_ALGO_MD4, + OPENSSL_ALGO_MD5, + OPENSSL_ALGO_SHA1, + OPENSSL_ALGO_SHA224, + OPENSSL_ALGO_SHA256, + OPENSSL_ALGO_SHA384, + OPENSSL_ALGO_SHA512, + OPENSSL_ALGO_RMD160 +); /* loop over key sizes for test */ -foreach($ksize as $k => $v) { - - /* generate new private key of specified size to use for tests */ - $pkey = openssl_pkey_new(array('digest_alg' => 'sha512', - 'private_key_type' => OPENSSL_KEYTYPE_RSA, - 'private_key_bits' => $v)); - openssl_pkey_export($pkey, $pass); +foreach ($pkeys as $pkey) { /* loop to create and verify results */ - foreach($algo as $key => $value) { + foreach ($algo as $value) { $spkac = openssl_spki_new($pkey, _uuid(), $value); var_dump(openssl_spki_export_challenge(preg_replace('/SPKAC=/', '', $spkac))); - var_dump(openssl_spki_export_challenge($spkac.'Make it fail')); + var_dump(openssl_spki_export_challenge($spkac . 'Make it fail')); } - openssl_free_key($pkey); } /* generate a random challenge */ -function _uuid() -{ - return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), - mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0x0fff) | 0x4000, - mt_rand(0, 0x3fff) | 0x8000, mt_rand(0, 0xffff), - mt_rand(0, 0xffff), mt_rand(0, 0xffff)); +function _uuid() { + return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), + mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0x0fff) | 0x4000, + mt_rand(0, 0x3fff) | 0x8000, mt_rand(0, 0xffff), + mt_rand(0, 0xffff), mt_rand(0, 0xffff)); } + ?> --EXPECTREGEX-- string\(36\) \"[0-9a-f]{8}\-([0-9a-f]{4}\-){3}[0-9a-f]{12}\" diff --git a/ext/openssl/tests/openssl_spki_new.phpt b/ext/openssl/tests/openssl_spki_new.phpt deleted file mode 100644 index e40f9bf28e..0000000000 --- a/ext/openssl/tests/openssl_spki_new.phpt +++ /dev/null @@ -1,77 +0,0 @@ ---TEST-- -Testing openssl_spki_new() -Tests SPKAC for all available private key sizes & hashing algorithms ---SKIPIF-- -<?php -if (!extension_loaded("openssl")) die("skip"); -if (!@openssl_pkey_new()) die("skip cannot create private key"); -?> ---FILE-- -<?php - -/* array of private key sizes to test */ -$ksize = array('1024'=>1024, - '2048'=>2048, - '4096'=>4096); - -/* array of available hashings to test */ -$algo = array('md4'=>OPENSSL_ALGO_MD4, - 'md5'=>OPENSSL_ALGO_MD5, - 'sha1'=>OPENSSL_ALGO_SHA1, - 'sha224'=>OPENSSL_ALGO_SHA224, - 'sha256'=>OPENSSL_ALGO_SHA256, - 'sha384'=>OPENSSL_ALGO_SHA384, - 'sha512'=>OPENSSL_ALGO_SHA512, - 'rmd160'=>OPENSSL_ALGO_RMD160); - -/* loop over key sizes for test */ -foreach($ksize as $k => $v) { - - /* generate new private key of specified size to use for tests */ - $pkey = openssl_pkey_new(array('digest_alg' => 'sha512', - 'private_key_type' => OPENSSL_KEYTYPE_RSA, - 'private_key_bits' => $v)); - openssl_pkey_export($pkey, $pass); - - /* loop to create and verify results */ - foreach($algo as $key => $value) { - var_dump(openssl_spki_new($pkey, _uuid(), $value)); - } - openssl_free_key($pkey); -} - -/* generate a random challenge */ -function _uuid() -{ - return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), - mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0x0fff) | 0x4000, - mt_rand(0, 0x3fff) | 0x8000, mt_rand(0, 0xffff), - mt_rand(0, 0xffff), mt_rand(0, 0xffff)); -} - -?> ---EXPECTF-- -string(478) "%s" -string(478) "%s" -string(478) "%s" -string(478) "%s" -string(478) "%s" -string(478) "%s" -string(478) "%s" -string(474) "%s" -string(830) "%s" -string(830) "%s" -string(830) "%s" -string(830) "%s" -string(830) "%s" -string(830) "%s" -string(830) "%s" -string(826) "%s" -string(1510) "%s" -string(1510) "%s" -string(1510) "%s" -string(1510) "%s" -string(1510) "%s" -string(1510) "%s" -string(1510) "%s" -string(1506) "%s" diff --git a/ext/openssl/tests/openssl_spki_new_basic.phpt b/ext/openssl/tests/openssl_spki_new_basic.phpt new file mode 100644 index 0000000000..b31d6f9184 --- /dev/null +++ b/ext/openssl/tests/openssl_spki_new_basic.phpt @@ -0,0 +1,73 @@ +--TEST-- +openssl_spki_new() test for creating SPKI string +--SKIPIF-- +<?php +if (!extension_loaded("openssl")) die("skip"); +?> +--FILE-- +<?php + +/* array of private key sizes to test */ +$key_sizes = array(1024, 2048, 4096); +$pkeys = array(); +foreach ($key_sizes as $key_size) { + $key_file = "file://" . dirname(__FILE__) . "/private_rsa_" . $key_size . ".key"; + $pkeys[] = openssl_pkey_get_private($key_file); +} + + +/* array of available hashings to test */ +$algo = array( + OPENSSL_ALGO_MD4, + OPENSSL_ALGO_MD5, + OPENSSL_ALGO_SHA1, + OPENSSL_ALGO_SHA224, + OPENSSL_ALGO_SHA256, + OPENSSL_ALGO_SHA384, + OPENSSL_ALGO_SHA512, + OPENSSL_ALGO_RMD160 +); + +/* loop over key sizes for test */ +foreach ($pkeys as $pkey) { + + /* loop to create and verify results */ + foreach ($algo as $value) { + var_dump(openssl_spki_new($pkey, _uuid(), $value)); + } +} + +/* generate a random challenge */ +function _uuid() { + return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), + mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0x0fff) | 0x4000, + mt_rand(0, 0x3fff) | 0x8000, mt_rand(0, 0xffff), + mt_rand(0, 0xffff), mt_rand(0, 0xffff)); +} + +?> +--EXPECTF-- +string(478) "%s" +string(478) "%s" +string(478) "%s" +string(478) "%s" +string(478) "%s" +string(478) "%s" +string(478) "%s" +string(474) "%s" +string(830) "%s" +string(830) "%s" +string(830) "%s" +string(830) "%s" +string(830) "%s" +string(830) "%s" +string(830) "%s" +string(826) "%s" +string(1510) "%s" +string(1510) "%s" +string(1510) "%s" +string(1510) "%s" +string(1510) "%s" +string(1510) "%s" +string(1510) "%s" +string(1506) "%s" diff --git a/ext/openssl/tests/openssl_spki_verify.phpt b/ext/openssl/tests/openssl_spki_verify.phpt deleted file mode 100644 index 52dc8e2045..0000000000 --- a/ext/openssl/tests/openssl_spki_verify.phpt +++ /dev/null @@ -1,91 +0,0 @@ ---TEST-- -Testing openssl_spki_verify() -Creates SPKAC for all available key sizes & signature algorithms and tests for valid signature ---INI-- -error_reporting=0 ---SKIPIF-- -<?php -if (!extension_loaded("openssl")) die("skip"); -if (!@openssl_pkey_new()) die("skip cannot create private key"); -?> ---FILE-- -<?php - -/* array of private key sizes to test */ -$ksize = array('1024'=>1024, - '2048'=>2048, - '4096'=>4096); - -/* array of available hashings to test */ -$algo = array('sha1'=>OPENSSL_ALGO_SHA1, - 'sha224'=>OPENSSL_ALGO_SHA224, - 'sha256'=>OPENSSL_ALGO_SHA256, - 'sha384'=>OPENSSL_ALGO_SHA384, - 'sha512'=>OPENSSL_ALGO_SHA512, - 'rmd160'=>OPENSSL_ALGO_RMD160); - -/* loop over key sizes for test */ -foreach($ksize as $k => $v) { - - /* generate new private key of specified size to use for tests */ - $pkey = openssl_pkey_new(array('digest_alg' => 'sha512', - 'private_key_type' => OPENSSL_KEYTYPE_RSA, - 'private_key_bits' => $v)); - openssl_pkey_export($pkey, $pass); - - /* loop to create and verify results */ - foreach($algo as $key => $value) { - $spkac = openssl_spki_new($pkey, _uuid(), $value); - var_dump(openssl_spki_verify(preg_replace('/SPKAC=/', '', $spkac))); - var_dump(openssl_spki_verify($spkac.'Make it fail')); - } - openssl_free_key($pkey); -} - -/* generate a random challenge */ -function _uuid() -{ - return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), - mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0x0fff) | 0x4000, - mt_rand(0, 0x3fff) | 0x8000, mt_rand(0, 0xffff), - mt_rand(0, 0xffff), mt_rand(0, 0xffff)); -} - -?> ---EXPECT-- -bool(true) -bool(false) -bool(true) -bool(false) -bool(true) -bool(false) -bool(true) -bool(false) -bool(true) -bool(false) -bool(true) -bool(false) -bool(true) -bool(false) -bool(true) -bool(false) -bool(true) -bool(false) -bool(true) -bool(false) -bool(true) -bool(false) -bool(true) -bool(false) -bool(true) -bool(false) -bool(true) -bool(false) -bool(true) -bool(false) -bool(true) -bool(false) -bool(true) -bool(false) -bool(true) -bool(false)
\ No newline at end of file diff --git a/ext/openssl/tests/openssl_spki_verify_basic.phpt b/ext/openssl/tests/openssl_spki_verify_basic.phpt new file mode 100644 index 0000000000..7b56a37e13 --- /dev/null +++ b/ext/openssl/tests/openssl_spki_verify_basic.phpt @@ -0,0 +1,88 @@ +--TEST-- +openssl_spki_verify() tests for valid signature +--INI-- +error_reporting=0 +--SKIPIF-- +<?php +if (!extension_loaded("openssl")) die("skip"); +?> +--FILE-- +<?php + +/* array of private key sizes to test */ +$key_sizes = array(1024, 2048, 4096); +$pkeys = array(); +foreach ($key_sizes as $key_size) { + $key_file = "file://" . dirname(__FILE__) . "/private_rsa_" . $key_size . ".key"; + $pkeys[] = openssl_pkey_get_private($key_file); +} + + +/* array of available hashings to test */ +$algo = array( + OPENSSL_ALGO_SHA1, + OPENSSL_ALGO_SHA224, + OPENSSL_ALGO_SHA256, + OPENSSL_ALGO_SHA384, + OPENSSL_ALGO_SHA512, + OPENSSL_ALGO_RMD160 +); + +/* loop over key sizes for test */ +foreach ($pkeys as $pkey) { + + /* loop to create and verify results */ + foreach ($algo as $value) { + $spkac = openssl_spki_new($pkey, _uuid(), $value); + var_dump(openssl_spki_verify(preg_replace('/SPKAC=/', '', $spkac))); + var_dump(openssl_spki_verify($spkac . 'Make it fail')); + } +} + +/* generate a random challenge */ +function _uuid() { + return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), + mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0x0fff) | 0x4000, + mt_rand(0, 0x3fff) | 0x8000, mt_rand(0, 0xffff), + mt_rand(0, 0xffff), mt_rand(0, 0xffff)); +} + + +?> +--EXPECT-- +bool(true) +bool(false) +bool(true) +bool(false) +bool(true) +bool(false) +bool(true) +bool(false) +bool(true) +bool(false) +bool(true) +bool(false) +bool(true) +bool(false) +bool(true) +bool(false) +bool(true) +bool(false) +bool(true) +bool(false) +bool(true) +bool(false) +bool(true) +bool(false) +bool(true) +bool(false) +bool(true) +bool(false) +bool(true) +bool(false) +bool(true) +bool(false) +bool(true) +bool(false) +bool(true) +bool(false) diff --git a/ext/openssl/tests/019.phpt b/ext/openssl/tests/openssl_verify_basic.phpt index c1f186c335..a21dfedb01 100644 --- a/ext/openssl/tests/019.phpt +++ b/ext/openssl/tests/openssl_verify_basic.phpt @@ -5,7 +5,7 @@ openssl_verify() tests --FILE-- <?php $data = "Testing openssl_verify()"; -$privkey = "file://" . dirname(__FILE__) . "/private.key"; +$privkey = "file://" . dirname(__FILE__) . "/private_rsa_1024.key"; $pubkey = "file://" . dirname(__FILE__) . "/public.key"; $wrong = "wrong"; diff --git a/ext/openssl/tests/009.phpt b/ext/openssl/tests/openssl_x509_check_private_key_basic.phpt index a7156dd8d0..b4842aae18 100644 --- a/ext/openssl/tests/009.phpt +++ b/ext/openssl/tests/openssl_x509_check_private_key_basic.phpt @@ -5,15 +5,15 @@ openssl_x509_check_private_key() tests --FILE-- <?php $fp = fopen(dirname(__FILE__) . "/cert.crt","r"); -$a = fread($fp,8192); +$a = fread($fp, 8192); fclose($fp); -$fp = fopen(dirname(__FILE__) . "/private.key","r"); -$b = fread($fp,8192); +$fp = fopen(dirname(__FILE__) . "/private_rsa_1024.key","r"); +$b = fread($fp, 8192); fclose($fp); $cert = "file://" . dirname(__FILE__) . "/cert.crt"; -$key = "file://" . dirname(__FILE__) . "/private.key"; +$key = "file://" . dirname(__FILE__) . "/private_rsa_1024.key"; var_dump(openssl_x509_check_private_key($cert, $key)); var_dump(openssl_x509_check_private_key("", $key)); diff --git a/ext/openssl/tests/openssl_x509_export_basic.phpt b/ext/openssl/tests/openssl_x509_export_basic.phpt new file mode 100644 index 0000000000..4177bd7798 --- /dev/null +++ b/ext/openssl/tests/openssl_x509_export_basic.phpt @@ -0,0 +1,45 @@ +--TEST-- +openssl_x509_export() tests +--SKIPIF-- +<?php if (!extension_loaded("openssl")) print "skip"; ?> +--FILE-- +<?php +$cert_file = dirname(__FILE__) . "/cert.crt"; + +$a = file_get_contents($cert_file); +$b = "file://" . $cert_file; +$c = "invalid cert"; +$d = openssl_x509_read($a); +$e = array(); + +var_dump(openssl_x509_export($a, $output)); // read cert as a binary string +var_dump(openssl_x509_export($b, $output2)); // read cert from a filename string +var_dump(openssl_x509_export($c, $output3)); // read an invalid cert, fails +var_dump(openssl_x509_export($d, $output4)); // read cert from a resource +var_dump(openssl_x509_export($e, $output5)); // read an array, fails + +if (PHP_EOL !== "\n") { + $a = str_replace(PHP_EOL, "\n", $a); +} + +var_dump(strcmp($output, $a)); +var_dump(strcmp($output, $output2)); +var_dump(strcmp($output, $output3)); +var_dump(strcmp($output, $output4)); // different +var_dump(strcmp($output, $output5)); // different +?> +--EXPECTF-- +bool(true) +bool(true) + +Warning: openssl_x509_export(): cannot get cert from parameter 1 in %s on line %d +bool(false) +bool(true) + +Warning: openssl_x509_export(): cannot get cert from parameter 1 in %s on line %d +bool(false) +int(0) +int(0) +int(%d) +int(0) +int(%d) diff --git a/ext/openssl/tests/openssl_x509_export_to_file_basic.phpt b/ext/openssl/tests/openssl_x509_export_to_file_basic.phpt new file mode 100644 index 0000000000..68ba93230d --- /dev/null +++ b/ext/openssl/tests/openssl_x509_export_to_file_basic.phpt @@ -0,0 +1,42 @@ +--TEST-- +openssl_x509_export_to_file() tests +--SKIPIF-- +<?php if (!extension_loaded("openssl")) print "skip"; ?> +--FILE-- +<?php +$outfilename = dirname(__FILE__) . "/openssl_x509_export_to_file__outfilename.tmp"; +$cert_file = dirname(__FILE__) . "/cert.crt"; + +$a = file_get_contents($cert_file); +$b = "file://" . $cert_file; +$c = "invalid cert"; +$d = openssl_x509_read($a); +$e = array(); + +var_dump(openssl_x509_export_to_file($a, $outfilename)); // read cert as a binary string +var_dump(openssl_x509_export_to_file($b, $outfilename)); // read cert from a filename string +var_dump(openssl_x509_export_to_file($c, $outfilename)); // read an invalid cert, fails +var_dump(openssl_x509_export_to_file($d, $outfilename)); // read cert from a resource +var_dump(openssl_x509_export_to_file($e, $outfilename)); // read an array, fails +echo "---\n"; +var_dump($exists = file_exists($outfilename)); +?> +--CLEAN-- +<?php +$outfilename = dirname(__FILE__) . "/openssl_x509_export_to_file__outfilename.tmp"; +if (file_exists($outfilename)) { + unlink($outfilename); +} +?> +--EXPECTF-- +bool(true) +bool(true) + +Warning: openssl_x509_export_to_file(): cannot get cert from parameter 1 in %s on line %d +bool(false) +bool(true) + +Warning: openssl_x509_export_to_file(): cannot get cert from parameter 1 in %s on line %d +bool(false) +--- +bool(true) diff --git a/ext/openssl/tests/openssl_x509_fingerprint.phpt b/ext/openssl/tests/openssl_x509_fingerprint_basic.phpt index 6cd464a894..766b158fab 100644 --- a/ext/openssl/tests/openssl_x509_fingerprint.phpt +++ b/ext/openssl/tests/openssl_x509_fingerprint_basic.phpt @@ -1,5 +1,5 @@ --TEST-- -Testing openssl_x509_fingerprint() +openssl_x509_fingerprint() tests --SKIPIF-- <?php if (!extension_loaded("openssl")) die("skip"); diff --git a/ext/openssl/tests/openssl_x509_free_basic.phpt b/ext/openssl/tests/openssl_x509_free_basic.phpt new file mode 100644 index 0000000000..d8b586e8b4 --- /dev/null +++ b/ext/openssl/tests/openssl_x509_free_basic.phpt @@ -0,0 +1,16 @@ +--TEST-- +openssl_x509_free() tests +--SKIPIF-- +<?php if (!extension_loaded("openssl")) print "skip"; ?> +--FILE-- +<?php +var_dump($res = openssl_x509_read("file://" . dirname(__FILE__) . "/cert.crt")); +openssl_x509_free($res); +var_dump($res); +openssl_x509_free(false); +?> +--EXPECTF-- +resource(%d) of type (OpenSSL X.509) +resource(%d) of type (Unknown) + +Warning: openssl_x509_free() expects parameter 1 to be resource, boolean given in %s on line %d diff --git a/ext/openssl/tests/openssl_x509_parse_basic.phpt b/ext/openssl/tests/openssl_x509_parse_basic.phpt index 325b2ee4b9..00e32c3b60 100644 --- a/ext/openssl/tests/openssl_x509_parse_basic.phpt +++ b/ext/openssl/tests/openssl_x509_parse_basic.phpt @@ -1,5 +1,5 @@ --TEST-- -openssl_x509_parse() basic test +openssl_x509_parse() tests --SKIPIF-- <?php if (!extension_loaded("openssl")) print "skip"; if (OPENSSL_VERSION_NUMBER < 0x10000000) die("skip Output requires OpenSSL 1.0"); diff --git a/ext/openssl/tests/openssl_x509_parse_basic_v9.phpt b/ext/openssl/tests/openssl_x509_parse_v9_basic.phpt index 89862eff50..89862eff50 100644 --- a/ext/openssl/tests/openssl_x509_parse_basic_v9.phpt +++ b/ext/openssl/tests/openssl_x509_parse_v9_basic.phpt diff --git a/ext/openssl/tests/openssl_x509_read_basic.phpt b/ext/openssl/tests/openssl_x509_read_basic.phpt new file mode 100644 index 0000000000..5f530534ff --- /dev/null +++ b/ext/openssl/tests/openssl_x509_read_basic.phpt @@ -0,0 +1,37 @@ +--TEST-- +openssl_x509_read() tests +--SKIPIF-- +<?php if (!extension_loaded("openssl")) print "skip"; ?> +--FILE-- +<?php +$fp = fopen(dirname(__FILE__) . "/cert.crt","r"); +$a = fread($fp,8192); +fclose($fp); + +$b = "file://" . dirname(__FILE__) . "/cert.crt"; +$c = "invalid cert"; +$d = openssl_x509_read($a); +$e = array(); +$f = array($b); + +var_dump(openssl_x509_read($a)); // read cert as a string +var_dump(openssl_x509_read($b)); // read cert as a filename string +var_dump(openssl_x509_read($c)); // read an invalid cert, fails +var_dump(openssl_x509_read($d)); // read cert from a resource +var_dump(openssl_x509_read($e)); // read an array +var_dump(openssl_x509_read($f)); // read an array with the filename +?> +--EXPECTF-- +resource(%d) of type (OpenSSL X.509) +resource(%d) of type (OpenSSL X.509) + +Warning: openssl_x509_read(): supplied parameter cannot be coerced into an X509 certificate! in %s on line %d +bool(false) +resource(%d) of type (OpenSSL X.509) + +Warning: openssl_x509_read(): supplied parameter cannot be coerced into an X509 certificate! in %s on line %d +bool(false) + +Warning: openssl_x509_read(): supplied parameter cannot be coerced into an X509 certificate! in %s on line %d +bool(false) + diff --git a/ext/openssl/tests/private.key b/ext/openssl/tests/private_rsa_1024.key index bce512e050..bce512e050 100644 --- a/ext/openssl/tests/private.key +++ b/ext/openssl/tests/private_rsa_1024.key diff --git a/ext/openssl/tests/private_rsa_2048.key b/ext/openssl/tests/private_rsa_2048.key new file mode 100644 index 0000000000..d83e1b85c9 --- /dev/null +++ b/ext/openssl/tests/private_rsa_2048.key @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEpAIBAAKCAQEArbUmVW1Y+rJzZRC3DYB0kdIgvk7MAday78ybGPPDhVlbAb4C +jWbaPs4nyUCTEt9KVG0H7pXHxDbWSsC2974zdvqlP0L2op1/M2SteTcGCBOdwGH2 +jORVAZL8/WbTOf9IpKAM77oN14scsyOlQB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7Xkw/6jw/JcGA2AOsb1R4wKBgQCFfnF54Q1GkEk4/m4tAA4bX4KWICUCyCAxZyXX +LYl23PhiuDr7gnqockevt8ZzHWMPQY6juyFGoZoZqtinv7lc7YAvsWEGxmMQ+KUI +Mkp4y4aSjn2GGNc8dVs5t9blNBZe/oRaMwxohzkz+/Y1vJ54TK5BHCRI7is6anAd +jTchOwKBgQDP9yOdQTfUwJRUMERWmzXWU2oDXeEMdpbGPLGJ4/e/hu1CW7bdQRoc +jBSEpn3hOodmdwdmoXtbJReMCE8qS6yVHNn4orpJf+uOBr5fVnHwttFfN8HID9js +Lml8jAAQItMFw1CEPR75NVdFb7ksNKlxE9376tG63JhrTttRGwO3CA== +-----END RSA PRIVATE KEY----- diff --git a/ext/openssl/tests/private_rsa_4096.key b/ext/openssl/tests/private_rsa_4096.key new file mode 100644 index 0000000000..8338c86cbb --- /dev/null +++ b/ext/openssl/tests/private_rsa_4096.key @@ -0,0 +1,51 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIJKAIBAAKCAgEAtlmPieG4yL/HQ1j98U+VqlAzO55+aSHKXOV9q5+uTevtzXVV +s+rOPUAlPkUi7kcp3Yrum+Y0rNCnTNpSmpFB2f/Y1rHb6Rxn8SXzWSq8BM0BhbCm +yE+PY3DyIBizX6isb13vJyvU7f8Ayv4xAQ/ve8ytFAnBXUdIhtQNygraxvr8aoZw +81cBRQ8NhBkk/qDZWVkOiePC9voZ05sENhL4aUZw3Xew2JtZyw+lRxheczkYYc71 +OQuOKoU06j3ZpLhdhtdjpOVC6csIk9qyq8ki8t9m66a2BdiPaz1cWGZGqQg4SDrJ +0XKG6/wdSWgdUKMp0wB2Kwph2SWwLm7BQEpdtMtXnNGB2dT+lffjtqRvyT4HKO03 +R9b7ZxUVA34Tzi+kX04g3e4qI4eD0bsHYwioUlkKf/q7E1+WjwaQ2LLbOUnWeKqb +wGBsZYMWeWGTc/FO4oyDJBG9gnsqmSHasAsxsW6ojsGnz9IXywpwInlz+R4pB+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