1--TEST-- 2openssl_x509_read() and openssl_x509_free() 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$f = array($b); 16 17var_dump($res = openssl_x509_read($a)); // read cert as a string 18openssl_x509_free($res); 19var_dump($res); 20var_dump($res = openssl_x509_read($b)); // read cert as a filename string 21openssl_x509_free($res); 22var_dump($res); 23var_dump($res = openssl_x509_read($c)); // read an invalid cert, fails 24openssl_x509_free($res); 25var_dump($res); 26var_dump($res = openssl_x509_read($d)); // read cert from a resource 27openssl_x509_free($res); 28var_dump($res); 29var_dump($res = openssl_x509_read($e)); // read an array 30openssl_x509_free($res); 31var_dump($res); 32var_dump($res = openssl_x509_read($f)); // read an array with the filename 33openssl_x509_free($res); 34var_dump($res); 35?> 36--EXPECTF-- 37resource(%d) of type (OpenSSL X.509) 38resource(%d) of type (Unknown) 39resource(%d) of type (OpenSSL X.509) 40resource(%d) of type (Unknown) 41 42Warning: openssl_x509_read(): supplied parameter cannot be coerced into an X509 certificate! in %s on line %d 43bool(false) 44 45Warning: openssl_x509_free() expects parameter 1 to be resource, boolean given in %s on line %d 46bool(false) 47resource(%d) of type (OpenSSL X.509) 48resource(%d) of type (Unknown) 49 50Warning: openssl_x509_read(): supplied parameter cannot be coerced into an X509 certificate! in %s on line %d 51bool(false) 52 53Warning: openssl_x509_free() expects parameter 1 to be resource, boolean given in %s on line %d 54bool(false) 55 56Warning: openssl_x509_read(): supplied parameter cannot be coerced into an X509 certificate! in %s on line %d 57bool(false) 58 59Warning: openssl_x509_free() expects parameter 1 to be resource, boolean given in %s on line %d 60bool(false) 61