1--TEST--
2openssl_pkcs12_export() tests
3--SKIPIF--
4<?php if (!extension_loaded("openssl")) print "skip"; ?>
5--FILE--
6<?php
7$cert_file = dirname(__FILE__) . "/public.crt";
8$cert = file_get_contents($cert_file);
9$cert_path = "file://" . $cert_file;
10$priv_file = dirname(__FILE__) . "/private.crt";
11$priv = file_get_contents($priv_file);
12$priv_path = "file://" . $priv_file;
13$cert_res = openssl_x509_read($cert);
14$priv_res = openssl_pkey_get_private($priv);
15$pass = "test";
16$invalid = "";
17$invalid_path = dirname(__FILE__) . "/invalid_path";
18$opts = [];
19
20var_dump(openssl_pkcs12_export($cert, $output, $priv, $pass)); // read certs as a string
21var_dump(openssl_pkcs12_read($output, $opts, $pass));
22var_dump(openssl_pkcs12_export($cert_path, $output, $priv_path, $pass)); // read certs from a filename string
23var_dump(openssl_pkcs12_read($output, $opts, $pass));
24var_dump(openssl_pkcs12_export($cert_res, $output, $priv_res, $pass)); // read certs from a resource
25var_dump(openssl_pkcs12_read($output, $opts, $pass));
26var_dump(openssl_pkcs12_export($cert, $output, $priv, $pass, array('extracerts' => $cert))); // extra optional cert
27var_dump(openssl_pkcs12_read($output, $opts, $pass));
28var_dump(count($opts)); // should be 3 certificates, priv, pub, extra optional cert
29
30
31var_dump(openssl_pkcs12_export($invalid, $output, $invalid, $pass));
32var_dump(openssl_pkcs12_export($invalid_path, $output, $invalid_path, $pass));
33var_dump(openssl_pkcs12_export($priv_res, $output, $cert_res, $pass));
34//var_dump(openssl_pkcs12_export($cert, $output, $priv, $pass, array("foo")));
35?>
36--EXPECTF--
37bool(true)
38bool(true)
39bool(true)
40bool(true)
41bool(true)
42bool(true)
43bool(true)
44bool(true)
45int(3)
46
47Warning: openssl_pkcs12_export(): cannot get cert from parameter 1 in %s on line %d
48bool(false)
49
50Warning: openssl_pkcs12_export(): cannot get cert from parameter 1 in %s on line %d
51bool(false)
52
53Warning: openssl_pkcs12_export(): supplied resource is not a valid OpenSSL X.509 resource in %s on line %d
54
55Warning: openssl_pkcs12_export(): cannot get cert from parameter 1 in %s on line %d
56bool(false)
57