25-test_x509.t 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #! /usr/bin/env perl
  2. # Copyright 2015-2016 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 strict;
  9. use warnings;
  10. use File::Spec;
  11. use OpenSSL::Test::Utils;
  12. use OpenSSL::Test qw/:DEFAULT srctop_file/;
  13. setup("test_x509");
  14. plan tests => 10;
  15. require_ok(srctop_file('test','recipes','tconversion.pl'));
  16. my $pem = srctop_file("test/certs", "cyrillic.pem");
  17. my $out = "cyrillic.out";
  18. my $msb = srctop_file("test/certs", "cyrillic.msb");
  19. my $utf = srctop_file("test/certs", "cyrillic.utf8");
  20. ok(run(app(["openssl", "x509", "-text", "-in", $pem, "-out", $out,
  21. "-nameopt", "esc_msb"])));
  22. is(cmp_text($out, srctop_file("test/certs", "cyrillic.msb")),
  23. 0, 'Comparing esc_msb output');
  24. ok(run(app(["openssl", "x509", "-text", "-in", $pem, "-out", $out,
  25. "-nameopt", "utf8"])));
  26. is(cmp_text($out, srctop_file("test/certs", "cyrillic.utf8")),
  27. 0, 'Comparing utf8 output');
  28. unlink $out;
  29. SKIP: {
  30. skip "EC disabled", 1 if disabled("ec");
  31. # producing and checking self-issued (but not self-signed) cert
  32. my @path = qw(test certs);
  33. my $subj = "/CN=CA"; # using same DN as in issuer of ee-cert.pem
  34. my $pkey = srctop_file(@path, "ca-key.pem"); # issuer private key
  35. my $pubkey = "ca-pubkey.pem"; # the corresponding issuer public key
  36. # use any (different) key for signing our self-issued cert:
  37. my $signkey = srctop_file(@path, "ee-ecdsa-key.pem");
  38. my $selfout = "self-issued.out";
  39. my $testcert = srctop_file(@path, "ee-cert.pem");
  40. ok(run(app(["openssl", "pkey", "-in", $pkey, "-pubout", "-out", $pubkey]))
  41. &&
  42. run(app(["openssl", "x509", "-new", "-force_pubkey", $pubkey,
  43. "-subj", $subj, "-signkey", $signkey, "-out", $selfout]))
  44. &&
  45. run(app(["openssl", "verify", "-no_check_time",
  46. "-trusted", $selfout, $testcert])));
  47. unlink $pubkey;
  48. unlink $selfout;
  49. }
  50. subtest 'x509 -- x.509 v1 certificate' => sub {
  51. tconversion("x509", srctop_file("test","testx509.pem"));
  52. };
  53. subtest 'x509 -- first x.509 v3 certificate' => sub {
  54. tconversion("x509", srctop_file("test","v3-cert1.pem"));
  55. };
  56. subtest 'x509 -- second x.509 v3 certificate' => sub {
  57. tconversion("x509", srctop_file("test","v3-cert2.pem"));
  58. };
  59. subtest 'x509 -- pathlen' => sub {
  60. ok(run(test(["v3ext", srctop_file("test/certs", "pathlen.pem")])));
  61. }