1e1051a39Sopenharmony_ci#! /usr/bin/env perl 2e1051a39Sopenharmony_ci# Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved. 3e1051a39Sopenharmony_ci# 4e1051a39Sopenharmony_ci# Licensed under the Apache License 2.0 (the "License"). You may not use 5e1051a39Sopenharmony_ci# this file except in compliance with the License. You can obtain a copy 6e1051a39Sopenharmony_ci# in the file LICENSE in the source distribution or at 7e1051a39Sopenharmony_ci# https://www.openssl.org/source/license.html 8e1051a39Sopenharmony_ci 9e1051a39Sopenharmony_ciuse strict; 10e1051a39Sopenharmony_ciuse warnings; 11e1051a39Sopenharmony_ci 12e1051a39Sopenharmony_ciuse File::Spec; 13e1051a39Sopenharmony_ciuse File::Spec::Functions qw/curdir abs2rel/; 14e1051a39Sopenharmony_ciuse File::Copy; 15e1051a39Sopenharmony_ciuse OpenSSL::Glob; 16e1051a39Sopenharmony_ciuse OpenSSL::Test qw/:DEFAULT srctop_dir bldtop_dir bldtop_file srctop_file data_file/; 17e1051a39Sopenharmony_ciuse OpenSSL::Test::Utils; 18e1051a39Sopenharmony_ci 19e1051a39Sopenharmony_ciBEGIN { 20e1051a39Sopenharmony_ci setup("test_cli_fips"); 21e1051a39Sopenharmony_ci} 22e1051a39Sopenharmony_ciuse lib srctop_dir('Configurations'); 23e1051a39Sopenharmony_ciuse lib bldtop_dir('.'); 24e1051a39Sopenharmony_ciuse platform; 25e1051a39Sopenharmony_ci 26e1051a39Sopenharmony_cimy $no_check = disabled("fips") || disabled('fips-securitychecks'); 27e1051a39Sopenharmony_ciplan skip_all => "Test only supported in a fips build with security checks" 28e1051a39Sopenharmony_ci if $no_check; 29e1051a39Sopenharmony_ciplan tests => 11; 30e1051a39Sopenharmony_ci 31e1051a39Sopenharmony_cimy $fipsmodule = bldtop_file('providers', platform->dso('fips')); 32e1051a39Sopenharmony_cimy $fipsconf = srctop_file("test", "fips-and-base.cnf"); 33e1051a39Sopenharmony_cimy $defaultconf = srctop_file("test", "default.cnf"); 34e1051a39Sopenharmony_cimy $tbs_data = $fipsmodule; 35e1051a39Sopenharmony_cimy $bogus_data = $fipsconf; 36e1051a39Sopenharmony_ci 37e1051a39Sopenharmony_ci$ENV{OPENSSL_CONF} = $fipsconf; 38e1051a39Sopenharmony_ci 39e1051a39Sopenharmony_ciok(run(app(['openssl', 'list', '-public-key-methods', '-verbose'])), 40e1051a39Sopenharmony_ci "provider listing of public key methods"); 41e1051a39Sopenharmony_ciok(run(app(['openssl', 'list', '-public-key-algorithms', '-verbose'])), 42e1051a39Sopenharmony_ci "provider listing of public key algorithms"); 43e1051a39Sopenharmony_ciok(run(app(['openssl', 'list', '-key-managers', '-verbose'])), 44e1051a39Sopenharmony_ci "provider listing of keymanagers"); 45e1051a39Sopenharmony_ciok(run(app(['openssl', 'list', '-key-exchange-algorithms', '-verbose'])), 46e1051a39Sopenharmony_ci "provider listing of key exchange algorithms"); 47e1051a39Sopenharmony_ciok(run(app(['openssl', 'list', '-kem-algorithms', '-verbose'])), 48e1051a39Sopenharmony_ci "provider listing of key encapsulation algorithms"); 49e1051a39Sopenharmony_ciok(run(app(['openssl', 'list', '-signature-algorithms', '-verbose'])), 50e1051a39Sopenharmony_ci "provider listing of signature algorithms"); 51e1051a39Sopenharmony_ciok(run(app(['openssl', 'list', '-asymcipher-algorithms', '-verbose'])), 52e1051a39Sopenharmony_ci "provider listing of encryption algorithms"); 53e1051a39Sopenharmony_ciok(run(app(['openssl', 'list', '-key-managers', '-verbose', '-select', 'DSA' ])), 54e1051a39Sopenharmony_ci "provider listing of one item in the keymanager"); 55e1051a39Sopenharmony_ci 56e1051a39Sopenharmony_cisub pubfrompriv { 57e1051a39Sopenharmony_ci my $prefix = shift; 58e1051a39Sopenharmony_ci my $key = shift; 59e1051a39Sopenharmony_ci my $pub_key = shift; 60e1051a39Sopenharmony_ci my $type = shift; 61e1051a39Sopenharmony_ci 62e1051a39Sopenharmony_ci ok(run(app(['openssl', 'pkey', 63e1051a39Sopenharmony_ci '-in', $key, 64e1051a39Sopenharmony_ci '-pubout', 65e1051a39Sopenharmony_ci '-out', $pub_key])), 66e1051a39Sopenharmony_ci $prefix.': '."Create the public key with $type parameters"); 67e1051a39Sopenharmony_ci 68e1051a39Sopenharmony_ci} 69e1051a39Sopenharmony_ci 70e1051a39Sopenharmony_cimy $tsignverify_count = 9; 71e1051a39Sopenharmony_cisub tsignverify { 72e1051a39Sopenharmony_ci my $prefix = shift; 73e1051a39Sopenharmony_ci my $fips_key = shift; 74e1051a39Sopenharmony_ci my $fips_pub_key = shift; 75e1051a39Sopenharmony_ci my $nonfips_key = shift; 76e1051a39Sopenharmony_ci my $nonfips_pub_key = shift; 77e1051a39Sopenharmony_ci my $fips_sigfile = $prefix.'.fips.sig'; 78e1051a39Sopenharmony_ci my $nonfips_sigfile = $prefix.'.nonfips.sig'; 79e1051a39Sopenharmony_ci my $sigfile = ''; 80e1051a39Sopenharmony_ci my $testtext = ''; 81e1051a39Sopenharmony_ci 82e1051a39Sopenharmony_ci $ENV{OPENSSL_CONF} = $fipsconf; 83e1051a39Sopenharmony_ci 84e1051a39Sopenharmony_ci $sigfile = $fips_sigfile; 85e1051a39Sopenharmony_ci $testtext = $prefix.': '. 86e1051a39Sopenharmony_ci 'Sign something with a FIPS key'; 87e1051a39Sopenharmony_ci ok(run(app(['openssl', 'dgst', '-sha256', 88e1051a39Sopenharmony_ci '-sign', $fips_key, 89e1051a39Sopenharmony_ci '-out', $sigfile, 90e1051a39Sopenharmony_ci $tbs_data])), 91e1051a39Sopenharmony_ci $testtext); 92e1051a39Sopenharmony_ci 93e1051a39Sopenharmony_ci $testtext = $prefix.': '. 94e1051a39Sopenharmony_ci 'Verify something with a FIPS key'; 95e1051a39Sopenharmony_ci ok(run(app(['openssl', 'dgst', '-sha256', 96e1051a39Sopenharmony_ci '-verify', $fips_pub_key, 97e1051a39Sopenharmony_ci '-signature', $sigfile, 98e1051a39Sopenharmony_ci $tbs_data])), 99e1051a39Sopenharmony_ci $testtext); 100e1051a39Sopenharmony_ci 101e1051a39Sopenharmony_ci $testtext = $prefix.': '. 102e1051a39Sopenharmony_ci 'Verify a valid signature against the wrong data with a FIPS key'. 103e1051a39Sopenharmony_ci ' (should fail)'; 104e1051a39Sopenharmony_ci ok(!run(app(['openssl', 'dgst', '-sha256', 105e1051a39Sopenharmony_ci '-verify', $fips_pub_key, 106e1051a39Sopenharmony_ci '-signature', $sigfile, 107e1051a39Sopenharmony_ci $bogus_data])), 108e1051a39Sopenharmony_ci $testtext); 109e1051a39Sopenharmony_ci 110e1051a39Sopenharmony_ci $ENV{OPENSSL_CONF} = $defaultconf; 111e1051a39Sopenharmony_ci 112e1051a39Sopenharmony_ci $sigfile = $nonfips_sigfile; 113e1051a39Sopenharmony_ci $testtext = $prefix.': '. 114e1051a39Sopenharmony_ci 'Sign something with a non-FIPS key'. 115e1051a39Sopenharmony_ci ' with the default provider'; 116e1051a39Sopenharmony_ci ok(run(app(['openssl', 'dgst', '-sha256', 117e1051a39Sopenharmony_ci '-sign', $nonfips_key, 118e1051a39Sopenharmony_ci '-out', $sigfile, 119e1051a39Sopenharmony_ci $tbs_data])), 120e1051a39Sopenharmony_ci $testtext); 121e1051a39Sopenharmony_ci 122e1051a39Sopenharmony_ci $testtext = $prefix.': '. 123e1051a39Sopenharmony_ci 'Verify something with a non-FIPS key'. 124e1051a39Sopenharmony_ci ' with the default provider'; 125e1051a39Sopenharmony_ci ok(run(app(['openssl', 'dgst', '-sha256', 126e1051a39Sopenharmony_ci '-verify', $nonfips_pub_key, 127e1051a39Sopenharmony_ci '-signature', $sigfile, 128e1051a39Sopenharmony_ci $tbs_data])), 129e1051a39Sopenharmony_ci $testtext); 130e1051a39Sopenharmony_ci 131e1051a39Sopenharmony_ci $ENV{OPENSSL_CONF} = $fipsconf; 132e1051a39Sopenharmony_ci 133e1051a39Sopenharmony_ci $testtext = $prefix.': '. 134e1051a39Sopenharmony_ci 'Sign something with a non-FIPS key'. 135e1051a39Sopenharmony_ci ' (should fail)'; 136e1051a39Sopenharmony_ci ok(!run(app(['openssl', 'dgst', '-sha256', 137e1051a39Sopenharmony_ci '-sign', $nonfips_key, 138e1051a39Sopenharmony_ci '-out', $prefix.'.nonfips.fail.sig', 139e1051a39Sopenharmony_ci $tbs_data])), 140e1051a39Sopenharmony_ci $testtext); 141e1051a39Sopenharmony_ci 142e1051a39Sopenharmony_ci $testtext = $prefix.': '. 143e1051a39Sopenharmony_ci 'Verify something with a non-FIPS key'. 144e1051a39Sopenharmony_ci ' (should fail)'; 145e1051a39Sopenharmony_ci ok(!run(app(['openssl', 'dgst', '-sha256', 146e1051a39Sopenharmony_ci '-verify', $nonfips_pub_key, 147e1051a39Sopenharmony_ci '-signature', $sigfile, 148e1051a39Sopenharmony_ci $tbs_data])), 149e1051a39Sopenharmony_ci $testtext); 150e1051a39Sopenharmony_ci 151e1051a39Sopenharmony_ci $testtext = $prefix.': '. 152e1051a39Sopenharmony_ci 'Verify something with a non-FIPS key'. 153e1051a39Sopenharmony_ci ' in FIPS mode but with a non-FIPS property query'; 154e1051a39Sopenharmony_ci ok(run(app(['openssl', 'dgst', 155e1051a39Sopenharmony_ci '-provider', 'default', 156e1051a39Sopenharmony_ci '-propquery', '?fips!=yes', 157e1051a39Sopenharmony_ci '-sha256', 158e1051a39Sopenharmony_ci '-verify', $nonfips_pub_key, 159e1051a39Sopenharmony_ci '-signature', $sigfile, 160e1051a39Sopenharmony_ci $tbs_data])), 161e1051a39Sopenharmony_ci $testtext); 162e1051a39Sopenharmony_ci 163e1051a39Sopenharmony_ci $testtext = $prefix.': '. 164e1051a39Sopenharmony_ci 'Verify a valid signature against the wrong data with a non-FIPS key'. 165e1051a39Sopenharmony_ci ' (should fail)'; 166e1051a39Sopenharmony_ci ok(!run(app(['openssl', 'dgst', '-sha256', 167e1051a39Sopenharmony_ci '-verify', $nonfips_pub_key, 168e1051a39Sopenharmony_ci '-signature', $sigfile, 169e1051a39Sopenharmony_ci $bogus_data])), 170e1051a39Sopenharmony_ci $testtext); 171e1051a39Sopenharmony_ci} 172e1051a39Sopenharmony_ci 173e1051a39Sopenharmony_ciSKIP : { 174e1051a39Sopenharmony_ci skip "FIPS EC tests because of no ec in this build", 1 175e1051a39Sopenharmony_ci if disabled("ec"); 176e1051a39Sopenharmony_ci 177e1051a39Sopenharmony_ci subtest EC => sub { 178e1051a39Sopenharmony_ci my $testtext_prefix = 'EC'; 179e1051a39Sopenharmony_ci my $a_fips_curve = 'prime256v1'; 180e1051a39Sopenharmony_ci my $fips_key = $testtext_prefix.'.fips.priv.pem'; 181e1051a39Sopenharmony_ci my $fips_pub_key = $testtext_prefix.'.fips.pub.pem'; 182e1051a39Sopenharmony_ci my $a_nonfips_curve = 'brainpoolP256r1'; 183e1051a39Sopenharmony_ci my $nonfips_key = $testtext_prefix.'.nonfips.priv.pem'; 184e1051a39Sopenharmony_ci my $nonfips_pub_key = $testtext_prefix.'.nonfips.pub.pem'; 185e1051a39Sopenharmony_ci my $testtext = ''; 186e1051a39Sopenharmony_ci my $curvename = ''; 187e1051a39Sopenharmony_ci 188e1051a39Sopenharmony_ci plan tests => 5 + $tsignverify_count; 189e1051a39Sopenharmony_ci 190e1051a39Sopenharmony_ci $ENV{OPENSSL_CONF} = $defaultconf; 191e1051a39Sopenharmony_ci $curvename = $a_nonfips_curve; 192e1051a39Sopenharmony_ci $testtext = $testtext_prefix.': '. 193e1051a39Sopenharmony_ci 'Generate a key with a non-FIPS algorithm with the default provider'; 194e1051a39Sopenharmony_ci ok(run(app(['openssl', 'genpkey', '-algorithm', 'EC', 195e1051a39Sopenharmony_ci '-pkeyopt', 'ec_paramgen_curve:'.$curvename, 196e1051a39Sopenharmony_ci '-out', $nonfips_key])), 197e1051a39Sopenharmony_ci $testtext); 198e1051a39Sopenharmony_ci 199e1051a39Sopenharmony_ci pubfrompriv($testtext_prefix, $nonfips_key, $nonfips_pub_key, "non-FIPS"); 200e1051a39Sopenharmony_ci 201e1051a39Sopenharmony_ci $ENV{OPENSSL_CONF} = $fipsconf; 202e1051a39Sopenharmony_ci 203e1051a39Sopenharmony_ci $curvename = $a_fips_curve; 204e1051a39Sopenharmony_ci $testtext = $testtext_prefix.': '. 205e1051a39Sopenharmony_ci 'Generate a key with a FIPS algorithm'; 206e1051a39Sopenharmony_ci ok(run(app(['openssl', 'genpkey', '-algorithm', 'EC', 207e1051a39Sopenharmony_ci '-pkeyopt', 'ec_paramgen_curve:'.$curvename, 208e1051a39Sopenharmony_ci '-out', $fips_key])), 209e1051a39Sopenharmony_ci $testtext); 210e1051a39Sopenharmony_ci 211e1051a39Sopenharmony_ci pubfrompriv($testtext_prefix, $fips_key, $fips_pub_key, "FIPS"); 212e1051a39Sopenharmony_ci 213e1051a39Sopenharmony_ci $curvename = $a_nonfips_curve; 214e1051a39Sopenharmony_ci $testtext = $testtext_prefix.': '. 215e1051a39Sopenharmony_ci 'Generate a key with a non-FIPS algorithm'. 216e1051a39Sopenharmony_ci ' (should fail)'; 217e1051a39Sopenharmony_ci ok(!run(app(['openssl', 'genpkey', '-algorithm', 'EC', 218e1051a39Sopenharmony_ci '-pkeyopt', 'ec_paramgen_curve:'.$curvename, 219e1051a39Sopenharmony_ci '-out', $testtext_prefix.'.'.$curvename.'.priv.pem'])), 220e1051a39Sopenharmony_ci $testtext); 221e1051a39Sopenharmony_ci 222e1051a39Sopenharmony_ci tsignverify($testtext_prefix, $fips_key, $fips_pub_key, $nonfips_key, 223e1051a39Sopenharmony_ci $nonfips_pub_key); 224e1051a39Sopenharmony_ci }; 225e1051a39Sopenharmony_ci} 226e1051a39Sopenharmony_ci 227e1051a39Sopenharmony_ciSKIP: { 228e1051a39Sopenharmony_ci skip "FIPS RSA tests because of no rsa in this build", 1 229e1051a39Sopenharmony_ci if disabled("rsa"); 230e1051a39Sopenharmony_ci 231e1051a39Sopenharmony_ci subtest RSA => sub { 232e1051a39Sopenharmony_ci my $testtext_prefix = 'RSA'; 233e1051a39Sopenharmony_ci my $fips_key = $testtext_prefix.'.fips.priv.pem'; 234e1051a39Sopenharmony_ci my $fips_pub_key = $testtext_prefix.'.fips.pub.pem'; 235e1051a39Sopenharmony_ci my $nonfips_key = $testtext_prefix.'.nonfips.priv.pem'; 236e1051a39Sopenharmony_ci my $nonfips_pub_key = $testtext_prefix.'.nonfips.pub.pem'; 237e1051a39Sopenharmony_ci my $testtext = ''; 238e1051a39Sopenharmony_ci 239e1051a39Sopenharmony_ci plan tests => 5 + $tsignverify_count; 240e1051a39Sopenharmony_ci 241e1051a39Sopenharmony_ci $ENV{OPENSSL_CONF} = $defaultconf; 242e1051a39Sopenharmony_ci $testtext = $testtext_prefix.': '. 243e1051a39Sopenharmony_ci 'Generate a key with a non-FIPS algorithm with the default provider'; 244e1051a39Sopenharmony_ci ok(run(app(['openssl', 'genpkey', '-algorithm', 'RSA', 245e1051a39Sopenharmony_ci '-pkeyopt', 'rsa_keygen_bits:512', 246e1051a39Sopenharmony_ci '-out', $nonfips_key])), 247e1051a39Sopenharmony_ci $testtext); 248e1051a39Sopenharmony_ci 249e1051a39Sopenharmony_ci pubfrompriv($testtext_prefix, $nonfips_key, $nonfips_pub_key, "non-FIPS"); 250e1051a39Sopenharmony_ci 251e1051a39Sopenharmony_ci $ENV{OPENSSL_CONF} = $fipsconf; 252e1051a39Sopenharmony_ci 253e1051a39Sopenharmony_ci $testtext = $testtext_prefix.': '. 254e1051a39Sopenharmony_ci 'Generate a key with a FIPS algorithm'; 255e1051a39Sopenharmony_ci ok(run(app(['openssl', 'genpkey', '-algorithm', 'RSA', 256e1051a39Sopenharmony_ci '-pkeyopt', 'rsa_keygen_bits:2048', 257e1051a39Sopenharmony_ci '-out', $fips_key])), 258e1051a39Sopenharmony_ci $testtext); 259e1051a39Sopenharmony_ci 260e1051a39Sopenharmony_ci pubfrompriv($testtext_prefix, $fips_key, $fips_pub_key, "FIPS"); 261e1051a39Sopenharmony_ci 262e1051a39Sopenharmony_ci $testtext = $testtext_prefix.': '. 263e1051a39Sopenharmony_ci 'Generate a key with a non-FIPS algorithm'. 264e1051a39Sopenharmony_ci ' (should fail)'; 265e1051a39Sopenharmony_ci ok(!run(app(['openssl', 'genpkey', '-algorithm', 'RSA', 266e1051a39Sopenharmony_ci '-pkeyopt', 'rsa_keygen_bits:512', 267e1051a39Sopenharmony_ci '-out', $testtext_prefix.'.fail.priv.pem'])), 268e1051a39Sopenharmony_ci $testtext); 269e1051a39Sopenharmony_ci 270e1051a39Sopenharmony_ci tsignverify($testtext_prefix, $fips_key, $fips_pub_key, $nonfips_key, 271e1051a39Sopenharmony_ci $nonfips_pub_key); 272e1051a39Sopenharmony_ci }; 273e1051a39Sopenharmony_ci} 274e1051a39Sopenharmony_ci 275e1051a39Sopenharmony_ciSKIP : { 276e1051a39Sopenharmony_ci skip "FIPS DSA tests because of no dsa in this build", 1 277e1051a39Sopenharmony_ci if disabled("dsa"); 278e1051a39Sopenharmony_ci 279e1051a39Sopenharmony_ci subtest DSA => sub { 280e1051a39Sopenharmony_ci my $testtext_prefix = 'DSA'; 281e1051a39Sopenharmony_ci my $fips_key = $testtext_prefix.'.fips.priv.pem'; 282e1051a39Sopenharmony_ci my $fips_pub_key = $testtext_prefix.'.fips.pub.pem'; 283e1051a39Sopenharmony_ci my $nonfips_key = $testtext_prefix.'.nonfips.priv.pem'; 284e1051a39Sopenharmony_ci my $nonfips_pub_key = $testtext_prefix.'.nonfips.pub.pem'; 285e1051a39Sopenharmony_ci my $testtext = ''; 286e1051a39Sopenharmony_ci my $fips_param = $testtext_prefix.'.fips.param.pem'; 287e1051a39Sopenharmony_ci my $nonfips_param = $testtext_prefix.'.nonfips.param.pem'; 288e1051a39Sopenharmony_ci my $shortnonfips_param = $testtext_prefix.'.shortnonfips.param.pem'; 289e1051a39Sopenharmony_ci 290e1051a39Sopenharmony_ci plan tests => 13 + $tsignverify_count; 291e1051a39Sopenharmony_ci 292e1051a39Sopenharmony_ci $ENV{OPENSSL_CONF} = $defaultconf; 293e1051a39Sopenharmony_ci 294e1051a39Sopenharmony_ci $testtext = $testtext_prefix.': '. 295e1051a39Sopenharmony_ci 'Generate non-FIPS params with the default provider'; 296e1051a39Sopenharmony_ci ok(run(app(['openssl', 'genpkey', '-genparam', 297e1051a39Sopenharmony_ci '-algorithm', 'DSA', 298e1051a39Sopenharmony_ci '-pkeyopt', 'type:fips186_2', 299e1051a39Sopenharmony_ci '-pkeyopt', 'dsa_paramgen_bits:512', 300e1051a39Sopenharmony_ci '-out', $nonfips_param])), 301e1051a39Sopenharmony_ci $testtext); 302e1051a39Sopenharmony_ci 303e1051a39Sopenharmony_ci $ENV{OPENSSL_CONF} = $fipsconf; 304e1051a39Sopenharmony_ci 305e1051a39Sopenharmony_ci $testtext = $testtext_prefix.': '. 306e1051a39Sopenharmony_ci 'Generate FIPS params'; 307e1051a39Sopenharmony_ci ok(run(app(['openssl', 'genpkey', '-genparam', 308e1051a39Sopenharmony_ci '-algorithm', 'DSA', 309e1051a39Sopenharmony_ci '-pkeyopt', 'dsa_paramgen_bits:2048', 310e1051a39Sopenharmony_ci '-out', $fips_param])), 311e1051a39Sopenharmony_ci $testtext); 312e1051a39Sopenharmony_ci 313e1051a39Sopenharmony_ci $testtext = $testtext_prefix.': '. 314e1051a39Sopenharmony_ci 'Generate non-FIPS params'. 315e1051a39Sopenharmony_ci ' (should fail)'; 316e1051a39Sopenharmony_ci ok(!run(app(['openssl', 'genpkey', '-genparam', 317e1051a39Sopenharmony_ci '-algorithm', 'DSA', 318e1051a39Sopenharmony_ci '-pkeyopt', 'dsa_paramgen_bits:512', 319e1051a39Sopenharmony_ci '-out', $testtext_prefix.'.fail.param.pem'])), 320e1051a39Sopenharmony_ci $testtext); 321e1051a39Sopenharmony_ci 322e1051a39Sopenharmony_ci $testtext = $testtext_prefix.': '. 323e1051a39Sopenharmony_ci 'Generate non-FIPS params using non-FIPS property query'. 324e1051a39Sopenharmony_ci ' (dsaparam)'; 325e1051a39Sopenharmony_ci ok(run(app(['openssl', 'dsaparam', '-provider', 'default', 326e1051a39Sopenharmony_ci '-propquery', '?fips!=yes', 327e1051a39Sopenharmony_ci '-out', $shortnonfips_param, '1024'])), 328e1051a39Sopenharmony_ci $testtext); 329e1051a39Sopenharmony_ci 330e1051a39Sopenharmony_ci $testtext = $testtext_prefix.': '. 331e1051a39Sopenharmony_ci 'Generate non-FIPS params using non-FIPS property query'. 332e1051a39Sopenharmony_ci ' (genpkey)'; 333e1051a39Sopenharmony_ci ok(run(app(['openssl', 'genpkey', '-provider', 'default', 334e1051a39Sopenharmony_ci '-propquery', '?fips!=yes', 335e1051a39Sopenharmony_ci '-genparam', '-algorithm', 'DSA', 336e1051a39Sopenharmony_ci '-pkeyopt', 'dsa_paramgen_bits:512'])), 337e1051a39Sopenharmony_ci $testtext); 338e1051a39Sopenharmony_ci 339e1051a39Sopenharmony_ci $ENV{OPENSSL_CONF} = $defaultconf; 340e1051a39Sopenharmony_ci 341e1051a39Sopenharmony_ci $testtext = $testtext_prefix.': '. 342e1051a39Sopenharmony_ci 'Generate a key with non-FIPS params with the default provider'; 343e1051a39Sopenharmony_ci ok(run(app(['openssl', 'genpkey', 344e1051a39Sopenharmony_ci '-paramfile', $nonfips_param, 345e1051a39Sopenharmony_ci '-pkeyopt', 'type:fips186_2', 346e1051a39Sopenharmony_ci '-out', $nonfips_key])), 347e1051a39Sopenharmony_ci $testtext); 348e1051a39Sopenharmony_ci 349e1051a39Sopenharmony_ci pubfrompriv($testtext_prefix, $nonfips_key, $nonfips_pub_key, "non-FIPS"); 350e1051a39Sopenharmony_ci 351e1051a39Sopenharmony_ci $ENV{OPENSSL_CONF} = $fipsconf; 352e1051a39Sopenharmony_ci 353e1051a39Sopenharmony_ci $testtext = $testtext_prefix.': '. 354e1051a39Sopenharmony_ci 'Generate a key with FIPS parameters'; 355e1051a39Sopenharmony_ci ok(run(app(['openssl', 'genpkey', 356e1051a39Sopenharmony_ci '-paramfile', $fips_param, 357e1051a39Sopenharmony_ci '-pkeyopt', 'type:fips186_4', 358e1051a39Sopenharmony_ci '-out', $fips_key])), 359e1051a39Sopenharmony_ci $testtext); 360e1051a39Sopenharmony_ci 361e1051a39Sopenharmony_ci pubfrompriv($testtext_prefix, $fips_key, $fips_pub_key, "FIPS"); 362e1051a39Sopenharmony_ci 363e1051a39Sopenharmony_ci $testtext = $testtext_prefix.': '. 364e1051a39Sopenharmony_ci 'Generate a key with non-FIPS parameters'. 365e1051a39Sopenharmony_ci ' (should fail)'; 366e1051a39Sopenharmony_ci ok(!run(app(['openssl', 'genpkey', 367e1051a39Sopenharmony_ci '-paramfile', $nonfips_param, 368e1051a39Sopenharmony_ci '-pkeyopt', 'type:fips186_2', 369e1051a39Sopenharmony_ci '-out', $testtext_prefix.'.fail.priv.pem'])), 370e1051a39Sopenharmony_ci $testtext); 371e1051a39Sopenharmony_ci 372e1051a39Sopenharmony_ci $testtext = $testtext_prefix.': '. 373e1051a39Sopenharmony_ci 'Generate a key with non-FIPS parameters using non-FIPS property'. 374e1051a39Sopenharmony_ci ' query (dsaparam)'; 375e1051a39Sopenharmony_ci ok(run(app(['openssl', 'dsaparam', '-provider', 'default', 376e1051a39Sopenharmony_ci '-propquery', '?fips!=yes', 377e1051a39Sopenharmony_ci '-noout', '-genkey', '1024'])), 378e1051a39Sopenharmony_ci $testtext); 379e1051a39Sopenharmony_ci 380e1051a39Sopenharmony_ci $testtext = $testtext_prefix.': '. 381e1051a39Sopenharmony_ci 'Generate a key with non-FIPS parameters using non-FIPS property'. 382e1051a39Sopenharmony_ci ' query (gendsa)'; 383e1051a39Sopenharmony_ci ok(run(app(['openssl', 'gendsa', '-provider', 'default', 384e1051a39Sopenharmony_ci '-propquery', '?fips!=yes', 385e1051a39Sopenharmony_ci $shortnonfips_param])), 386e1051a39Sopenharmony_ci $testtext); 387e1051a39Sopenharmony_ci 388e1051a39Sopenharmony_ci $testtext = $testtext_prefix.': '. 389e1051a39Sopenharmony_ci 'Generate a key with non-FIPS parameters using non-FIPS property'. 390e1051a39Sopenharmony_ci ' query (genpkey)'; 391e1051a39Sopenharmony_ci ok(run(app(['openssl', 'genpkey', '-provider', 'default', 392e1051a39Sopenharmony_ci '-propquery', '?fips!=yes', 393e1051a39Sopenharmony_ci '-paramfile', $nonfips_param, 394e1051a39Sopenharmony_ci '-pkeyopt', 'type:fips186_2', 395e1051a39Sopenharmony_ci '-out', $testtext_prefix.'.fail.priv.pem'])), 396e1051a39Sopenharmony_ci $testtext); 397e1051a39Sopenharmony_ci 398e1051a39Sopenharmony_ci tsignverify($testtext_prefix, $fips_key, $fips_pub_key, $nonfips_key, 399e1051a39Sopenharmony_ci $nonfips_pub_key); 400e1051a39Sopenharmony_ci }; 401e1051a39Sopenharmony_ci} 402