xref: /openssl/test/recipes/25-test_x509.t (revision 1e307e65)
1#! /usr/bin/env perl
2# Copyright 2015-2024 The OpenSSL Project Authors. All Rights Reserved.
3#
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
8
9
10use strict;
11use warnings;
12
13use File::Spec;
14use OpenSSL::Test::Utils;
15use OpenSSL::Test qw/:DEFAULT srctop_file/;
16
17setup("test_x509");
18
19plan tests => 124;
20
21# Prevent MSys2 filename munging for arguments that look like file paths but
22# aren't
23$ENV{MSYS2_ARG_CONV_EXCL} = "/CN=";
24
25require_ok(srctop_file("test", "recipes", "tconversion.pl"));
26
27my @certs = qw(test certs);
28my $pem = srctop_file(@certs, "cyrillic.pem");
29my $out_msb = "out-cyrillic.msb";
30my $out_utf8 = "out-cyrillic.utf8";
31my $der = "cyrillic.der";
32my $der2 = "cyrillic.der";
33my $msb = srctop_file(@certs, "cyrillic.msb");
34my $utf = srctop_file(@certs, "cyrillic.utf8");
35
36ok(run(app(["openssl", "x509", "-text", "-in", $pem, "-out", $out_msb,
37            "-nameopt", "esc_msb"])));
38is(cmp_text($out_msb, $msb),
39   0, 'Comparing esc_msb output with cyrillic.msb');
40ok(run(app(["openssl", "x509", "-text", "-in", $pem, "-out", $out_utf8,
41            "-nameopt", "utf8"])));
42is(cmp_text($out_utf8, $utf),
43   0, 'Comparing utf8 output with cyrillic.utf8');
44
45SKIP: {
46    skip "DES disabled", 1 if disabled("des");
47    skip "Platform doesn't support command line UTF-8", 1 if $^O =~ /^(VMS|msys)$/;
48
49    my $p12 = srctop_file("test", "shibboleth.pfx");
50    my $p12pass = "σύνθημα γνώρισμα";
51    my $out_pem = "out.pem";
52    ok(run(app(["openssl", "x509", "-text", "-in", $p12, "-out", $out_pem,
53                "-passin", "pass:$p12pass"])));
54    # not unlinking $out_pem
55}
56
57ok(!run(app(["openssl", "x509", "-in", $pem, "-inform", "DER",
58             "-out", $der, "-outform", "DER"])),
59   "Checking failure of mismatching -inform DER");
60ok(run(app(["openssl", "x509", "-in", $pem, "-inform", "PEM",
61            "-out", $der, "-outform", "DER"])),
62   "Conversion to DER");
63ok(!run(app(["openssl", "x509", "-in", $der, "-inform", "PEM",
64             "-out", $der2, "-outform", "DER"])),
65   "Checking failure of mismatching -inform PEM");
66
67# producing and checking self-issued (but not self-signed) cert
68my $subj = "/CN=CA"; # using same DN as in issuer of ee-cert.pem
69my $extfile = srctop_file("test", "v3_ca_exts.cnf");
70my $pkey = srctop_file(@certs, "ca-key.pem"); # issuer private key
71my $pubkey = "ca-pubkey.pem"; # the corresponding issuer public key
72# use any (different) key for signing our self-issued cert:
73my $key = srctop_file(@certs, "serverkey.pem");
74my $selfout = "self-issued.out";
75my $testcert = srctop_file(@certs, "ee-cert.pem");
76ok(run(app(["openssl", "pkey", "-in", $pkey, "-pubout", "-out", $pubkey]))
77&& run(app(["openssl", "x509", "-new", "-force_pubkey", $pubkey, "-subj", $subj,
78            "-extfile", $extfile, "-key", $key, "-out", $selfout]))
79&& run(app(["openssl", "verify", "-no_check_time",
80            "-trusted", $selfout, "-partial_chain", $testcert])));
81# not unlinking $pubkey
82# not unlinking $selfout
83
84# test -set_issuer option
85my $ca_issu = srctop_file(@certs, "ca-cert.pem"); # issuer cert
86my $caout_issu = "ca-issu.out";
87ok(run(app(["openssl", "x509", "-new", "-force_pubkey", $key, "-subj", "/CN=EE",
88            "-set_issuer", "/CN=TEST-CA", "-extfile", $extfile, "-CA", $ca_issu,
89            "-CAkey", $pkey, "-text", "-out", $caout_issu])));
90ok(get_issuer($caout_issu) =~ /CN=TEST-CA/);
91# not unlinking $caout
92
93# simple way of directly producing a CA-signed cert with private/pubkey input
94my $ca = srctop_file(@certs, "ca-cert.pem"); # issuer cert
95my $caout = "ca-issued.out";
96ok(run(app(["openssl", "x509", "-new", "-force_pubkey", $key, "-subj", "/CN=EE",
97            "-extfile", $extfile, "-CA", $ca, "-CAkey", $pkey, "-out", $caout]))
98&& run(app(["openssl", "verify", "-no_check_time",
99            "-trusted", $ca, "-partial_chain", $caout])));
100
101subtest 'x509 -- x.509 v1 certificate' => sub {
102    tconversion( -type => 'x509', -prefix => 'x509v1',
103                 -in => srctop_file("test", "testx509.pem") );
104};
105subtest 'x509 -- first x.509 v3 certificate' => sub {
106    tconversion( -type => 'x509', -prefix => 'x509v3-1',
107                 -in => srctop_file("test", "v3-cert1.pem") );
108};
109subtest 'x509 -- second x.509 v3 certificate' => sub {
110    tconversion( -type => 'x509', -prefix => 'x509v3-2',
111                 -in => srctop_file("test", "v3-cert2.pem") );
112};
113
114subtest 'x509 -- pathlen' => sub {
115    ok(run(test(["v3ext", srctop_file(@certs, "pathlen.pem")])));
116};
117
118cert_contains(srctop_file(@certs, "fake-gp.pem"),
119              "2.16.528.1.1003.1.3.5.5.2-1-0000006666-Z-12345678-01.015-12345678",
120              1, 'x500 -- subjectAltName');
121
122cert_contains(srctop_file(@certs, "ext-noAssertion.pem"),
123              "No Assertion",
124              1, 'X.509 Not Assertion Extension');
125
126cert_contains(srctop_file(@certs, "ext-groupAC.pem"),
127              "Group Attribute Certificate",
128              1, 'X.509 Group Attribute Certificate Extension');
129
130cert_contains(srctop_file(@certs, "ext-sOAIdentifier.pem"),
131              "Source of Authority",
132              1, 'X.509 Source of Authority Extension');
133
134cert_contains(srctop_file(@certs, "ext-noRevAvail.pem"),
135              "No Revocation Available",
136              1, 'X.509 No Revocation Available');
137
138cert_contains(srctop_file(@certs, "ext-singleUse.pem"),
139              "Single Use",
140              1, 'X509v3 Single Use');
141
142cert_contains(srctop_file(@certs, "ext-indirectIssuer.pem"),
143              "Indirect Issuer",
144              1, 'X.509 Indirect Issuer');
145
146my $tgt_info_cert = srctop_file(@certs, "ext-targetingInformation.pem");
147cert_contains($tgt_info_cert,
148              "AC Targeting",
149              1, 'X.509 Targeting Information Extension');
150cert_contains($tgt_info_cert,
151              "Targets:",
152              1, 'X.509 Targeting Information Targets');
153cert_contains($tgt_info_cert,
154              "Target:",
155              1, 'X.509 Targeting Information Target');
156cert_contains($tgt_info_cert,
157              "Target Name: DirName:CN = W",
158              1, 'X.509 Targeting Information Target Name');
159cert_contains($tgt_info_cert,
160              "Target Group: DNS:wildboarsoftware.com",
161              1, 'X.509 Targeting Information Target Name');
162cert_contains($tgt_info_cert,
163              "Issuer Names:",
164              1, 'X.509 Targeting Information Issuer Names');
165cert_contains($tgt_info_cert,
166              "Issuer Serial: 01020304",
167              1, 'X.509 Targeting Information Issuer Serial');
168cert_contains($tgt_info_cert,
169              "Issuer UID: B0",
170              1, 'X.509 Targeting Information Issuer UID');
171cert_contains($tgt_info_cert,
172              "Digest Type: Public Key",
173              1, 'X.509 Targeting Information Object Digest Type');
174
175my $hnc_cert = srctop_file(@certs, "ext-holderNameConstraints.pem");
176cert_contains($hnc_cert,
177              "X509v3 Holder Name Constraints",
178              1, 'X.509 Holder Name Constraints');
179cert_contains($hnc_cert,
180              "Permitted:",
181              1, 'X.509 Holder Name Constraints Permitted');
182cert_contains($hnc_cert,
183              "DirName:CN = Wildboar",
184              1, 'X.509 Holder Name Constraint');
185
186my $dnc_cert = srctop_file(@certs, "ext-delegatedNameConstraints.pem");
187cert_contains($dnc_cert,
188              "X509v3 Delegated Name Constraints",
189              1, 'X.509 Delegated Name Constraints');
190cert_contains($dnc_cert,
191              "Permitted:",
192              1, 'X.509 Delegated Name Constraints Permitted');
193cert_contains($dnc_cert,
194              "DirName:CN = Wildboar",
195              1, 'X.509 Delegated Name Constraint');
196my $sda_cert = srctop_file(@certs, "ext-subjectDirectoryAttributes.pem");
197cert_contains($sda_cert,
198              "Steve Brule",
199              1, 'X.509 Subject Directory Attributes');
200cert_contains($sda_cert,
201              "CN=Hi mom",
202              1, 'X.509 Subject Directory Attributes');
203cert_contains($sda_cert,
204              "<No Values>",
205              1, 'X.509 Subject Directory Attributes');
206cert_contains($sda_cert,
207              "Funkytown",
208              1, 'X.509 Subject Directory Attributes');
209cert_contains($sda_cert,
210              "commonName",
211              1, 'X.509 Subject Directory Attributes');
212cert_contains($sda_cert,
213              "owner",
214              1, 'X.509 Subject Directory Attributes');
215cert_contains($sda_cert,
216              "givenName",
217              1, 'X.509 Subject Directory Attributes');
218cert_contains($sda_cert,
219              "localityName",
220              1, 'X.509 Subject Directory Attributes');
221
222my $ass_info_cert = srctop_file(@certs, "ext-associatedInformation.pem");
223cert_contains($ass_info_cert,
224              "Steve Brule",
225              1, 'X509v3 Associated Information');
226cert_contains($ass_info_cert,
227              "CN=Hi mom",
228              1, 'X509v3 Associated Information');
229cert_contains($ass_info_cert,
230              "<No Values>",
231              1, 'X509v3 Associated Information');
232cert_contains($ass_info_cert,
233              "Funkytown",
234              1, 'X509v3 Associated Information');
235cert_contains($ass_info_cert,
236              "commonName",
237              1, 'X509v3 Associated Information');
238cert_contains($ass_info_cert,
239              "owner",
240              1, 'X509v3 Associated Information');
241cert_contains($sda_cert,
242              "givenName",
243              1, 'X509v3 Associated Information');
244cert_contains($ass_info_cert,
245              "localityName",
246              1, 'X509v3 Associated Information');
247
248my $acc_cert_pol = srctop_file(@certs, "ext-acceptableCertPolicies.pem");
249cert_contains($acc_cert_pol,
250              "X509v3 Acceptable Certification Policies",
251              1, 'X509v3 Acceptable Certification Policies');
252# Yes, I know these OIDs make no sense in a policies extension. It's just a test.
253cert_contains($acc_cert_pol,
254              "organizationalUnitName",
255              1, 'X509v3 Acceptable Certification Policies');
256cert_contains($acc_cert_pol,
257              "description",
258              1, 'X509v3 Acceptable Certification Policies');
259
260my $acc_priv_pol = srctop_file(@certs, "ext-acceptablePrivilegePolicies.pem");
261cert_contains($acc_priv_pol,
262              "X509v3 Acceptable Privilege Policies",
263              1, 'X509v3 Acceptable Privilege Policies');
264# Yes, I know these OIDs make no sense in a policies extension. It's just a test.
265cert_contains($acc_priv_pol,
266              "commonName",
267              1, 'X509v3 Acceptable Certification Policies');
268cert_contains($acc_priv_pol,
269              "organizationName",
270              1, 'X509v3 Acceptable Certification Policies');
271
272my $user_notice_cert = srctop_file(@certs, "ext-userNotice.pem");
273cert_contains($user_notice_cert,
274              "Organization: Wildboar Software",
275              1, 'X509v3 User Notice');
276cert_contains($user_notice_cert,
277              "Numbers: 123, 456",
278              1, 'X509v3 User Notice');
279cert_contains($user_notice_cert,
280              "Explicit Text: Hey there big boi",
281              1, 'X509v3 User Notice');
282cert_contains($user_notice_cert,
283              "Number: 50505",
284              1, 'X509v3 User Notice');
285cert_contains($user_notice_cert,
286              "Explicit Text: Ice ice baby",
287              1, 'X509v3 User Notice');
288
289my $battcons_cert = srctop_file(@certs, "ext-basicAttConstraints.pem");
290cert_contains($battcons_cert,
291              "authority:TRUE",
292              1, 'X.509 Basic Attribute Constraints Authority');
293cert_contains($battcons_cert,
294              "pathlen:3",
295              1, 'X.509 Basic Attribute Constraints Path Length');
296
297my $audit_id_cert = srctop_file(@certs, "ext-auditIdentity.pem");
298cert_contains($audit_id_cert,
299              "09:08:07",
300              1, 'X509v3 Audit Identity');
301
302my $iobo_cert = srctop_file(@certs, "ext-issuedOnBehalfOf.pem");
303cert_contains($iobo_cert,
304              "DirName:CN = Wildboar",
305              1, 'X.509 Issued On Behalf Of');
306
307my $auth_att_id_cert = srctop_file(@certs, "ext-authorityAttributeIdentifier.pem");
308cert_contains($auth_att_id_cert,
309              "DirName:CN = Wildboar",
310              1, 'X.509 Authority Attribute Identifier');
311cert_contains($auth_att_id_cert,
312              "Issuer Serial: 01030507",
313              1, 'X.509 Authority Attribute Identifier');
314cert_contains($auth_att_id_cert,
315              "Issuer UID: B2",
316              1, 'X.509 Authority Attribute Identifier');
317
318my $role_spec_cert = srctop_file(@certs, "ext-roleSpecCertIdentifier.pem");
319cert_contains($role_spec_cert,
320              "Role Name: DirName:CN = Wildboar",
321              1, 'X.509 Role Spec Certificate Identifier');
322cert_contains($role_spec_cert,
323              "Role Certificate Issuer: DirName:CN",
324              1, 'X.509 Role Spec Certificate Identifier');
325cert_contains($role_spec_cert,
326              "Role Certificate Serial Number: 33818120 \\(0x2040608\\)",
327              1, 'X.509 Role Spec Certificate Identifier');
328cert_contains($role_spec_cert,
329              "DNS:wildboarsoftware.com",
330              1, 'X.509 Role Spec Certificate Identifier');
331cert_contains($role_spec_cert,
332              "Registered ID:description",
333              1, 'X.509 Role Spec Certificate Identifier');
334
335my $attr_desc_cert = srctop_file(@certs, "ext-attributeDescriptor.pem");
336cert_contains($attr_desc_cert,
337              "Identifier: 2.5.4.3",
338              1, 'X.509 Attribute Descriptor');
339# This comes from the syntax field, which starts on the next line.
340cert_contains($attr_desc_cert,
341              "UnboundedDirectoryString",
342              1, 'X.509 Attribute Descriptor');
343cert_contains($attr_desc_cert,
344              "Name: commonName",
345              1, 'X.509 Attribute Descriptor');
346# These comes from the dominationRule field.
347cert_contains($attr_desc_cert,
348              "Privilege Policy Identifier: 2.5.4.10",
349              1, 'X.509 Attribute Descriptor');
350cert_contains($attr_desc_cert,
351              "DirName:CN = Wildboar",
352              1, 'X.509 Attribute Descriptor');
353cert_contains($attr_desc_cert,
354              "Algorithm: sha256",
355              1, 'X.509 Attribute Descriptor');
356
357my $time_spec_abs_cert = srctop_file(@certs, "ext-timeSpecification-absolute.pem");
358cert_contains($time_spec_abs_cert,
359              "Timezone: UTC-05:00",
360              1, 'X.509 Time Specification (Absolute)');
361cert_contains($time_spec_abs_cert,
362              "Absolute: Any time between Dec 20 13:07:21 2022 GMT and Dec 20 13:07:21 2022 GMT",
363              1, 'X.509 Time Specification (Absolute)');
364
365my $time_spec_per_cert = srctop_file(@certs, "ext-timeSpecification-periodic.pem");
366cert_contains($time_spec_per_cert,
367              "Timezone: UTC-05:00",
368              1, 'X.509 Time Specification (Periodic)');
369cert_contains($time_spec_per_cert,
370              "NOT this time:",
371              1, 'X.509 Time Specification (Periodic)');
372cert_contains($time_spec_per_cert,
373              "05:43:21 - 12:34:56",
374              1, 'X.509 Time Specification (Periodic)');
375cert_contains($time_spec_per_cert,
376              "Days of the week: SUN, MON",
377              1, 'X.509 Time Specification (Periodic)');
378cert_contains($time_spec_per_cert,
379              "Weeks of the month: 3, 4",
380              1, 'X.509 Time Specification (Periodic)');
381cert_contains($time_spec_per_cert,
382              "Months: MAY, JUN",
383              1, 'X.509 Time Specification (Periodic)');
384cert_contains($time_spec_per_cert,
385              "Years: 2022, 2023",
386              1, 'X.509 Time Specification (Periodic)');
387cert_contains($time_spec_per_cert,
388              "Months: JUL, AUG",
389              1, 'X.509 Time Specification (Periodic)');
390cert_contains($time_spec_per_cert,
391              "Years: 2023, 2024",
392              1, 'X.509 Time Specification (Periodic)');
393
394my $attr_map_cert = srctop_file(@certs, "ext-attributeMappings.pem");
395cert_contains($attr_map_cert,
396              "commonName == localityName",
397              1, 'X.509 Attribute Mappings');
398# localityName has an INTEGER value here, which was intentional to test the
399# display of non-string values.
400cert_contains($attr_map_cert,
401              "commonName:asdf == localityName:03:3E",
402              1, 'X.509 Attribute Mappings');
403
404sub test_errors { # actually tests diagnostics of OSSL_STORE
405    my ($expected, $cert, @opts) = @_;
406    my $infile = srctop_file(@certs, $cert);
407    my @args = qw(openssl x509 -in);
408    push(@args, $infile, @opts);
409    my $tmpfile = 'out.txt';
410    my $res =  grep(/-text/, @opts) ? run(app([@args], stdout => $tmpfile))
411                                    : !run(app([@args], stderr => $tmpfile));
412    my $found = 0;
413    open(my $in, '<', $tmpfile) or die "Could not open file $tmpfile";
414    while(<$in>) {
415        print; # this may help debugging
416        $res &&= !m/asn1 encoding/; # output must not include ASN.1 parse errors
417        $found = 1 if m/$expected/; # output must include $expected
418    }
419    close $in;
420    # $tmpfile is kept to help with investigation in case of failure
421    return $res && $found;
422}
423
424# 3 tests for non-existence of spurious OSSL_STORE ASN.1 parse error output.
425# This requires provoking a failure exit of the app after reading input files.
426ok(test_errors("Bad output format", "root-cert.pem", '-outform', 'http'),
427   "load root-cert errors");
428ok(test_errors("RC2-40-CBC", "v3-certs-RC2.p12", '-passin', 'pass:v3-certs'),
429   "load v3-certs-RC2 no asn1 errors"); # error msg should mention "RC2-40-CBC"
430SKIP: {
431    skip "sm2 not disabled", 1 if !disabled("sm2");
432
433    ok(test_errors("Unable to load Public Key", "sm2.pem", '-text'),
434       "error loading unsupported sm2 cert");
435}
436
437# 3 tests for -dateopts formats
438ok(run(app(["openssl", "x509", "-noout", "-dates", "-dateopt", "rfc_822",
439	     "-in", srctop_file("test/certs", "ca-cert.pem")])),
440   "Run with rfc_8222 -dateopt format");
441ok(run(app(["openssl", "x509", "-noout", "-dates", "-dateopt", "iso_8601",
442	     "-in", srctop_file("test/certs", "ca-cert.pem")])),
443   "Run with iso_8601 -dateopt format");
444ok(!run(app(["openssl", "x509", "-noout", "-dates", "-dateopt", "invalid_format",
445	     "-in", srctop_file("test/certs", "ca-cert.pem")])),
446   "Run with invalid -dateopt format");
447
448# Tests for signing certs (broken in 1.1.1o)
449my $a_key = "a-key.pem";
450my $a_cert = "a-cert.pem";
451my $a2_cert = "a2-cert.pem";
452my $ca_key = "ca-key.pem";
453my $ca_cert = "ca-cert.pem";
454my $cnf = srctop_file('apps', 'openssl.cnf');
455
456# Create cert A
457ok(run(app(["openssl", "req", "-x509", "-newkey", "rsa:2048",
458            "-config", $cnf,
459            "-keyout", $a_key, "-out", $a_cert, "-days", "365",
460            "-nodes", "-subj", "/CN=test.example.com"])));
461# Create cert CA - note key size
462ok(run(app(["openssl", "req", "-x509", "-newkey", "rsa:4096",
463            "-config", $cnf,
464            "-keyout", $ca_key, "-out", $ca_cert, "-days", "3650",
465            "-nodes", "-subj", "/CN=ca.example.com"])));
466# Sign cert A with CA (errors on 1.1.1o)
467ok(run(app(["openssl", "x509", "-in", $a_cert, "-CA", $ca_cert,
468            "-CAkey", $ca_key, "-set_serial", "1234567890",
469            "-preserve_dates", "-sha256", "-text", "-out", $a2_cert])));
470# verify issuer is CA
471ok(get_issuer($a2_cert) =~ /CN=ca.example.com/);
472
473my $in_csr = srctop_file('test', 'certs', 'x509-check.csr');
474my $in_key = srctop_file('test', 'certs', 'x509-check-key.pem');
475my $invextfile = srctop_file('test', 'invalid-x509.cnf');
476# Test that invalid extensions settings fail
477ok(!run(app(["openssl", "x509", "-req", "-in", $in_csr, "-signkey", $in_key,
478            "-out", "/dev/null", "-days", "3650" , "-extensions", "ext",
479            "-extfile", $invextfile])));
480
481# Tests for issue #16080 (fixed in 1.1.1o)
482my $b_key = "b-key.pem";
483my $b_csr = "b-cert.csr";
484my $b_cert = "b-cert.pem";
485# Create the CSR
486ok(run(app(["openssl", "req", "-new", "-newkey", "rsa:4096",
487            "-keyout", $b_key, "-out", $b_csr, "-nodes",
488            "-config", $cnf,
489            "-subj", "/CN=b.example.com"])));
490# Sign it - position of "-text" matters!
491ok(run(app(["openssl", "x509", "-req", "-text", "-CAcreateserial",
492            "-CA", $ca_cert, "-CAkey", $ca_key,
493            "-in", $b_csr, "-out", $b_cert])));
494# Verify issuer is CA
495ok(get_issuer($b_cert) =~ /CN=ca.example.com/);
496
497# although no explicit extensions given:
498has_version($b_cert, 3);
499has_SKID($b_cert, 1);
500has_AKID($b_cert, 1);
501
502# Tests for https://github.com/openssl/openssl/issues/10442 (fixed in 1.1.1a)
503# (incorrect default `-CAcreateserial` if `-CA` path has a dot in it)
504my $folder_with_dot = "test_x509.folder";
505ok(mkdir $folder_with_dot);
506my $ca_cert_dot_in_dir = File::Spec->catfile($folder_with_dot, "ca-cert.pem");
507ok(copy($ca_cert,$ca_cert_dot_in_dir));
508my $ca_serial_dot_in_dir = File::Spec->catfile($folder_with_dot, "ca-cert.srl");
509
510ok(run(app(["openssl", "x509", "-req", "-text", "-CAcreateserial",
511            "-CA", $ca_cert_dot_in_dir, "-CAkey", $ca_key,
512            "-in", $b_csr])));
513ok(-e $ca_serial_dot_in_dir);
514
515# Tests for explicit start and end dates of certificates
516my %today = (strftime("%Y-%m-%d", gmtime) => 1);
517my $enddate;
518ok(run(app(["openssl", "x509", "-req", "-text",
519	    "-key", $b_key,
520	    "-not_before", "20231031000000Z",
521	    "-not_after", "today",
522            "-in", $b_csr, "-out", $b_cert]))
523&& get_not_before($b_cert) =~ /Oct 31 00:00:00 2023 GMT/
524&& ++$today{strftime("%Y-%m-%d", gmtime)}
525&& (grep { defined $today{$_} } get_not_after_date($b_cert)));
526# explicit start and end dates
527ok(run(app(["openssl", "x509", "-req", "-text",
528	    "-key", $b_key,
529	    "-not_before", "20231031000000Z",
530	    "-not_after", "20231231000000Z",
531	    "-days", "99",
532            "-in", $b_csr, "-out", $b_cert]))
533&& get_not_before($b_cert) =~ /Oct 31 00:00:00 2023 GMT/
534&& get_not_after($b_cert) =~ /Dec 31 00:00:00 2023 GMT/);
535# start date today and days
536%today = (strftime("%Y-%m-%d", gmtime) => 1);
537$enddate = strftime("%Y-%m-%d", gmtime(time + 99 * 24 * 60 * 60));
538ok(run(app(["openssl", "x509", "-req", "-text",
539	    "-key", $b_key,
540	    "-not_before", "today",
541	    "-days", "99",
542            "-in", $b_csr, "-out", $b_cert]))
543&& ++$today{strftime("%Y-%m-%d", gmtime)}
544&& (grep { defined $today{$_} } get_not_before_date($b_cert))
545&& get_not_after_date($b_cert) eq $enddate);
546# end date before start date
547ok(!run(app(["openssl", "x509", "-req", "-text",
548	      "-key", $b_key,
549	      "-not_before", "today",
550	      "-not_after", "20231031000000Z",
551              "-in", $b_csr, "-out", $b_cert])));
552# default days option
553%today = (strftime("%Y-%m-%d", gmtime) => 1);
554$enddate = strftime("%Y-%m-%d", gmtime(time + 30 * 24 * 60 * 60));
555ok(run(app(["openssl", "x509", "-req", "-text",
556	    "-key", $b_key,
557            "-in", $b_csr, "-out", $b_cert]))
558&& ++$today{strftime("%Y-%m-%d", gmtime)}
559&& (grep { defined $today{$_} } get_not_before_date($b_cert))
560&& get_not_after_date($b_cert) eq $enddate);
561
562SKIP: {
563    skip "EC is not supported by this OpenSSL build", 1
564        if disabled("ec");
565    my $psscert = srctop_file(@certs, "ee-self-signed-pss.pem");
566
567    ok(run(test(["x509_test", $psscert])), "running x509_test");
568}
569