summaryrefslogtreecommitdiff
path: root/ext/openssl/tests/openssl_cms_encrypt_pem.phpt
diff options
context:
space:
mode:
authorEliot Lear <lear@ofcourseimright.com>2020-03-09 16:01:20 +0100
committerJakub Zelenka <bukka@php.net>2020-06-07 16:58:34 +0100
commit8583b8a9bf658a9058e7796513f8cf576d66e48b (patch)
treed2e50ebc6a2484bd263c862510bd26cd2709ab07 /ext/openssl/tests/openssl_cms_encrypt_pem.phpt
parent7439941d55ea9cf7e1280b6b30f596e34a56512c (diff)
downloadphp-git-8583b8a9bf658a9058e7796513f8cf576d66e48b.tar.gz
Add support for Cryptographic Message Syntax (CMS)
It add CMS (RFC 5652) support, which is an update to PKCS7. The functions are analogous BUT NOT IDENTICAL to openssl_pkcs7*. In particular, support for different encodings (PEM, DER, SMIME) is now available.
Diffstat (limited to 'ext/openssl/tests/openssl_cms_encrypt_pem.phpt')
-rw-r--r--ext/openssl/tests/openssl_cms_encrypt_pem.phpt48
1 files changed, 48 insertions, 0 deletions
diff --git a/ext/openssl/tests/openssl_cms_encrypt_pem.phpt b/ext/openssl/tests/openssl_cms_encrypt_pem.phpt
new file mode 100644
index 0000000000..4b99b65465
--- /dev/null
+++ b/ext/openssl/tests/openssl_cms_encrypt_pem.phpt
@@ -0,0 +1,48 @@
+--TEST--
+openssl_cms_encrypt() pem test
+--SKIPIF--
+<?php if (!extension_loaded("openssl")) print "skip";
+?>
+--FILE--
+<?php
+$infile = __DIR__ . "/plain.txt";
+$tname = tempnam(sys_get_temp_dir(), "ssl");
+if ($tname === false)
+ die("failed to get a temporary filename!");
+$cryptfile= $tname . ".pem";
+$decryptfile = $tname . ".pemout";
+$single_cert = "file://" . __DIR__ . "/cert.crt";
+$privkey = "file://" . __DIR__ . "/private_rsa_1024.key";
+$headers = array("test@test", "testing openssl_cms_encrypt()");
+
+var_dump(openssl_cms_encrypt($infile, $cryptfile, $single_cert, $headers, OPENSSL_CMS_BINARY, OPENSSL_ENCODING_PEM));
+if (openssl_cms_decrypt($cryptfile, $decryptfile, $single_cert, $privkey, OPENSSL_ENCODING_PEM) == false) {
+ print "PEM decrypt error\n";
+ print "recipient:\n";
+ readfile($single_cert);
+ print "input:\n";
+ readfile($infile);
+ print "outfile:\n";
+ readfile($cryptfile);
+ while (( $errstr=openssl_error_string()) != false) {
+ print $errstr . "\n";
+ }
+} else {
+ readfile($decryptfile);
+}
+
+if (file_exists($cryptfile)) {
+ echo "true\n";
+ unlink($cryptfile);
+}
+if (file_exists($decryptfile)) {
+ echo "true\n";
+ unlink($decryptfile);
+}
+unlink($tname);
+?>
+--EXPECTF--
+bool(true)
+Now is the winter of our discontent.
+true
+true