25-test_req.t 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #! /usr/bin/env perl
  2. # Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
  3. #
  4. # Licensed under the OpenSSL license (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 OpenSSL::Test::Utils;
  11. use OpenSSL::Test qw/:DEFAULT srctop_file/;
  12. setup("test_req");
  13. plan tests => 4;
  14. require_ok(srctop_file('test','recipes','tconversion.pl'));
  15. open RND, ">>", ".rnd";
  16. print RND "string to make the random number generator think it has randomness";
  17. close RND;
  18. subtest "generating certificate requests" => sub {
  19. my @req_new;
  20. if (disabled("rsa")) {
  21. @req_new = ("-newkey", "dsa:".srctop_file("apps", "dsa512.pem"));
  22. } else {
  23. @req_new = ("-new");
  24. note("There should be a 2 sequences of .'s and some +'s.");
  25. note("There should not be more that at most 80 per line");
  26. }
  27. plan tests => 2;
  28. ok(run(app(["openssl", "req", "-config", srctop_file("test", "test.cnf"),
  29. @req_new, "-out", "testreq.pem"])),
  30. "Generating request");
  31. ok(run(app(["openssl", "req", "-config", srctop_file("test", "test.cnf"),
  32. "-verify", "-in", "testreq.pem", "-noout"])),
  33. "Verifying signature on request");
  34. };
  35. my @openssl_args = ("req", "-config", srctop_file("apps", "openssl.cnf"));
  36. run_conversion('req conversions',
  37. "testreq.pem");
  38. run_conversion('req conversions -- testreq2',
  39. srctop_file("test", "testreq2.pem"));
  40. unlink "testkey.pem", "testreq.pem";
  41. sub run_conversion {
  42. my $title = shift;
  43. my $reqfile = shift;
  44. subtest $title => sub {
  45. run(app(["openssl", @openssl_args,
  46. "-in", $reqfile, "-inform", "p",
  47. "-noout", "-text"],
  48. stderr => "req-check.err", stdout => undef));
  49. open DATA, "req-check.err";
  50. SKIP: {
  51. plan skip_all => "skipping req conversion test for $reqfile"
  52. if grep /Unknown Public Key/, map { s/\R//; } <DATA>;
  53. tconversion("req", $reqfile, @openssl_args);
  54. }
  55. close DATA;
  56. unlink "req-check.err";
  57. done_testing();
  58. };
  59. }