From 9fa6e0c12cb35adb188aa518469e9ca84a7545c4 Mon Sep 17 00:00:00 2001 From: Bob Beck Date: Wed, 8 Oct 2025 15:11:13 -0600 Subject: [PATCH] Add some tests for the OPENSSL_gmtime family of public API. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit As well as some basic sanity testing for the internal asn1_time conversion functions. Reviewed-by: Neil Horman Reviewed-by: Saša Nedvědický (Merged from https://github.com/openssl/openssl/pull/28949) --- crypto/asn1/asn1_local.h | 2 - doc/man3/OPENSSL_gmtime.pod | 93 ++++-- include/crypto/asn1.h | 2 + test/asn1_internal_test.c | 89 ++++++ test/asn1_time_test.c | 613 ++++++++++++++++++++++++++++++++++++ 5 files changed, 765 insertions(+), 34 deletions(-) diff --git a/crypto/asn1/asn1_local.h b/crypto/asn1/asn1_local.h index f92c1c5a3f9..11a54be603b 100644 --- a/crypto/asn1/asn1_local.h +++ b/crypto/asn1/asn1_local.h @@ -90,8 +90,6 @@ int ossl_c2i_uint64_int(uint64_t *ret, int *neg, const unsigned char **pp, long len); int ossl_i2c_uint64_int(unsigned char *p, uint64_t r, int neg); -ASN1_TIME *ossl_asn1_time_from_tm(ASN1_TIME *s, struct tm *ts, int type); - int ossl_asn1_item_ex_new_intern(ASN1_VALUE **pval, const ASN1_ITEM *it, OSSL_LIB_CTX *libctx, const char *propq); int ossl_asn1_time_time_t_to_tm(const time_t *time, struct tm *out_tm); diff --git a/doc/man3/OPENSSL_gmtime.pod b/doc/man3/OPENSSL_gmtime.pod index 0c7fd4b80db..9df0e2990c9 100644 --- a/doc/man3/OPENSSL_gmtime.pod +++ b/doc/man3/OPENSSL_gmtime.pod @@ -20,16 +20,19 @@ OPENSSL_tm_to_posix - platform-agnostic OpenSSL time routines #include int OPENSSL_timegm(const struct tm *tm, time_t *out_time); - int OPENSSL_posix_to_tm(int64_t time struct tm *out_tm); - int OPENSSL_tm_to_posix(struct tm t_tm int64_t *out); + int OPENSSL_posix_to_tm(int64_t time, struct tm *out_tm); + int OPENSSL_tm_to_posix(struct tm t_tm, int64_t *out); =head1 DESCRIPTION -OPENSSL_gmtime() returns the UTC time specified by I into the -provided I argument. |timer| must be in the range of year 0 to -9999. Only the fields I, I, I, I, -I, and I will be updated in I on success, -all other fields will be zeroed. +OPENSSL_gmtime() returns the Unix/Posix time specified by I +into the provided I argument. |timer| must be a value of the +number of seconds relative to 0 hours, 0 minutes, 0 seconds, January 1, +1970, Coordinated Universal Time, without including leap seconds, and +must be in the range of the year 0 to 9999 inclusively. I will +be zeroed, and only the fields I, I, I, +I, I, and I will be updated in I on +success. OPENSSL_gmtime_adj() adds the offsets in I and I to I. @@ -39,47 +42,73 @@ OPENSSL_timegm() converts a time structure in UTC time in I to a time_t valu I. OPENSSL_posix_to_tm() converts a int64_t POSIX time value in I