20-test_enc_more.t 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #! /usr/bin/env perl
  2. # Copyright 2017-2020 The OpenSSL Project Authors. All Rights Reserved.
  3. # Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
  4. #
  5. # Licensed under the Apache License 2.0 (the "License"). You may not use
  6. # this file except in compliance with the License. You can obtain a copy
  7. # in the file LICENSE in the source distribution or at
  8. # https://www.openssl.org/source/license.html
  9. use strict;
  10. use warnings;
  11. use File::Spec::Functions qw/catfile/;
  12. use File::Copy;
  13. use File::Compare qw/compare_text/;
  14. use File::Basename;
  15. use OpenSSL::Test qw/:DEFAULT srctop_file bldtop_dir/;
  16. use OpenSSL::Test::Utils;
  17. setup("test_evp_more");
  18. my $testsrc = srctop_file("test", "recipes", basename($0));
  19. my $cipherlist = undef;
  20. my $plaintext = catfile(".", "testdatafile");
  21. my $fail = "";
  22. my $cmd = "openssl";
  23. my $provpath = bldtop_dir("providers");
  24. my @prov = ("-provider-path", $provpath, "-provider", "default");
  25. push @prov, ("-provider", "legacy") unless disabled("legacy");
  26. my $ciphersstatus = undef;
  27. my @ciphers =
  28. grep(! /wrap|^$|^[^-]/,
  29. (map { split /\s+/ }
  30. run(app([$cmd, "enc", "-list"]),
  31. capture => 1, statusvar => \$ciphersstatus)));
  32. @ciphers = grep {!/^-(bf|blowfish|cast|des$|des-cbc|des-cfb|des-ecb|des-ofb
  33. |desx|idea|rc2|rc4|seed)/x} @ciphers
  34. if disabled("legacy");
  35. plan tests => 2 + scalar @ciphers;
  36. SKIP: {
  37. skip "Problems getting ciphers...", 1 + scalar(@ciphers)
  38. unless ok($ciphersstatus, "Running 'openssl enc -list'");
  39. unless (ok(copy($testsrc, $plaintext), "Copying $testsrc to $plaintext")) {
  40. diag($!);
  41. skip "Not initialized, skipping...", scalar(@ciphers);
  42. }
  43. foreach my $cipher (@ciphers) {
  44. my $ciphername = substr $cipher, 1;
  45. my $cipherfile = "$plaintext.$ciphername.cipher";
  46. my $clearfile = "$plaintext.$ciphername.clear";
  47. my @common = ( $cmd, "enc", "$cipher", "-k", "test" );
  48. ok(run(app([@common, @prov, "-e", "-in", $plaintext, "-out", $cipherfile]))
  49. && compare_text($plaintext, $cipherfile) != 0
  50. && run(app([@common, @prov, "-d", "-in", $cipherfile, "-out", $clearfile]))
  51. && compare_text($plaintext, $clearfile) == 0
  52. , $ciphername);
  53. }
  54. }