1--TEST--
2openssl_cms_encrypt() der test
3--SKIPIF--
4<?php if (!extension_loaded("openssl")) print "skip";
5?>
6--FILE--
7<?php
8$infile = __DIR__ . "/plain.txt";
9$tname = tempnam(sys_get_temp_dir(), "ssl");
10if ($tname === false)
11    die("failed to get a temporary filename!");
12$cryptfile= $tname . ".der";
13$decryptfile = $tname . ".out";
14$single_cert = "file://" . __DIR__ . "/cert.crt";
15$privkey = "file://" . __DIR__ . "/private_rsa_1024.key";
16$headers = array("test@test", "testing openssl_cms_encrypt()");
17
18var_dump(openssl_cms_encrypt($infile, $cryptfile, $single_cert, $headers, OPENSSL_CMS_BINARY, OPENSSL_ENCODING_DER));
19if (openssl_cms_decrypt($cryptfile, $decryptfile, $single_cert, $privkey, OPENSSL_ENCODING_DER) == false) {
20    print "DER decrypt error\n";
21    print "recipient:\n";
22    readfile($single_cert);
23    print "input:\n";
24    readfile($infile);
25    $der=file_get_contents($cryptfile);
26    print "outfile base64:\n" . base64_encode($der) . "\n--------\n";
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
50