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