]>
git.ipfire.org Git - thirdparty/openssl.git/blob - test/recipes/15-test_genrsa.t
ffa334f15eb051574e4ad94509abb1e39a066407
2 # Copyright 2017-2020 The OpenSSL Project Authors. All Rights Reserved.
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
14 use OpenSSL
::Test qw
/:DEFAULT srctop_file srctop_dir bldtop_dir bldtop_file/;
15 use OpenSSL
::Test
::Utils
;
21 use lib srctop_dir
('Configurations');
22 use lib bldtop_dir
('.');
25 my $no_fips = disabled
('fips') || ($ENV{NO_FIPS
} // 0);
28 ($no_fips ?
0 : 2) # FIPS install test + fips related test
31 # We want to know that an absurdly small number of bits isn't support
32 if (disabled
("deprecated-3.0")) {
33 is
(run
(app
([ 'openssl', 'genpkey', '-out', 'genrsatest.pem',
34 '-algorithm', 'RSA', '-pkeyopt', 'rsa_keygen_bits:8',
35 '-pkeyopt', 'rsa_keygen_pubexp:3'])),
38 is
(run
(app
([ 'openssl', 'genrsa', '-3', '-out', 'genrsatest.pem', '8'])),
42 # Depending on the shared library, we might have different lower limits.
43 # Let's find it! This is a simple binary search
44 # ------------------------------------------------------------
45 # NOTE: $good may need an update in the future
46 # ------------------------------------------------------------
47 note
"Looking for lowest amount of bits";
48 my $bad = 3; # Log2 of number of bits (2 << 3 == 8)
49 my $good = 11; # Log2 of number of bits (2 << 11 == 2048)
51 while ($good > $bad + 1) {
52 my $checked = int(($good + $bad + 1) / 2);
53 my $bits = 2 ** $checked;
54 if (disabled
("deprecated-3.0")) {
55 $fin = run
(app
([ 'openssl', 'genpkey', '-out', 'genrsatest.pem',
56 '-algorithm', 'RSA', '-pkeyopt', 'rsa_keygen_pubexp:65537',
57 '-pkeyopt', "rsa_keygen_bits:$bits",
60 $fin = run
(app
([ 'openssl', 'genrsa', '-3', '-out', 'genrsatest.pem',
65 note
2 ** $checked, " bits is good";
68 note
2 ** $checked, " bits is bad";
72 $good++ if $good == $bad;
74 note
"Found lowest allowed amount of bits to be $good";
76 ok
(run
(app
([ 'openssl', 'genpkey', '-algorithm', 'RSA',
77 '-pkeyopt', 'rsa_keygen_pubexp:65537',
78 '-pkeyopt', "rsa_keygen_bits:$good",
79 '-out', 'genrsatest.pem' ])),
81 ok
(run
(app
([ 'openssl', 'pkey', '-check', '-in', 'genrsatest.pem', '-noout' ])),
83 ok
(run
(app
([ 'openssl', 'genpkey', '-algorithm', 'RSA',
84 '-pkeyopt', 'rsa_keygen_pubexp:65537',
85 '-pkeyopt', "rsa_keygen_bits:$good",
86 '-out', 'genrsatest.pem' ])),
89 ok
(run
(app
([ 'openssl', 'genpkey', '-algorithm', 'RSA',
90 '-pkeyopt', 'rsa_keygen_bits:2048',
91 '-out', 'genrsatest2048.pem' ])),
93 ok
(run
(app
([ 'openssl', 'pkey', '-check', '-in', 'genrsatest2048.pem', '-noout' ])),
96 ok
(!run
(app
([ 'openssl', 'genpkey', '-algorithm', 'RSA',
97 '-pkeyopt', 'hexe:02',
98 '-out', 'genrsatest.pem' ])),
99 "genpkey with a bad public exponent should fail");
100 ok
(!run
(app
([ 'openssl', 'genpkey', '-algorithm', 'RSA',
101 '-pkeyopt', 'e:65538',
102 '-out', 'genrsatest.pem' ])),
103 "genpkey with a even public exponent should fail");
107 skip
"Skipping rsa command line test", 4 if disabled
("deprecated-3.0");
109 ok
(run
(app
([ 'openssl', 'genrsa', '-3', '-out', 'genrsatest.pem', $good ])),
111 ok
(run
(app
([ 'openssl', 'rsa', '-check', '-in', 'genrsatest.pem', '-noout' ])),
113 ok
(run
(app
([ 'openssl', 'genrsa', '-f4', '-out', 'genrsatest.pem', $good ])),
115 ok
(run
(app
([ 'openssl', 'rsa', '-check', '-in', 'genrsatest.pem', '-noout' ])),
120 my $provconf = srctop_file
("test", "fips-and-base.cnf");
121 my $provpath = bldtop_dir
("providers");
122 my @prov = ( "-provider-path", $provpath,
123 "-config", $provconf);
124 my $infile = bldtop_file
('providers', platform
->dso('fips'));
126 ok
(run
(app
(['openssl', 'fipsinstall',
127 '-out', bldtop_file
('providers', 'fipsmodule.cnf'),
129 '-provider_name', 'fips', '-mac_name', 'HMAC',
130 '-section_name', 'fips_sect'])),
133 $ENV{OPENSSL_TEST_LIBCTX
} = "1";
134 ok
(run
(app
(['openssl', 'genpkey',
137 '-pkeyopt', 'bits:2080',
138 '-out', 'genrsatest2080.pem'])),
139 "Generating RSA key with > 2048 bits and < 3072 bits");