X509_CMP_TIME(3)

πŸ“¦ version 4.4.0, in alpine 3.24, arch rolling

πŸ’– X509_CMP_TIME(3) πŸ’–

okay so this is from the Library Functions Manual, and it's literally the ASN.1 Time utilities page β€” bestie, if you've ever needed to compare a certificate's time to right now or do some cursed little time-offset math, this is your girl 🌸


✨ NAME ✨

X509_cmp_time, X509_cmp_current_time, X509_time_adj_ex, X509_time_adj, X509_gmtime_adj β€” ASN.1 Time utilities πŸ‘‘


πŸŽ€ SYNOPSIS πŸŽ€

library β€œlibcrypto” #include <openssl/x509.h>

int
X509_cmp_time(const ASN1_TIME *asn1_time, time_t *cmp_time);

int
X509_cmp_current_time(const ASN1_TIME *asn1_time);

ASN1_TIME *
X509_time_adj_ex(ASN1_TIME *out_time, int offset_day, long offset_sec,
    time_t *in_time);

ASN1_TIME *
X509_time_adj(ASN1_TIME *out_time, long offset_sec, time_t *in_time);

ASN1_TIME *
X509_gmtime_adj(ASN1_TIME *out_time, long offset_sec);

πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea β˜• β€” each of these does one specific little job, and honestly they're all serving:

  • X509_cmp_time() parses asn1_time and compares it to cmp_time β€” or, if cmp_time is NULL, it compares against the current time instead. iykyk πŸ•
  • X509_cmp_current_time() compares it to the current time. that's it, that's the whole vibe.
  • X509_time_adj_ex() sets out_time to a time that is offset_day and offset_sec later than in_time. and listen β€” offset_day and offset_sec can both be negative, which sets a time before in_time. time travel works both directions bestie πŸ’… also offset_sec is allowed to exceed the number of seconds in a day, so don't stress about it overflowing your brain. if in_time is NULL, the current time gets used instead. and if out_time is NULL, a brand-new ASN1_TIME structure is allocated and returned to you, like a lil gift 🎁
  • X509_time_adj() does the exact same thing, but with a 0 day offset. same energy, fewer args ✨
  • X509_gmtime_adj() does the same thing but uses the current time instead of in_time β€” so it sets out_time to a time offset_sec seconds later than the current time. very "now plus a bit" of it πŸ•°οΈ

πŸ’€ RETURN VALUES πŸ’€

  • X509_cmp_time() and X509_cmp_current_time() return -1 if asn1_time is earlier than or equal to cmp_time, 1 if it is later, or 0 on error. that 0 is giving "something went wrong, don't @ me" 😭
  • X509_time_adj_ex(), X509_time_adj(), and X509_gmtime_adj() return a pointer to the updated or newly allocated ASN1_TIME structure β€” or NULL on error. so like, check it, bestie 🫢

🌈 SEE ALSO 🌈

ASN1_TIME_new(3), ASN1_TIME_set(3), time(3)

go read those too, they're all part of the same friend group πŸ’œ


🧚 HISTORY 🧚

  • X509_cmp_current_time() and X509_gmtime_adj() first appeared in SSLeay 0.6.0 and have been available since OpenBSD 2.4. vintage icons πŸ’…
  • X509_cmp_time() and X509_time_adj() first appeared in OpenSSL 0.9.6 and have been available since OpenBSD 2.9. era-defining honestly ⭐
  • X509_time_adj_ex() first appeared in OpenSSL 1.0.0 and has been available since OpenBSD 4.9. the newbie of the bunch πŸŽ€

ngl this whole page is short and sweet β€” but that -1 / 1 / 0 return thing is highkey a trap, so like, read it twice before you ship πŸ™ˆ

and that's the whole page, bestie β€” brought to you by Debian, dated June 8, 2025 πŸ“ mwah, go write some correct time comparisons πŸ’–

πŸ“¦ where this page comes from