123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- #! /usr/bin/env perl
- # Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
- #
- # Licensed under the Apache License 2.0 (the "License"). You may not use
- # this file except in compliance with the License. You can obtain a copy
- # in the file LICENSE in the source distribution or at
- # https://www.openssl.org/source/license.html
- use strict;
- use warnings;
- use File::Spec;
- use File::Copy;
- use OpenSSL::Glob;
- use OpenSSL::Test qw/:DEFAULT srctop_dir bldtop_dir bldtop_file/;
- use OpenSSL::Test::Utils;
- BEGIN {
- setup("test_fipsinstall");
- }
- use lib srctop_dir('Configurations');
- use lib bldtop_dir('.');
- use platform;
- plan skip_all => "Test only supported in a fips build" if disabled("fips");
- plan tests => 12;
- my $infile = bldtop_file('providers', platform->dso('fips'));
- my $fipskey = $ENV{FIPSKEY} // '00';
- # fail if no module name
- ok(!run(app(['openssl', 'fipsinstall', '-out', 'fips.cnf', '-module',
- '-provider_name', 'fips',
- '-macopt', 'digest:SHA256', '-macopt', "hexkey:$fipskey",
- '-section_name', 'fips_install'])),
- "fipsinstall fail");
- # fail to verify if the configuration file is missing
- ok(!run(app(['openssl', 'fipsinstall', '-in', 'dummy.tmp', '-module', $infile,
- '-provider_name', 'fips', '-mac_name', 'HMAC',
- '-macopt', 'digest:SHA256', '-macopt', "hexkey:$fipskey",
- '-section_name', 'fips_install', '-verify'])),
- "fipsinstall verify fail");
- # output a fips.cnf file containing mac data
- ok(run(app(['openssl', 'fipsinstall', '-out', 'fips.cnf', '-module', $infile,
- '-provider_name', 'fips', '-mac_name', 'HMAC',
- '-macopt', 'digest:SHA256', '-macopt', "hexkey:$fipskey",
- '-section_name', 'fips_install'])),
- "fipsinstall");
- # verify the fips.cnf file
- ok(run(app(['openssl', 'fipsinstall', '-in', 'fips.cnf', '-module', $infile,
- '-provider_name', 'fips', '-mac_name', 'HMAC',
- '-macopt', 'digest:SHA256', '-macopt', "hexkey:$fipskey",
- '-section_name', 'fips_install', '-verify'])),
- "fipsinstall verify");
- # fail to verify the fips.cnf file if a different key is used
- ok(!run(app(['openssl', 'fipsinstall', '-in', 'fips.cnf', '-module', $infile,
- '-provider_name', 'fips', '-mac_name', 'HMAC',
- '-macopt', 'digest:SHA256', '-macopt', "hexkey:01",
- '-section_name', 'fips_install', '-verify'])),
- "fipsinstall verify fail bad key");
- # fail to verify the fips.cnf file if a different mac digest is used
- ok(!run(app(['openssl', 'fipsinstall', '-in', 'fips.cnf', '-module', $infile,
- '-provider_name', 'fips', '-mac_name', 'HMAC',
- '-macopt', 'digest:SHA512', '-macopt', "hexkey:$fipskey",
- '-section_name', 'fips_install', '-verify'])),
- "fipsinstall verify fail incorrect digest");
- # corrupt the module hmac
- ok(!run(app(['openssl', 'fipsinstall', '-out', 'fips.cnf', '-module', $infile,
- '-provider_name', 'fips', '-mac_name', 'HMAC',
- '-macopt', 'digest:SHA256', '-macopt', "hexkey:$fipskey",
- '-section_name', 'fips_install', '-corrupt_desc', 'HMAC'])),
- "fipsinstall fails when the module integrity is corrupted");
- # corrupt the first digest
- ok(!run(app(['openssl', 'fipsinstall', '-out', 'fips.cnf', '-module', $infile,
- '-provider_name', 'fips', '-mac_name', 'HMAC',
- '-macopt', 'digest:SHA256', '-macopt', "hexkey:$fipskey",
- '-section_name', 'fips_install', '-corrupt_desc', 'SHA1'])),
- "fipsinstall fails when the digest result is corrupted");
- # corrupt another digest
- ok(!run(app(['openssl', 'fipsinstall', '-out', 'fips.cnf', '-module', $infile,
- '-provider_name', 'fips', '-mac_name', 'HMAC',
- '-macopt', 'digest:SHA256', '-macopt', "hexkey:$fipskey",
- '-section_name', 'fips_install', '-corrupt_desc', 'SHA3'])),
- "fipsinstall fails when the digest result is corrupted");
- # corrupt DRBG
- ok(!run(app(['openssl', 'fipsinstall', '-out', 'fips.cnf', '-module', $infile,
- '-provider_name', 'fips', '-mac_name', 'HMAC',
- '-macopt', 'digest:SHA256', '-macopt', "hexkey:$fipskey",
- '-section_name', 'fips_install', '-corrupt_desc', 'CTR'])),
- "fipsinstall fails when the DRBG CTR result is corrupted");
- # corrupt a KAS test
- SKIP: {
- skip "Skipping KAS DH corruption test because of no dh in this build", 1
- if disabled("dh");
- ok(!run(app(['openssl', 'fipsinstall', '-out', 'fips.conf', '-module', $infile,
- '-provider_name', 'fips', '-mac_name', 'HMAC',
- '-macopt', 'digest:SHA256', '-macopt', "hexkey:$fipskey",
- '-section_name', 'fips_install',
- '-corrupt_desc', 'DH',
- '-corrupt_type', 'KAT_KA'])),
- "fipsinstall fails when the kas result is corrupted");
- }
- # corrupt a Signature test
- SKIP: {
- skip "Skipping Signature DSA corruption test because of no dsa in this build", 1
- if disabled("dsa");
- ok(!run(app(['openssl', 'fipsinstall', '-out', 'fips.conf', '-module', $infile,
- '-provider_name', 'fips', '-mac_name', 'HMAC',
- '-macopt', 'digest:SHA256', '-macopt', "hexkey:$fipskey",
- '-section_name', 'fips_install',
- '-corrupt_desc', 'DSA',
- '-corrupt_type', 'KAT_Signature'])),
- "fipsinstall fails when the signature result is corrupted");
- }
|