1 .\" $OpenBSD: ASN1_TIME_set.3,v 1.3 2017/08/20 17:16:40 schwarze Exp $
2 .\" OpenSSL ASN1_TIME_set.pod cf37aaa3 Aug 4 11:24:03 2017 +1000
3 .\" OpenSSL ASN1_TIME_set.pod e9b77246 Jan 20 19:58:49 2017 +0100
5 .\" This file was written by Dr. Stephen Henson <steve@openssl.org>
6 .\" and Todd Short <tshort@akamai.com>.
7 .\" Copyright (c) 2015, 2017 The OpenSSL Project. All rights reserved.
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
13 .\" 1. Redistributions of source code must retain the above copyright
14 .\" notice, this list of conditions and the following disclaimer.
16 .\" 2. Redistributions in binary form must reproduce the above copyright
17 .\" notice, this list of conditions and the following disclaimer in
18 .\" the documentation and/or other materials provided with the
21 .\" 3. All advertising materials mentioning features or use of this
22 .\" software must display the following acknowledgment:
23 .\" "This product includes software developed by the OpenSSL Project
24 .\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
26 .\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27 .\" endorse or promote products derived from this software without
28 .\" prior written permission. For written permission, please contact
29 .\" openssl-core@openssl.org.
31 .\" 5. Products derived from this software may not be called "OpenSSL"
32 .\" nor may "OpenSSL" appear in their names without prior written
33 .\" permission of the OpenSSL Project.
35 .\" 6. Redistributions of any form whatsoever must retain the following
37 .\" "This product includes software developed by the OpenSSL Project
38 .\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
40 .\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41 .\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44 .\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 .\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47 .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49 .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51 .\" OF THE POSSIBILITY OF SUCH DAMAGE.
53 .Dd $Mdocdate: August 20 2017 $
58 .Nm ASN1_UTCTIME_set ,
59 .Nm ASN1_GENERALIZEDTIME_set ,
61 .Nm ASN1_UTCTIME_adj ,
62 .Nm ASN1_GENERALIZEDTIME_adj ,
63 .Nm ASN1_TIME_set_string ,
64 .Nm ASN1_UTCTIME_set_string ,
65 .Nm ASN1_GENERALIZEDTIME_set_string ,
67 .Nm ASN1_UTCTIME_check ,
68 .Nm ASN1_GENERALIZEDTIME_check ,
70 .Nm ASN1_UTCTIME_print ,
71 .Nm ASN1_GENERALIZEDTIME_print ,
72 .Nm ASN1_UTCTIME_cmp_time_t ,
73 .Nm ASN1_TIME_to_generalizedtime
74 .Nd ASN.1 Time functions
86 .Ft ASN1_GENERALIZEDTIME *
87 .Fo ASN1_GENERALIZEDTIME_set
88 .Fa "ASN1_GENERALIZEDTIME *s"
100 .Fa "ASN1_UTCTIME *s"
103 .Fa "long offset_sec"
105 .Ft ASN1_GENERALIZEDTIME *
106 .Fo ASN1_GENERALIZEDTIME_adj
107 .Fa "ASN1_GENERALIZEDTIME *s"
110 .Fa "long offset_sec"
113 .Fo ASN1_TIME_set_string
115 .Fa "const char *str"
118 .Fo ASN1_UTCTIME_set_string
119 .Fa "ASN1_UTCTIME *s"
120 .Fa "const char *str"
123 .Fo ASN1_GENERALIZEDTIME_set_string
124 .Fa "ASN1_GENERALIZEDTIME *s"
125 .Fa "const char *str"
129 .Fa "const ASN1_TIME *t"
132 .Fo ASN1_UTCTIME_check
133 .Fa "const ASN1_UTCTIME *t"
136 .Fo ASN1_GENERALIZEDTIME_check
137 .Fa "const ASN1_GENERALIZEDTIME *t"
142 .Fa "const ASN1_TIME *s"
145 .Fo ASN1_UTCTIME_print
147 .Fa "const ASN1_UTCTIME *s"
150 .Fo ASN1_GENERALIZEDTIME_print
152 .Fa "const ASN1_GENERALIZEDTIME *s"
155 .Fo ASN1_UTCTIME_cmp_time_t
156 .Fa "const ASN1_UTCTIME *s"
159 .Ft ASN1_GENERALIZEDTIME *
160 .Fo ASN1_TIME_to_generalizedtime
162 .Fa "ASN1_GENERALIZEDTIME **out"
167 .Fn ASN1_UTCTIME_set ,
169 .Fn ASN1_GENERALIZEDTIME_set
170 set the time structure
172 to the time represented by the
180 a new time structure is allocated and returned.
184 .Fn ASN1_UTCTIME_adj ,
186 .Fn ASN1_GENERALIZEDTIME_adj
187 set the time structure
189 to the time represented by the time
201 can be negative to set a time before
205 value can also exceed the number of seconds in a day.
210 a new time structure is allocated and returned.
213 may change the type from
214 .Vt ASN1_GENERALIZEDTIME
217 or vise-versa depending on the resulting year.
221 .Fn ASN1_GENERALIZEDTIME_adj
222 do not modify the type of the return structure.
225 .Fn ASN1_TIME_set_string ,
226 .Fn ASN1_UTCTIME_set_string ,
228 .Fn ASN1_GENERALIZEDTIME_set_string
229 set the time structure
231 to the time represented by the string
233 which must be in appropriate ASN.1 time format (for example
234 YYMMDDHHMMSSZ or YYYYMMDDHHMMSSZ).
243 these functions only perform a format check on
247 .Fn ASN1_TIME_check ,
248 .Fn ASN1_UTCTIME_check ,
250 .Fn ASN1_GENERALIZEDTIME_check
251 check the syntax of the time structure
255 .Fn ASN1_TIME_print ,
256 .Fn ASN1_UTCTIME_print ,
258 .Fn ASN1_GENERALIZEDTIME_print
264 in human readable format.
265 It will be of the format MMM DD HH:MM:SS YYYY [GMT], for example "Feb 3
267 It does not include a newline.
268 If the time structure has an invalid format,
269 it prints out "Bad time value" and returns an error.
271 .Fn ASN1_GENERALIZEDTIME_print
272 may include a fractional part following the second.
275 .Fn ASN1_UTCTIME_cmp_time_t
276 compares the two times represented by
282 .Fn ASN1_TIME_to_generalizedtime
287 .Vt ASN1_GENERALIZEDTIME ,
295 then a new object is allocated and must be freed after use.
299 structure corresponds to the ASN.1 structure
301 defined in RFC 5280 et al.
302 The time setting functions obey the rules outlined in RFC 5280: if the
303 date can be represented by UTCTime it is used, otherwise GeneralizedTime is
310 .Vt ASN1_GENERALIZEDTIME
311 structures are represented as
313 structures internally and can be freed using
314 .Xr ASN1_STRING_free 3 .
318 structure can represent years from 0000 to 9999 but no attempt is
319 made to correct ancient calendar changes (for example from Julian
320 to Gregorian calendars).
323 is limited to a year range of 1950 through 2049.
325 It is recommended that
327 functions be used instead of
330 .Vt ASN1_GENERALIZEDTIME
331 functions because the
334 .Vt ASN1_GENERALIZEDTIME
335 functions act only on that specific time format, while the
337 functions operate on either format.
340 .Fn ASN1_UTCTIME_set ,
341 .Fn ASN1_GENERALIZEDTIME_set ,
343 .Fn ASN1_UTCTIME_adj ,
344 .Fn ASN1_GENERALIZEDTIME_adj ,
346 .Fn ASN1_TIME_to_generalizedtime
347 return a pointer to a time structure or
349 if an error occurred.
351 .Fn ASN1_TIME_set_string ,
352 .Fn ASN1_UTCTIME_set_string ,
354 .Fn ASN1_GENERALIZEDTIME_set_string
355 return 1 if the time value is successfully set or 0 otherwise.
357 .Fn ASN1_TIME_check ,
358 .Fn ASN1_UTCTIME_check ,
360 .Fn ASN1_GENERALIZEDTIME_check
361 return 1 if the time structure is syntactically correct or 0 otherwise.
363 .Fn ASN1_TIME_print ,
364 .Fn ASN1_UTCTIME_print ,
366 .Fn ASN1_GENERALIZEDTIME_print
367 return 1 if the time is successfully printed or 0 if an error
368 occurred (I/O error or invalid time format).
370 .Fn ASN1_UTCTIME_cmp_time_t
375 0 if both are equal, 1 if
381 Set a time structure to one hour after the current time and print it
383 .Bd -literal -offset indent
385 #include <openssl/asn1.h>
392 tm = ASN1_TIME_adj(NULL, t, 0, 60 * 60);
393 b = BIO_new_fp(stdout, BIO_NOCLOSE);
394 ASN1_TIME_print(b, tm);
395 ASN1_STRING_free(tm);
399 .Fn ASN1_TIME_cmp_time_t
400 first appeared in OpenSSL 1.1.1.
402 Some applications add offset times directly to a
404 value and pass the results to
407 This can cause problems as the
409 value can overflow on some systems resulting in unexpected results.
410 New applications should use
412 instead and pass the offset value in the
416 parameters instead of directly manipulating a
420 .Fn ASN1_TIME_print ,
421 .Fn ASN1_UTCTIME_print ,
423 .Fn ASN1_GENERALIZEDTIME_print
424 do not print the time zone: they either print "GMT" or nothing.
425 But all certificates complying with RFC 5280 et al use GMT anyway.