X509_CMP_TIME(3ossl)
β¨ X509_CMP_TIME π
okay bestie, so this is a page from the OpenSSL manual β specifically the third section, the library-calls girlies. And it's all about the X509 time functions: X509_cmp_time, X509_cmp_current_time, X509_cmp_timeframe, X509_time_adj, X509_time_adj_ex, and X509_gmtime_adj. Yes that's six whole functions in one page, she's an overachiever, we love her for it. π
πΈ SYNOPSIS πΈ
here's the receipts, exactly as written, no editing, no notes:
int X509_cmp_time(const ASN1_TIME *asn1_time, 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);
ASN1_TIME *X509_time_adj(ASN1_TIME *asn1_time, long offset_sec, time_t *in_tm);
ASN1_TIME *X509_time_adj_ex(ASN1_TIME *asn1_time, int offset_day, long
offset_sec, time_t *in_tm);
ASN1_TIME *X509_gmtime_adj(ASN1_TIME *asn1_time, long offset_sec);
π¦ DESCRIPTION π¦
okay so, three of these compare, three of these adjust. let's go one by one because there's lore here.
X509_cmp_time()β compares theASN1_TIMEsitting inasn1_timeagainst the time living inin_tm.X509_cmp_current_time()β compares theASN1_TIMEinasn1_timeagainst the current time, expressed as atime_t.X509_cmp_timeframe()β compares the given time period against the reference time that's included in the verification parametersvpmβ but only ifvpmis not NULL and it containsX509_V_FLAG_USE_CHECK_TIME. otherwise? the current time gets used as the reference time instead. lowkey a whole conditional situation, but she's consistent. β¨
now the adjusting girlies:
X509_time_adj_ex()β sets theASN1_TIMEstructureasn1_timeto the time that isoffset_dayandoffset_secafterin_tm. two offsets, day AND sec, she's doing both, icon behaviour.X509_time_adj()β sets theASN1_TIMEstructureasn1_timeto the timeoffset_secafterin_tm. but bestie, listen: this method can only handle second offsets up to the capacity oflong. so the newerX509_time_adj_ex()API should be preferred. ngl, the old one is giving legacy π
π«Ά for both of those methods: ifasn1_timeis NULL, a newASN1_TIMEstructure gets allocated and returned. you don't have to bring your own, she'll make one.
π«Ά and in all of the methods on this page: ifin_tmis NULL, the current time β expressed astime_tβ is used. convenient fr fr.
asn1_time must satisfy the ASN1_TIME format mandated by RFC 5280, i.e., its format must be either YYMMDDHHMMSSZ or YYYYMMDDHHMMSSZ. no other shapes, she has a type. no cap.
X509_gmtime_adj()β sets theASN1_TIMEstructureasn1_timeto the timeoffset_secafter the current time. it's literally equivalent to callingX509_time_adj()with the last parameter as NULL. same vibe, shorter name.
π BUGS π
π¨ okay this one's important and it's a little cursed: unlike many standard comparison functions,X509_cmp_time()andX509_cmp_current_time()return 0 on error. not -1, not 1, zero. so if you're out here treating the return value like a normal comparison result, the error case is gonna blend right in. watch out bestie, that's a trap π
π₯ RETURN VALUES π₯
let's do the receipts, one function at a time.
X509_cmp_time() and X509_cmp_current_time():
- return
-1ifasn1_timeis earlier than, or equal to,in_tm(resp. current time) - return
1otherwise - and return
0on error (yes, again, the bug note, it haunts us π)
X509_cmp_timeframe():
- returns
0ifvpmis not NULL and the verification parameters do not containX509_V_FLAG_USE_CHECK_TIMEbut do containX509_V_FLAG_NO_CHECK_TIME - otherwise:
- returns
1if the end time is not NULL and the reference time (which has been determined as stated above π) is past the end time - returns
-1if the start time is not NULL and the reference time is before - else returns
0to indicate that the reference time is in range β which implies that the end time is not before the start time if both are present
- returns
X509_time_adj(), X509_time_adj_ex() and X509_gmtime_adj():
- return a pointer to the updated
ASN1_TIMEstructure - and
NULLon error. that's it, that's the contract. π
β HISTORY β
X509_cmp_timeframe()was added in OpenSSL 3.0. so if you're on something older, that one's not coming to the party, sorry babes. π
π COPYRIGHT π
Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.
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 <https://www.openssl.org/source/license.html>.
and that's the whole page, bestie, you ate that π go forth and compare your timestamps responsibly β¨ππ¦
this was version 3.5.9, dated 2026-09-29, from the OpenSSL manual, section 3ossl β mwah, signing off π π
π¦ where this page comes from
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms