25-test_verify_store.t 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #! /usr/bin/env perl
  2. # Copyright 2019-2020 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 OpenSSL::Test qw/:DEFAULT with bldtop_file srctop_file cmdstr/;
  11. use OpenSSL::Test::Utils;
  12. setup("test_verify_store");
  13. plan tests => 10;
  14. my $dummycnf = srctop_file("apps", "openssl.cnf");
  15. my $cnf = srctop_file("test", "ca-and-certs.cnf");
  16. my $CAkey = "keyCA.ss";
  17. my $CAcert="certCA.ss";
  18. my $CAserial="certCA.srl";
  19. my $CAreq="reqCA.ss";
  20. my $CAreq2="req2CA.ss"; # temp
  21. my $Ukey="keyU.ss";
  22. my $Ureq="reqU.ss";
  23. my $Ucert="certU.ss";
  24. SKIP: {
  25. req( 'make cert request',
  26. qw(-new -section userreq),
  27. -config => $cnf,
  28. -out => $CAreq,
  29. -keyout => $CAkey );
  30. skip 'failure', 8 unless
  31. x509( 'convert request into self-signed cert',
  32. qw(-req -CAcreateserial -days 30),
  33. qw(-extensions v3_ca),
  34. -in => $CAreq,
  35. -out => $CAcert,
  36. -signkey => $CAkey,
  37. -extfile => $cnf );
  38. skip 'failure', 7 unless
  39. x509( 'convert cert into a cert request',
  40. qw(-x509toreq),
  41. -in => $CAcert,
  42. -out => $CAreq2,
  43. -signkey => $CAkey );
  44. skip 'failure', 6 unless
  45. req( 'verify request 1',
  46. qw(-verify -noout -section userreq),
  47. -config => $dummycnf,
  48. -in => $CAreq );
  49. skip 'failure', 5 unless
  50. req( 'verify request 2',
  51. qw(-verify -noout -section userreq),
  52. -config => $dummycnf,
  53. -in => $CAreq2 );
  54. skip 'failure', 4 unless
  55. verify( 'verify signature',
  56. -CAstore => $CAcert,
  57. $CAcert );
  58. skip 'failure', 3 unless
  59. req( 'make a user cert request',
  60. qw(-new -section userreq),
  61. -config => $cnf,
  62. -out => $Ureq,
  63. -keyout => $Ukey );
  64. skip 'failure', 2 unless
  65. x509( 'sign user cert request',
  66. qw(-req -CAcreateserial -days 30 -extensions v3_ee),
  67. -in => $Ureq,
  68. -out => $Ucert,
  69. -CA => $CAcert,
  70. -CAkey => $CAkey,
  71. -CAserial => $CAserial,
  72. -extfile => $cnf )
  73. && verify( undef,
  74. -CAstore => $CAcert,
  75. $Ucert );
  76. skip 'failure', 0 unless
  77. x509( 'Certificate details',
  78. qw(-subject -issuer -startdate -enddate -noout),
  79. -in => $Ucert );
  80. }
  81. sub verify {
  82. my $title = shift;
  83. ok(run(app([qw(openssl verify), @_])), $title);
  84. }
  85. sub req {
  86. my $title = shift;
  87. ok(run(app([qw(openssl req), @_])), $title);
  88. }
  89. sub x509 {
  90. my $title = shift;
  91. ok(run(app([qw(openssl x509), @_])), $title);
  92. }