1--TEST--
2openssl_cms_encrypt() pem test
3--EXTENSIONS--
4openssl
5--FILE--
6<?php
7$infile = __DIR__ . "/plain.txt";
8$tname = tempnam(sys_get_temp_dir(), "ssl");
9if ($tname === false)
10    die("failed to get a temporary filename!");
11$cryptfile= $tname . ".pem";
12$decryptfile = $tname . ".pemout";
13$single_cert = "file://" . __DIR__ . "/cert.crt";
14$privkey = "file://" . __DIR__ . "/private_rsa_1024.key";
15$headers = array("test@test", "testing openssl_cms_encrypt()");
16$cipher = OPENSSL_CIPHER_AES_128_CBC;
17
18var_dump(openssl_cms_encrypt($infile, $cryptfile, $single_cert, $headers, OPENSSL_CMS_BINARY, OPENSSL_ENCODING_PEM, $cipher));
19if (openssl_cms_decrypt($cryptfile, $decryptfile, $single_cert, $privkey, OPENSSL_ENCODING_PEM) == false) {
20    print "PEM decrypt error\n";
21    print "recipient:\n";
22    readfile($single_cert);
23    print "input:\n";
24    readfile($infile);
25    print "outfile:\n";
26    readfile($cryptfile);
27    while (( $errstr=openssl_error_string()) != false) {
28        print $errstr . "\n";
29    }
30} else {
31    readfile($decryptfile);
32}
33
34if (file_exists($cryptfile)) {
35    echo "true\n";
36    unlink($cryptfile);
37}
38if (file_exists($decryptfile)) {
39    echo "true\n";
40    unlink($decryptfile);
41}
42unlink($tname);
43?>
44--EXPECT--
45bool(true)
46Now is the winter of our discontent.
47true
48true
49