summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorschwarze <>2022-11-13 22:11:44 +0000
committerschwarze <>2022-11-13 22:11:44 +0000
commitab1d96bf7a7de9f890e648c3d59851c386457003 (patch)
treef78575b8a4411c69906793de43321fdabea33cc4 /src
parentb10fff2d2486c7f66b4a443e8ad68ef2b2021928 (diff)
downloadopenbsd-ab1d96bf7a7de9f890e648c3d59851c386457003.tar.gz
openbsd-ab1d96bf7a7de9f890e648c3d59851c386457003.tar.bz2
openbsd-ab1d96bf7a7de9f890e648c3d59851c386457003.zip
Various improvements; joint work with beck@:
1. Explain up front what "ASN1_TIME" is (suggested by beck@, wording by me). 2. For opaque structs, use the generic term "object", like we already do it in many other LibreSSL manual pages. 3. Drop some redundant phrases. 4. Improve the EXAMPLES section (by beck@, with fixes by me). 6. Add a STANDARDS section. ...and some other minor polishing. OK beck@
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/man/ASN1_TIME_set.3136
1 files changed, 72 insertions, 64 deletions
diff --git a/src/lib/libcrypto/man/ASN1_TIME_set.3 b/src/lib/libcrypto/man/ASN1_TIME_set.3
index b8a567ece0..4f6a99673a 100644
--- a/src/lib/libcrypto/man/ASN1_TIME_set.3
+++ b/src/lib/libcrypto/man/ASN1_TIME_set.3
@@ -1,4 +1,4 @@
1.\" $OpenBSD: ASN1_TIME_set.3,v 1.18 2022/11/10 17:44:05 schwarze Exp $ 1.\" $OpenBSD: ASN1_TIME_set.3,v 1.19 2022/11/13 22:11:44 schwarze Exp $
2.\" full merge up to: OpenSSL 3d0f1cb9 Jul 11 03:01:24 2017 +0800 2.\" full merge up to: OpenSSL 3d0f1cb9 Jul 11 03:01:24 2017 +0800
3.\" selective merge up to: OpenSSL 24a535ea Sep 22 13:14:20 2020 +0100 3.\" selective merge up to: OpenSSL 24a535ea Sep 22 13:14:20 2020 +0100
4.\" 4.\"
@@ -6,14 +6,15 @@
6.\" The changes are covered by the following Copyright and license: 6.\" The changes are covered by the following Copyright and license:
7.\" 7.\"
8.\" Copyright (c) 2022 Ingo Schwarze <schwarze@openbsd.org> 8.\" Copyright (c) 2022 Ingo Schwarze <schwarze@openbsd.org>
9.\" Copyright (c) 2022 Bob Beck <beck@openbsd.org>
9.\" 10.\"
10.\" Permission to use, copy, modify, and distribute this software for any 11.\" Permission to use, copy, modify, and distribute this software for any
11.\" purpose with or without fee is hereby granted, provided that the above 12.\" purpose with or without fee is hereby granted, provided that the above
12.\" copyright notice and this permission notice appear in all copies. 13.\" copyright notice and this permission notice appear in all copies.
13.\" 14.\"
14.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 15.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
15.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 16.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 17.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
17.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 18.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 19.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 20.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
@@ -67,7 +68,7 @@
67.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 68.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
68.\" OF THE POSSIBILITY OF SUCH DAMAGE. 69.\" OF THE POSSIBILITY OF SUCH DAMAGE.
69.\" 70.\"
70.Dd $Mdocdate: November 10 2022 $ 71.Dd $Mdocdate: November 13 2022 $
71.Dt ASN1_TIME_SET 3 72.Dt ASN1_TIME_SET 3
72.Os 73.Os
73.Sh NAME 74.Sh NAME
@@ -217,12 +218,35 @@
217.Fa "ASN1_GENERALIZEDTIME **out" 218.Fa "ASN1_GENERALIZEDTIME **out"
218.Fc 219.Fc
219.Sh DESCRIPTION 220.Sh DESCRIPTION
221An
222.Vt ASN1_TIME
223object is a shallow wrapper around a string containing an ASN.1
224.Vt Time
225value in the restricted format valid in X.509 certificates.
226An
227.Vt ASN1_TIME
228object is either an
229.Vt ASN1_UTCTIME
230object containing a string of the format
231.Ar YYMMDDHHMMSS Ns Cm Z
232which is valid for the years 1950 to 2049, or an
233.Vt ASN1_GENERALIZEDTIME
234object containing a string of the format
235.Ar YYYYMMDDHHMMSS Ns Cm Z
236which is valid for the years 0000 to 1949 and 2050 to 9999.
237In both cases, the mandatory suffix
238.Sq Cm Z
239represents the GMT time zone.
240LibreSSL by design does not support the full syntax of ASN.1 times.
241In particular, it neither supports fractional seconds
242nor any other time zone.
243.Pp
220The functions 244The functions
221.Fn ASN1_TIME_set , 245.Fn ASN1_TIME_set ,
222.Fn ASN1_UTCTIME_set , 246.Fn ASN1_UTCTIME_set ,
223and 247and
224.Fn ASN1_GENERALIZEDTIME_set 248.Fn ASN1_GENERALIZEDTIME_set
225set the time structure 249set the time object
226.Fa s 250.Fa s
227to the time represented by the 251to the time represented by the
228.Vt time_t 252.Vt time_t
@@ -232,14 +256,14 @@ If
232.Fa s 256.Fa s
233is 257is
234.Dv NULL , 258.Dv NULL ,
235a new time structure is allocated and returned. 259a new time object is allocated and returned.
236.Pp 260.Pp
237The functions 261The functions
238.Fn ASN1_TIME_adj , 262.Fn ASN1_TIME_adj ,
239.Fn ASN1_UTCTIME_adj , 263.Fn ASN1_UTCTIME_adj ,
240and 264and
241.Fn ASN1_GENERALIZEDTIME_adj 265.Fn ASN1_GENERALIZEDTIME_adj
242set the time structure 266set the time object
243.Fa s 267.Fa s
244to the time represented by the time 268to the time represented by the time
245.Fa offset_day 269.Fa offset_day
@@ -262,7 +286,7 @@ If
262.Fa s 286.Fa s
263is 287is
264.Dv NULL , 288.Dv NULL ,
265a new time structure is allocated and returned. 289a new time object is allocated and returned.
266.Pp 290.Pp
267.Fn ASN1_TIME_adj 291.Fn ASN1_TIME_adj
268may change the type from 292may change the type from
@@ -274,7 +298,7 @@ The functions
274.Fn ASN1_UTCTIME_adj 298.Fn ASN1_UTCTIME_adj
275and 299and
276.Fn ASN1_GENERALIZEDTIME_adj 300.Fn ASN1_GENERALIZEDTIME_adj
277do not modify the type of the return structure. 301do not modify the type of the return object.
278.Pp 302.Pp
279The functions 303The functions
280.Fn ASN1_TIME_set_string , 304.Fn ASN1_TIME_set_string ,
@@ -282,9 +306,9 @@ The functions
282.Fn ASN1_UTCTIME_set_string , 306.Fn ASN1_UTCTIME_set_string ,
283and 307and
284.Fn ASN1_GENERALIZEDTIME_set_string 308.Fn ASN1_GENERALIZEDTIME_set_string
285set the time structure 309set the time object
286.Fa s 310.Fa s
287to the time represented by the string 311to the time string
288.Fa str , 312.Fa str ,
289which must be in appropriate ASN.1 time format: 313which must be in appropriate ASN.1 time format:
290YYMMDDHHMMSSZ for 314YYMMDDHHMMSSZ for
@@ -308,32 +332,28 @@ In LibreSSL,
308.Fn ASN1_TIME_set_string 332.Fn ASN1_TIME_set_string
309and 333and
310.Fn ASN1_TIME_set_string_X509 334.Fn ASN1_TIME_set_string_X509
311behave identically. 335behave identically and always set the time object
312In other implementations, 336to a valid value to use in an X.509 certificate.
313.Fn ASN1_TIME_set_string ,
314.Fn ASN1_UTCTIME_set_string ,
315and
316.Fn ASN1_GENERALIZEDTIME_set_string 337.Fn ASN1_GENERALIZEDTIME_set_string
317may accept additional formats that violate RFC 5280. 338may encode a time string that is not valid in an X.509 certificate.
318.Pp 339.Pp
319The function 340The function
320.Fn ASN1_TIME_normalize 341.Fn ASN1_TIME_normalize
321converts an 342converts an
322.Vt ASN1_GENERALIZEDTIME 343.Vt ASN1_GENERALIZEDTIME
323or 344into a time value that can be used in a certificate
345by changing it to an
324.Vt ASN1_UTCTIME 346.Vt ASN1_UTCTIME
325into a time value that can be used in a certificate. 347if possible.
326It is intended to be used after the 348It has no effect on an
327.Fn ASN1_TIME_set_string 349.Vt ASN1_UTCTIME .
328functions to ensure the value is valid for use as an
329.Vt ASN1_TIME .
330.Pp 350.Pp
331The functions 351The functions
332.Fn ASN1_TIME_check , 352.Fn ASN1_TIME_check ,
333.Fn ASN1_UTCTIME_check , 353.Fn ASN1_UTCTIME_check ,
334and 354and
335.Fn ASN1_GENERALIZEDTIME_check 355.Fn ASN1_GENERALIZEDTIME_check
336check the syntax of the time structure 356check the syntax of the time string contained in the object
337.Fa s . 357.Fa s .
338.Pp 358.Pp
339The functions 359The functions
@@ -350,11 +370,8 @@ in human readable format.
350It will be of the format MMM DD HH:MM:SS YYYY [GMT], for example "Feb 3 370It will be of the format MMM DD HH:MM:SS YYYY [GMT], for example "Feb 3
35100:55:52 2015 GMT". 37100:55:52 2015 GMT".
352It does not include a newline. 372It does not include a newline.
353If the time structure has an invalid format, 373If the time string has an invalid format,
354it prints out "Bad time value" and returns an error. 374it prints out "Bad time value" and returns an error.
355The output of
356.Fn ASN1_GENERALIZEDTIME_print
357may include a fractional part following the second.
358.Pp 375.Pp
359The function 376The function
360.Fn ASN1_TIME_to_tm 377.Fn ASN1_TIME_to_tm
@@ -368,7 +385,7 @@ If
368is 385is
369.Dv NULL , 386.Dv NULL ,
370then the current time is converted. 387then the current time is converted.
371The output time is GMT. 388The output time is always in the GMT time zone.
372The 389The
373.Fa tm_sec , tm_min , tm_hour , tm_mday , tm_mon , 390.Fa tm_sec , tm_min , tm_hour , tm_mday , tm_mon ,
374and 391and
@@ -465,33 +482,15 @@ is
465then a new object is allocated and must be freed after use. 482then a new object is allocated and must be freed after use.
466.Pp 483.Pp
467The 484The
468.Vt ASN1_TIME
469structure corresponds to the ASN.1 structure
470.Sy Time
471defined in RFC 5280 et al.
472The time setting functions obey the rules outlined in RFC 5280: if the
473date can be represented by UTCTime it is used, otherwise GeneralizedTime is
474used.
475.Pp
476The
477.Vt ASN1_TIME , 485.Vt ASN1_TIME ,
478.Vt ASN1_UTCTIME , 486.Vt ASN1_UTCTIME ,
479and 487and
480.Vt ASN1_GENERALIZEDTIME 488.Vt ASN1_GENERALIZEDTIME
481structures are represented as 489objects are represented as
482.Vt ASN1_STRING 490.Vt ASN1_STRING
483structures internally and can be freed using 491objects internally and can be freed using
484.Xr ASN1_STRING_free 3 . 492.Xr ASN1_STRING_free 3 .
485.Pp 493.Pp
486The
487.Vt ASN1_TIME
488structure can represent years from 0000 to 9999 but no attempt is
489made to correct ancient calendar changes (for example from Julian
490to Gregorian calendars).
491.Pp
492.Vt ASN1_UTCTIME
493is limited to a year range of 1950 through 2049.
494.Pp
495It is recommended that 494It is recommended that
496.Vt ASN1_TIME 495.Vt ASN1_TIME
497functions be used instead of 496functions be used instead of
@@ -514,7 +513,7 @@ functions operate on either format.
514.Fn ASN1_GENERALIZEDTIME_adj , 513.Fn ASN1_GENERALIZEDTIME_adj ,
515and 514and
516.Fn ASN1_TIME_to_generalizedtime 515.Fn ASN1_TIME_to_generalizedtime
517return a pointer to a time structure or 516return a pointer to a time object or
518.Dv NULL 517.Dv NULL
519if an error occurred. 518if an error occurred.
520.Pp 519.Pp
@@ -532,7 +531,8 @@ returns 1 on success or 0 on error.
532.Fn ASN1_UTCTIME_check , 531.Fn ASN1_UTCTIME_check ,
533and 532and
534.Fn ASN1_GENERALIZEDTIME_check 533.Fn ASN1_GENERALIZEDTIME_check
535return 1 if the time structure is syntactically correct or 0 otherwise. 534return 1 if the time string contained in the object is syntactically
535correct or 0 otherwise.
536.Pp 536.Pp
537.Fn ASN1_TIME_print , 537.Fn ASN1_TIME_print ,
538.Fn ASN1_UTCTIME_print , 538.Fn ASN1_UTCTIME_print ,
@@ -547,7 +547,7 @@ or 0 if an error occurred, usually due to an invalid time format.
547.Pp 547.Pp
548.Fn ASN1_TIME_diff 548.Fn ASN1_TIME_diff
549returns 1 for success or 0 for failure. 549returns 1 for success or 0 for failure.
550It can for example fail if a time structure passed in has invalid syntax. 550It can for example fail if a time string passed in has invalid syntax.
551.Pp 551.Pp
552.Fn ASN1_TIME_cmp_time_t , 552.Fn ASN1_TIME_cmp_time_t ,
553.Fn ASN1_UTCTIME_cmp_time_t , 553.Fn ASN1_UTCTIME_cmp_time_t ,
@@ -563,27 +563,42 @@ is later than
563.Fa t , 563.Fa t ,
564or \-2 on error. 564or \-2 on error.
565.Sh EXAMPLES 565.Sh EXAMPLES
566Set a time structure to one hour after the current time and print it 566Set a time object to one hour after the current time and print it
567out: 567out:
568.Bd -literal -offset indent 568.Bd -literal -offset indent
569#include <time.h> 569#include <time.h>
570#include <openssl/asn1.h> 570#include <openssl/asn1.h>
571 571
572ASN1_TIME *tm; 572ASN1_TIME *asn1_time;
573time_t t; 573time_t t;
574BIO *b; 574BIO *b;
575 575
576t = time(NULL); 576t = time(NULL);
577tm = ASN1_TIME_adj(NULL, t, 0, 60 * 60); 577asn1_time = ASN1_TIME_adj(NULL, t, 0, 60 * 60);
578b = BIO_new_fp(stdout, BIO_NOCLOSE); 578b = BIO_new_fp(stdout, BIO_NOCLOSE);
579ASN1_TIME_print(b, tm); 579if (asn1_time != NULL) {
580ASN1_STRING_free(tm); 580 ASN1_TIME_print(b, asn1_time);
581 BIO_printf(b, "\en");
582} else {
583 BIO_printf(b, "Time out of range or un-representable\en");
584}
585ASN1_STRING_free(asn1_time);
581BIO_free(b); 586BIO_free(b);
582.Ed 587.Ed
583.Sh SEE ALSO 588.Sh SEE ALSO
584.Xr ASN1_TIME_new 3 , 589.Xr ASN1_TIME_new 3 ,
585.Xr ASN1_time_parse 3 , 590.Xr ASN1_time_parse 3 ,
586.Xr X509_cmp_time 3 591.Xr X509_cmp_time 3
592.Sh STANDARDS
593The usage of the ASN.1
594.Vt Time ,
595.Vt UTCTime ,
596and
597.Vt GeneralizedTime
598data types in X.509 certificates is specified in
599RFC 5280, Internet X.509 Public Key Infrastructure Certificate and
600Certificate Revocation List (CRL) Profile,
601section 4.1.2.5 (TBS Certificate Validity).
587.Sh HISTORY 602.Sh HISTORY
588.Fn ASN1_UTCTIME_check 603.Fn ASN1_UTCTIME_check
589and 604and
@@ -654,10 +669,3 @@ and
654parameters instead of directly manipulating a 669parameters instead of directly manipulating a
655.Vt time_t 670.Vt time_t
656value. 671value.
657.Sh BUGS
658.Fn ASN1_TIME_print ,
659.Fn ASN1_UTCTIME_print ,
660and
661.Fn ASN1_GENERALIZEDTIME_print
662do not print the time zone: they either print "GMT" or nothing.
663But all certificates complying with RFC 5280 et al use GMT anyway.