summaryrefslogtreecommitdiff
path: root/ext/openssl
diff options
context:
space:
mode:
authorJakub Zelenka <bukka@php.net>2016-02-29 19:28:40 +0000
committerJakub Zelenka <bukka@php.net>2016-02-29 19:28:40 +0000
commit80015ba741fc857074050086db6c7b2a4716d6d5 (patch)
tree9e0b85868c092ae83a0df2bd4f33f79ba773aab2 /ext/openssl
parent4ea2a0fd60cdf75d746909198ea69f1e3e4ba193 (diff)
parent31dc08a904f2a91b582396b6ba118abfd12cf246 (diff)
downloadphp-git-80015ba741fc857074050086db6c7b2a4716d6d5.tar.gz
Merge branch 'PHP-7.0' into openssl_error_store
Diffstat (limited to 'ext/openssl')
-rw-r--r--ext/openssl/openssl.c6
-rw-r--r--ext/openssl/tests/openssl_csr_new_basic.phpt10
-rw-r--r--ext/openssl/tests/openssl_x509_check_private_key_basic.phpt4
-rw-r--r--ext/openssl/tests/openssl_x509_export_basic.phpt57
-rw-r--r--ext/openssl/tests/openssl_x509_export_to_file_basic.phpt42
-rw-r--r--ext/openssl/tests/openssl_x509_fingerprint_basic.phpt2
-rw-r--r--ext/openssl/tests/openssl_x509_free_basic.phpt16
-rw-r--r--ext/openssl/tests/openssl_x509_parse_basic.phpt2
-rw-r--r--ext/openssl/tests/openssl_x509_read_basic.phpt37
9 files changed, 89 insertions, 87 deletions
diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c
index 26eb120253..3298efc6f7 100644
--- a/ext/openssl/openssl.c
+++ b/ext/openssl/openssl.c
@@ -5241,7 +5241,7 @@ PHP_FUNCTION(openssl_seal)
iv_len = EVP_CIPHER_iv_length(cipher);
if (!iv && iv_len > 0) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
+ php_error_docref(NULL, E_WARNING,
"Cipher algorithm requires an IV to be supplied as a sixth parameter");
RETURN_FALSE;
}
@@ -5523,14 +5523,14 @@ static zend_bool php_openssl_validate_iv(char **piv, size_t *piv_len, size_t iv_
}
if (*piv_len < iv_required_len) {
- php_error_docref(NULL, E_WARNING, "IV passed is only %d bytes long, cipher expects an IV of precisely %d bytes, padding with \\0", *piv_len, iv_required_len);
+ php_error_docref(NULL, E_WARNING, "IV passed is only %zd bytes long, cipher expects an IV of precisely %zd bytes, padding with \\0", *piv_len, iv_required_len);
memcpy(iv_new, *piv, *piv_len);
*piv_len = iv_required_len;
*piv = iv_new;
return 1;
}
- php_error_docref(NULL, E_WARNING, "IV passed is %d bytes long which is longer than the %d expected by selected cipher, truncating", *piv_len, iv_required_len);
+ php_error_docref(NULL, E_WARNING, "IV passed is %zd bytes long which is longer than the %zd expected by selected cipher, truncating", *piv_len, iv_required_len);
memcpy(iv_new, *piv, iv_required_len);
*piv_len = iv_required_len;
*piv = iv_new;
diff --git a/ext/openssl/tests/openssl_csr_new_basic.phpt b/ext/openssl/tests/openssl_csr_new_basic.phpt
index a3a4746b39..e0f52d739f 100644
--- a/ext/openssl/tests/openssl_csr_new_basic.phpt
+++ b/ext/openssl/tests/openssl_csr_new_basic.phpt
@@ -9,16 +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()));
+
+$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();
-var_dump(openssl_csr_new(["countryName" => "DE"], $x, ["x509_extensions" => 0xDEADBEEF]));
+$x = openssl_pkey_new($conf);
+var_dump(openssl_csr_new(["countryName" => "DE"], $x, $conf + ["x509_extensions" => 0xDEADBEEF]));
echo "Done\n";
diff --git a/ext/openssl/tests/openssl_x509_check_private_key_basic.phpt b/ext/openssl/tests/openssl_x509_check_private_key_basic.phpt
index df18322453..b4842aae18 100644
--- a/ext/openssl/tests/openssl_x509_check_private_key_basic.phpt
+++ b/ext/openssl/tests/openssl_x509_check_private_key_basic.phpt
@@ -5,11 +5,11 @@ 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_rsa_1024.key","r");
-$b = fread($fp,8192);
+$b = fread($fp, 8192);
fclose($fp);
$cert = "file://" . dirname(__FILE__) . "/cert.crt";
diff --git a/ext/openssl/tests/openssl_x509_export_basic.phpt b/ext/openssl/tests/openssl_x509_export_basic.phpt
index 712fe4ca80..4177bd7798 100644
--- a/ext/openssl/tests/openssl_x509_export_basic.phpt
+++ b/ext/openssl/tests/openssl_x509_export_basic.phpt
@@ -1,43 +1,22 @@
--TEST--
-openssl_x509_export() and openssl_x509_export_to_file() tests
+openssl_x509_export() tests
--SKIPIF--
<?php if (!extension_loaded("openssl")) print "skip"; ?>
--FILE--
<?php
-$fp = fopen(dirname(__FILE__) . "/cert.crt","r");
-$a = fread($fp,8192);
-fclose($fp);
+$cert_file = dirname(__FILE__) . "/cert.crt";
-$b = "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
-
-$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";
+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);
@@ -46,9 +25,8 @@ if (PHP_EOL !== "\n") {
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
-
+var_dump(strcmp($output, $output4)); // different
+var_dump(strcmp($output, $output5)); // different
?>
--EXPECTF--
bool(true)
@@ -60,19 +38,6 @@ 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)
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_basic.phpt b/ext/openssl/tests/openssl_x509_fingerprint_basic.phpt
index 6cd464a894..766b158fab 100644
--- a/ext/openssl/tests/openssl_x509_fingerprint_basic.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_read_basic.phpt b/ext/openssl/tests/openssl_x509_read_basic.phpt
index cc36e989c6..5f530534ff 100644
--- a/ext/openssl/tests/openssl_x509_read_basic.phpt
+++ b/ext/openssl/tests/openssl_x509_read_basic.phpt
@@ -1,5 +1,5 @@
--TEST--
-openssl_x509_read() tests with testing openssl_x509_free as well
+openssl_x509_read() tests
--SKIPIF--
<?php if (!extension_loaded("openssl")) print "skip"; ?>
--FILE--
@@ -14,47 +14,24 @@ $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);
+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 (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)