| 
									
										
										
										
											2016-04-22 19:21:51 +08:00
										 |  |  | #! /usr/bin/env perl | 
					
						
							| 
									
										
										
										
											2022-05-03 18:52:38 +08:00
										 |  |  | # Copyright 2015-2022 The OpenSSL Project Authors. All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2016-04-22 19:21:51 +08:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2018-12-06 20:05:25 +08:00
										 |  |  | # Licensed under the Apache License 2.0 (the "License").  You may not use | 
					
						
							| 
									
										
										
										
											2016-04-22 19:21:51 +08:00
										 |  |  | # 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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-18 02:15:22 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | use strict; | 
					
						
							|  |  |  | use warnings; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-04 07:05:06 +08:00
										 |  |  | use OpenSSL::Test::Utils; | 
					
						
							| 
									
										
										
										
											2016-01-30 08:05:33 +08:00
										 |  |  | use OpenSSL::Test qw/:DEFAULT srctop_file/; | 
					
						
							| 
									
										
										
										
											2015-04-18 02:15:22 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | setup("test_req"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-01 20:55:03 +08:00
										 |  |  | plan tests => 92; | 
					
						
							| 
									
										
										
										
											2015-04-18 02:15:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-24 18:25:47 +08:00
										 |  |  | require_ok(srctop_file('test', 'recipes', 'tconversion.pl')); | 
					
						
							| 
									
										
										
										
											2015-04-18 02:15:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-20 02:49:25 +08:00
										 |  |  | my @certs = qw(test certs); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-10 02:55:17 +08:00
										 |  |  | # What type of key to generate? | 
					
						
							|  |  |  | my @req_new; | 
					
						
							|  |  |  | if (disabled("rsa")) { | 
					
						
							|  |  |  |     @req_new = ("-newkey", "dsa:".srctop_file("apps", "dsa512.pem")); | 
					
						
							|  |  |  | } else { | 
					
						
							|  |  |  |     @req_new = ("-new"); | 
					
						
							|  |  |  |     note("There should be a 2 sequences of .'s and some +'s."); | 
					
						
							|  |  |  |     note("There should not be more that at most 80 per line"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-25 23:05:20 +08:00
										 |  |  | # Prevent MSys2 filename munging for arguments that look like file paths but | 
					
						
							|  |  |  | # aren't | 
					
						
							|  |  |  | $ENV{MSYS2_ARG_CONV_EXCL} = "/CN="; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-10 02:55:17 +08:00
										 |  |  | # Check for duplicate -addext parameters, and one "working" case. | 
					
						
							|  |  |  | my @addext_args = ( "openssl", "req", "-new", "-out", "testreq.pem", | 
					
						
							| 
									
										
										
										
											2021-08-24 15:31:53 +08:00
										 |  |  |                     "-key",  srctop_file(@certs, "ee-key.pem"), | 
					
						
							| 
									
										
										
										
											2018-07-10 02:55:17 +08:00
										 |  |  |     "-config", srctop_file("test", "test.cnf"), @req_new ); | 
					
						
							| 
									
										
										
										
											2018-07-06 07:57:22 +08:00
										 |  |  | my $val = "subjectAltName=DNS:example.com"; | 
					
						
							|  |  |  | my $val2 = " " . $val; | 
					
						
							|  |  |  | my $val3 = $val; | 
					
						
							|  |  |  | $val3 =~ s/=/    =/; | 
					
						
							| 
									
										
										
										
											2018-07-10 02:55:17 +08:00
										 |  |  | ok( run(app([@addext_args, "-addext", $val]))); | 
					
						
							|  |  |  | ok(!run(app([@addext_args, "-addext", $val, "-addext", $val]))); | 
					
						
							|  |  |  | ok(!run(app([@addext_args, "-addext", $val, "-addext", $val2]))); | 
					
						
							|  |  |  | ok(!run(app([@addext_args, "-addext", $val, "-addext", $val3]))); | 
					
						
							|  |  |  | ok(!run(app([@addext_args, "-addext", $val2, "-addext", $val3]))); | 
					
						
							| 
									
										
										
										
											2018-07-06 07:57:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-01 20:55:03 +08:00
										 |  |  | # If a CSR is provided with neither of -key or -CA/-CAkey, this should fail. | 
					
						
							|  |  |  | ok(!run(app(["openssl", "req", "-x509", | 
					
						
							|  |  |  |                 "-in", srctop_file(@certs, "x509-check.csr"), | 
					
						
							|  |  |  |                 "-out", "testreq.pem"]))); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-05 03:41:53 +08:00
										 |  |  | subtest "generating alt certificate requests with RSA" => sub { | 
					
						
							|  |  |  |     plan tests => 3; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     SKIP: { | 
					
						
							|  |  |  |         skip "RSA is not supported by this OpenSSL build", 2 | 
					
						
							|  |  |  |             if disabled("rsa"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         ok(run(app(["openssl", "req", | 
					
						
							|  |  |  |                     "-config", srctop_file("test", "test.cnf"), | 
					
						
							|  |  |  |                     "-section", "altreq", | 
					
						
							|  |  |  |                     "-new", "-out", "testreq-rsa.pem", "-utf8", | 
					
						
							|  |  |  |                     "-key", srctop_file("test", "testrsa.pem")])), | 
					
						
							|  |  |  |            "Generating request"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         ok(run(app(["openssl", "req", | 
					
						
							|  |  |  |                     "-config", srctop_file("test", "test.cnf"), | 
					
						
							|  |  |  |                     "-verify", "-in", "testreq-rsa.pem", "-noout"])), | 
					
						
							|  |  |  |            "Verifying signature on request"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         ok(run(app(["openssl", "req", | 
					
						
							|  |  |  |                     "-config", srctop_file("test", "test.cnf"), | 
					
						
							|  |  |  |                     "-section", "altreq", | 
					
						
							|  |  |  |                     "-verify", "-in", "testreq-rsa.pem", "-noout"])), | 
					
						
							|  |  |  |            "Verifying signature on request"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 23:17:31 +08:00
										 |  |  | subtest "generating certificate requests with RSA" => sub { | 
					
						
							| 
									
										
										
										
											2021-08-04 17:36:24 +08:00
										 |  |  |     plan tests => 8; | 
					
						
							| 
									
										
										
										
											2019-10-31 23:17:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     SKIP: { | 
					
						
							|  |  |  |         skip "RSA is not supported by this OpenSSL build", 2 | 
					
						
							|  |  |  |             if disabled("rsa"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-03 20:40:06 +08:00
										 |  |  |         ok(!run(app(["openssl", "req", | 
					
						
							|  |  |  |                      "-config", srctop_file("test", "test.cnf"), | 
					
						
							|  |  |  |                      "-new", "-out", "testreq-rsa.pem", "-utf8", | 
					
						
							|  |  |  |                      "-key", srctop_file("test", "testrsa.pem"), | 
					
						
							|  |  |  |                      "-keyform", "DER"])), | 
					
						
							|  |  |  |            "Checking that mismatching keyform fails"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 23:17:31 +08:00
										 |  |  |         ok(run(app(["openssl", "req", | 
					
						
							|  |  |  |                     "-config", srctop_file("test", "test.cnf"), | 
					
						
							| 
									
										
										
										
											2020-02-13 07:28:31 +08:00
										 |  |  |                     "-new", "-out", "testreq-rsa.pem", "-utf8", | 
					
						
							| 
									
										
										
										
											2021-05-03 20:40:06 +08:00
										 |  |  |                     "-key", srctop_file("test", "testrsa.pem"), | 
					
						
							|  |  |  |                     "-keyform", "PEM"])), | 
					
						
							| 
									
										
										
										
											2019-10-31 23:17:31 +08:00
										 |  |  |            "Generating request"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         ok(run(app(["openssl", "req", | 
					
						
							|  |  |  |                     "-config", srctop_file("test", "test.cnf"), | 
					
						
							| 
									
										
										
										
											2020-02-13 07:28:31 +08:00
										 |  |  |                     "-verify", "-in", "testreq-rsa.pem", "-noout"])), | 
					
						
							| 
									
										
										
										
											2019-10-31 23:17:31 +08:00
										 |  |  |            "Verifying signature on request"); | 
					
						
							| 
									
										
										
										
											2021-05-05 02:47:42 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 17:36:24 +08:00
										 |  |  |         ok(run(app(["openssl", "req", | 
					
						
							|  |  |  |                     "-config", srctop_file("test", "test.cnf"), | 
					
						
							|  |  |  |                     "-modulus", "-in", "testreq-rsa.pem", "-noout"])), | 
					
						
							|  |  |  |            "Printing a modulus of the request key"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-05 02:47:42 +08:00
										 |  |  |         ok(run(app(["openssl", "req", | 
					
						
							|  |  |  |                     "-config", srctop_file("test", "test.cnf"), | 
					
						
							|  |  |  |                     "-new", "-out", "testreq_withattrs_pem.pem", "-utf8", | 
					
						
							|  |  |  |                     "-key", srctop_file("test", "testrsa_withattrs.pem")])), | 
					
						
							|  |  |  |            "Generating request from a key with extra attributes - PEM"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         ok(run(app(["openssl", "req", | 
					
						
							|  |  |  |                     "-config", srctop_file("test", "test.cnf"), | 
					
						
							|  |  |  |                     "-verify", "-in", "testreq_withattrs_pem.pem", "-noout"])), | 
					
						
							|  |  |  |            "Verifying signature on request from a key with extra attributes - PEM"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         ok(run(app(["openssl", "req", | 
					
						
							|  |  |  |                     "-config", srctop_file("test", "test.cnf"), | 
					
						
							|  |  |  |                     "-new", "-out", "testreq_withattrs_der.pem", "-utf8", | 
					
						
							|  |  |  |                     "-key", srctop_file("test", "testrsa_withattrs.der"), | 
					
						
							| 
									
										
										
										
											2021-06-18 15:46:40 +08:00
										 |  |  |                     "-keyform", "DER"])), | 
					
						
							| 
									
										
										
										
											2021-05-05 02:47:42 +08:00
										 |  |  |            "Generating request from a key with extra attributes - PEM"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         ok(run(app(["openssl", "req", | 
					
						
							|  |  |  |                     "-config", srctop_file("test", "test.cnf"), | 
					
						
							|  |  |  |                     "-verify", "-in", "testreq_withattrs_der.pem", "-noout"])), | 
					
						
							|  |  |  |            "Verifying signature on request from a key with extra attributes - PEM"); | 
					
						
							| 
									
										
										
										
											2019-10-31 23:17:31 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-26 18:39:27 +08:00
										 |  |  | subtest "generating certificate requests with RSA-PSS" => sub { | 
					
						
							| 
									
										
										
										
											2021-01-30 00:02:32 +08:00
										 |  |  |     plan tests => 12; | 
					
						
							| 
									
										
										
										
											2021-01-26 18:39:27 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     SKIP: { | 
					
						
							|  |  |  |         skip "RSA is not supported by this OpenSSL build", 2 | 
					
						
							|  |  |  |             if disabled("rsa"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         ok(run(app(["openssl", "req", | 
					
						
							|  |  |  |                     "-config", srctop_file("test", "test.cnf"), | 
					
						
							|  |  |  |                     "-new", "-out", "testreq-rsapss.pem", "-utf8", | 
					
						
							|  |  |  |                     "-key", srctop_file("test", "testrsapss.pem")])), | 
					
						
							|  |  |  |            "Generating request"); | 
					
						
							|  |  |  |         ok(run(app(["openssl", "req", | 
					
						
							|  |  |  |                     "-config", srctop_file("test", "test.cnf"), | 
					
						
							|  |  |  |                     "-verify", "-in", "testreq-rsapss.pem", "-noout"])), | 
					
						
							|  |  |  |            "Verifying signature on request"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         ok(run(app(["openssl", "req", | 
					
						
							|  |  |  |                     "-config", srctop_file("test", "test.cnf"), | 
					
						
							|  |  |  |                     "-new", "-out", "testreq-rsapss2.pem", "-utf8", | 
					
						
							|  |  |  |                     "-sigopt", "rsa_padding_mode:pss", | 
					
						
							|  |  |  |                     "-sigopt", "rsa_pss_saltlen:-1", | 
					
						
							|  |  |  |                     "-key", srctop_file("test", "testrsapss.pem")])), | 
					
						
							|  |  |  |            "Generating request"); | 
					
						
							|  |  |  |         ok(run(app(["openssl", "req", | 
					
						
							|  |  |  |                     "-config", srctop_file("test", "test.cnf"), | 
					
						
							|  |  |  |                     "-verify", "-in", "testreq-rsapss2.pem", "-noout"])), | 
					
						
							|  |  |  |            "Verifying signature on request"); | 
					
						
							| 
									
										
										
										
											2021-01-30 00:02:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         ok(run(app(["openssl", "req", | 
					
						
							|  |  |  |                     "-config", srctop_file("test", "test.cnf"), | 
					
						
							|  |  |  |                     "-new", "-out", "testreq-rsapssmand.pem", "-utf8", | 
					
						
							|  |  |  |                     "-sigopt", "rsa_padding_mode:pss", | 
					
						
							|  |  |  |                     "-key", srctop_file("test", "testrsapssmandatory.pem")])), | 
					
						
							|  |  |  |            "Generating request"); | 
					
						
							|  |  |  |         ok(run(app(["openssl", "req", | 
					
						
							|  |  |  |                     "-config", srctop_file("test", "test.cnf"), | 
					
						
							|  |  |  |                     "-verify", "-in", "testreq-rsapssmand.pem", "-noout"])), | 
					
						
							|  |  |  |            "Verifying signature on request"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         ok(run(app(["openssl", "req", | 
					
						
							|  |  |  |                     "-config", srctop_file("test", "test.cnf"), | 
					
						
							|  |  |  |                     "-new", "-out", "testreq-rsapssmand2.pem", "-utf8", | 
					
						
							|  |  |  |                     "-sigopt", "rsa_pss_saltlen:100", | 
					
						
							|  |  |  |                     "-key", srctop_file("test", "testrsapssmandatory.pem")])), | 
					
						
							|  |  |  |            "Generating request"); | 
					
						
							|  |  |  |         ok(run(app(["openssl", "req", | 
					
						
							|  |  |  |                     "-config", srctop_file("test", "test.cnf"), | 
					
						
							|  |  |  |                     "-verify", "-in", "testreq-rsapssmand2.pem", "-noout"])), | 
					
						
							|  |  |  |            "Verifying signature on request"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         ok(!run(app(["openssl", "req", | 
					
						
							|  |  |  |                      "-config", srctop_file("test", "test.cnf"), | 
					
						
							|  |  |  |                      "-new", "-out", "testreq-rsapss3.pem", "-utf8", | 
					
						
							|  |  |  |                      "-sigopt", "rsa_padding_mode:pkcs1", | 
					
						
							|  |  |  |                      "-key", srctop_file("test", "testrsapss.pem")])), | 
					
						
							|  |  |  |            "Generating request with expected failure"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         ok(!run(app(["openssl", "req", | 
					
						
							|  |  |  |                      "-config", srctop_file("test", "test.cnf"), | 
					
						
							|  |  |  |                      "-new", "-out", "testreq-rsapss3.pem", "-utf8", | 
					
						
							|  |  |  |                      "-sigopt", "rsa_pss_saltlen:-4", | 
					
						
							|  |  |  |                      "-key", srctop_file("test", "testrsapss.pem")])), | 
					
						
							|  |  |  |            "Generating request with expected failure"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         ok(!run(app(["openssl", "req", | 
					
						
							|  |  |  |                      "-config", srctop_file("test", "test.cnf"), | 
					
						
							|  |  |  |                      "-new", "-out", "testreq-rsapssmand3.pem", "-utf8", | 
					
						
							|  |  |  |                      "-sigopt", "rsa_pss_saltlen:10", | 
					
						
							|  |  |  |                      "-key", srctop_file("test", "testrsapssmandatory.pem")])), | 
					
						
							|  |  |  |            "Generating request with expected failure"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         ok(!run(app(["openssl", "req", | 
					
						
							|  |  |  |                      "-config", srctop_file("test", "test.cnf"), | 
					
						
							|  |  |  |                      "-new", "-out", "testreq-rsapssmand3.pem", "-utf8", | 
					
						
							|  |  |  |                      "-sha256", | 
					
						
							|  |  |  |                      "-key", srctop_file("test", "testrsapssmandatory.pem")])), | 
					
						
							|  |  |  |            "Generating request with expected failure"); | 
					
						
							| 
									
										
										
										
											2021-01-26 18:39:27 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 23:17:31 +08:00
										 |  |  | subtest "generating certificate requests with DSA" => sub { | 
					
						
							|  |  |  |     plan tests => 2; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     SKIP: { | 
					
						
							|  |  |  |         skip "DSA is not supported by this OpenSSL build", 2 | 
					
						
							|  |  |  |             if disabled("dsa"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         ok(run(app(["openssl", "req", | 
					
						
							|  |  |  |                     "-config", srctop_file("test", "test.cnf"), | 
					
						
							| 
									
										
										
										
											2020-02-13 07:28:31 +08:00
										 |  |  |                     "-new", "-out", "testreq-dsa.pem", "-utf8", | 
					
						
							| 
									
										
										
										
											2019-10-31 23:17:31 +08:00
										 |  |  |                     "-key", srctop_file("test", "testdsa.pem")])), | 
					
						
							|  |  |  |            "Generating request"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         ok(run(app(["openssl", "req", | 
					
						
							|  |  |  |                     "-config", srctop_file("test", "test.cnf"), | 
					
						
							| 
									
										
										
										
											2020-02-13 07:28:31 +08:00
										 |  |  |                     "-verify", "-in", "testreq-dsa.pem", "-noout"])), | 
					
						
							| 
									
										
										
										
											2019-10-31 23:17:31 +08:00
										 |  |  |            "Verifying signature on request"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | subtest "generating certificate requests with ECDSA" => sub { | 
					
						
							|  |  |  |     plan tests => 2; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     SKIP: { | 
					
						
							|  |  |  |         skip "ECDSA is not supported by this OpenSSL build", 2 | 
					
						
							|  |  |  |             if disabled("ec"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         ok(run(app(["openssl", "req", | 
					
						
							|  |  |  |                     "-config", srctop_file("test", "test.cnf"), | 
					
						
							| 
									
										
										
										
											2020-02-13 07:28:31 +08:00
										 |  |  |                     "-new", "-out", "testreq-ec.pem", "-utf8", | 
					
						
							| 
									
										
										
										
											2019-10-31 23:17:31 +08:00
										 |  |  |                     "-key", srctop_file("test", "testec-p256.pem")])), | 
					
						
							|  |  |  |            "Generating request"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         ok(run(app(["openssl", "req", | 
					
						
							|  |  |  |                     "-config", srctop_file("test", "test.cnf"), | 
					
						
							| 
									
										
										
										
											2020-02-13 07:28:31 +08:00
										 |  |  |                     "-verify", "-in", "testreq-ec.pem", "-noout"])), | 
					
						
							| 
									
										
										
										
											2019-10-31 23:17:31 +08:00
										 |  |  |            "Verifying signature on request"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-11 18:13:10 +08:00
										 |  |  | subtest "generating certificate requests with Ed25519" => sub { | 
					
						
							|  |  |  |     plan tests => 2; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     SKIP: { | 
					
						
							|  |  |  |         skip "Ed25519 is not supported by this OpenSSL build", 2 | 
					
						
							| 
									
										
										
										
											2020-09-15 23:48:55 +08:00
										 |  |  |             if disabled("ec"); | 
					
						
							| 
									
										
										
										
											2019-11-11 18:13:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-15 23:48:55 +08:00
										 |  |  |         ok(run(app(["openssl", "req", | 
					
						
							| 
									
										
										
										
											2019-11-11 18:13:10 +08:00
										 |  |  |                     "-config", srctop_file("test", "test.cnf"), | 
					
						
							| 
									
										
										
										
											2020-02-13 07:28:31 +08:00
										 |  |  |                     "-new", "-out", "testreq-ed25519.pem", "-utf8", | 
					
						
							| 
									
										
										
										
											2019-11-11 18:13:10 +08:00
										 |  |  |                     "-key", srctop_file("test", "tested25519.pem")])), | 
					
						
							|  |  |  |            "Generating request"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-15 23:48:55 +08:00
										 |  |  |         ok(run(app(["openssl", "req", | 
					
						
							| 
									
										
										
										
											2019-11-11 18:13:10 +08:00
										 |  |  |                     "-config", srctop_file("test", "test.cnf"), | 
					
						
							| 
									
										
										
										
											2020-02-13 07:28:31 +08:00
										 |  |  |                     "-verify", "-in", "testreq-ed25519.pem", "-noout"])), | 
					
						
							| 
									
										
										
										
											2019-11-11 18:13:10 +08:00
										 |  |  |            "Verifying signature on request"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | subtest "generating certificate requests with Ed448" => sub { | 
					
						
							|  |  |  |     plan tests => 2; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     SKIP: { | 
					
						
							|  |  |  |         skip "Ed448 is not supported by this OpenSSL build", 2 | 
					
						
							| 
									
										
										
										
											2020-09-15 23:48:55 +08:00
										 |  |  |             if disabled("ec"); | 
					
						
							| 
									
										
										
										
											2019-11-11 18:13:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-15 23:48:55 +08:00
										 |  |  |         ok(run(app(["openssl", "req", | 
					
						
							| 
									
										
										
										
											2019-11-11 18:13:10 +08:00
										 |  |  |                     "-config", srctop_file("test", "test.cnf"), | 
					
						
							| 
									
										
										
										
											2020-02-13 07:28:31 +08:00
										 |  |  |                     "-new", "-out", "testreq-ed448.pem", "-utf8", | 
					
						
							| 
									
										
										
										
											2019-11-11 18:13:10 +08:00
										 |  |  |                     "-key", srctop_file("test", "tested448.pem")])), | 
					
						
							|  |  |  |            "Generating request"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-15 23:48:55 +08:00
										 |  |  |         ok(run(app(["openssl", "req", | 
					
						
							| 
									
										
										
										
											2019-11-11 18:13:10 +08:00
										 |  |  |                     "-config", srctop_file("test", "test.cnf"), | 
					
						
							| 
									
										
										
										
											2020-02-13 07:28:31 +08:00
										 |  |  |                     "-verify", "-in", "testreq-ed448.pem", "-noout"])), | 
					
						
							| 
									
										
										
										
											2019-11-11 18:13:10 +08:00
										 |  |  |            "Verifying signature on request"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-04 07:05:06 +08:00
										 |  |  | subtest "generating certificate requests" => sub { | 
					
						
							|  |  |  |     plan tests => 2; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ok(run(app(["openssl", "req", "-config", srctop_file("test", "test.cnf"), | 
					
						
							| 
									
										
										
										
											2021-08-24 15:31:53 +08:00
										 |  |  |                 "-key", srctop_file(@certs, "ee-key.pem"), | 
					
						
							| 
									
										
										
										
											2019-10-31 23:17:31 +08:00
										 |  |  |                 @req_new, "-out", "testreq.pem"])), | 
					
						
							| 
									
										
										
										
											2016-06-04 07:05:06 +08:00
										 |  |  |        "Generating request"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ok(run(app(["openssl", "req", "-config", srctop_file("test", "test.cnf"), | 
					
						
							| 
									
										
										
										
											2019-10-31 23:17:31 +08:00
										 |  |  |                 "-verify", "-in", "testreq.pem", "-noout"])), | 
					
						
							| 
									
										
										
										
											2016-06-04 07:05:06 +08:00
										 |  |  |        "Verifying signature on request"); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-05 14:46:48 +08:00
										 |  |  | subtest "generating SM2 certificate requests" => sub { | 
					
						
							| 
									
										
										
										
											2019-07-30 23:05:44 +08:00
										 |  |  |     plan tests => 4; | 
					
						
							| 
									
										
										
										
											2019-06-05 14:46:48 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     SKIP: { | 
					
						
							| 
									
										
										
										
											2019-07-30 23:05:44 +08:00
										 |  |  |         skip "SM2 is not supported by this OpenSSL build", 4 | 
					
						
							| 
									
										
										
										
											2020-09-18 17:41:58 +08:00
										 |  |  |         if disabled("sm2"); | 
					
						
							|  |  |  |         ok(run(app(["openssl", "req", | 
					
						
							| 
									
										
										
										
											2019-10-31 23:17:31 +08:00
										 |  |  |                     "-config", srctop_file("test", "test.cnf"), | 
					
						
							| 
									
										
										
										
											2020-12-20 02:49:25 +08:00
										 |  |  |                     "-new", "-key", srctop_file(@certs, "sm2.key"), | 
					
						
							| 
									
										
										
										
											2020-03-11 06:10:29 +08:00
										 |  |  |                     "-sigopt", "distid:1234567812345678", | 
					
						
							| 
									
										
										
										
											2020-02-13 07:28:31 +08:00
										 |  |  |                     "-out", "testreq-sm2.pem", "-sm3"])), | 
					
						
							| 
									
										
										
										
											2019-06-05 14:46:48 +08:00
										 |  |  |            "Generating SM2 certificate request"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-18 17:41:58 +08:00
										 |  |  |         ok(run(app(["openssl", "req", | 
					
						
							| 
									
										
										
										
											2019-10-31 23:17:31 +08:00
										 |  |  |                     "-config", srctop_file("test", "test.cnf"), | 
					
						
							| 
									
										
										
										
											2020-02-13 07:28:31 +08:00
										 |  |  |                     "-verify", "-in", "testreq-sm2.pem", "-noout", | 
					
						
							| 
									
										
										
										
											2020-03-11 06:10:29 +08:00
										 |  |  |                     "-vfyopt", "distid:1234567812345678", "-sm3"])), | 
					
						
							| 
									
										
										
										
											2019-06-05 14:46:48 +08:00
										 |  |  |            "Verifying signature on SM2 certificate request"); | 
					
						
							| 
									
										
										
										
											2019-07-30 23:05:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-18 17:41:58 +08:00
										 |  |  |         ok(run(app(["openssl", "req", | 
					
						
							| 
									
										
										
										
											2019-10-31 23:17:31 +08:00
										 |  |  |                     "-config", srctop_file("test", "test.cnf"), | 
					
						
							| 
									
										
										
										
											2020-12-20 02:49:25 +08:00
										 |  |  |                     "-new", "-key", srctop_file(@certs, "sm2.key"), | 
					
						
							| 
									
										
										
										
											2020-03-11 06:10:29 +08:00
										 |  |  |                     "-sigopt", "hexdistid:DEADBEEF", | 
					
						
							| 
									
										
										
										
											2020-02-13 07:28:31 +08:00
										 |  |  |                     "-out", "testreq-sm2.pem", "-sm3"])), | 
					
						
							| 
									
										
										
										
											2019-07-30 23:05:44 +08:00
										 |  |  |            "Generating SM2 certificate request with hex id"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-18 17:41:58 +08:00
										 |  |  |         ok(run(app(["openssl", "req", | 
					
						
							| 
									
										
										
										
											2019-10-31 23:17:31 +08:00
										 |  |  |                     "-config", srctop_file("test", "test.cnf"), | 
					
						
							| 
									
										
										
										
											2020-02-13 07:28:31 +08:00
										 |  |  |                     "-verify", "-in", "testreq-sm2.pem", "-noout", | 
					
						
							| 
									
										
										
										
											2020-03-11 06:10:29 +08:00
										 |  |  |                     "-vfyopt", "hexdistid:DEADBEEF", "-sm3"])), | 
					
						
							| 
									
										
										
										
											2019-07-30 23:05:44 +08:00
										 |  |  |            "Verifying signature on SM2 certificate request"); | 
					
						
							| 
									
										
										
										
											2019-06-05 14:46:48 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-30 08:05:33 +08:00
										 |  |  | my @openssl_args = ("req", "-config", srctop_file("apps", "openssl.cnf")); | 
					
						
							| 
									
										
										
										
											2015-04-18 02:15:22 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | run_conversion('req conversions', | 
					
						
							| 
									
										
										
										
											2019-10-31 23:17:31 +08:00
										 |  |  |                "testreq.pem"); | 
					
						
							| 
									
										
										
										
											2015-04-18 02:15:22 +08:00
										 |  |  | run_conversion('req conversions -- testreq2', | 
					
						
							| 
									
										
										
										
											2019-10-31 23:17:31 +08:00
										 |  |  |                srctop_file("test", "testreq2.pem")); | 
					
						
							| 
									
										
										
										
											2016-06-04 07:05:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-18 02:15:22 +08:00
										 |  |  | sub run_conversion { | 
					
						
							|  |  |  |     my $title = shift; | 
					
						
							|  |  |  |     my $reqfile = shift; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     subtest $title => sub { | 
					
						
							| 
									
										
										
										
											2019-10-31 23:17:31 +08:00
										 |  |  |         run(app(["openssl", @openssl_args, | 
					
						
							|  |  |  |                  "-in", $reqfile, "-inform", "p", | 
					
						
							|  |  |  |                  "-noout", "-text"], | 
					
						
							|  |  |  |                 stderr => "req-check.err", stdout => undef)); | 
					
						
							|  |  |  |         open DATA, "req-check.err"; | 
					
						
							|  |  |  |         SKIP: { | 
					
						
							|  |  |  |             plan skip_all => "skipping req conversion test for $reqfile" | 
					
						
							|  |  |  |                 if grep /Unknown Public Key/, map { s/\R//; } <DATA>; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-15 22:53:29 +08:00
										 |  |  |             tconversion( -type => 'req', -in => $reqfile, | 
					
						
							|  |  |  |                          -args => [ @openssl_args ] ); | 
					
						
							| 
									
										
										
										
											2019-10-31 23:17:31 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |         close DATA; | 
					
						
							|  |  |  |         unlink "req-check.err"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         done_testing(); | 
					
						
							| 
									
										
										
										
											2015-04-18 02:15:22 +08:00
										 |  |  |     }; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-12-20 02:49:25 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Test both generation and verification of certs w.r.t. RFC 5280 requirements | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | my $ca_cert; # will be set below | 
					
						
							|  |  |  | sub generate_cert { | 
					
						
							|  |  |  |     my $cert = shift @_; | 
					
						
							|  |  |  |     my $ss = $cert =~ m/self-signed/; | 
					
						
							|  |  |  |     my $is_ca = $cert =~ m/CA/; | 
					
						
							|  |  |  |     my $cn = $is_ca ? "CA" : "EE"; | 
					
						
							|  |  |  |     my $ca_key = srctop_file(@certs, "ca-key.pem"); | 
					
						
							|  |  |  |     my $key = $is_ca ? $ca_key : srctop_file(@certs, "ee-key.pem"); | 
					
						
							| 
									
										
										
										
											2021-06-18 14:16:13 +08:00
										 |  |  |     my @cmd = ("openssl", "req", "-config", "", "-x509", | 
					
						
							| 
									
										
										
										
											2022-03-01 20:55:03 +08:00
										 |  |  |                "-subj", "/CN=$cn", @_, "-out", $cert); | 
					
						
							|  |  |  |     push(@cmd, ("-key", $key)) if $ss; | 
					
						
							| 
									
										
										
										
											2020-12-20 02:49:25 +08:00
										 |  |  |     push(@cmd, ("-CA", $ca_cert, "-CAkey", $ca_key)) unless $ss; | 
					
						
							|  |  |  |     ok(run(app([@cmd])), "generate $cert"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | sub has_SKID { | 
					
						
							|  |  |  |     my $cert = shift @_; | 
					
						
							|  |  |  |     my $expect = shift @_; | 
					
						
							|  |  |  |     cert_contains($cert, "Subject Key Identifier", $expect); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | sub has_AKID { | 
					
						
							|  |  |  |     my $cert = shift @_; | 
					
						
							|  |  |  |     my $expect = shift @_; | 
					
						
							|  |  |  |     cert_contains($cert, "Authority Key Identifier", $expect); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-12-24 19:43:39 +08:00
										 |  |  | sub has_keyUsage { | 
					
						
							|  |  |  |     my $cert = shift @_; | 
					
						
							|  |  |  |     my $expect = shift @_; | 
					
						
							|  |  |  |     cert_contains($cert, "Key Usage", $expect); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-12-20 02:49:25 +08:00
										 |  |  | sub strict_verify { | 
					
						
							|  |  |  |     my $cert = shift @_; | 
					
						
							|  |  |  |     my $expect = shift @_; | 
					
						
							|  |  |  |     my $trusted = shift @_; | 
					
						
							|  |  |  |     $trusted = $cert unless $trusted; | 
					
						
							|  |  |  |     ok(run(app(["openssl", "verify", "-x509_strict", "-trusted", $trusted, | 
					
						
							|  |  |  |                 "-partial_chain", $cert])) == $expect, | 
					
						
							|  |  |  |        "strict verify allow $cert"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | my @v3_ca = ("-addext", "basicConstraints = critical,CA:true", | 
					
						
							|  |  |  |              "-addext", "keyUsage = keyCertSign"); | 
					
						
							| 
									
										
										
										
											2020-12-24 18:25:47 +08:00
										 |  |  | my $SKID_AKID = "subjectKeyIdentifier,authorityKeyIdentifier"; | 
					
						
							| 
									
										
										
										
											2021-08-24 15:31:53 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | # # SKID | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | my $cert = "self-signed_v3_CA_hash_SKID.pem"; | 
					
						
							|  |  |  | generate_cert($cert, @v3_ca, "-addext", "subjectKeyIdentifier = hash"); | 
					
						
							|  |  |  | has_SKID($cert, 1); # explicit hash SKID | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $cert = "self-signed_v3_CA_no_SKID.pem"; | 
					
						
							|  |  |  | generate_cert($cert, @v3_ca, "-addext", "subjectKeyIdentifier = none"); | 
					
						
							|  |  |  | cert_ext_has_n_different_lines($cert, 0, $SKID_AKID); # no SKID and no AKID | 
					
						
							|  |  |  | #TODO strict_verify($cert, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $cert = "self-signed_v3_CA_given_SKID.pem"; | 
					
						
							|  |  |  | generate_cert($cert, @v3_ca, "-addext", "subjectKeyIdentifier = 45"); | 
					
						
							|  |  |  | cert_contains($cert, "Subject Key Identifier: 45 ", 1); # given SKID | 
					
						
							|  |  |  | strict_verify($cert, 1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # AKID of self-signed certs | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $cert = "self-signed_v1_CA_no_KIDs.pem"; | 
					
						
							| 
									
										
										
										
											2020-12-20 02:49:25 +08:00
										 |  |  | generate_cert($cert); | 
					
						
							| 
									
										
										
										
											2020-12-24 18:25:47 +08:00
										 |  |  | cert_ext_has_n_different_lines($cert, 0, $SKID_AKID); # no SKID and no AKID | 
					
						
							| 
									
										
										
										
											2020-12-20 02:49:25 +08:00
										 |  |  | #TODO strict_verify($cert, 1); # self-signed v1 root cert should be accepted as CA | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-24 15:31:53 +08:00
										 |  |  | $ca_cert = "self-signed_v3_CA_default_SKID.pem"; # will also be used below | 
					
						
							| 
									
										
										
										
											2020-12-20 02:49:25 +08:00
										 |  |  | generate_cert($ca_cert, @v3_ca); | 
					
						
							| 
									
										
										
										
											2021-08-24 15:31:53 +08:00
										 |  |  | has_SKID($ca_cert, 1); # default SKID | 
					
						
							|  |  |  | has_AKID($ca_cert, 0); # no default AKID | 
					
						
							| 
									
										
										
										
											2020-12-20 02:49:25 +08:00
										 |  |  | strict_verify($ca_cert, 1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-24 15:31:53 +08:00
										 |  |  | $cert = "self-signed_v3_CA_no_AKID.pem"; | 
					
						
							|  |  |  | generate_cert($cert, @v3_ca, "-addext", "authorityKeyIdentifier = none"); | 
					
						
							|  |  |  | has_AKID($cert, 0); # forced no AKID | 
					
						
							| 
									
										
										
										
											2020-12-20 02:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-24 15:31:53 +08:00
										 |  |  | $cert = "self-signed_v3_CA_explicit_AKID.pem"; | 
					
						
							|  |  |  | generate_cert($cert, @v3_ca, "-addext", "authorityKeyIdentifier = keyid"); | 
					
						
							|  |  |  | has_AKID($cert, 0); # for self-signed cert, AKID suppressed and not forced | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $cert = "self-signed_v3_CA_forced_AKID.pem"; | 
					
						
							|  |  |  | generate_cert($cert, @v3_ca, "-addext", "authorityKeyIdentifier = keyid:always"); | 
					
						
							|  |  |  | cert_ext_has_n_different_lines($cert, 3, $SKID_AKID); # forced AKID, AKID == SKID | 
					
						
							| 
									
										
										
										
											2020-12-20 02:49:25 +08:00
										 |  |  | strict_verify($cert, 1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-24 15:31:53 +08:00
										 |  |  | $cert = "self-signed_v3_CA_issuer_AKID.pem"; | 
					
						
							|  |  |  | generate_cert($cert, @v3_ca, "-addext", "authorityKeyIdentifier = issuer"); | 
					
						
							|  |  |  | has_AKID($cert, 0); # suppressed AKID since not forced | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $cert = "self-signed_v3_CA_forced_issuer_AKID.pem"; | 
					
						
							|  |  |  | generate_cert($cert, @v3_ca, "-addext", "authorityKeyIdentifier = issuer:always"); | 
					
						
							|  |  |  | cert_contains($cert, "Authority Key Identifier: DirName:/CN=CA serial:", 1); # forced issuer AKID | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $cert = "self-signed_v3_CA_nonforced_keyid_issuer_AKID.pem"; | 
					
						
							|  |  |  | generate_cert($cert, @v3_ca, "-addext", "authorityKeyIdentifier = keyid, issuer"); | 
					
						
							|  |  |  | has_AKID($cert, 0); # AKID not present because not forced and cert self-signed | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $cert = "self-signed_v3_CA_keyid_forced_issuer_AKID.pem"; | 
					
						
							|  |  |  | generate_cert($cert, @v3_ca, "-addext", "authorityKeyIdentifier = keyid, issuer:always"); | 
					
						
							|  |  |  | cert_contains($cert, "Authority Key Identifier: DirName:/CN=CA serial:", 1); # issuer AKID forced, with keyid not forced | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $cert = "self-signed_v3_CA_forced_keyid_issuer_AKID.pem"; | 
					
						
							|  |  |  | generate_cert($cert, @v3_ca, "-addext", "authorityKeyIdentifier = keyid:always, issuer"); | 
					
						
							|  |  |  | has_AKID($cert, 1); # AKID with keyid forced | 
					
						
							|  |  |  | cert_contains($cert, "Authority Key Identifier: DirName:/CN=CA serial:", 0); # no issuer AKID | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $cert = "self-signed_v3_CA_forced_keyid_forced_issuer_AKID.pem"; | 
					
						
							|  |  |  | generate_cert($cert, @v3_ca, "-addext", "authorityKeyIdentifier = keyid:always, issuer:always"); | 
					
						
							|  |  |  | cert_contains($cert, "Authority Key Identifier: keyid(:[0-9A-Fa-f]{2})+ DirName:/CN=CA serial:", 1); # AKID with keyid and issuer forced | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-20 02:49:25 +08:00
										 |  |  | $cert = "self-signed_v3_EE_wrong_keyUsage.pem"; | 
					
						
							|  |  |  | generate_cert($cert, "-addext", "keyUsage = keyCertSign"); | 
					
						
							|  |  |  | #TODO strict_verify($cert, 1); # should be accepted because RFC 5280 does not apply | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-24 15:31:53 +08:00
										 |  |  | # AKID of self-issued but not self-signed certs | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $cert = "self-issued_x509_v3_CA_default_KIDs.pem"; | 
					
						
							|  |  |  | ok(run(app([("openssl", "x509", "-copy_extensions", "copy", | 
					
						
							|  |  |  |              "-req", "-in", srctop_file(@certs, "ext-check.csr"), | 
					
						
							|  |  |  |              "-key", srctop_file(@certs, "ca-key.pem"), | 
					
						
							|  |  |  |              "-force_pubkey", srctop_file("test", "testrsapub.pem"), | 
					
						
							|  |  |  |              "-out", $cert)])), "generate using x509: $cert"); | 
					
						
							|  |  |  | cert_contains($cert, "Issuer: CN=test .*? Subject: CN=test", 1); | 
					
						
							|  |  |  | cert_ext_has_n_different_lines($cert, 4, $SKID_AKID); # SKID != AKID | 
					
						
							|  |  |  | strict_verify($cert, 1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $cert = "self-issued_v3_CA_default_KIDs.pem"; | 
					
						
							|  |  |  | generate_cert($cert, "-addext", "keyUsage = dataEncipherment", | 
					
						
							|  |  |  |     "-in", srctop_file(@certs, "x509-check.csr")); | 
					
						
							|  |  |  | cert_contains($cert, "Issuer: CN=CA .*? Subject: CN=CA", 1); | 
					
						
							|  |  |  | cert_ext_has_n_different_lines($cert, 4, $SKID_AKID); # SKID != AKID | 
					
						
							|  |  |  | strict_verify($cert, 1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $cert = "self-issued_v3_CA_no_AKID.pem"; | 
					
						
							|  |  |  | generate_cert($cert, "-addext", "authorityKeyIdentifier = none", | 
					
						
							|  |  |  |     "-in", srctop_file(@certs, "x509-check.csr")); | 
					
						
							|  |  |  | has_AKID($cert, 0); | 
					
						
							|  |  |  | strict_verify($cert, 1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $cert = "self-issued_v3_CA_explicit_AKID.pem"; | 
					
						
							|  |  |  | generate_cert($cert, "-addext", "authorityKeyIdentifier = keyid", | 
					
						
							|  |  |  |     "-in", srctop_file(@certs, "x509-check.csr")); | 
					
						
							|  |  |  | cert_ext_has_n_different_lines($cert, 4, $SKID_AKID); # SKID != AKID | 
					
						
							|  |  |  | strict_verify($cert, 1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $cert = "self-issued_v3_CA_forced_AKID.pem"; | 
					
						
							|  |  |  | generate_cert($cert, "-addext", "authorityKeyIdentifier = keyid:always", | 
					
						
							|  |  |  |     "-in", srctop_file(@certs, "x509-check.csr")); | 
					
						
							|  |  |  | cert_ext_has_n_different_lines($cert, 4, $SKID_AKID); # SKID != AKID | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $cert = "self-issued_v3_CA_issuer_AKID.pem"; | 
					
						
							|  |  |  | generate_cert($cert, @v3_ca, "-addext", "authorityKeyIdentifier = issuer", | 
					
						
							|  |  |  |     "-in", srctop_file(@certs, "x509-check.csr")); | 
					
						
							|  |  |  | cert_contains($cert, "Authority Key Identifier: DirName:/CN=CA serial:", 1); # just issuer AKID | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $cert = "self-issued_v3_CA_forced_issuer_AKID.pem"; | 
					
						
							|  |  |  | generate_cert($cert, @v3_ca, "-addext", "authorityKeyIdentifier = issuer:always", | 
					
						
							|  |  |  |     "-in", srctop_file(@certs, "x509-check.csr")); | 
					
						
							|  |  |  | cert_contains($cert, "Authority Key Identifier: DirName:/CN=CA serial:", 1); # just issuer AKID | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $cert = "self-issued_v3_CA_keyid_issuer_AKID.pem"; | 
					
						
							|  |  |  | generate_cert($cert, "-addext", "authorityKeyIdentifier = keyid, issuer", | 
					
						
							|  |  |  |     "-in", srctop_file(@certs, "x509-check.csr")); | 
					
						
							|  |  |  | cert_ext_has_n_different_lines($cert, 4, $SKID_AKID); # SKID != AKID, not forced | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $cert = "self-issued_v3_CA_keyid_forced_issuer_AKID.pem"; | 
					
						
							|  |  |  | generate_cert($cert, "-addext", "authorityKeyIdentifier = keyid, issuer:always", | 
					
						
							|  |  |  |     "-in", srctop_file(@certs, "x509-check.csr")); | 
					
						
							|  |  |  | cert_ext_has_n_different_lines($cert, 6, $SKID_AKID); # SKID != AKID, with forced issuer | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $cert = "self-issued_v3_CA_forced_keyid_and_issuer_AKID.pem"; | 
					
						
							|  |  |  | generate_cert($cert, "-addext", "authorityKeyIdentifier = keyid:always, issuer:always", | 
					
						
							|  |  |  |     "-in", srctop_file(@certs, "x509-check.csr")); | 
					
						
							|  |  |  | cert_ext_has_n_different_lines($cert, 6, $SKID_AKID); # SKID != AKID, both forced | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # AKID of not self-issued certs | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $cert = "regular_v3_EE_default_KIDs.pem"; | 
					
						
							| 
									
										
										
										
											2022-03-01 20:55:03 +08:00
										 |  |  | generate_cert($cert, "-addext", "keyUsage = dataEncipherment", | 
					
						
							|  |  |  |     "-key", srctop_file(@certs, "ee-key.pem")); | 
					
						
							| 
									
										
										
										
											2020-12-24 18:25:47 +08:00
										 |  |  | cert_ext_has_n_different_lines($cert, 4, $SKID_AKID); # SKID != AKID | 
					
						
							| 
									
										
										
										
											2020-12-20 02:49:25 +08:00
										 |  |  | strict_verify($cert, 1, $ca_cert); | 
					
						
							| 
									
										
										
										
											2022-03-01 20:55:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-24 15:31:53 +08:00
										 |  |  | $cert = "regular_v3_EE_copied_exts_default_KIDs.pem"; | 
					
						
							|  |  |  | generate_cert($cert, "-copy_extensions", "copy", | 
					
						
							|  |  |  |               "-in", srctop_file(@certs, "ext-check.csr")); | 
					
						
							|  |  |  | cert_ext_has_n_different_lines($cert, 4, $SKID_AKID); # SKID != AKID | 
					
						
							|  |  |  | strict_verify($cert, 1); | 
					
						
							| 
									
										
										
										
											2020-12-20 02:49:25 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | $cert = "v3_EE_no_AKID.pem"; | 
					
						
							| 
									
										
										
										
											2022-03-01 20:55:03 +08:00
										 |  |  | generate_cert($cert, "-addext", "authorityKeyIdentifier = none", | 
					
						
							|  |  |  |     "-key", srctop_file(@certs, "ee-key.pem")); | 
					
						
							| 
									
										
										
										
											2020-12-20 02:49:25 +08:00
										 |  |  | has_SKID($cert, 1); | 
					
						
							|  |  |  | has_AKID($cert, 0); | 
					
						
							|  |  |  | strict_verify($cert, 0, $ca_cert); | 
					
						
							| 
									
										
										
										
											2020-12-24 18:25:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-24 19:43:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-24 15:31:53 +08:00
										 |  |  | # Key Usage | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $cert = "self-signed_CA_no_keyUsage.pem"; | 
					
						
							| 
									
										
										
										
											2020-12-24 19:43:39 +08:00
										 |  |  | generate_cert($cert, "-in", srctop_file(@certs, "ext-check.csr")); | 
					
						
							|  |  |  | has_keyUsage($cert, 0); | 
					
						
							| 
									
										
										
										
											2021-08-24 15:31:53 +08:00
										 |  |  | $cert = "self-signed_CA_with_keyUsages.pem"; | 
					
						
							| 
									
										
										
										
											2020-12-24 19:43:39 +08:00
										 |  |  | generate_cert($cert, "-in", srctop_file(@certs, "ext-check.csr"), | 
					
						
							|  |  |  |     "-copy_extensions", "copy"); | 
					
						
							|  |  |  | has_keyUsage($cert, 1); |