2016-04-22 19:21:51 +08:00
|
|
|
#! /usr/bin/env perl
|
2020-04-23 20:55:52 +08:00
|
|
|
# Copyright 2015-2020 The OpenSSL Project Authors. All Rights Reserved.
|
2016-04-22 19:21:51 +08:00
|
|
|
#
|
2018-12-06 20:05:25 +08:00
|
|
|
# Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-04-22 19:21:51 +08:00
|
|
|
# this file except in compliance with the License. You can obtain a copy
|
|
|
|
# in the file LICENSE in the source distribution or at
|
|
|
|
# https://www.openssl.org/source/license.html
|
|
|
|
|
2015-04-18 02:07:13 +08:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use File::Spec::Functions qw/catfile/;
|
|
|
|
use File::Copy;
|
|
|
|
use File::Compare qw/compare_text/;
|
|
|
|
use File::Basename;
|
2020-04-09 10:47:46 +08:00
|
|
|
use OpenSSL::Test qw/:DEFAULT srctop_file bldtop_dir/;
|
2015-04-18 02:07:13 +08:00
|
|
|
|
|
|
|
setup("test_enc");
|
|
|
|
|
|
|
|
# We do it this way, because setup() may have moved us around,
|
|
|
|
# so the directory portion of $0 might not be correct any more.
|
|
|
|
# However, the name hasn't changed.
|
2016-01-30 08:05:33 +08:00
|
|
|
my $testsrc = srctop_file("test","recipes",basename($0));
|
2015-04-18 02:07:13 +08:00
|
|
|
|
|
|
|
my $test = catfile(".", "p");
|
|
|
|
|
|
|
|
my $cmd = "openssl";
|
2020-04-09 10:47:46 +08:00
|
|
|
my $provpath = bldtop_dir("providers");
|
2020-08-17 13:40:00 +08:00
|
|
|
my @prov = ("-provider-path", $provpath, "-provider", "default", "-provider", "legacy");
|
2015-04-18 02:07:13 +08:00
|
|
|
|
2017-03-21 18:26:28 +08:00
|
|
|
my $ciphersstatus = undef;
|
2015-04-18 02:07:13 +08:00
|
|
|
my @ciphers =
|
2015-10-13 04:24:27 +08:00
|
|
|
map { s/^\s+//; s/\s+$//; split /\s+/ }
|
2017-03-21 18:26:28 +08:00
|
|
|
run(app([$cmd, "list", "-cipher-commands"]),
|
|
|
|
capture => 1, statusvar => \$ciphersstatus);
|
2015-04-18 02:07:13 +08:00
|
|
|
|
2017-03-21 18:26:28 +08:00
|
|
|
plan tests => 2 + (scalar @ciphers)*2;
|
2015-04-18 02:07:13 +08:00
|
|
|
|
|
|
|
SKIP: {
|
2017-03-21 18:26:28 +08:00
|
|
|
skip "Problems getting ciphers...", 1 + scalar(@ciphers)
|
|
|
|
unless ok($ciphersstatus, "Running 'openssl list -cipher-commands'");
|
|
|
|
unless (ok(copy($testsrc, $test), "Copying $testsrc to $test")) {
|
|
|
|
diag($!);
|
|
|
|
skip "Not initialized, skipping...", scalar(@ciphers);
|
|
|
|
}
|
2015-04-18 02:07:13 +08:00
|
|
|
|
|
|
|
foreach my $c (@ciphers) {
|
|
|
|
my %variant = ("$c" => [],
|
|
|
|
"$c base64" => [ "-a" ]);
|
|
|
|
|
|
|
|
foreach my $t (sort keys %variant) {
|
|
|
|
my $cipherfile = "$test.$c.cipher";
|
|
|
|
my $clearfile = "$test.$c.clear";
|
|
|
|
my @e = ( "$c", "-bufsize", "113", @{$variant{$t}}, "-e", "-k", "test" );
|
|
|
|
my @d = ( "$c", "-bufsize", "157", @{$variant{$t}}, "-d", "-k", "test" );
|
|
|
|
if ($c eq "cat") {
|
|
|
|
$cipherfile = "$test.cipher";
|
|
|
|
$clearfile = "$test.clear";
|
|
|
|
@e = ( "enc", @{$variant{$t}}, "-e" );
|
|
|
|
@d = ( "enc", @{$variant{$t}}, "-d" );
|
|
|
|
}
|
|
|
|
|
2020-04-09 10:47:46 +08:00
|
|
|
ok(run(app([$cmd, @e, @prov, "-in", $test, "-out", $cipherfile]))
|
|
|
|
&& run(app([$cmd, @d, @prov, "-in", $cipherfile, "-out", $clearfile]))
|
2015-04-18 02:07:13 +08:00
|
|
|
&& compare_text($test,$clearfile) == 0, $t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|