1e1051a39Sopenharmony_ci#! /usr/bin/env perl 2e1051a39Sopenharmony_ci# Copyright 2015-2021 The OpenSSL Project Authors. All Rights Reserved. 3e1051a39Sopenharmony_ci# 4e1051a39Sopenharmony_ci# Licensed under the Apache License 2.0 (the "License"). You may not use 5e1051a39Sopenharmony_ci# this file except in compliance with the License. You can obtain a copy 6e1051a39Sopenharmony_ci# in the file LICENSE in the source distribution or at 7e1051a39Sopenharmony_ci# https://www.openssl.org/source/license.html 8e1051a39Sopenharmony_ci 9e1051a39Sopenharmony_ci 10e1051a39Sopenharmony_ciuse strict; 11e1051a39Sopenharmony_ciuse warnings; 12e1051a39Sopenharmony_ci 13e1051a39Sopenharmony_ciuse File::Spec::Functions qw/catfile/; 14e1051a39Sopenharmony_ciuse File::Copy; 15e1051a39Sopenharmony_ciuse File::Compare qw/compare_text/; 16e1051a39Sopenharmony_ciuse File::Basename; 17e1051a39Sopenharmony_ciuse OpenSSL::Test qw/:DEFAULT srctop_file bldtop_dir/; 18e1051a39Sopenharmony_ciuse OpenSSL::Test::Utils; 19e1051a39Sopenharmony_ci 20e1051a39Sopenharmony_cisetup("test_enc"); 21e1051a39Sopenharmony_ciplan skip_all => "Deprecated functions are disabled in this OpenSSL build" 22e1051a39Sopenharmony_ci if disabled("deprecated"); 23e1051a39Sopenharmony_ci 24e1051a39Sopenharmony_ci# We do it this way, because setup() may have moved us around, 25e1051a39Sopenharmony_ci# so the directory portion of $0 might not be correct any more. 26e1051a39Sopenharmony_ci# However, the name hasn't changed. 27e1051a39Sopenharmony_cimy $testsrc = srctop_file("test","recipes",basename($0)); 28e1051a39Sopenharmony_ci 29e1051a39Sopenharmony_cimy $test = catfile(".", "p"); 30e1051a39Sopenharmony_ci 31e1051a39Sopenharmony_cimy $cmd = "openssl"; 32e1051a39Sopenharmony_cimy $provpath = bldtop_dir("providers"); 33e1051a39Sopenharmony_cimy @prov = ("-provider-path", $provpath, "-provider", "default"); 34e1051a39Sopenharmony_cipush @prov, ("-provider", "legacy") unless disabled("legacy"); 35e1051a39Sopenharmony_cimy $ciphersstatus = undef; 36e1051a39Sopenharmony_cimy @ciphers = 37e1051a39Sopenharmony_ci map { s/^\s+//; s/\s+$//; split /\s+/ } 38e1051a39Sopenharmony_ci run(app([$cmd, "list", "-cipher-commands"]), 39e1051a39Sopenharmony_ci capture => 1, statusvar => \$ciphersstatus); 40e1051a39Sopenharmony_ci@ciphers = grep {!/^(bf|cast|des$|des-cbc|des-cfb|des-ecb|des-ofb|desx|idea 41e1051a39Sopenharmony_ci |rc2|rc4|seed)/x} @ciphers 42e1051a39Sopenharmony_ci if disabled("legacy"); 43e1051a39Sopenharmony_ci 44e1051a39Sopenharmony_ciplan tests => 2 + (scalar @ciphers)*2; 45e1051a39Sopenharmony_ci 46e1051a39Sopenharmony_ci SKIP: { 47e1051a39Sopenharmony_ci skip "Problems getting ciphers...", 1 + scalar(@ciphers) 48e1051a39Sopenharmony_ci unless ok($ciphersstatus, "Running 'openssl list -cipher-commands'"); 49e1051a39Sopenharmony_ci unless (ok(copy($testsrc, $test), "Copying $testsrc to $test")) { 50e1051a39Sopenharmony_ci diag($!); 51e1051a39Sopenharmony_ci skip "Not initialized, skipping...", scalar(@ciphers); 52e1051a39Sopenharmony_ci } 53e1051a39Sopenharmony_ci 54e1051a39Sopenharmony_ci foreach my $c (@ciphers) { 55e1051a39Sopenharmony_ci my %variant = ("$c" => [], 56e1051a39Sopenharmony_ci "$c base64" => [ "-a" ]); 57e1051a39Sopenharmony_ci 58e1051a39Sopenharmony_ci foreach my $t (sort keys %variant) { 59e1051a39Sopenharmony_ci my $cipherfile = "$test.$c.cipher"; 60e1051a39Sopenharmony_ci my $clearfile = "$test.$c.clear"; 61e1051a39Sopenharmony_ci my @e = ( "$c", "-bufsize", "113", @{$variant{$t}}, "-e", "-k", "test" ); 62e1051a39Sopenharmony_ci my @d = ( "$c", "-bufsize", "157", @{$variant{$t}}, "-d", "-k", "test" ); 63e1051a39Sopenharmony_ci if ($c eq "cat") { 64e1051a39Sopenharmony_ci $cipherfile = "$test.cipher"; 65e1051a39Sopenharmony_ci $clearfile = "$test.clear"; 66e1051a39Sopenharmony_ci @e = ( "enc", @{$variant{$t}}, "-e" ); 67e1051a39Sopenharmony_ci @d = ( "enc", @{$variant{$t}}, "-d" ); 68e1051a39Sopenharmony_ci } 69e1051a39Sopenharmony_ci 70e1051a39Sopenharmony_ci ok(run(app([$cmd, @e, @prov, "-in", $test, "-out", $cipherfile])) 71e1051a39Sopenharmony_ci && run(app([$cmd, @d, @prov, "-in", $cipherfile, "-out", $clearfile])) 72e1051a39Sopenharmony_ci && compare_text($test,$clearfile) == 0, $t); 73e1051a39Sopenharmony_ci } 74e1051a39Sopenharmony_ci } 75e1051a39Sopenharmony_ci} 76