1--TEST-- 2openssl_x509_export() and openssl_x509_export_to_file() tests 3--SKIPIF-- 4<?php if (!extension_loaded("openssl")) print "skip"; ?> 5--FILE-- 6<?php 7$fp = fopen(dirname(__FILE__) . "/cert.crt","r"); 8$a = fread($fp,8192); 9fclose($fp); 10 11$b = "file://" . dirname(__FILE__) . "/cert.crt"; 12$c = "invalid cert"; 13$d = openssl_x509_read($a); 14$e = array(); 15 16var_dump(openssl_x509_export($a, $output)); // read cert as a binary string 17var_dump(openssl_x509_export($b, $output2)); // read cert from a filename string 18var_dump(openssl_x509_export($c, $output3)); // read an invalid cert, fails 19var_dump(openssl_x509_export($d, $output4)); // read cert from a resource 20var_dump(openssl_x509_export($e, $output5)); // read an array, fails 21 22$outfilename = tempnam("/tmp", "ssl"); 23if ($outfilename === false) 24 die("failed to get a temporary filename!"); 25 26echo "---\n"; 27 28var_dump(openssl_x509_export_to_file($a, $outfilename)); // read cert as a binary string 29var_dump(openssl_x509_export_to_file($b, $outfilename)); // read cert from a filename string 30var_dump(openssl_x509_export_to_file($c, $outfilename)); // read an invalid cert, fails 31var_dump(openssl_x509_export_to_file($d, $outfilename)); // read cert from a resource 32var_dump(openssl_x509_export_to_file($e, $outfilename)); // read an array, fails 33echo "---\n"; 34 35var_dump($exists = file_exists($outfilename)); 36if ($exists) { 37 @unlink($outfilename); 38} 39echo "---\n"; 40 41var_dump(strcmp($output, $a)); 42var_dump(strcmp($output, $output2)); 43var_dump(strcmp($output, $output3)); 44var_dump(strcmp($output, $output4)); // different 45var_dump(strcmp($output, $output5)); // different 46?> 47--EXPECTF-- 48bool(true) 49bool(true) 50 51Warning: openssl_x509_export(): cannot get cert from parameter 1 in %s on line %d 52bool(false) 53bool(true) 54 55Warning: openssl_x509_export(): cannot get cert from parameter 1 in %s on line %d 56bool(false) 57--- 58bool(true) 59bool(true) 60 61Warning: openssl_x509_export_to_file(): cannot get cert from parameter 1 in %s on line %d 62bool(false) 63bool(true) 64 65Warning: openssl_x509_export_to_file(): cannot get cert from parameter 1 in %s on line %d 66bool(false) 67--- 68bool(true) 69--- 70int(0) 71int(0) 72int(%d) 73int(0) 74int(%d) 75