]>
git.ipfire.org Git - thirdparty/openssl.git/blob - test/recipes/25-test_req.t
2 # Copyright 2015-2018 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
13 use OpenSSL
::Test
::Utils
;
14 use OpenSSL
::Test qw
/:DEFAULT srctop_file/;
20 require_ok
(srctop_file
('test','recipes','tconversion.pl'));
22 # What type of key to generate?
24 if (disabled
("rsa")) {
25 @req_new = ("-newkey", "dsa:".srctop_file
("apps", "dsa512.pem"));
28 note
("There should be a 2 sequences of .'s and some +'s.");
29 note
("There should not be more that at most 80 per line");
32 # Check for duplicate -addext parameters, and one "working" case.
33 my @addext_args = ( "openssl", "req", "-new", "-out", "testreq.pem",
34 "-config", srctop_file
("test", "test.cnf"), @req_new );
35 my $val = "subjectAltName=DNS:example.com";
36 my $val2 = " " . $val;
39 ok
( run
(app
([@addext_args, "-addext", $val])));
40 ok
(!run
(app
([@addext_args, "-addext", $val, "-addext", $val])));
41 ok
(!run
(app
([@addext_args, "-addext", $val, "-addext", $val2])));
42 ok
(!run
(app
([@addext_args, "-addext", $val, "-addext", $val3])));
43 ok
(!run
(app
([@addext_args, "-addext", $val2, "-addext", $val3])));
45 subtest
"generating certificate requests with RSA" => sub {
49 skip
"RSA is not supported by this OpenSSL build", 2
52 ok
(run
(app
(["openssl", "req",
53 "-config", srctop_file
("test", "test.cnf"),
54 "-new", "-out", "testreq.pem", "-utf8",
55 "-key", srctop_file
("test", "testrsa.pem")])),
56 "Generating request");
58 ok
(run
(app
(["openssl", "req",
59 "-config", srctop_file
("test", "test.cnf"),
60 "-verify", "-in", "testreq.pem", "-noout"])),
61 "Verifying signature on request");
65 subtest
"generating certificate requests with DSA" => sub {
69 skip
"DSA is not supported by this OpenSSL build", 2
72 ok
(run
(app
(["openssl", "req",
73 "-config", srctop_file
("test", "test.cnf"),
74 "-new", "-out", "testreq.pem", "-utf8",
75 "-key", srctop_file
("test", "testdsa.pem")])),
76 "Generating request");
78 ok
(run
(app
(["openssl", "req",
79 "-config", srctop_file
("test", "test.cnf"),
80 "-verify", "-in", "testreq.pem", "-noout"])),
81 "Verifying signature on request");
85 subtest
"generating certificate requests with ECDSA" => sub {
89 skip
"ECDSA is not supported by this OpenSSL build", 2
92 ok
(run
(app
(["openssl", "req",
93 "-config", srctop_file
("test", "test.cnf"),
94 "-new", "-out", "testreq.pem", "-utf8",
95 "-key", srctop_file
("test", "testec-p256.pem")])),
96 "Generating request");
98 ok
(run
(app
(["openssl", "req",
99 "-config", srctop_file
("test", "test.cnf"),
100 "-verify", "-in", "testreq.pem", "-noout"])),
101 "Verifying signature on request");
105 subtest
"generating certificate requests" => sub {
108 ok
(run
(app
(["openssl", "req", "-config", srctop_file
("test", "test.cnf"),
109 @req_new, "-out", "testreq.pem"])),
110 "Generating request");
112 ok
(run
(app
(["openssl", "req", "-config", srctop_file
("test", "test.cnf"),
113 "-verify", "-in", "testreq.pem", "-noout"])),
114 "Verifying signature on request");
117 subtest
"generating SM2 certificate requests" => sub {
121 skip
"SM2 is not supported by this OpenSSL build", 4
123 ok
(run
(app
(["openssl", "req",
124 "-config", srctop_file
("test", "test.cnf"),
125 "-new", "-key", srctop_file
("test", "certs", "sm2.key"),
126 "-sigopt", "sm2_id:1234567812345678",
127 "-out", "testreq.pem", "-sm3"])),
128 "Generating SM2 certificate request");
130 ok
(run
(app
(["openssl", "req",
131 "-config", srctop_file
("test", "test.cnf"),
132 "-verify", "-in", "testreq.pem", "-noout",
133 "-sm2-id", "1234567812345678", "-sm3"])),
134 "Verifying signature on SM2 certificate request");
136 ok
(run
(app
(["openssl", "req",
137 "-config", srctop_file
("test", "test.cnf"),
138 "-new", "-key", srctop_file
("test", "certs", "sm2.key"),
139 "-sigopt", "sm2_hex_id:DEADBEEF",
140 "-out", "testreq.pem", "-sm3"])),
141 "Generating SM2 certificate request with hex id");
143 ok
(run
(app
(["openssl", "req",
144 "-config", srctop_file
("test", "test.cnf"),
145 "-verify", "-in", "testreq.pem", "-noout",
146 "-sm2-hex-id", "DEADBEEF", "-sm3"])),
147 "Verifying signature on SM2 certificate request");
151 my @openssl_args = ("req", "-config", srctop_file
("apps", "openssl.cnf"));
153 run_conversion
('req conversions',
155 run_conversion
('req conversions -- testreq2',
156 srctop_file
("test", "testreq2.pem"));
158 unlink "testkey.pem", "testreq.pem";
164 subtest
$title => sub {
165 run
(app
(["openssl", @openssl_args,
166 "-in", $reqfile, "-inform", "p",
168 stderr
=> "req-check.err", stdout
=> undef));
169 open DATA
, "req-check.err";
171 plan skip_all
=> "skipping req conversion test for $reqfile"
172 if grep /Unknown Public Key/, map { s/\R//; } <DATA
>;
174 tconversion
("req", $reqfile, @openssl_args);
177 unlink "req-check.err";