2008-07-18 23:52:01 +00:00
|
|
|
--TEST--
|
|
|
|
openssl_pkcs7_decrypt() tests
|
|
|
|
--SKIPIF--
|
|
|
|
<?php if (!extension_loaded("openssl")) print "skip"; ?>
|
|
|
|
--FILE--
|
|
|
|
<?php
|
|
|
|
$infile = dirname(__FILE__) . "/cert.crt";
|
2016-01-31 13:54:16 +00:00
|
|
|
$privkey = "file://" . dirname(__FILE__) . "/private_rsa_1024.key";
|
2016-06-17 15:03:13 +00:00
|
|
|
$encrypted = tempnam(sys_get_temp_dir(), "ssl");
|
2008-07-18 23:52:01 +00:00
|
|
|
if ($encrypted === false)
|
2018-06-21 15:38:19 +00:00
|
|
|
die("failed to get a temporary filename!");
|
2016-06-17 15:03:13 +00:00
|
|
|
$outfile = tempnam(sys_get_temp_dir(), "ssl");
|
2008-07-18 23:52:01 +00:00
|
|
|
if ($outfile === false) {
|
2018-06-21 15:38:19 +00:00
|
|
|
unlink($outfile);
|
|
|
|
die("failed to get a temporary filename!");
|
2008-07-18 23:52:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$single_cert = "file://" . dirname(__FILE__) . "/cert.crt";
|
|
|
|
$headers = array("test@test", "testing openssl_pkcs7_encrypt()");
|
|
|
|
$wrong = "wrong";
|
|
|
|
$empty = "";
|
|
|
|
|
|
|
|
openssl_pkcs7_encrypt($infile, $encrypted, $single_cert, $headers);
|
|
|
|
var_dump(openssl_pkcs7_decrypt($encrypted, $outfile, $single_cert, $privkey));
|
2017-10-30 14:16:03 +00:00
|
|
|
var_dump(openssl_pkcs7_decrypt($encrypted, $outfile, openssl_x509_read($single_cert), $privkey));
|
2008-07-18 23:52:01 +00:00
|
|
|
var_dump(openssl_pkcs7_decrypt($encrypted, $outfile, $single_cert, $wrong));
|
|
|
|
var_dump(openssl_pkcs7_decrypt($encrypted, $outfile, $wrong, $privkey));
|
|
|
|
var_dump(openssl_pkcs7_decrypt($encrypted, $outfile, null, $privkey));
|
|
|
|
var_dump(openssl_pkcs7_decrypt($wrong, $outfile, $single_cert, $privkey));
|
|
|
|
var_dump(openssl_pkcs7_decrypt($empty, $outfile, $single_cert, $privkey));
|
|
|
|
var_dump(openssl_pkcs7_decrypt($encrypted, $empty, $single_cert, $privkey));
|
|
|
|
var_dump(openssl_pkcs7_decrypt($encrypted, $outfile, $empty, $privkey));
|
|
|
|
var_dump(openssl_pkcs7_decrypt($encrypted, $outfile, $single_cert, $empty));
|
|
|
|
|
|
|
|
if (file_exists($encrypted)) {
|
2018-06-21 15:38:19 +00:00
|
|
|
echo "true\n";
|
|
|
|
unlink($encrypted);
|
2008-07-18 23:52:01 +00:00
|
|
|
}
|
|
|
|
if (file_exists($outfile)) {
|
2018-06-21 15:38:19 +00:00
|
|
|
echo "true\n";
|
|
|
|
unlink($outfile);
|
2008-07-18 23:52:01 +00:00
|
|
|
}
|
|
|
|
?>
|
|
|
|
--EXPECTF--
|
|
|
|
bool(true)
|
2017-10-30 14:16:03 +00:00
|
|
|
bool(true)
|
2008-07-18 23:52:01 +00:00
|
|
|
|
|
|
|
Warning: openssl_pkcs7_decrypt(): unable to get private key in %s on line %d
|
|
|
|
bool(false)
|
|
|
|
|
|
|
|
Warning: openssl_pkcs7_decrypt(): unable to coerce parameter 3 to x509 cert in %s on line %d
|
|
|
|
bool(false)
|
|
|
|
|
|
|
|
Warning: openssl_pkcs7_decrypt(): unable to coerce parameter 3 to x509 cert in %s on line %d
|
|
|
|
bool(false)
|
|
|
|
bool(false)
|
|
|
|
bool(false)
|
|
|
|
bool(false)
|
|
|
|
|
|
|
|
Warning: openssl_pkcs7_decrypt(): unable to coerce parameter 3 to x509 cert in %s on line %d
|
|
|
|
bool(false)
|
|
|
|
|
|
|
|
Warning: openssl_pkcs7_decrypt(): unable to get private key in %s on line %d
|
|
|
|
bool(false)
|
|
|
|
true
|
|
|
|
true
|