mk-fipsmodule-cnf.pl 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #! /usr/bin/env perl
  2. # Copyright 2021-2023 The OpenSSL Project Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License 2.0 (the "License"). You may not use
  5. # this file except in compliance with the License. You can obtain a copy
  6. # in the file LICENSE in the source distribution or at
  7. # https://www.openssl.org/source/license.html
  8. use Getopt::Long;
  9. # Module options for pedantic FIPS mode
  10. # self_test_onload happens if install_mac isn't included, don't add it below
  11. my $conditional_errors = 1;
  12. my $security_checks = 1;
  13. my $ems_check = 1;
  14. my $drgb_no_trunc_dgst = 1;
  15. my $activate = 1;
  16. my $mac_key;
  17. my $module_name;
  18. my $section_name = "fips_sect";
  19. GetOptions("key=s" => \$mac_key,
  20. "module=s" => \$module_name,
  21. "section_name=s" => \$section_name)
  22. or die "Error when getting command line arguments";
  23. my $mac_keylen = length($mac_key);
  24. use Digest::SHA qw(hmac_sha256_hex);
  25. my $module_size = [ stat($module_name) ]->[7];
  26. open my $fh, "<:raw", $module_name or die "Trying to open $module_name: $!";
  27. read $fh, my $data, $module_size or die "Trying to read $module_name: $!";
  28. close $fh;
  29. # Calculate HMAC-SHA256 in hex, and split it into a list of two character
  30. # chunks, and join the chunks with colons.
  31. my @module_mac
  32. = ( uc(hmac_sha256_hex($data, pack("H$mac_keylen", $mac_key))) =~ m/../g );
  33. my $module_mac = join(':', @module_mac);
  34. print <<_____;
  35. [$section_name]
  36. activate = $activate
  37. conditional-errors = $conditional_errors
  38. security-checks = $security_checks
  39. tls1-prf-ems-check = $ems_check
  40. drbg-no-trunc-md = $drgb_no_trunc_dgst
  41. module-mac = $module_mac
  42. _____