Debian Codegraph @

upstream/debian-unstable/man3/ASN1_TIME_set.3ssl

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\" ========================================================================
56 .\"
57 .IX Title "ASN1_TIME_SET 3SSL"
58 .TH ASN1_TIME_SET 3SSL 2026-04-07 3.6.2 OpenSSL
59 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
60 .\" way too many mistakes in technical documents.
61 .if n .ad l
62 .nh
63 .SH NAME
64 ASN1_TIME_set, ASN1_UTCTIME_set, ASN1_GENERALIZEDTIME_set,
65 ASN1_TIME_adj, ASN1_UTCTIME_adj, ASN1_GENERALIZEDTIME_adj,
66 ASN1_TIME_check, ASN1_UTCTIME_check, ASN1_GENERALIZEDTIME_check,
67 ASN1_TIME_set_string, ASN1_UTCTIME_set_string, ASN1_GENERALIZEDTIME_set_string,
68 ASN1_TIME_set_string_X509,
69 ASN1_TIME_normalize,
70 ASN1_TIME_to_tm,
71 ASN1_TIME_print, ASN1_TIME_print_ex, ASN1_UTCTIME_print, ASN1_GENERALIZEDTIME_print,
72 ASN1_TIME_diff,
73 ASN1_TIME_cmp_time_t, ASN1_UTCTIME_cmp_time_t,
74 ASN1_TIME_compare,
75 ASN1_TIME_to_generalizedtime,
76 ASN1_TIME_dup, ASN1_UTCTIME_dup, ASN1_GENERALIZEDTIME_dup \- ASN.1 Time functions
77 .SH SYNOPSIS
78 .IX Header "SYNOPSIS"
79 .Vb 4
80 \& ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t);
81 \& ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t);
82 \& ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,
83 \& time_t t);
84 \&
85 \& ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t, int offset_day,
86 \& long offset_sec);
87 \& ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t,
88 \& int offset_day, long offset_sec);
89 \& ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s,
90 \& time_t t, int offset_day,
91 \& long offset_sec);
92 \&
93 \& int ASN1_TIME_set_string(ASN1_TIME *s, const char *str);
94 \& int ASN1_TIME_set_string_X509(ASN1_TIME *s, const char *str);
95 \& int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str);
96 \& int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s,
97 \& const char *str);
98 \&
99 \& int ASN1_TIME_normalize(ASN1_TIME *s);
100 \&
101 \& int ASN1_TIME_check(const ASN1_TIME *t);
102 \& int ASN1_UTCTIME_check(const ASN1_UTCTIME *t);
103 \& int ASN1_GENERALIZEDTIME_check(const ASN1_GENERALIZEDTIME *t);
104 \&
105 \& int ASN1_TIME_print(BIO *b, const ASN1_TIME *s);
106 \& int ASN1_TIME_print_ex(BIO *bp, const ASN1_TIME *tm, unsigned long flags);
107 \& int ASN1_UTCTIME_print(BIO *b, const ASN1_UTCTIME *s);
108 \& int ASN1_GENERALIZEDTIME_print(BIO *b, const ASN1_GENERALIZEDTIME *s);
109 \&
110 \& int ASN1_TIME_to_tm(const ASN1_TIME *s, struct tm *tm);
111 \& int ASN1_TIME_diff(int *pday, int *psec, const ASN1_TIME *from,
112 \& const ASN1_TIME *to);
113 \&
114 \& int ASN1_TIME_cmp_time_t(const ASN1_TIME *s, time_t t);
115 \& int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t);
116 \&
117 \& int ASN1_TIME_compare(const ASN1_TIME *a, const ASN1_TIME *b);
118 \&
119 \& ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t,
120 \& ASN1_GENERALIZEDTIME **out);
121 \&
122 \& ASN1_TIME *ASN1_TIME_dup(const ASN1_TIME *t);
123 \& ASN1_UTCTIME *ASN1_UTCTIME_dup(const ASN1_UTCTIME *t);
124 \& ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_dup(const ASN1_GENERALIZEDTIME *t);
125 .Ve
126 .SH DESCRIPTION
127 .IX Header "DESCRIPTION"
128 The \fBASN1_TIME_set()\fR, \fBASN1_UTCTIME_set()\fR and \fBASN1_GENERALIZEDTIME_set()\fR
129 functions set the structure \fIs\fR to the time represented by the time_t
130 value \fIt\fR. If \fIs\fR is NULL a new time structure is allocated and returned.
131 .PP
132 The \fBASN1_TIME_adj()\fR, \fBASN1_UTCTIME_adj()\fR and \fBASN1_GENERALIZEDTIME_adj()\fR
133 functions set the time structure \fIs\fR to the time represented
134 by the time \fIoffset_day\fR and \fIoffset_sec\fR after the time_t value \fIt\fR.
135 The values of \fIoffset_day\fR or \fIoffset_sec\fR can be negative to set a
136 time before \fIt\fR. The \fIoffset_sec\fR value can also exceed the number of
137 seconds in a day. If \fIs\fR is NULL a new structure is allocated
138 and returned.
139 .PP
140 The \fBASN1_TIME_set_string()\fR, \fBASN1_UTCTIME_set_string()\fR and
141 \&\fBASN1_GENERALIZEDTIME_set_string()\fR functions set the time structure \fIs\fR
142 to the time represented by string \fIstr\fR which must be in appropriate ASN.1
143 time format (for example YYMMDDHHMMSSZ or YYYYMMDDHHMMSSZ). If \fIs\fR is NULL
144 this function performs a format check on \fIstr\fR only. The string \fIstr\fR
145 is copied into \fIs\fR.
146 .PP
147 \&\fBASN1_TIME_set_string_X509()\fR sets \fBASN1_TIME\fR structure \fIs\fR to the time
148 represented by string \fIstr\fR which must be in appropriate time format
149 that RFC 5280 requires, which means it only allows YYMMDDHHMMSSZ and
150 YYYYMMDDHHMMSSZ (leap second is rejected), all other ASN.1 time format
151 are not allowed. If \fIs\fR is NULL this function performs a format check
152 on \fIstr\fR only.
153 .PP
154 The \fBASN1_TIME_normalize()\fR function converts an \fBASN1_GENERALIZEDTIME\fR or
155 \&\fBASN1_UTCTIME\fR into a time value that can be used in a certificate. It
156 should be used after the \fBASN1_TIME_set_string()\fR functions and before
157 \&\fBASN1_TIME_print()\fR functions to get consistent (i.e. GMT) results.
158 .PP
159 The \fBASN1_TIME_check()\fR, \fBASN1_UTCTIME_check()\fR and \fBASN1_GENERALIZEDTIME_check()\fR
160 functions check the syntax of the time structure \fIs\fR.
161 .PP
162 The \fBASN1_TIME_print()\fR, \fBASN1_UTCTIME_print()\fR and \fBASN1_GENERALIZEDTIME_print()\fR
163 functions print the time structure \fIs\fR to BIO \fIb\fR in human readable
164 format. It will be of the format MMM DD HH:MM:SS[.s*] YYYY GMT, for example
165 "Feb 3 00:55:52 2015 GMT", which does not include a newline.
166 If the time structure has invalid format it prints out "Bad time value" and
167 returns an error. The output for generalized time may include a fractional part
168 following the second.
169 .PP
170 \&\fBASN1_TIME_print_ex()\fR provides \fIflags\fR to specify the output format of the
171 datetime. This can be either \fBASN1_DTFLGS_RFC822\fR or \fBASN1_DTFLGS_ISO8601\fR.
172 .PP
173 \&\fBASN1_TIME_to_tm()\fR converts the time \fIs\fR to the standard \fItm\fR structure.
174 If \fIs\fR is NULL, then the current time is converted. The output time is GMT.
175 The \fItm_sec\fR, \fItm_min\fR, \fItm_hour\fR, \fItm_mday\fR, \fItm_wday\fR, \fItm_yday\fR,
176 \&\fItm_mon\fR and \fItm_year\fR fields of \fItm\fR structure are set to proper values,
177 whereas all other fields are set to 0. If \fItm\fR is NULL this function performs
178 a format check on \fIs\fR only. If \fIs\fR is in Generalized format with fractional
179 seconds, e.g. YYYYMMDDHHMMSS.SSSZ, the fractional seconds will be lost while
180 converting \fIs\fR to \fItm\fR structure.
181 .PP
182 \&\fBASN1_TIME_diff()\fR sets \fI*pday\fR and \fI*psec\fR to the time difference between
183 \&\fIfrom\fR and \fIto\fR. If \fIto\fR represents a time later than \fIfrom\fR then
184 one or both (depending on the time difference) of \fI*pday\fR and \fI*psec\fR
185 will be positive. If \fIto\fR represents a time earlier than \fIfrom\fR then
186 one or both of \fI*pday\fR and \fI*psec\fR will be negative. If \fIto\fR and \fIfrom\fR
187 represent the same time then \fI*pday\fR and \fI*psec\fR will both be zero.
188 If both \fI*pday\fR and \fI*psec\fR are nonzero they will always have the same
189 sign. The value of \fI*psec\fR will always be less than the number of seconds
190 in a day. If \fIfrom\fR or \fIto\fR is NULL the current time is used.
191 .PP
192 The \fBASN1_TIME_cmp_time_t()\fR and \fBASN1_UTCTIME_cmp_time_t()\fR functions compare
193 the two times represented by the time structure \fIs\fR and the time_t \fIt\fR.
194 .PP
195 The \fBASN1_TIME_compare()\fR function compares the two times represented by the
196 time structures \fIa\fR and \fIb\fR.
197 .PP
198 The \fBASN1_TIME_to_generalizedtime()\fR function converts an \fBASN1_TIME\fR to an
199 \&\fBASN1_GENERALIZEDTIME\fR, regardless of year. If either \fIout\fR or
200 \&\fI*out\fR are NULL, then a new object is allocated and must be freed after use.
201 .PP
202 The \fBASN1_TIME_dup()\fR, \fBASN1_UTCTIME_dup()\fR and \fBASN1_GENERALIZEDTIME_dup()\fR functions
203 duplicate the time structure \fIt\fR and return the duplicated result
204 correspondingly.
205 .SH NOTES
206 .IX Header "NOTES"
207 The \fBASN1_TIME\fR structure corresponds to the ASN.1 structure \fBTime\fR
208 defined in RFC5280 et al. The time setting functions obey the rules outlined
209 in RFC5280: if the date can be represented by UTCTime it is used, else
210 GeneralizedTime is used.
211 .PP
212 The \fBASN1_TIME\fR, \fBASN1_UTCTIME\fR and \fBASN1_GENERALIZEDTIME\fR structures are
213 represented as an \fBASN1_STRING\fR internally and can be freed up using
214 \&\fBASN1_STRING_free()\fR.
215 .PP
216 The \fBASN1_TIME\fR structure can represent years from 0000 to 9999 but no attempt
217 is made to correct ancient calendar changes (for example from Julian to
218 Gregorian calendars).
219 .PP
220 \&\fBASN1_UTCTIME\fR is limited to a year range of 1950 through 2049.
221 .PP
222 Some applications add offset times directly to a time_t value and pass the
223 results to \fBASN1_TIME_set()\fR (or equivalent). This can cause problems as the
224 time_t value can overflow on some systems resulting in unexpected results.
225 New applications should use \fBASN1_TIME_adj()\fR instead and pass the offset value
226 in the \fIoffset_sec\fR and \fIoffset_day\fR parameters instead of directly
227 manipulating a time_t value.
228 .PP
229 \&\fBASN1_TIME_adj()\fR may change the type from \fBASN1_GENERALIZEDTIME\fR to
230 \&\fBASN1_UTCTIME\fR, or vice versa, based on the resulting year.
231 \&\fBASN1_GENERALIZEDTIME_adj()\fR and \fBASN1_UTCTIME_adj()\fR will not modify the type
232 of the return structure.
233 .PP
234 It is recommended that functions starting with \fBASN1_TIME\fR be used instead of
235 those starting with \fBASN1_UTCTIME\fR or \fBASN1_GENERALIZEDTIME\fR. The functions
236 starting with \fBASN1_UTCTIME\fR and \fBASN1_GENERALIZEDTIME\fR act only on that
237 specific time format. The functions starting with \fBASN1_TIME\fR will operate on
238 either format.
239 .PP
240 Users familiar with RFC822 should note that when specifying the flag
241 \&\fBASN1_DTFLGS_RFC822\fR the year will be formatted as documented above,
242 i.e., using 4 digits, not 2 as specified in RFC822.
243 .SH BUGS
244 .IX Header "BUGS"
245 \&\fBASN1_TIME_print()\fR, \fBASN1_UTCTIME_print()\fR and \fBASN1_GENERALIZEDTIME_print()\fR do
246 not print out the timezone: it either prints out "GMT" or nothing. But all
247 certificates complying with RFC5280 et al use GMT anyway.
248 .PP
249 \&\fBASN1_TIME_print()\fR, \fBASN1_TIME_print_ex()\fR, \fBASN1_UTCTIME_print()\fR and
250 \&\fBASN1_GENERALIZEDTIME_print()\fR do not distinguish if they fail because
251 of an I/O error or invalid time format.
252 .PP
253 Use the \fBASN1_TIME_normalize()\fR function to normalize the time value before
254 printing to get GMT results.
255 .SH "RETURN VALUES"
256 .IX Header "RETURN VALUES"
257 \&\fBASN1_TIME_set()\fR, \fBASN1_UTCTIME_set()\fR, \fBASN1_GENERALIZEDTIME_set()\fR,
258 \&\fBASN1_TIME_adj()\fR, \fBASN1_UTCTIME_adj()\fR and \fBASN1_GENERALIZEDTIME_set()\fR return
259 a pointer to a time structure or NULL if an error occurred.
260 .PP
261 \&\fBASN1_TIME_set_string()\fR, \fBASN1_UTCTIME_set_string()\fR,
262 \&\fBASN1_GENERALIZEDTIME_set_string()\fR and \fBASN1_TIME_set_string_X509()\fR return
263 1 if the time value is successfully set and 0 otherwise.
264 .PP
265 \&\fBASN1_TIME_normalize()\fR returns 1 on success, and 0 on error.
266 .PP
267 \&\fBASN1_TIME_check()\fR, ASN1_UTCTIME_check and \fBASN1_GENERALIZEDTIME_check()\fR return 1
268 if the structure is syntactically correct and 0 otherwise.
269 .PP
270 \&\fBASN1_TIME_print()\fR, \fBASN1_UTCTIME_print()\fR and \fBASN1_GENERALIZEDTIME_print()\fR
271 return 1 if the time is successfully printed out and
272 0 if an I/O error occurred an error occurred (I/O error or invalid time format).
273 .PP
274 \&\fBASN1_TIME_to_tm()\fR returns 1 if the time is successfully parsed and 0 if an
275 error occurred (invalid time format).
276 .PP
277 \&\fBASN1_TIME_diff()\fR returns 1 for success and 0 for failure. It can fail if the
278 passed-in time structure has invalid syntax, for example.
279 .PP
280 \&\fBASN1_TIME_cmp_time_t()\fR and \fBASN1_UTCTIME_cmp_time_t()\fR return \-1 if \fIs\fR is
281 before \fIt\fR, 0 if \fIs\fR equals \fIt\fR, or 1 if \fIs\fR is after \fIt\fR. \-2 is returned
282 on error.
283 .PP
284 \&\fBASN1_TIME_compare()\fR returns \-1 if \fIa\fR is before \fIb\fR, 0 if \fIa\fR equals \fIb\fR,
285 or 1 if \fIa\fR is after \fIb\fR. \-2 is returned on error.
286 .PP
287 \&\fBASN1_TIME_to_generalizedtime()\fR returns a pointer to the appropriate time
288 structure on success or NULL if an error occurred.
289 .PP
290 \&\fBASN1_TIME_dup()\fR, \fBASN1_UTCTIME_dup()\fR and \fBASN1_GENERALIZEDTIME_dup()\fR return a
291 pointer to a time structure or NULL if an error occurred.
292 .SH EXAMPLES
293 .IX Header "EXAMPLES"
294 Set a time structure to one hour after the current time and print it out:
295 .PP
296 .Vb 2
297 \& #include <time.h>
298 \& #include <openssl/asn1.h>
299 \&
300 \& ASN1_TIME *tm;
301 \& time_t t;
302 \& BIO *b;
303 \&
304 \& t = time(NULL);
305 \& tm = ASN1_TIME_adj(NULL, t, 0, 60 * 60);
306 \& b = BIO_new_fp(stdout, BIO_NOCLOSE);
307 \& ASN1_TIME_print(b, tm);
308 \& ASN1_STRING_free(tm);
309 \& BIO_free(b);
310 .Ve
311 .PP
312 Determine if one time is later or sooner than the current time:
313 .PP
314 .Vb 1
315 \& int day, sec;
316 \&
317 \& if (!ASN1_TIME_diff(&day, &sec, NULL, to))
318 \& /* Invalid time format */
319 \&
320 \& if (day > 0 || sec > 0)
321 \& printf("Later\en");
322 \& else if (day < 0 || sec < 0)
323 \& printf("Sooner\en");
324 \& else
325 \& printf("Same\en");
326 .Ve
327 .SH HISTORY
328 .IX Header "HISTORY"
329 The \fBASN1_TIME_to_tm()\fR function was added in OpenSSL 1.1.1.
330 The \fBASN1_TIME_set_string_X509()\fR function was added in OpenSSL 1.1.1.
331 The \fBASN1_TIME_normalize()\fR function was added in OpenSSL 1.1.1.
332 The \fBASN1_TIME_cmp_time_t()\fR function was added in OpenSSL 1.1.1.
333 The \fBASN1_TIME_compare()\fR function was added in OpenSSL 1.1.1.
334 .SH COPYRIGHT
335 .IX Header "COPYRIGHT"
336 Copyright 2015\-2025 The OpenSSL Project Authors. All Rights Reserved.
337 .PP
338 Licensed under the Apache License 2.0 (the "License"). You may not use
339 this file except in compliance with the License. You can obtain a copy
340 in the file LICENSE in the source distribution or at
341 <https://www.openssl.org/source/license.html>.