1 .\" Automatically generated by Pod::Man 4.11 (Pod::Simple 3.40)
4 .\" ========================================================================
5 .de Sp \" Vertical space (when we can't use .PP)
9 .de Vb \" Begin verbatim text
14 .de Ve \" End verbatim text
18 .\" Set up some character translations and predefined strings. \*(-- will
19 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
20 .\" double quote, and \*(R" will give a right double quote. \*(C+ will
21 .\" give a nicer C++. Capital omega is used to do unbreakable dashes and
22 .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
23 .\" nothing in troff, for use with C<>.
25 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
29 . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
30 . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
45 .\" Escape single quotes in literal strings from groff's Unicode transform.
49 .\" If the F register is >0, we'll generate index entries on stderr for
50 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
51 .\" entries marked with X<> in POD. Of course, you'll have to process the
52 .\" output yourself in some meaningful fashion.
54 .\" Avoid warning from groff about undefined register 'F'.
58 .if \n(.g .if rF .nr rF 1
59 .if (\n(rF:(\n(.g==0)) \{\
62 . tm Index:\\$1\t\\n%\t"\\$2"
72 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
73 .\" Fear. Run. Save yourself. No user-serviceable parts.
74 . \" fudge factors for nroff and troff
83 . ds #H ((1u-(\\\\n(.fu%2u))*.13m)
89 . \" simple accents for nroff and troff
99 . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
100 . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
101 . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
102 . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
103 . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
104 . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
106 . \" troff and (daisy-wheel) nroff accents
107 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
108 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
109 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
110 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
111 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
112 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
113 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
114 .ds ae a\h'-(\w'a'u*4/10)'e
115 .ds Ae A\h'-(\w'A'u*4/10)'E
116 . \" corrections for vroff
117 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
118 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
119 . \" for low resolution devices (crt and lpr)
120 .if \n(.H>23 .if \n(.V>19 \
133 .\" ========================================================================
135 .IX Title "ASN1_TIME_SET 3"
136 .TH ASN1_TIME_SET 3 "2020-04-21" "1.1.1g" "OpenSSL"
137 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
138 .\" way too many mistakes in technical documents.
142 ASN1_TIME_set, ASN1_UTCTIME_set, ASN1_GENERALIZEDTIME_set, ASN1_TIME_adj, ASN1_UTCTIME_adj, ASN1_GENERALIZEDTIME_adj, ASN1_TIME_check, ASN1_UTCTIME_check, ASN1_GENERALIZEDTIME_check, ASN1_TIME_set_string, ASN1_UTCTIME_set_string, ASN1_GENERALIZEDTIME_set_string, ASN1_TIME_set_string_X509, ASN1_TIME_normalize, ASN1_TIME_to_tm, ASN1_TIME_print, ASN1_UTCTIME_print, ASN1_GENERALIZEDTIME_print, ASN1_TIME_diff, ASN1_TIME_cmp_time_t, ASN1_UTCTIME_cmp_time_t, ASN1_TIME_compare, ASN1_TIME_to_generalizedtime \- ASN.1 Time functions
144 .IX Header "SYNOPSIS"
146 \& ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t);
147 \& ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t);
148 \& ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,
151 \& ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t, int offset_day,
153 \& ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t,
154 \& int offset_day, long offset_sec);
155 \& ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s,
156 \& time_t t, int offset_day,
159 \& int ASN1_TIME_set_string(ASN1_TIME *s, const char *str);
160 \& int ASN1_TIME_set_string_X509(ASN1_TIME *s, const char *str);
161 \& int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str);
162 \& int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s,
165 \& int ASN1_TIME_normalize(ASN1_TIME *s);
167 \& int ASN1_TIME_check(const ASN1_TIME *t);
168 \& int ASN1_UTCTIME_check(const ASN1_UTCTIME *t);
169 \& int ASN1_GENERALIZEDTIME_check(const ASN1_GENERALIZEDTIME *t);
171 \& int ASN1_TIME_print(BIO *b, const ASN1_TIME *s);
172 \& int ASN1_UTCTIME_print(BIO *b, const ASN1_UTCTIME *s);
173 \& int ASN1_GENERALIZEDTIME_print(BIO *b, const ASN1_GENERALIZEDTIME *s);
175 \& int ASN1_TIME_to_tm(const ASN1_TIME *s, struct tm *tm);
176 \& int ASN1_TIME_diff(int *pday, int *psec, const ASN1_TIME *from,
177 \& const ASN1_TIME *to);
179 \& int ASN1_TIME_cmp_time_t(const ASN1_TIME *s, time_t t);
180 \& int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t);
182 \& int ASN1_TIME_compare(const ASN1_TIME *a, const ASN1_TIME *b);
184 \& ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t,
185 \& ASN1_GENERALIZEDTIME **out);
188 .IX Header "DESCRIPTION"
189 The \fBASN1_TIME_set()\fR, \fBASN1_UTCTIME_set()\fR and \fBASN1_GENERALIZEDTIME_set()\fR
190 functions set the structure \fBs\fR to the time represented by the time_t
191 value \fBt\fR. If \fBs\fR is \s-1NULL\s0 a new time structure is allocated and returned.
193 The \fBASN1_TIME_adj()\fR, \fBASN1_UTCTIME_adj()\fR and \fBASN1_GENERALIZEDTIME_adj()\fR
194 functions set the time structure \fBs\fR to the time represented
195 by the time \fBoffset_day\fR and \fBoffset_sec\fR after the time_t value \fBt\fR.
196 The values of \fBoffset_day\fR or \fBoffset_sec\fR can be negative to set a
197 time before \fBt\fR. The \fBoffset_sec\fR value can also exceed the number of
198 seconds in a day. If \fBs\fR is \s-1NULL\s0 a new structure is allocated
201 The \fBASN1_TIME_set_string()\fR, \fBASN1_UTCTIME_set_string()\fR and
202 \&\fBASN1_GENERALIZEDTIME_set_string()\fR functions set the time structure \fBs\fR
203 to the time represented by string \fBstr\fR which must be in appropriate \s-1ASN.1\s0
204 time format (for example \s-1YYMMDDHHMMSSZ\s0 or \s-1YYYYMMDDHHMMSSZ\s0). If \fBs\fR is \s-1NULL\s0
205 this function performs a format check on \fBstr\fR only. The string \fBstr\fR
206 is copied into \fBs\fR.
208 \&\fBASN1_TIME_set_string_X509()\fR sets \s-1ASN1_TIME\s0 structure \fBs\fR to the time
209 represented by string \fBstr\fR which must be in appropriate time format
210 that \s-1RFC 5280\s0 requires, which means it only allows \s-1YYMMDDHHMMSSZ\s0 and
211 \&\s-1YYYYMMDDHHMMSSZ\s0 (leap second is rejected), all other \s-1ASN.1\s0 time format
212 are not allowed. If \fBs\fR is \s-1NULL\s0 this function performs a format check
215 The \fBASN1_TIME_normalize()\fR function converts an \s-1ASN1_GENERALIZEDTIME\s0 or
216 \&\s-1ASN1_UTCTIME\s0 into a time value that can be used in a certificate. It
217 should be used after the \fBASN1_TIME_set_string()\fR functions and before
218 \&\fBASN1_TIME_print()\fR functions to get consistent (i.e. \s-1GMT\s0) results.
220 The \fBASN1_TIME_check()\fR, \fBASN1_UTCTIME_check()\fR and \fBASN1_GENERALIZEDTIME_check()\fR
221 functions check the syntax of the time structure \fBs\fR.
223 The \fBASN1_TIME_print()\fR, \fBASN1_UTCTIME_print()\fR and \fBASN1_GENERALIZEDTIME_print()\fR
224 functions print the time structure \fBs\fR to \s-1BIO\s0 \fBb\fR in human readable
225 format. It will be of the format \s-1MMM DD HH:MM:SS YYYY\s0 [\s-1GMT\s0], for example
226 \&\*(L"Feb 3 00:55:52 2015 \s-1GMT\*(R"\s0 it does not include a newline. If the time
227 structure has invalid format it prints out \*(L"Bad time value\*(R" and returns
228 an error. The output for generalized time may include a fractional part
229 following the second.
231 \&\fBASN1_TIME_to_tm()\fR converts the time \fBs\fR to the standard \fBtm\fR structure.
232 If \fBs\fR is \s-1NULL,\s0 then the current time is converted. The output time is \s-1GMT.\s0
233 The \fBtm_sec\fR, \fBtm_min\fR, \fBtm_hour\fR, \fBtm_mday\fR, \fBtm_wday\fR, \fBtm_yday\fR,
234 \&\fBtm_mon\fR and \fBtm_year\fR fields of \fBtm\fR structure are set to proper values,
235 whereas all other fields are set to 0. If \fBtm\fR is \s-1NULL\s0 this function performs
236 a format check on \fBs\fR only. If \fBs\fR is in Generalized format with fractional
237 seconds, e.g. \s-1YYYYMMDDHHMMSS.SSSZ,\s0 the fractional seconds will be lost while
238 converting \fBs\fR to \fBtm\fR structure.
240 \&\fBASN1_TIME_diff()\fR sets \fB*pday\fR and \fB*psec\fR to the time difference between
241 \&\fBfrom\fR and \fBto\fR. If \fBto\fR represents a time later than \fBfrom\fR then
242 one or both (depending on the time difference) of \fB*pday\fR and \fB*psec\fR
243 will be positive. If \fBto\fR represents a time earlier than \fBfrom\fR then
244 one or both of \fB*pday\fR and \fB*psec\fR will be negative. If \fBto\fR and \fBfrom\fR
245 represent the same time then \fB*pday\fR and \fB*psec\fR will both be zero.
246 If both \fB*pday\fR and \fB*psec\fR are non-zero they will always have the same
247 sign. The value of \fB*psec\fR will always be less than the number of seconds
248 in a day. If \fBfrom\fR or \fBto\fR is \s-1NULL\s0 the current time is used.
250 The \fBASN1_TIME_cmp_time_t()\fR and \fBASN1_UTCTIME_cmp_time_t()\fR functions compare
251 the two times represented by the time structure \fBs\fR and the time_t \fBt\fR.
253 The \fBASN1_TIME_compare()\fR function compares the two times represented by the
254 time structures \fBa\fR and \fBb\fR.
256 The \fBASN1_TIME_to_generalizedtime()\fR function converts an \s-1ASN1_TIME\s0 to an
257 \&\s-1ASN1_GENERALIZEDTIME,\s0 regardless of year. If either \fBout\fR or
258 \&\fB*out\fR are \s-1NULL,\s0 then a new object is allocated and must be freed after use.
261 The \s-1ASN1_TIME\s0 structure corresponds to the \s-1ASN.1\s0 structure \fBTime\fR
262 defined in \s-1RFC5280\s0 et al. The time setting functions obey the rules outlined
263 in \s-1RFC5280:\s0 if the date can be represented by UTCTime it is used, else
264 GeneralizedTime is used.
266 The \s-1ASN1_TIME, ASN1_UTCTIME\s0 and \s-1ASN1_GENERALIZEDTIME\s0 structures are represented
267 as an \s-1ASN1_STRING\s0 internally and can be freed up using \fBASN1_STRING_free()\fR.
269 The \s-1ASN1_TIME\s0 structure can represent years from 0000 to 9999 but no attempt
270 is made to correct ancient calendar changes (for example from Julian to
271 Gregorian calendars).
273 \&\s-1ASN1_UTCTIME\s0 is limited to a year range of 1950 through 2049.
275 Some applications add offset times directly to a time_t value and pass the
276 results to \fBASN1_TIME_set()\fR (or equivalent). This can cause problems as the
277 time_t value can overflow on some systems resulting in unexpected results.
278 New applications should use \fBASN1_TIME_adj()\fR instead and pass the offset value
279 in the \fBoffset_sec\fR and \fBoffset_day\fR parameters instead of directly
280 manipulating a time_t value.
282 \&\fBASN1_TIME_adj()\fR may change the type from \s-1ASN1_GENERALIZEDTIME\s0 to \s-1ASN1_UTCTIME,\s0
283 or vice versa, based on the resulting year. The \fBASN1_GENERALIZEDTIME_adj()\fR and
284 \&\fBASN1_UTCTIME_adj()\fR functions will not modify the type of the return structure.
286 It is recommended that functions starting with \s-1ASN1_TIME\s0 be used instead of
287 those starting with \s-1ASN1_UTCTIME\s0 or \s-1ASN1_GENERALIZEDTIME.\s0 The functions
288 starting with \s-1ASN1_UTCTIME\s0 and \s-1ASN1_GENERALIZEDTIME\s0 act only on that specific
289 time format. The functions starting with \s-1ASN1_TIME\s0 will operate on either
293 \&\fBASN1_TIME_print()\fR, \fBASN1_UTCTIME_print()\fR and \fBASN1_GENERALIZEDTIME_print()\fR
294 do not print out the time zone: it either prints out \*(L"\s-1GMT\*(R"\s0 or nothing. But all
295 certificates complying with \s-1RFC5280\s0 et al use \s-1GMT\s0 anyway.
297 Use the \fBASN1_TIME_normalize()\fR function to normalize the time value before
298 printing to get \s-1GMT\s0 results.
300 .IX Header "RETURN VALUES"
301 \&\fBASN1_TIME_set()\fR, \fBASN1_UTCTIME_set()\fR, \fBASN1_GENERALIZEDTIME_set()\fR, \fBASN1_TIME_adj()\fR,
302 ASN1_UTCTIME_adj and ASN1_GENERALIZEDTIME_set return a pointer to a time structure
303 or \s-1NULL\s0 if an error occurred.
305 \&\fBASN1_TIME_set_string()\fR, \fBASN1_UTCTIME_set_string()\fR, \fBASN1_GENERALIZEDTIME_set_string()\fR
306 \&\fBASN1_TIME_set_string_X509()\fR return 1 if the time value is successfully set and 0 otherwise.
308 \&\fBASN1_TIME_normalize()\fR returns 1 on success, and 0 on error.
310 \&\fBASN1_TIME_check()\fR, ASN1_UTCTIME_check and \fBASN1_GENERALIZEDTIME_check()\fR return 1
311 if the structure is syntactically correct and 0 otherwise.
313 \&\fBASN1_TIME_print()\fR, \fBASN1_UTCTIME_print()\fR and \fBASN1_GENERALIZEDTIME_print()\fR return 1
314 if the time is successfully printed out and 0 if an error occurred (I/O error or
315 invalid time format).
317 \&\fBASN1_TIME_to_tm()\fR returns 1 if the time is successfully parsed and 0 if an
318 error occurred (invalid time format).
320 \&\fBASN1_TIME_diff()\fR returns 1 for success and 0 for failure. It can fail if the
321 passed-in time structure has invalid syntax, for example.
323 \&\fBASN1_TIME_cmp_time_t()\fR and \fBASN1_UTCTIME_cmp_time_t()\fR return \-1 if \fBs\fR is
324 before \fBt\fR, 0 if \fBs\fR equals \fBt\fR, or 1 if \fBs\fR is after \fBt\fR. \-2 is returned
327 \&\fBASN1_TIME_compare()\fR returns \-1 if \fBa\fR is before \fBb\fR, 0 if \fBa\fR equals \fBb\fR, or 1 if \fBa\fR is after \fBb\fR. \-2 is returned on error.
329 \&\fBASN1_TIME_to_generalizedtime()\fR returns a pointer to
330 the appropriate time structure on success or \s-1NULL\s0 if an error occurred.
332 .IX Header "EXAMPLES"
333 Set a time structure to one hour after the current time and print it out:
337 \& #include <openssl/asn1.h>
344 \& tm = ASN1_TIME_adj(NULL, t, 0, 60 * 60);
345 \& b = BIO_new_fp(stdout, BIO_NOCLOSE);
346 \& ASN1_TIME_print(b, tm);
347 \& ASN1_STRING_free(tm);
351 Determine if one time is later or sooner than the current time:
356 \& if (!ASN1_TIME_diff(&day, &sec, NULL, to))
357 \& /* Invalid time format */
359 \& if (day > 0 || sec > 0)
360 \& printf("Later\en");
361 \& else if (day < 0 || sec < 0)
362 \& printf("Sooner\en");
364 \& printf("Same\en");
368 The \fBASN1_TIME_to_tm()\fR function was added in OpenSSL 1.1.1.
369 The \fBASN1_TIME_set_string_X509()\fR function was added in OpenSSL 1.1.1.
370 The \fBASN1_TIME_normalize()\fR function was added in OpenSSL 1.1.1.
371 The \fBASN1_TIME_cmp_time_t()\fR function was added in OpenSSL 1.1.1.
372 The \fBASN1_TIME_compare()\fR function was added in OpenSSL 1.1.1.
374 .IX Header "COPYRIGHT"
375 Copyright 2015\-2019 The OpenSSL Project Authors. All Rights Reserved.
377 Licensed under the OpenSSL license (the \*(L"License\*(R"). You may not use
378 this file except in compliance with the License. You can obtain a copy
379 in the file \s-1LICENSE\s0 in the source distribution or at
380 <https://www.openssl.org/source/license.html>.