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