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 |
|
---|
10 |
|
---|
11 | use strict;
|
---|
12 | use warnings;
|
---|
13 |
|
---|
14 | use File::Spec::Functions qw/catfile/;
|
---|
15 | use File::Copy;
|
---|
16 | use File::Compare qw/compare_text/;
|
---|
17 | use File::Basename;
|
---|
18 | use OpenSSL::Test qw/:DEFAULT srctop_file bldtop_dir/;
|
---|
19 | use OpenSSL::Test::Utils;
|
---|
20 |
|
---|
21 |
|
---|
22 | setup("test_evp_more");
|
---|
23 |
|
---|
24 | my $testsrc = srctop_file("test", "recipes", basename($0));
|
---|
25 |
|
---|
26 | my $cipherlist = undef;
|
---|
27 | my $plaintext = catfile(".", "testdatafile");
|
---|
28 | my $fail = "";
|
---|
29 | my $cmd = "openssl";
|
---|
30 | my $provpath = bldtop_dir("providers");
|
---|
31 | my @prov = ("-provider-path", $provpath, "-provider", "default");
|
---|
32 | push @prov, ("-provider", "legacy") unless disabled("legacy");
|
---|
33 |
|
---|
34 | my $ciphersstatus = undef;
|
---|
35 | my @ciphers =
|
---|
36 | grep(! /wrap|^$|^[^-]/,
|
---|
37 | (map { split /\s+/ }
|
---|
38 | run(app([$cmd, "enc", "-list"]),
|
---|
39 | capture => 1, statusvar => \$ciphersstatus)));
|
---|
40 | @ciphers = grep {!/^-(bf|blowfish|cast|des$|des-cbc|des-cfb|des-ecb|des-ofb
|
---|
41 | |desx|idea|rc2|rc4|seed)/x} @ciphers
|
---|
42 | if disabled("legacy");
|
---|
43 |
|
---|
44 | plan tests => 2 + scalar @ciphers;
|
---|
45 |
|
---|
46 | SKIP: {
|
---|
47 | skip "Problems getting ciphers...", 1 + scalar(@ciphers)
|
---|
48 | unless ok($ciphersstatus, "Running 'openssl enc -list'");
|
---|
49 | unless (ok(copy($testsrc, $plaintext), "Copying $testsrc to $plaintext")) {
|
---|
50 | diag($!);
|
---|
51 | skip "Not initialized, skipping...", scalar(@ciphers);
|
---|
52 | }
|
---|
53 |
|
---|
54 | foreach my $cipher (@ciphers) {
|
---|
55 | my $ciphername = substr $cipher, 1;
|
---|
56 | my $cipherfile = "$plaintext.$ciphername.cipher";
|
---|
57 | my $clearfile = "$plaintext.$ciphername.clear";
|
---|
58 | my @common = ( $cmd, "enc", "$cipher", "-k", "test" );
|
---|
59 |
|
---|
60 | ok(run(app([@common, @prov, "-e", "-in", $plaintext, "-out", $cipherfile]))
|
---|
61 | && compare_text($plaintext, $cipherfile) != 0
|
---|
62 | && run(app([@common, @prov, "-d", "-in", $cipherfile, "-out", $clearfile]))
|
---|
63 | && compare_text($plaintext, $clearfile) == 0
|
---|
64 | , $ciphername);
|
---|
65 | }
|
---|
66 | }
|
---|