1--TEST--
2openssl_cms_decrypt() tests
3--SKIPIF--
4<?php if (!extension_loaded("openssl")) print "skip"; ?>
5--FILE--
6<?php
7$infile = __DIR__ . "/plain.txt";
8$privkey = "file://" . __DIR__ . "/private_rsa_1024.key";
9$encrypted = tempnam(sys_get_temp_dir(), "cms_dec_basic");
10if ($encrypted === false)
11    die("failed to get a temporary filename!");
12$outfile = $encrypted . ".out";
13
14$single_cert = "file://" . __DIR__ . "/cert.crt";
15$headers = array("test@test", "testing openssl_cms_encrypt()");
16$wrong = "wrong";
17$empty = "";
18
19openssl_cms_encrypt($infile, $encrypted, $single_cert, $headers);
20
21var_dump(openssl_cms_decrypt($encrypted, $outfile, $single_cert, $privkey));
22print("\nDecrypted text:\n");
23readfile($outfile);
24var_dump(openssl_cms_decrypt($encrypted, $outfile, openssl_x509_read($single_cert), $privkey));
25var_dump(openssl_cms_decrypt($encrypted, $outfile, $single_cert, $wrong));
26var_dump(openssl_cms_decrypt($encrypted, $outfile, $wrong, $privkey));
27var_dump(openssl_cms_decrypt($encrypted, $outfile, null, $privkey));
28var_dump(openssl_cms_decrypt($wrong, $outfile, $single_cert, $privkey));
29var_dump(openssl_cms_decrypt($empty, $outfile, $single_cert, $privkey));
30var_dump(openssl_cms_decrypt($encrypted, $empty, $single_cert, $privkey));
31var_dump(openssl_cms_decrypt($encrypted, $outfile, $empty, $privkey));
32var_dump(openssl_cms_decrypt($encrypted, $outfile, $single_cert, $empty));
33
34if (file_exists($encrypted)) {
35    echo "true\n";
36    unlink($encrypted);
37}
38if (file_exists($outfile)) {
39    echo "true\n";
40    unlink($outfile);
41}
42?>
43--EXPECTF--
44bool(true)
45
46Decrypted text:
47Now is the winter of our discontent.
48bool(true)
49
50Warning: openssl_cms_decrypt(): Unable to get private key in %s on line %d
51bool(false)
52
53Warning: openssl_cms_decrypt(): X.509 Certificate cannot be retrieved in %s on line %d
54bool(false)
55
56Warning: openssl_cms_decrypt(): X.509 Certificate cannot be retrieved in %s on line %d
57bool(false)
58bool(false)
59bool(false)
60bool(false)
61
62Warning: openssl_cms_decrypt(): X.509 Certificate cannot be retrieved in %s on line %d
63bool(false)
64
65Warning: openssl_cms_decrypt(): Unable to get private key in %s on line %d
66bool(false)
67true
68true
69