]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - secure/lib/libcrypto/man/man3/ASN1_TIME_set.3
MFC: r360175
[FreeBSD/FreeBSD.git] / secure / lib / libcrypto / man / man3 / ASN1_TIME_set.3
1 .\" Automatically generated by Pod::Man 4.11 (Pod::Simple 3.40)
2 .\"
3 .\" Standard preamble:
4 .\" ========================================================================
5 .de Sp \" Vertical space (when we can't use .PP)
6 .if t .sp .5v
7 .if n .sp
8 ..
9 .de Vb \" Begin verbatim text
10 .ft CW
11 .nf
12 .ne \\$1
13 ..
14 .de Ve \" End verbatim text
15 .ft R
16 .fi
17 ..
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<>.
24 .tr \(*W-
25 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
26 .ie n \{\
27 .    ds -- \(*W-
28 .    ds PI pi
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
31 .    ds L" ""
32 .    ds R" ""
33 .    ds C` ""
34 .    ds C' ""
35 'br\}
36 .el\{\
37 .    ds -- \|\(em\|
38 .    ds PI \(*p
39 .    ds L" ``
40 .    ds R" ''
41 .    ds C`
42 .    ds C'
43 'br\}
44 .\"
45 .\" Escape single quotes in literal strings from groff's Unicode transform.
46 .ie \n(.g .ds Aq \(aq
47 .el       .ds Aq '
48 .\"
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.
53 .\"
54 .\" Avoid warning from groff about undefined register 'F'.
55 .de IX
56 ..
57 .nr rF 0
58 .if \n(.g .if rF .nr rF 1
59 .if (\n(rF:(\n(.g==0)) \{\
60 .    if \nF \{\
61 .        de IX
62 .        tm Index:\\$1\t\\n%\t"\\$2"
63 ..
64 .        if !\nF==2 \{\
65 .            nr % 0
66 .            nr F 2
67 .        \}
68 .    \}
69 .\}
70 .rr rF
71 .\"
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
75 .if n \{\
76 .    ds #H 0
77 .    ds #V .8m
78 .    ds #F .3m
79 .    ds #[ \f1
80 .    ds #] \fP
81 .\}
82 .if t \{\
83 .    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
84 .    ds #V .6m
85 .    ds #F 0
86 .    ds #[ \&
87 .    ds #] \&
88 .\}
89 .    \" simple accents for nroff and troff
90 .if n \{\
91 .    ds ' \&
92 .    ds ` \&
93 .    ds ^ \&
94 .    ds , \&
95 .    ds ~ ~
96 .    ds /
97 .\}
98 .if t \{\
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'
105 .\}
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 \
121 \{\
122 .    ds : e
123 .    ds 8 ss
124 .    ds o a
125 .    ds d- d\h'-1'\(ga
126 .    ds D- D\h'-1'\(hy
127 .    ds th \o'bp'
128 .    ds Th \o'LP'
129 .    ds ae ae
130 .    ds Ae AE
131 .\}
132 .rm #[ #] #H #V #F C
133 .\" ========================================================================
134 .\"
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.
139 .if n .ad l
140 .nh
141 .SH "NAME"
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
143 .SH "SYNOPSIS"
144 .IX Header "SYNOPSIS"
145 .Vb 4
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,
149 \&                                                time_t t);
150 \&
151 \& ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t, int offset_day,
152 \&                          long offset_sec);
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,
157 \&                                                long offset_sec);
158 \&
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,
163 \&                                     const char *str);
164 \&
165 \& int ASN1_TIME_normalize(ASN1_TIME *s);
166 \&
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);
170 \&
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);
174 \&
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);
178 \&
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);
181 \&
182 \& int ASN1_TIME_compare(const ASN1_TIME *a, const ASN1_TIME *b);
183 \&
184 \& ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t,
185 \&                                                    ASN1_GENERALIZEDTIME **out);
186 .Ve
187 .SH "DESCRIPTION"
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.
192 .PP
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
199 and returned.
200 .PP
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.
207 .PP
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
213 on \fBstr\fR only.
214 .PP
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.
219 .PP
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.
222 .PP
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.
230 .PP
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.
239 .PP
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.
249 .PP
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.
252 .PP
253 The \fBASN1_TIME_compare()\fR function compares the two times represented by the
254 time structures \fBa\fR and \fBb\fR.
255 .PP
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.
259 .SH "NOTES"
260 .IX Header "NOTES"
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.
265 .PP
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.
268 .PP
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).
272 .PP
273 \&\s-1ASN1_UTCTIME\s0 is limited to a year range of 1950 through 2049.
274 .PP
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.
281 .PP
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.
285 .PP
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
290 format.
291 .SH "BUGS"
292 .IX Header "BUGS"
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.
296 .PP
297 Use the \fBASN1_TIME_normalize()\fR function to normalize the time value before
298 printing to get \s-1GMT\s0 results.
299 .SH "RETURN VALUES"
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.
304 .PP
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.
307 .PP
308 \&\fBASN1_TIME_normalize()\fR returns 1 on success, and 0 on error.
309 .PP
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.
312 .PP
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).
316 .PP
317 \&\fBASN1_TIME_to_tm()\fR returns 1 if the time is successfully parsed and 0 if an
318 error occurred (invalid time format).
319 .PP
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.
322 .PP
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
325 on error.
326 .PP
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.
328 .PP
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.
331 .SH "EXAMPLES"
332 .IX Header "EXAMPLES"
333 Set a time structure to one hour after the current time and print it out:
334 .PP
335 .Vb 2
336 \& #include <time.h>
337 \& #include <openssl/asn1.h>
338 \&
339 \& ASN1_TIME *tm;
340 \& time_t t;
341 \& BIO *b;
342 \&
343 \& t = time(NULL);
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);
348 \& BIO_free(b);
349 .Ve
350 .PP
351 Determine if one time is later or sooner than the current time:
352 .PP
353 .Vb 1
354 \& int day, sec;
355 \&
356 \& if (!ASN1_TIME_diff(&day, &sec, NULL, to))
357 \&     /* Invalid time format */
358 \&
359 \& if (day > 0 || sec > 0)
360 \&     printf("Later\en");
361 \& else if (day < 0 || sec < 0)
362 \&     printf("Sooner\en");
363 \& else
364 \&     printf("Same\en");
365 .Ve
366 .SH "HISTORY"
367 .IX Header "HISTORY"
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.
373 .SH "COPYRIGHT"
374 .IX Header "COPYRIGHT"
375 Copyright 2015\-2019 The OpenSSL Project Authors. All Rights Reserved.
376 .PP
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>.