03-test_fipsinstall.t 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #! /usr/bin/env perl
  2. # Copyright 2019-2020 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 strict;
  9. use warnings;
  10. use File::Spec;
  11. use File::Copy;
  12. use OpenSSL::Glob;
  13. use OpenSSL::Test qw/:DEFAULT srctop_dir bldtop_dir bldtop_file/;
  14. use OpenSSL::Test::Utils;
  15. BEGIN {
  16. setup("test_fipsinstall");
  17. }
  18. use lib srctop_dir('Configurations');
  19. use lib bldtop_dir('.');
  20. use platform;
  21. plan skip_all => "Test only supported in a fips build" if disabled("fips");
  22. plan tests => 12;
  23. my $infile = bldtop_file('providers', platform->dso('fips'));
  24. my $fipskey = $ENV{FIPSKEY} // '00';
  25. # fail if no module name
  26. ok(!run(app(['openssl', 'fipsinstall', '-out', 'fips.cnf', '-module',
  27. '-provider_name', 'fips',
  28. '-macopt', 'digest:SHA256', '-macopt', "hexkey:$fipskey",
  29. '-section_name', 'fips_install'])),
  30. "fipsinstall fail");
  31. # fail to verify if the configuration file is missing
  32. ok(!run(app(['openssl', 'fipsinstall', '-in', 'dummy.tmp', '-module', $infile,
  33. '-provider_name', 'fips', '-mac_name', 'HMAC',
  34. '-macopt', 'digest:SHA256', '-macopt', "hexkey:$fipskey",
  35. '-section_name', 'fips_install', '-verify'])),
  36. "fipsinstall verify fail");
  37. # output a fips.cnf file containing mac data
  38. ok(run(app(['openssl', 'fipsinstall', '-out', 'fips.cnf', '-module', $infile,
  39. '-provider_name', 'fips', '-mac_name', 'HMAC',
  40. '-macopt', 'digest:SHA256', '-macopt', "hexkey:$fipskey",
  41. '-section_name', 'fips_install'])),
  42. "fipsinstall");
  43. # verify the fips.cnf file
  44. ok(run(app(['openssl', 'fipsinstall', '-in', 'fips.cnf', '-module', $infile,
  45. '-provider_name', 'fips', '-mac_name', 'HMAC',
  46. '-macopt', 'digest:SHA256', '-macopt', "hexkey:$fipskey",
  47. '-section_name', 'fips_install', '-verify'])),
  48. "fipsinstall verify");
  49. # fail to verify the fips.cnf file if a different key is used
  50. ok(!run(app(['openssl', 'fipsinstall', '-in', 'fips.cnf', '-module', $infile,
  51. '-provider_name', 'fips', '-mac_name', 'HMAC',
  52. '-macopt', 'digest:SHA256', '-macopt', "hexkey:01",
  53. '-section_name', 'fips_install', '-verify'])),
  54. "fipsinstall verify fail bad key");
  55. # fail to verify the fips.cnf file if a different mac digest is used
  56. ok(!run(app(['openssl', 'fipsinstall', '-in', 'fips.cnf', '-module', $infile,
  57. '-provider_name', 'fips', '-mac_name', 'HMAC',
  58. '-macopt', 'digest:SHA512', '-macopt', "hexkey:$fipskey",
  59. '-section_name', 'fips_install', '-verify'])),
  60. "fipsinstall verify fail incorrect digest");
  61. # corrupt the module hmac
  62. ok(!run(app(['openssl', 'fipsinstall', '-out', 'fips.cnf', '-module', $infile,
  63. '-provider_name', 'fips', '-mac_name', 'HMAC',
  64. '-macopt', 'digest:SHA256', '-macopt', "hexkey:$fipskey",
  65. '-section_name', 'fips_install', '-corrupt_desc', 'HMAC'])),
  66. "fipsinstall fails when the module integrity is corrupted");
  67. # corrupt the first digest
  68. ok(!run(app(['openssl', 'fipsinstall', '-out', 'fips.cnf', '-module', $infile,
  69. '-provider_name', 'fips', '-mac_name', 'HMAC',
  70. '-macopt', 'digest:SHA256', '-macopt', "hexkey:$fipskey",
  71. '-section_name', 'fips_install', '-corrupt_desc', 'SHA1'])),
  72. "fipsinstall fails when the digest result is corrupted");
  73. # corrupt another digest
  74. ok(!run(app(['openssl', 'fipsinstall', '-out', 'fips.cnf', '-module', $infile,
  75. '-provider_name', 'fips', '-mac_name', 'HMAC',
  76. '-macopt', 'digest:SHA256', '-macopt', "hexkey:$fipskey",
  77. '-section_name', 'fips_install', '-corrupt_desc', 'SHA3'])),
  78. "fipsinstall fails when the digest result is corrupted");
  79. # corrupt DRBG
  80. ok(!run(app(['openssl', 'fipsinstall', '-out', 'fips.cnf', '-module', $infile,
  81. '-provider_name', 'fips', '-mac_name', 'HMAC',
  82. '-macopt', 'digest:SHA256', '-macopt', "hexkey:$fipskey",
  83. '-section_name', 'fips_install', '-corrupt_desc', 'CTR'])),
  84. "fipsinstall fails when the DRBG CTR result is corrupted");
  85. # corrupt a KAS test
  86. SKIP: {
  87. skip "Skipping KAS DH corruption test because of no dh in this build", 1
  88. if disabled("dh");
  89. ok(!run(app(['openssl', 'fipsinstall', '-out', 'fips.conf', '-module', $infile,
  90. '-provider_name', 'fips', '-mac_name', 'HMAC',
  91. '-macopt', 'digest:SHA256', '-macopt', "hexkey:$fipskey",
  92. '-section_name', 'fips_install',
  93. '-corrupt_desc', 'DH',
  94. '-corrupt_type', 'KAT_KA'])),
  95. "fipsinstall fails when the kas result is corrupted");
  96. }
  97. # corrupt a Signature test
  98. SKIP: {
  99. skip "Skipping Signature DSA corruption test because of no dsa in this build", 1
  100. if disabled("dsa");
  101. ok(!run(app(['openssl', 'fipsinstall', '-out', 'fips.conf', '-module', $infile,
  102. '-provider_name', 'fips', '-mac_name', 'HMAC',
  103. '-macopt', 'digest:SHA256', '-macopt', "hexkey:$fipskey",
  104. '-section_name', 'fips_install',
  105. '-corrupt_desc', 'DSA',
  106. '-corrupt_type', 'KAT_Signature'])),
  107. "fipsinstall fails when the signature result is corrupted");
  108. }