60-test_x509_check_cert_pkey.t 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #! /usr/bin/env perl
  2. # Copyright 2017-2021 The OpenSSL Project Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License 2.0 (the "License"). You may not use
  5. # this file except in compliance with the License. You can obtain a copy
  6. # in the file LICENSE in the source distribution or at
  7. # https://www.openssl.org/source/license.html
  8. use OpenSSL::Test qw/:DEFAULT srctop_file/;
  9. use OpenSSL::Test::Utils;
  10. setup("test_x509_check_cert_pkey");
  11. plan tests => 11;
  12. sub src_file {
  13. return srctop_file("test", "certs", shift);
  14. }
  15. sub test_PEM_X509_INFO_read {
  16. my $file = shift;
  17. my $num = shift;
  18. ok(run(test(["x509_check_cert_pkey_test", src_file($file), $num])),
  19. "test_PEM_X509_INFO_read $file");
  20. }
  21. # rsa
  22. ok(run(test(["x509_check_cert_pkey_test",
  23. src_file("servercert.pem"),
  24. src_file("serverkey.pem"), "cert", "ok"])));
  25. # mismatched rsa
  26. ok(run(test(["x509_check_cert_pkey_test",
  27. src_file("servercert.pem"),
  28. src_file("wrongkey.pem"), "cert", "failed"])));
  29. SKIP: {
  30. skip "DSA disabled", 1, if disabled("dsa");
  31. # dsa
  32. ok(run(test(["x509_check_cert_pkey_test",
  33. src_file("server-dsa-cert.pem"),
  34. src_file("server-dsa-key.pem"), "cert", "ok"])));
  35. }
  36. # ecc
  37. SKIP: {
  38. skip "EC disabled", 2 if disabled("ec");
  39. ok(run(test(["x509_check_cert_pkey_test",
  40. src_file("server-ecdsa-cert.pem"),
  41. src_file("server-ecdsa-key.pem"), "cert", "ok"])));
  42. test_PEM_X509_INFO_read("ec_privkey_with_chain.pem", "5");
  43. }
  44. # certificate request (rsa)
  45. ok(run(test(["x509_check_cert_pkey_test",
  46. src_file("x509-check.csr"),
  47. src_file("x509-check-key.pem"), "req", "ok"])));
  48. # mismatched certificate request (rsa)
  49. ok(run(test(["x509_check_cert_pkey_test",
  50. src_file("x509-check.csr"),
  51. src_file("wrongkey.pem"), "req", "failed"])));
  52. test_PEM_X509_INFO_read("root-cert.pem", "1");
  53. test_PEM_X509_INFO_read("root-key.pem", "1");
  54. test_PEM_X509_INFO_read("key-pass-12345.pem", "1");
  55. test_PEM_X509_INFO_read("cyrillic_crl.utf8", "1");