Skip to content

Commit f12b4ac

Browse files
committed
support notbefore/notafter dates beyond 2050
support date format YYYYMMDDHHMMSS
1 parent 6a031ca commit f12b4ac

File tree

2 files changed

+63
-14
lines changed

2 files changed

+63
-14
lines changed

README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ Verify if the `etc/clca.cfg` and `etc/openssl.cnf` settings are OK.
111111

112112
Run
113113

114-
`$ clca initialize --startdate YYMMDDHHMMSS --enddate YYMMDDHHMMSS`
114+
`$ clca initialize --startdate DATESPEC --enddate DATESPEC`
115115

116116
The script performes several sanity checks and refuses to overwrite
117117
an existing CA. If the CA certificates have been manually removed
@@ -123,6 +123,8 @@ year must be specified with two digits only!
123123

124124
Date/time may be specified in truncated form, omitting any number of "right-hand side" date/time components (e. g. "YYMM").
125125

126+
Run `clca help datespec` for more details on the date specification.
127+
126128
Unless you are using a HSM you will be prompted to enter
127129
the PINs protecting the CA private key during the creation of the CA.
128130

@@ -137,7 +139,7 @@ can be issued.
137139

138140
Call
139141

140-
`$ clca certify --profile PROFILE [--startdate YYMMDDHHMMSS --enddate YYMMDDHHMMSS] <request file>`
142+
`$ clca certify --profile PROFILE [--startdate DATESPEC --enddate DATESPEC] <request file>`
141143

142144
in order to certify a PKCS #10 request. The request format (DER/PEM)
143145
is automatically detected.
@@ -154,6 +156,8 @@ Note that the year must be specified with two digits only!
154156

155157
Date/time may be specified in truncated form, omitting any number of "right-hand side" date/time components (e. g. "YYMM").
156158

159+
Run `clca help datespec` for more details on the date specification.
160+
157161
If no startdate/enddate is specified the default validity from the profile is used.
158162

159163
Omitting startdate and enddate is only recommended for end entity certificates,

bin/clca

+57-12
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ fi
188188

189189
######################################################################
190190

191-
VERSION="1.8"
191+
VERSION="1.10"
192192

193193
showhelp()
194194
{
@@ -291,7 +291,7 @@ EOF
291291
;;
292292
certify)
293293
$CAT <<EOF
294-
Usage: clca certify --profile <name> [--startdate YYMMDDHHMMSS] [--enddate YYMMDDHHMMSS] [--reqformat P10|SSCERT|KEY] [--subject <subject>] [--san TYPE:SAN] [--batch] <request file>
294+
Usage: clca certify --profile <name> [--startdate DATESPEC] [--enddate DATESPEC] [--reqformat P10|SSCERT|KEY] [--subject <subject>] [--san TYPE:SAN] [--batch] <request file>
295295
296296
Signs a PKCS#10 certificate request (DER/PEM format is automatically
297297
detected). Certificate extensions and validity are determined by
@@ -333,8 +333,8 @@ The certificate database is updated and a copy of the certificate
333333
is written to the file 'newcert.pem' in the current directory.
334334
335335
If --startdate or --enddate are specified, these dates are used for
336-
the certificate's lifetime. The dates must be specified in the format
337-
YYMMDDHHMMSS and are interpreted as UTC times.
336+
the certificate's lifetime. The dates must be specified in the DATESPEC
337+
format and are interpreted as UTC times.
338338
The date specification can be abbreviated by omitting parts of the
339339
date/time specification (e. g. "YYMM" only). Omitted date/time components
340340
are initialized to the lowest possible value.
@@ -351,6 +351,7 @@ clca certify --profile endentity
351351
--san "otherName:1.3.6.1.4.1.311.20.2.3;UTF8:[email protected]" foo.csr
352352
353353
EOF
354+
showhelp datespec
354355
;;
355356
revoke)
356357
$CAT <<EOF
@@ -380,7 +381,7 @@ EOF
380381
;;
381382
initialize)
382383
$CAT <<EOF
383-
Usage: clca initialize [--req <filename>] [--startdate YYMMDDHHMMSS] [--enddate YYMMDDHHMMSS]
384+
Usage: clca initialize [--req <filename>] [--startdate DATESPEC] [--enddate DATESPEC]
384385
385386
Initializes the CA database and creates either a self-signed certificate
386387
or a PKCS#10 certificate request.
@@ -421,6 +422,7 @@ The following steps must be performed to create a CA:
421422
3. Create the CA using the initialize command
422423
423424
EOF
425+
showhelp datespec
424426
;;
425427
check)
426428
$CAT <<EOF
@@ -452,7 +454,31 @@ YYYYMMDDHHMMSS-clca-backup.tar.gz in the current directory (caps replaced
452454
with timestamp).
453455
EOF
454456
;;
455-
457+
datespec)
458+
$CAT <<EOF
459+
DATESPEC
460+
A DATESPEC is an absolute timestamp representing a point in time. Two different
461+
formats are supported:
462+
463+
Truncated format ("traditional") format: YY[MM[DD[HH[MM]SS[Z]]]]]
464+
The truncated format uses a two-digit year representation and optionally allows
465+
any number of two-digit date/time specification components up to seconds.
466+
It is possible to specify only portions of the date, starting from the
467+
left-hand side and leaving out the lower tier date components, e. g. "YY" or
468+
"YYMMDD".
469+
The missing date elements are implicitly filled with the lowest sensible value
470+
(01 for months and days, 00 for hours, minutes and seconds).
471+
472+
Complete format: YYYYMMDDHHMMSS[Z]
473+
If the specified timestamp is exactly 14 digits long it is assumed to contain
474+
a full date/time specification. A trailing "Z" is optional (see "Time zone").
475+
476+
Time zone:
477+
A full DATESPEC always contains a time zone specification which is following the
478+
actual timestamp value. It may be omitted when specifying the timestamp on the command
479+
line. The default time zone is "Z" and specifies the UTC (Zulu) time zone.
480+
481+
EOF
456482
esac
457483
}
458484

@@ -529,7 +555,7 @@ EOF
529555
fi
530556
}
531557

532-
# arg: user specified date, format YYMMDDHHMMSSZ
558+
# arg: DATESPEC, format YY[MM[DD[HH[MM]SS[Z]]]]] or YYYYMMDDHHMMSS[Z]
533559
# It is possible to specify only portions of the date,
534560
# starting from the left-hand side and leave out the
535561
# lower tier date components, e. g. "YY" or "YYMMDD".
@@ -539,18 +565,33 @@ EOF
539565
sanitize_openssl_date() {
540566
$PERL -e '
541567
my $date = shift;
542-
my ($yy, $mm, $dd, $hh, $min, $ss, $z) = ($date =~ m{^(\d\d)(\d\d)?(\d\d)?(\d\d)?(\d\d)?(\d\d)?(Z)?$});
543568
569+
my $yy;
570+
my $mm;
571+
my $dd;
572+
my $hh;
573+
my $min;
574+
my $ss;
575+
my $z;
576+
577+
# check for YYYYMMDDHHMMSS[Z] syntax
578+
($yy, $mm, $dd, $hh, $min, $ss, $z) = ($date =~ m{^(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(Z)?$});
579+
580+
# not a complete date spec, try the traditional (possibly truncated) one
544581
if (! defined $yy) {
545-
print STDERR "ERROR: specified date is not of the form YYMMDDHHMMSSZ (or a subset)\n";
582+
($yy, $mm, $dd, $hh, $min, $ss, $z) = ($date =~ m{^(\d\d)(\d\d)?(\d\d)?(\d\d)?(\d\d)?(\d\d)?(Z)?$});
583+
}
584+
585+
if (! defined $yy) {
586+
print STDERR "ERROR: specified date is not of the form YY[MM[DD[HH[MM[SS[Z]]]]]] or YYYYMMDDHHMMSS[Z]\n";
546587
exit 1;
547588
}
548589
549-
if ($yy < 10 || $yy > 50) {
550-
print STDERR "WARNING: Year 20$yy in date specification. Please double-check.\n";
590+
if ($yy < 10 || ($yy > 50 && $yy < 100)) {
591+
print STDERR "WARNING: Year 20$yy used in traditional date specification. Please double-check.\n";
551592
}
552593
if ($yy == 20) {
553-
print STDERR "WARNING: Year 2020 specified. Please double-check.\n";
594+
print STDERR "WARNING: Year 2020 specified in traditional date spec. Please double-check.\n";
554595
}
555596
$mm = "01" unless defined $mm;
556597
$dd = "01" unless defined $dd;
@@ -1503,6 +1544,10 @@ check()
15031544
showhelp check
15041545
abort 1
15051546
;;
1547+
--testdate)
1548+
sanitize_openssl_date $2
1549+
abort 0
1550+
;;
15061551
*)
15071552
showhelp check
15081553
abort 1

0 commit comments

Comments
 (0)