diff options
author | beck <> | 2023-11-13 12:46:07 +0000 |
---|---|---|
committer | beck <> | 2023-11-13 12:46:07 +0000 |
commit | db4f0c111d3d2ec9fb666f340137159c7cbf1030 (patch) | |
tree | ea8d9b88ee224bef60061210ef255c9bf4048a1c /src | |
parent | 91a189958d0b2acfe88adbe68093b38cecc1ce92 (diff) | |
download | openbsd-db4f0c111d3d2ec9fb666f340137159c7cbf1030.tar.gz openbsd-db4f0c111d3d2ec9fb666f340137159c7cbf1030.tar.bz2 openbsd-db4f0c111d3d2ec9fb666f340137159c7cbf1030.zip |
Prepare to expose OPENSSL_gmtime and OPENSSL_timegm as public
This matches when BoringSSL has done, and allows for getting
rid of the dependency on system timegm() and gmtime() in libtls.
which will make life easier for portable, and remove our
dependency on the potentially very slow system versions.
ok tb@ - tb will handle the minor bump bits and expose
on the next minor bump
CVS :----------------------------------------------------------------------
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/asn1/a_time_posix.c | 18 | ||||
-rw-r--r-- | src/lib/libcrypto/asn1/asn1.h | 7 | ||||
-rw-r--r-- | src/lib/libcrypto/hidden/openssl/asn1.h | 4 | ||||
-rw-r--r-- | src/lib/libcrypto/man/ASN1_TIME_set.3 | 44 |
4 files changed, 68 insertions, 5 deletions
diff --git a/src/lib/libcrypto/asn1/a_time_posix.c b/src/lib/libcrypto/asn1/a_time_posix.c index 9327aa8bf0..5d10d21d3c 100644 --- a/src/lib/libcrypto/asn1/a_time_posix.c +++ b/src/lib/libcrypto/asn1/a_time_posix.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: a_time_posix.c,v 1.3 2023/01/01 16:58:23 miod Exp $ */ | 1 | /* $OpenBSD: a_time_posix.c,v 1.4 2023/11/13 12:46:07 beck Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2022, Google Inc. | 3 | * Copyright (c) 2022, Google Inc. |
4 | * Copyright (c) 2022, Bob Beck <beck@obtuse.com> | 4 | * Copyright (c) 2022, Bob Beck <beck@obtuse.com> |
@@ -26,6 +26,8 @@ | |||
26 | #include <string.h> | 26 | #include <string.h> |
27 | #include <time.h> | 27 | #include <time.h> |
28 | 28 | ||
29 | #include <openssl/asn1.h> | ||
30 | |||
29 | #define SECS_PER_HOUR (int64_t)(60 * 60) | 31 | #define SECS_PER_HOUR (int64_t)(60 * 60) |
30 | #define SECS_PER_DAY (int64_t)(24 * SECS_PER_HOUR) | 32 | #define SECS_PER_DAY (int64_t)(24 * SECS_PER_HOUR) |
31 | 33 | ||
@@ -221,6 +223,20 @@ asn1_time_time_t_to_tm(const time_t *time, struct tm *out_tm) | |||
221 | } | 223 | } |
222 | 224 | ||
223 | int | 225 | int |
226 | OPENSSL_timegm(const struct tm *tm, time_t *out) { | ||
227 | return asn1_time_tm_to_time_t(tm, out); | ||
228 | } | ||
229 | LCRYPTO_ALIAS(OPENSSL_timegm); | ||
230 | |||
231 | struct tm * | ||
232 | OPENSSL_gmtime(const time_t *time, struct tm *out_tm) { | ||
233 | if (!asn1_time_time_t_to_tm(time, out_tm)) | ||
234 | return NULL; | ||
235 | return out_tm; | ||
236 | } | ||
237 | LCRYPTO_ALIAS(OPENSSL_gmtime); | ||
238 | |||
239 | int | ||
224 | OPENSSL_gmtime_adj(struct tm *tm, int off_day, long offset_sec) | 240 | OPENSSL_gmtime_adj(struct tm *tm, int off_day, long offset_sec) |
225 | { | 241 | { |
226 | int64_t posix_time; | 242 | int64_t posix_time; |
diff --git a/src/lib/libcrypto/asn1/asn1.h b/src/lib/libcrypto/asn1/asn1.h index 5eeee3317b..0816f2ac9a 100644 --- a/src/lib/libcrypto/asn1/asn1.h +++ b/src/lib/libcrypto/asn1/asn1.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: asn1.h,v 1.80 2023/07/28 10:33:13 tb Exp $ */ | 1 | /* $OpenBSD: asn1.h,v 1.81 2023/11/13 12:46:07 beck Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -914,6 +914,11 @@ int SMIME_text(BIO *in, BIO *out); | |||
914 | 914 | ||
915 | void ERR_load_ASN1_strings(void); | 915 | void ERR_load_ASN1_strings(void); |
916 | 916 | ||
917 | #if defined(LIBRESSL_INTERNAL) || defined(LIBRESSL_NEXT_API) | ||
918 | int OPENSSL_timegm(const struct tm *tm, time_t *out); | ||
919 | struct tm *OPENSSL_gmtime(const time_t *time, struct tm *out_tm); | ||
920 | #endif | ||
921 | |||
917 | /* Error codes for the ASN1 functions. */ | 922 | /* Error codes for the ASN1 functions. */ |
918 | 923 | ||
919 | /* Function codes. */ | 924 | /* Function codes. */ |
diff --git a/src/lib/libcrypto/hidden/openssl/asn1.h b/src/lib/libcrypto/hidden/openssl/asn1.h index fb1393f2a4..11db7b9902 100644 --- a/src/lib/libcrypto/hidden/openssl/asn1.h +++ b/src/lib/libcrypto/hidden/openssl/asn1.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: asn1.h,v 1.6 2023/07/28 10:33:13 tb Exp $ */ | 1 | /* $OpenBSD: asn1.h,v 1.7 2023/11/13 12:46:07 beck Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2023 Bob Beck <beck@openbsd.org> | 3 | * Copyright (c) 2023 Bob Beck <beck@openbsd.org> |
4 | * | 4 | * |
@@ -249,5 +249,7 @@ LCRYPTO_USED(SMIME_text); | |||
249 | LCRYPTO_USED(ERR_load_ASN1_strings); | 249 | LCRYPTO_USED(ERR_load_ASN1_strings); |
250 | LCRYPTO_USED(ASN1_time_parse); | 250 | LCRYPTO_USED(ASN1_time_parse); |
251 | LCRYPTO_USED(ASN1_time_tm_cmp); | 251 | LCRYPTO_USED(ASN1_time_tm_cmp); |
252 | LCRYPTO_USED(OPENSSL_gmtime); | ||
253 | LCRYPTO_USED(OPENSSL_timegm); | ||
252 | 254 | ||
253 | #endif /* _LIBCRYPTO_ASN1_H */ | 255 | #endif /* _LIBCRYPTO_ASN1_H */ |
diff --git a/src/lib/libcrypto/man/ASN1_TIME_set.3 b/src/lib/libcrypto/man/ASN1_TIME_set.3 index 4f6a99673a..3b649e05be 100644 --- a/src/lib/libcrypto/man/ASN1_TIME_set.3 +++ b/src/lib/libcrypto/man/ASN1_TIME_set.3 | |||
@@ -1,4 +1,4 @@ | |||
1 | .\" $OpenBSD: ASN1_TIME_set.3,v 1.19 2022/11/13 22:11:44 schwarze Exp $ | 1 | .\" $OpenBSD: ASN1_TIME_set.3,v 1.20 2023/11/13 12:46:07 beck Exp $ |
2 | .\" full merge up to: OpenSSL 3d0f1cb9 Jul 11 03:01:24 2017 +0800 | 2 | .\" full merge up to: OpenSSL 3d0f1cb9 Jul 11 03:01:24 2017 +0800 |
3 | .\" selective merge up to: OpenSSL 24a535ea Sep 22 13:14:20 2020 +0100 | 3 | .\" selective merge up to: OpenSSL 24a535ea Sep 22 13:14:20 2020 +0100 |
4 | .\" | 4 | .\" |
@@ -68,7 +68,7 @@ | |||
68 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | 68 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
69 | .\" OF THE POSSIBILITY OF SUCH DAMAGE. | 69 | .\" OF THE POSSIBILITY OF SUCH DAMAGE. |
70 | .\" | 70 | .\" |
71 | .Dd $Mdocdate: November 13 2022 $ | 71 | .Dd $Mdocdate: November 13 2023 $ |
72 | .Dt ASN1_TIME_SET 3 | 72 | .Dt ASN1_TIME_SET 3 |
73 | .Os | 73 | .Os |
74 | .Sh NAME | 74 | .Sh NAME |
@@ -95,6 +95,8 @@ | |||
95 | .Nm ASN1_UTCTIME_cmp_time_t , | 95 | .Nm ASN1_UTCTIME_cmp_time_t , |
96 | .Nm ASN1_TIME_compare , | 96 | .Nm ASN1_TIME_compare , |
97 | .Nm ASN1_TIME_to_generalizedtime | 97 | .Nm ASN1_TIME_to_generalizedtime |
98 | .Nm OPENSSL_gmtime, | ||
99 | .Nm OPENSSL_timegm, | ||
98 | .Nd ASN.1 Time functions | 100 | .Nd ASN.1 Time functions |
99 | .Sh SYNOPSIS | 101 | .Sh SYNOPSIS |
100 | .In openssl/asn1.h | 102 | .In openssl/asn1.h |
@@ -217,6 +219,16 @@ | |||
217 | .Fa "const ASN1_TIME *t" | 219 | .Fa "const ASN1_TIME *t" |
218 | .Fa "ASN1_GENERALIZEDTIME **out" | 220 | .Fa "ASN1_GENERALIZEDTIME **out" |
219 | .Fc | 221 | .Fc |
222 | .Ft struct tm * | ||
223 | .Fo OPENSSL_gmtime | ||
224 | .Fa "const time_t *time" | ||
225 | .Fa "struct tm *out_tm" | ||
226 | .Fc | ||
227 | .Ft int | ||
228 | .Fo OPENSSL_timegm | ||
229 | .Fa "const struct tm *tm" | ||
230 | .Fa "time_t *out_time" | ||
231 | .Fc | ||
220 | .Sh DESCRIPTION | 232 | .Sh DESCRIPTION |
221 | An | 233 | An |
222 | .Vt ASN1_TIME | 234 | .Vt ASN1_TIME |
@@ -562,6 +574,28 @@ is earlier than | |||
562 | is later than | 574 | is later than |
563 | .Fa t , | 575 | .Fa t , |
564 | or \-2 on error. | 576 | or \-2 on error. |
577 | .Pp | ||
578 | .Fn OPENSSL_timegm | ||
579 | converts a time structure in UTC time in | ||
580 | .Fa tm | ||
581 | to a time_t value in | ||
582 | .Fa out_time | ||
583 | .Fn OPENSSL_timegm | ||
584 | returns 1 for success or 0 for failure. | ||
585 | It can fail if the time is not representable in a time_t, | ||
586 | or falls outside the range allowed in RFC 5280 times. | ||
587 | .Pp | ||
588 | .Fn OPENSSL_gmtime | ||
589 | converts a time_t value in | ||
590 | .Fa time | ||
591 | to a struct tm in | ||
592 | .Fa out_tm | ||
593 | .Fn OPENSSL_gmtime | ||
594 | returns | ||
595 | .Fa out_tm | ||
596 | on success or NULL for failure. | ||
597 | It can fail if the time is not representable in a struct tm, | ||
598 | or falls outside the range allowed in RFC 5280 times. | ||
565 | .Sh EXAMPLES | 599 | .Sh EXAMPLES |
566 | Set a time object to one hour after the current time and print it | 600 | Set a time object to one hour after the current time and print it |
567 | out: | 601 | out: |
@@ -651,6 +685,12 @@ and | |||
651 | .Fn ASN1_TIME_compare | 685 | .Fn ASN1_TIME_compare |
652 | first appeared in OpenSSL 1.1.1 and have been available since | 686 | first appeared in OpenSSL 1.1.1 and have been available since |
653 | .Ox 7.2 . | 687 | .Ox 7.2 . |
688 | .Pp | ||
689 | .Fn OPENSSL_gmtime | ||
690 | and | ||
691 | .Fn OPENSSL_timegm | ||
692 | first appeared in BoringSSL and have been available since | ||
693 | .Ox 7.5 . | ||
654 | .Sh CAVEATS | 694 | .Sh CAVEATS |
655 | Some applications add offset times directly to a | 695 | Some applications add offset times directly to a |
656 | .Vt time_t | 696 | .Vt time_t |