25-test_eai_data.t 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #! /usr/bin/env perl
  2. # Copyright 2019-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 strict;
  9. use warnings;
  10. use File::Spec;
  11. use OpenSSL::Test::Utils;
  12. use OpenSSL::Test qw/:DEFAULT srctop_file with/;
  13. setup("test_eai_data");
  14. #./util/wrap.pl apps/openssl verify -nameopt utf8 -no_check_time -CAfile test/recipes/25-test_eai_data/ascii_chain.pem test/recipes/25-test_eai_data/ascii_leaf.pem
  15. #./util/wrap.pl apps/openssl verify -nameopt utf8 -no_check_time -CAfile test/recipes/25-test_eai_data/utf8_chain.pem test/recipes/25-test_eai_data/utf8_leaf.pem
  16. #./util/wrap.pl apps/openssl verify -nameopt utf8 -no_check_time -CAfile test/recipes/25-test_eai_data/utf8_chain.pem test/recipes/25-test_eai_data/ascii_leaf.pem
  17. #./util/wrap.pl apps/openssl verify -nameopt utf8 -no_check_time -CAfile test/recipes/25-test_eai_data/ascii_chain.pem test/recipes/25-test_eai_data/utf8_leaf.pem
  18. plan tests => 12;
  19. require_ok(srctop_file('test','recipes','tconversion.pl'));
  20. my $folder = "test/recipes/25-test_eai_data";
  21. my $ascii_pem = srctop_file($folder, "ascii_leaf.pem");
  22. my $utf8_pem = srctop_file($folder, "utf8_leaf.pem");
  23. my $ascii_chain_pem = srctop_file($folder, "ascii_chain.pem");
  24. my $utf8_chain_pem = srctop_file($folder, "utf8_chain.pem");
  25. my $out;
  26. my $outcnt = 0;
  27. sub outname {
  28. $outcnt++;
  29. return "sanout-$outcnt.tmp";
  30. }
  31. $out = outname();
  32. ok(run(app(["openssl", "x509", "-ext", "subjectAltName", "-in", $ascii_pem, "-noout", "-out", $out])));
  33. is(cmp_text($out, srctop_file($folder, "san.ascii")), 0, 'Comparing othername for ASCII domain');
  34. $out = outname();
  35. ok(run(app(["openssl", "x509", "-ext", "subjectAltName", "-in", $utf8_pem, "-noout", "-out", $out])));
  36. is(cmp_text($out, srctop_file($folder, "san.utf8")), 0, 'Comparing othername for IDN domain');
  37. SKIP: {
  38. skip "Unicode tests disabled on MingW", 2 if $^O =~ /^msys$/;
  39. ok(run(app(["openssl", "verify", "-nameopt", "utf8", "-no_check_time", "-verify_email", "学生\@elementary.school.example.com", "-CAfile", $ascii_chain_pem, $ascii_pem])));
  40. ok(run(app(["openssl", "verify", "-nameopt", "utf8", "-no_check_time", "-verify_email", "医生\@大学.example.com", "-CAfile", $utf8_chain_pem, $utf8_pem])));
  41. }
  42. ok(run(app(["openssl", "verify", "-nameopt", "utf8", "-no_check_time", "-CAfile", $ascii_chain_pem, $ascii_pem])));
  43. ok(run(app(["openssl", "verify", "-nameopt", "utf8", "-no_check_time", "-CAfile", $utf8_chain_pem, $utf8_pem])));
  44. ok(!run(app(["openssl", "verify", "-nameopt", "utf8", "-no_check_time", "-CAfile", $ascii_chain_pem, $utf8_pem])));
  45. ok(!run(app(["openssl", "verify", "-nameopt", "utf8", "-no_check_time", "-CAfile", $utf8_chain_pem, $ascii_pem])));
  46. #Check that we get the expected failure return code
  47. with({ exit_checker => sub { return shift == 2; } },
  48. sub {
  49. ok(run(app(["openssl", "verify", "-CAfile",
  50. srctop_file("test", "certs", "bad-othername-namec.pem"),
  51. "-partial_chain", "-no_check_time", "-verify_email",
  52. 'foo@example.com',
  53. srctop_file("test", "certs", "bad-othername-namec.pem")])));
  54. });