openssl_x509_fingerprint_basic.phpt 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. --TEST--
  2. openssl_x509_fingerprint() tests
  3. --SKIPIF--
  4. <?php if (!extension_loaded("openssl")) die("skip"); ?>
  5. --FILE--
  6. <?php
  7. $cert = "file://" . dirname(__FILE__) . "/cert.crt";
  8. echo "** Testing with no parameters **\n";
  9. var_dump(openssl_x509_fingerprint());
  10. echo "** Testing default functionality **\n";
  11. var_dump(openssl_x509_fingerprint($cert));
  12. echo "** Testing hash method md5 **\n";
  13. var_dump(openssl_x509_fingerprint($cert, 'md5'));
  14. echo "**Testing raw output md5 **\n";
  15. var_dump(bin2hex(openssl_x509_fingerprint($cert, 'md5', true)));
  16. echo "** Testing hash method sha1 with resource **\n";
  17. $r = openssl_x509_read($cert);
  18. var_dump(openssl_x509_fingerprint($r, 'sha1'));
  19. echo "** Testing bad certification **\n";
  20. var_dump(openssl_x509_fingerprint('123'));
  21. echo "** Testing bad hash method **\n";
  22. var_dump(openssl_x509_fingerprint($cert, 'xx45'));
  23. ?>
  24. --EXPECTF--
  25. ** Testing with no parameters **
  26. Warning: openssl_x509_fingerprint() expects at least 1 parameter, 0 given in %s on line %d
  27. NULL
  28. ** Testing default functionality **
  29. string(40) "6e6fd1ea10a5a23071d61c728ee9b40df6dbc33c"
  30. ** Testing hash method md5 **
  31. string(32) "ac77008e172897e06c0b065294487a67"
  32. **Testing raw output md5 **
  33. string(32) "ac77008e172897e06c0b065294487a67"
  34. ** Testing hash method sha1 with resource **
  35. string(40) "6e6fd1ea10a5a23071d61c728ee9b40df6dbc33c"
  36. ** Testing bad certification **
  37. Warning: openssl_x509_fingerprint(): cannot get cert from parameter 1 in %s on line %d
  38. bool(false)
  39. ** Testing bad hash method **
  40. Warning: openssl_x509_fingerprint(): Unknown signature algorithm in %s on line %d
  41. bool(false)