fipsinstall.pl 1.4 KB

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