1--TEST--
2openssl_pkcs7_encrypt() tests
3--EXTENSIONS--
4openssl
5--FILE--
6<?php
7$infile = __DIR__ . "/cert.crt";
8$outfile = tempnam(sys_get_temp_dir(), "ssl");
9if ($outfile === false)
10    die("failed to get a temporary filename!");
11$outfile2 = tempnam(sys_get_temp_dir(), "ssl");
12if ($outfile2 === false)
13    die("failed to get a temporary filename!");
14$outfile3 = tempnam(sys_get_temp_dir(), "ssl");
15if ($outfile3 === false)
16    die("failed to get a temporary filename!");
17
18$single_cert = "file://" . __DIR__ . "/cert.crt";
19$privkey = "file://" . __DIR__ . "/private_rsa_1024.key";
20$multi_certs = array($single_cert, $single_cert);
21$assoc_headers = array("To" => "test@test", "Subject" => "testing openssl_pkcs7_encrypt()");
22$headers = array("test@test", "testing openssl_pkcs7_encrypt()");
23$empty_headers = array();
24$wrong = "wrong";
25$empty = "";
26$cipher = OPENSSL_CIPHER_AES_128_CBC;
27
28var_dump(openssl_pkcs7_encrypt($infile, $outfile, $single_cert, $headers, 0, $cipher));
29var_dump(openssl_pkcs7_encrypt($infile, $outfile, openssl_x509_read($single_cert), $headers, 0, $cipher));
30var_dump(openssl_pkcs7_decrypt($outfile, $outfile2, $single_cert, $privkey));
31var_dump(openssl_pkcs7_encrypt($infile, $outfile, $single_cert, $assoc_headers, 0, $cipher));
32var_dump(openssl_pkcs7_encrypt($infile, $outfile, $single_cert, $empty_headers, 0, $cipher));
33var_dump(openssl_pkcs7_encrypt($wrong, $outfile, $single_cert, $headers, 0, $cipher));
34var_dump(openssl_pkcs7_encrypt($empty, $outfile, $single_cert, $headers, 0, $cipher));
35var_dump(openssl_pkcs7_encrypt($infile, $empty, $single_cert, $headers, 0, $cipher));
36var_dump(openssl_pkcs7_encrypt($infile, $outfile, $wrong, $headers, 0, $cipher));
37var_dump(openssl_pkcs7_encrypt($infile, $outfile, $empty, $headers, 0, $cipher));
38var_dump(openssl_pkcs7_encrypt($infile, $outfile, $multi_certs, $headers, 0, $cipher));
39var_dump(openssl_pkcs7_encrypt($infile, $outfile, array_map('openssl_x509_read', $multi_certs), $headers, 0, $cipher));
40var_dump(openssl_pkcs7_encrypt($infile, $outfile3, $single_cert, $headers, PKCS7_NOOLDMIMETYPE, $cipher));
41
42if (file_exists($outfile)) {
43    echo "true\n";
44    unlink($outfile);
45}
46if (file_exists($outfile2)) {
47    echo "true\n";
48    unlink($outfile2);
49}
50
51if (file_exists($outfile3)) {
52    $content = file_get_contents($outfile3, false, null, 0, 256);
53    if (str_contains($content, 'Content-Type: application/pkcs7-mime; smime-type=enveloped-data; name="smime.p7m"')) {
54        echo "true\n";
55    }
56    unset($content);
57    unlink($outfile3);
58}
59?>
60--EXPECT--
61bool(true)
62bool(true)
63bool(true)
64bool(true)
65bool(true)
66bool(false)
67bool(false)
68bool(false)
69bool(false)
70bool(false)
71bool(true)
72bool(true)
73bool(true)
74true
75true
76true
77