1--TEST--
2openssl_pkcs12_export() tests
3--EXTENSIONS--
4openssl
5--FILE--
6<?php
7$cert_file = __DIR__ . "/public.crt";
8$cert = file_get_contents($cert_file);
9$cert_path = "file://" . $cert_file;
10$priv_file = __DIR__ . "/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 = __DIR__ . "/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));
33try {
34    var_dump(openssl_pkcs12_export($priv_res, $output, $cert_res, $pass));
35} catch (TypeError $e) {
36    echo $e->getMessage(), "\n";
37}
38//var_dump(openssl_pkcs12_export($cert, $output, $priv, $pass, array("foo")));
39?>
40--EXPECTF--
41bool(true)
42bool(true)
43bool(true)
44bool(true)
45bool(true)
46bool(true)
47bool(true)
48bool(true)
49int(3)
50
51Warning: openssl_pkcs12_export(): X.509 Certificate cannot be retrieved in %s on line %d
52bool(false)
53
54Warning: openssl_pkcs12_export(): X.509 Certificate cannot be retrieved in %s on line %d
55bool(false)
56openssl_pkcs12_export(): Argument #1 ($certificate) must be of type OpenSSLCertificate|string, OpenSSLAsymmetricKey given
57