com php-src: Merge branch 'PHP-5.6' into PHP-7.0: ext/openssl/t ests/openssl_csr_sign_basic.phpt ext/openssl/tests/op enssl_pkcs7_decrypt_error.phpt
ext/openssl/tests/op enssl_pkey_export_basic.phpt ext/openssl/tests/openss l_x509_export_basic.phpt

From: Date: Wed, 03 Feb 2016 16:22:39 +0000
Subject: com php-src: Merge branch 'PHP-5.6' into PHP-7.0: ext/openssl/t ests/openssl_csr_sign_basic.phpt ext/openssl/tests/op enssl_pkcs7_decrypt_error.phpt
ext/openssl/tests/op enssl_pkey_export_basic.phpt ext/openssl/tests/openss l_x509_export_basic.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-90936@lists.php.net to get a copy of this message
Commit: cdf99ffc6959c7038ce49ea5bf6e364c83cefd40 Author: Jakub Zelenka <bukka@php.net> Wed, 3 Feb 2016 16:22:39 +0000 Parents: 3a2c9e6e1dfe4b6b39b32dd09b18675c8dc8d5bc 1f3906c1ce24931fac60735c48bff3cfda760409 Branches: PHP-7.0 Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=cdf99ffc6959c7038ce49ea5bf6e364c83cefd40 Log: Merge branch 'PHP-5.6' into PHP-7.0 Changed paths: AM ext/openssl/tests/openssl_csr_sign_basic.phpt AM ext/openssl/tests/openssl_pkcs7_decrypt_error.phpt AM ext/openssl/tests/openssl_pkey_export_basic.phpt AM ext/openssl/tests/openssl_x509_export_basic.phpt

diff --cc ext/openssl/tests/openssl_csr_sign_basic.phpt index 0000000,ae948e3..34cf50a mode 000000,100644..100644 --- a/ext/openssl/tests/openssl_csr_sign_basic.phpt +++ b/ext/openssl/tests/openssl_csr_sign_basic.phpt @@@ -1,0 -1,80 +1,80 @@@ + --TEST-- + openssl_csr_sign() tests + --SKIPIF-- + <?php if (!extension_loaded("openssl")) print "skip"; ?> + --FILE-- + <?php + $cert = "file://" . dirname(__FILE__) . "/cert.crt"; + $priv = "file://" . dirname(__FILE__) . "/private_rsa_1024.key"; + $wrong = "wrong"; + $pub = "file://" . dirname(__FILE__) . "/public.key"; + $config = __DIR__ . DIRECTORY_SEPARATOR . 'openssl.cnf'; + $config_arg = array('config' => $config); + + $dn = array( + "countryName" => "BR", + "stateOrProvinceName" => "Rio Grande do Sul", + "localityName" => "Porto Alegre", + "commonName" => "Henrique do N. Angelo", + "emailAddress" => "hnangelo@php.net" + ); + + $args = array( + "digest_alg" => "sha1", + "private_key_bits" => 2048, + "private_key_type" => OPENSSL_KEYTYPE_DSA, + "encrypt_key" => true, + "config" => $config + ); + + $privkey = openssl_pkey_new($config_arg); + $csr = openssl_csr_new($dn, $privkey, $args); + var_dump(openssl_csr_sign($csr, null, $privkey, 365, $args)); + var_dump(openssl_csr_sign($csr, null, $privkey, 365, $config_arg)); + var_dump(openssl_csr_sign($csr, $cert, $priv, 365, $config_arg)); + var_dump(openssl_csr_sign($csr, $wrong, $privkey, 365)); + var_dump(openssl_csr_sign($csr, null, $wrong, 365)); + var_dump(openssl_csr_sign($csr, null, $privkey, $wrong)); + var_dump(openssl_csr_sign($csr, null, $privkey, 365, $wrong)); + var_dump(openssl_csr_sign($wrong, null, $privkey, 365)); + var_dump(openssl_csr_sign(array(), null, $privkey, 365)); + var_dump(openssl_csr_sign($csr, array(), $privkey, 365)); + var_dump(openssl_csr_sign($csr, null, array(), 365)); + var_dump(openssl_csr_sign($csr, null, $privkey, array())); + var_dump(openssl_csr_sign($csr, null, $privkey, 365, $config_arg)); + ?> + --EXPECTF-- + resource(%d) of type (OpenSSL X.509) + resource(%d) of type (OpenSSL X.509) + resource(%d) of type (OpenSSL X.509) + + Warning: openssl_csr_sign(): cannot get cert from parameter 2 in %s on line %d + bool(false) + + Warning: openssl_csr_sign(): cannot get private key from parameter 3 in %s on line %d + bool(false) + -Warning: openssl_csr_sign() expects parameter 4 to be long, string given in %s on line %d ++Warning: openssl_csr_sign() expects parameter 4 to be integer, string given in %s on line %d + NULL + + Warning: openssl_csr_sign() expects parameter 5 to be array, string given in %s on line %d + NULL + + Warning: openssl_csr_sign(): cannot get CSR from parameter 1 in %s on line %d + bool(false) + + Warning: openssl_csr_sign(): cannot get CSR from parameter 1 in %s on line %d + bool(false) + + Warning: openssl_csr_sign(): cannot get cert from parameter 2 in %s on line %d + bool(false) + + Warning: openssl_csr_sign(): key array must be of the form array(0 => key, 1 => phrase) in %s on line %d + + Warning: openssl_csr_sign(): cannot get private key from parameter 3 in %s on line %d + bool(false) + -Warning: openssl_csr_sign() expects parameter 4 to be long, array given in %s on line %d ++Warning: openssl_csr_sign() expects parameter 4 to be integer, array given in %s on line %d + NULL + resource(%d) of type (OpenSSL X.509) + diff --cc ext/openssl/tests/openssl_pkcs7_decrypt_error.phpt index 0000000,0fdb985..e8ba264 mode 000000,100644..100644 --- a/ext/openssl/tests/openssl_pkcs7_decrypt_error.phpt +++ b/ext/openssl/tests/openssl_pkcs7_decrypt_error.phpt @@@ -1,0 -1,43 +1,42 @@@ + --TEST-- + openssl_pkcs7_decrypt() and invalid parameters + --SKIPIF-- + <?php if (!extension_loaded("openssl")) print "skip"; ?> + --FILE-- + <?php + + function myErrorHandler($errno, $errstr, $errfile, $errline) { + var_dump($errstr); + } + set_error_handler("myErrorHandler"); + + $a = 1; + $b = 1; + $c = new stdclass; + $d = new stdclass; + + var_dump(openssl_pkcs7_decrypt($a, $b, $c, $d)); + var_dump($c); + + var_dump(openssl_pkcs7_decrypt($b, $b, $b, $b)); + var_dump(openssl_pkcs7_decrypt($a, $b, "", "")); + var_dump(openssl_pkcs7_decrypt($a, $b, true, false)); + var_dump(openssl_pkcs7_decrypt($a, $b, 0, 0)); + + echo "Done\n"; + ?> + --EXPECTF-- + string(57) "Object of class stdClass could not be converted to string" -string(45) "Object of class stdClass to string conversion" + string(66) "openssl_pkcs7_decrypt(): unable to coerce parameter 3 to x509 cert" + bool(false) + object(stdClass)#1 (0) { + } + string(66) "openssl_pkcs7_decrypt(): unable to coerce parameter 3 to x509 cert" + bool(false) + string(66) "openssl_pkcs7_decrypt(): unable to coerce parameter 3 to x509 cert" + bool(false) + string(66) "openssl_pkcs7_decrypt(): unable to coerce parameter 3 to x509 cert" + bool(false) + string(66) "openssl_pkcs7_decrypt(): unable to coerce parameter 3 to x509 cert" + bool(false) + Done diff --cc ext/openssl/tests/openssl_pkey_export_basic.phpt index 0000000,8311ab1..d229d6b mode 000000,100644..100644 --- a/ext/openssl/tests/openssl_pkey_export_basic.phpt +++ b/ext/openssl/tests/openssl_pkey_export_basic.phpt @@@ -1,0 -1,52 +1,54 @@@ + --TEST-- + openssl_pkey_export() with EC key + --SKIPIF-- + <?php + if (!extension_loaded("openssl")) die("skip"); + if (!defined('OPENSSL_KEYTYPE_EC')) die("skip no EC available"); + ?> + --FILE-- + <?php + $key = openssl_pkey_get_private('file://' . dirname(__FILE__) . '/private_ec.key'); + var_dump($key); + -var_dump(openssl_pkey_export($key, $output)); ++$config_arg = array("config" => __DIR__ . DIRECTORY_SEPARATOR . "openssl.cnf"); ++ ++var_dump(openssl_pkey_export($key, $output, NULL, $config_arg)); + echo $output; + + // Load the private key from the exported pem string + $details = openssl_pkey_get_details(openssl_pkey_get_private($output)); + var_dump(OPENSSL_KEYTYPE_EC === $details['type']); + + // Export key with passphrase -openssl_pkey_export($key, $output, 'passphrase'); ++openssl_pkey_export($key, $output, 'passphrase', $config_arg); + + $details = openssl_pkey_get_details(openssl_pkey_get_private($output, 'passphrase')); + var_dump(OPENSSL_KEYTYPE_EC === $details['type']); + + // Read public key + $pKey = openssl_pkey_get_public('file://' . dirname(__FILE__) . '/public_ec.key'); + var_dump($pKey); + // The details are the same for a public or private key + var_dump($details === openssl_pkey_get_details($pKey)); + + + // Export to file + $tempname = tempnam(sys_get_temp_dir(), 'openssl_ec'); -var_dump(openssl_pkey_export_to_file($key, $tempname)); ++var_dump(openssl_pkey_export_to_file($key, $tempname, NULL, $config_arg)); + $details = openssl_pkey_get_details(openssl_pkey_get_private('file://' . $tempname)); + var_dump(OPENSSL_KEYTYPE_EC === $details['type']); + + // Clean the temporary file + @unlink($tempname); + + ?> + --EXPECTF-- + resource(%d) of type (OpenSSL key) + bool(true) + -----BEGIN EC PRIVATE KEY-----%a-----END EC PRIVATE KEY----- + bool(true) + bool(true) + resource(%d) of type (OpenSSL key) + bool(true) + bool(true) + bool(true) diff --cc ext/openssl/tests/openssl_x509_export_basic.phpt index 0000000,e0988c0..712fe4c mode 000000,100644..100644 --- a/ext/openssl/tests/openssl_x509_export_basic.phpt +++ b/ext/openssl/tests/openssl_x509_export_basic.phpt @@@ -1,0 -1,75 +1,80 @@@ + --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)
« previous php.cvs (#90936) next »