2 openssl_x509_export() and openssl_x509_export_to_file() tests
4 <?php if (!extension_loaded("openssl")) print "skip"; ?>
7 $fp = fopen(dirname(__FILE__) . "/cert.crt","r");
11 $b = "file://" . dirname(__FILE__) . "/cert.crt";
13 $d = openssl_x509_read($a);
16 var_dump(openssl_x509_export($a, $output)); // read cert as a binary string
17 var_dump(openssl_x509_export($b, $output2)); // read cert from a filename string
18 var_dump(openssl_x509_export($c, $output3)); // read an invalid cert, fails
19 var_dump(openssl_x509_export($d, $output4)); // read cert from a resource
20 var_dump(openssl_x509_export($e, $output5)); // read an array, fails
22 $outfilename = tempnam("/tmp", "ssl");
23 if ($outfilename === false)
24 die("failed to get a temporary filename!");
28 var_dump(openssl_x509_export_to_file($a, $outfilename)); // read cert as a binary string
29 var_dump(openssl_x509_export_to_file($b, $outfilename)); // read cert from a filename string
30 var_dump(openssl_x509_export_to_file($c, $outfilename)); // read an invalid cert, fails
31 var_dump(openssl_x509_export_to_file($d, $outfilename)); // read cert from a resource
32 var_dump(openssl_x509_export_to_file($e, $outfilename)); // read an array, fails
35 var_dump($exists = file_exists($outfilename));
37 @unlink($outfilename);
41 var_dump(strcmp($output, $a));
42 var_dump(strcmp($output, $output2));
43 var_dump(strcmp($output, $output3));
44 var_dump(strcmp($output, $output4)); // different
45 var_dump(strcmp($output, $output5)); // different
51 Warning: openssl_x509_export(): cannot get cert from parameter 1 in %s on line %d
55 Warning: openssl_x509_export(): cannot get cert from parameter 1 in %s on line %d
61 Warning: openssl_x509_export_to_file(): cannot get cert from parameter 1 in %s on line %d
65 Warning: openssl_x509_export_to_file(): cannot get cert from parameter 1 in %s on line %d