1--TEST--
2openssl_pkcs7_sign() tests
3--SKIPIF--
4<?php if (!extension_loaded("openssl")) print "skip"; ?>
5--FILE--
6<?php
7$infile = dirname(__FILE__) . "/cert.crt";
8$outfile = tempnam(sys_get_temp_dir(), "ssl");
9if ($outfile === false) {
10    die("failed to get a temporary filename!");
11}
12
13$privkey = "file://" . dirname(__FILE__) . "/private_rsa_1024.key";
14$single_cert = "file://" . dirname(__FILE__) . "/cert.crt";
15$assoc_headers = array("To" => "test@test", "Subject" => "testing openssl_pkcs7_sign()");
16$headers = array("test@test", "testing openssl_pkcs7_sign()");
17$empty_headers = array();
18$wrong = "wrong";
19$empty = "";
20
21var_dump(openssl_pkcs7_sign($infile, $outfile, openssl_x509_read($single_cert), $privkey, $headers));
22var_dump(openssl_pkcs7_sign($infile, $outfile, $single_cert, $privkey, $headers));
23var_dump(openssl_pkcs7_sign($infile, $outfile, $single_cert, $privkey, $assoc_headers));
24var_dump(openssl_pkcs7_sign($infile, $outfile, $single_cert, $privkey, $empty_headers));
25var_dump(openssl_pkcs7_sign($infile, $outfile, $single_cert, $privkey, $wrong));
26var_dump(openssl_pkcs7_sign($wrong, $outfile, $single_cert, $privkey, $headers));
27var_dump(openssl_pkcs7_sign($empty, $outfile, $single_cert, $privkey, $headers));
28var_dump(openssl_pkcs7_sign($infile, $empty, $single_cert, $privkey, $headers));
29var_dump(openssl_pkcs7_sign($infile, $outfile, $wrong, $privkey, $headers));
30var_dump(openssl_pkcs7_sign($infile, $outfile, $empty, $privkey, $headers));
31var_dump(openssl_pkcs7_sign($infile, $outfile, $single_cert, $privkey, $empty));
32var_dump(openssl_pkcs7_sign($infile, $outfile, $single_cert, $wrong, $headers));
33
34if (file_exists($outfile)) {
35    echo "true\n";
36    unlink($outfile);
37}
38?>
39--EXPECTF--
40bool(true)
41bool(true)
42bool(true)
43bool(true)
44
45Warning: openssl_pkcs7_sign() expects parameter 5 to be array, string given in %s on line %d
46NULL
47
48Warning: openssl_pkcs7_sign(): error opening input file %s in %s on line %d
49bool(false)
50
51Warning: openssl_pkcs7_sign(): error opening input file %s in %s on line %d
52bool(false)
53
54Warning: openssl_pkcs7_sign(): error opening output file %s in %s on line %d
55bool(false)
56
57Warning: openssl_pkcs7_sign(): error getting cert in %s on line %d
58bool(false)
59
60Warning: openssl_pkcs7_sign(): error getting cert in %s on line %d
61bool(false)
62
63Warning: openssl_pkcs7_sign() expects parameter 5 to be array, string given in %s on line %d
64NULL
65
66Warning: openssl_pkcs7_sign(): error getting private key in %s on line %d
67bool(false)
68true
69