.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man v6.0.2 (Pod::Simple 3.48) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Required to disable full justification in groff 1.23.0. .if n .ds AD l .\" ======================================================================== .\" .IX Title "X509_CHECK_CERTIFICATE_TIMES 3ossl" .TH X509_CHECK_CERTIFICATE_TIMES 3ossl 2026-09-29 4.0.3 OpenSSL .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME X509_check_certificate_times, X509_time_adj, X509_time_adj_ex, X509_gmtime_adj, X509_cmp_time, X509_cmp_current_time, X509_cmp_timeframe \- X509 time functions .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 7 \& int X509_check_certificate_times(const X509_VERIFY_PARAM *vpm, const X509 *x, \& int *error); \& ASN1_TIME *X509_time_adj(ASN1_TIME *asn1_time, long offset_sec, \& const time_t *in_tm); \& ASN1_TIME *X509_time_adj_ex(ASN1_TIME *asn1_time, int offset_day, long \& offset_sec, const time_t *in_tm); \& ASN1_TIME *X509_gmtime_adj(ASN1_TIME *asn1_time, long offset_sec); .Ve .PP The following functions have been deprecated since OpenSSL 4.0, and can be hidden entirely by defining \fBOPENSSL_API_COMPAT\fR with a suitable version value, see \fBopenssl_user_macros\fR\|(7): .PP .Vb 4 \& int X509_cmp_time(const ASN1_TIME *asn1_time, const time_t *in_tm); \& int X509_cmp_current_time(const ASN1_TIME *asn1_time); \& int X509_cmp_timeframe(const X509_VERIFY_PARAM *vpm, \& const ASN1_TIME *start, const ASN1_TIME *end); .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" \&\fBX509_check_certificate_times()\fR compares the notBefore and notAfter times in certificate \fIx\fR to check the certificate for temporal validity. The time used for the check will be the current system time, unless The the reference time included in the verification parameter \fIvpm\fR is non NULL and \fIvpm\fR has the flag \fBX509_V_FLAG_USE_CHECK_TIME\fR set. .PP The notBefore and notAfter times in the certificate will be accepted only if they are either the format of a GeneralizedTime (YYYYMMDDHHMMSSZ), or a UTCTime (YYMMDDHHMMSSZ) as per RFC5280, with the exception that the requirement: "CAs conforming to this profile MUST always encode certificate validity dates through the year 2049 as UTCTime; certificate validity dates in 2050 or later MUST be encoded as GeneralizedTime." is not enforced. .PP \&\fBX509_cmp_time()\fR compares the ASN1_TIME in \fIasn1_time\fR with the time in . .PP \&\fBX509_cmp_current_time()\fR compares the ASN1_TIME in \&\fIasn1_time\fR with the current time, expressed as time_t. .PP \&\fBX509_cmp_timeframe()\fR compares the given time period with the reference time included in the verification parameters \fIvpm\fR if they are not NULL and contain \&\fBX509_V_FLAG_USE_CHECK_TIME\fR; else the current time is used as reference time. .PP \&\fBX509_time_adj_ex()\fR sets the ASN1_TIME structure \fIasn1_time\fR to the time \&\fIoffset_day\fR and \fIoffset_sec\fR after \fIin_tm\fR. .PP \&\fBX509_time_adj()\fR sets the ASN1_TIME structure \fIasn1_time\fR to the time \&\fIoffset_sec\fR after \fIin_tm\fR. This method can only handle second offsets up to the capacity of long, so the newer \fBX509_time_adj_ex()\fR API should be preferred. .PP In both methods, if \fIasn1_time\fR is NULL, a new ASN1_TIME structure is allocated and returned. .PP In all methods, if \fIin_tm\fR is NULL, the current time, expressed as time_t, is used. .PP \&\fIasn1_time\fR must satisfy the ASN1_TIME format mandated by RFC 5280, i.e., its format must be either YYMMDDHHMMSSZ or YYYYMMDDHHMMSSZ. .PP \&\fBX509_gmtime_adj()\fR sets the ASN1_TIME structure \fIasn1_time\fR to the time \&\fIoffset_sec\fR after the current time. It is equivalent to calling \&\fBX509_time_adj()\fR with the last parameter as NULL. .SH BUGS .IX Header "BUGS" Unlike many standard comparison functions, The deprecated functions \&\fBX509_cmp_time()\fR and \fBX509_cmp_current_time()\fR return 0 on error, and return \-1 when the values are equal. .PP The deprecated function \fBX509_cmp_timeframe()\fR may accept invalid certificate times as infinitely valid. .SH "RETURN VALUES" .IX Header "RETURN VALUES" \&\fBX509_check_certiticate_times()\fR returns 1 if the certificate is temporally valid at the verification time as per the rules from RFC 5280. It returns 0 otherwise. if \fIerror\fR is non NULL, the integer value it points to will be set to an error code when the certificate is not temporally valid, or 0 when the certificate is temporally valid. .PP The integer pointed to by \fIerror\fR will be set to X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD or X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD if the certificate has an invalid notBefore or notAfter field, respectively. .PP The integer pointed to by \fIerror\fR will be set to X509_V_ERR_CERT_NOT_YET_VALID or X509_V_ERR_CERT_HAS_EXPIRED if the verification time is outside of the certificate\*(Aqs correctly encoded validity window as per RFC5280. .PP \&\fBX509_cmp_time()\fR and \fBX509_cmp_current_time()\fR return \-1 if \fIasn1_time\fR is earlier than, or equal to, \fIin_tm\fR (resp. current time), and 1 otherwise. These methods return 0 on error. .PP \&\fBX509_cmp_timeframe()\fR compares a reference time to a start and end ASN1_TIME value range. The reference time is compared to the start value of the range inclusively, and to the end value of the range exclusively. The reference time used will retrieved from \fIvpm\fR if the flag \fI509_V_FLAG_USE_CHECK_TIME\fR is set in \fIvpm\fR, otherwise it will be the current time. The start time used will be \fIstart\fR if it is non NULL, and a valid ASN1_TIME value, otherwise it will be infinitely in the past. The end time used will be \fIend\fR if it is non NULL and a valid ASN1_TIME value, otherwise it will be infinitely in the future. 0 is returned unconditionally if the flag \&\fIX509_V_FLAG_NO_CHECK_TIME\fR is set in \fIvpm\fR. Otherwise 0 will be returned if the reference time is in the range of the start time and end time as described above. 1 is returned to indicate the reference time is after or equal to the end time. \-1 is returned to indicate the reference time is before the start time. As this function treats invalid ASN1_TIME inputs as unlimited times, it should not be used to for temporal verification of certificates using untrusted inputs that have not been pre\-validated to be correct ASN1_TIME values for a certificate as per RFC 5280, as invalid values will be accepted as valid forever. .PP \&\fBX509_time_adj()\fR, \fBX509_time_adj_ex()\fR and \fBX509_gmtime_adj()\fR return a pointer to the updated ASN1_TIME structure, and NULL on error. .SH "SEE ALSO" .IX Header "SEE ALSO" \&\fBASN1_GENERALIZEDTIME_check\fR\|(3) \&\fBASN1_UTCTIME_check\fR\|(3) \&\fBASN1_TIME_to_tm\fR\|(3) \&\fBOPENSSL_tm_to_posix\fR\|(3) \fBOPENSSL_posix_to_tm\fR\|(3) \&\fBX509_verify_cert_error_string\fR\|(3) .SH HISTORY .IX Header "HISTORY" \&\fBX509_cmp_timeframe()\fR, \fBX509_cmp_current_time()\fR, and \&\fBX509_cmp_timeframe()\fR were deprecated in OpenSSL 4.0 .PP For replacement, consider using \fBX509_check_certificate_times()\fR for use with X509 certificates. For applications checking individual ASN1_TIME values, consider using \fBASN1_TIME_to_tm\fR\|(3) with appropriate validity checking of the \fIASN1_TIME\fR value for your application, and subsequent comparison of either the resulting \fItm\fR structure, or conversion to posix seconds via \fBOPENSSL_tm_to_posix\fR\|(3) .PP \&\fBX509_check_certificate_times()\fR was added in OpenSSL 4.0. .SH COPYRIGHT .IX Header "COPYRIGHT" Copyright 2017\-2026 The OpenSSL Project Authors. All Rights Reserved. .PP Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at .