TEST: make and use a fipsinstall script
[openssl.git] / test / fipsinstall.pl
1 #! /usr/bin/env perl
2
3 use strict;
4 use warnings;
5
6 use File::Spec;
7
8 use if $^O eq "VMS", "VMS::Filespec";
9
10 my $bldtop_dir;
11
12 # First script argument MUST be the build top directory
13 BEGIN {
14     $bldtop_dir = $ARGV[0];
15     # 'use lib' needs Unix-ish paths
16     $bldtop_dir = VMS::Filespec::unixpath($bldtop_dir) if $^O eq "VMS";
17 }
18
19 use lib $bldtop_dir;
20 use FindBin;
21 use lib "$FindBin::Bin/../Configurations";
22 use platform;
23
24 my @providers = ($bldtop_dir, 'providers');
25 my $fips_cnf = File::Spec->catfile(@providers, 'fipsinstall.cnf');
26 my $fips_module = File::Spec->catfile(@providers, platform->dso('fips'));
27 my $openssl = File::Spec->catfile($bldtop_dir, 'apps',
28                                   platform->bin('openssl'));
29
30 # We create the command like this to make it readable, then massage it with
31 # a space replacement regexp to make it usable with system()
32 my $cmd = <<_____;
33 $openssl fipsinstall \
34     -out "{fips_cnf}" \
35     -module "{fips_module}" \
36     -provider_name "fips" \
37     -mac_name "HMAC" -macopt "digest:SHA256" -macopt "hexkey:00" \
38     -section_name "fips_sect"
39 _____
40 $cmd =~ s|\s+| |gm;
41 $cmd =~ s|{fips_cnf}|$fips_cnf|;
42 $cmd =~ s|{fips_module}|$fips_module|;
43
44 my $exit = 0;
45 system($cmd);
46 die "Failed to run '$cmd'\n" if $? == -1;
47 # If there was a signal, use it as exit code with high bit set.
48 $exit = (($? & 255) | 128) if ($? & 255) != 0;
49 # Otherwise, just return fipsinstall's exit code
50 $exit = ($? >> 8);
51
52 exit($exit);
53