Fix use of time_t internally and APIs#19107
Conversation
This changes internal (libssl) times to use ossl_time. Replacement public APIs (for backwards compatibility) are introduced to support time_t in the interface (rather than long).
|
Seems like some overlap between this and #19082... |
Yes, I must've missed that one! |
| #define SECONDSSTR "30" | ||
|
|
||
| /* not as accurate as in the library, but no worse than original code */ | ||
| OSSL_TIME ossl_time_now(void) |
There was a problem hiding this comment.
Why not include crypto/time.c and get the accurate version?
| OPENSSL_gmtime_diff() calculates the difference between the two B<struct tm> | ||
| structures B<from> and B<to>. The difference in days is placed into B<pday>, | ||
| the remaining seconds are placed to B<psec>. The value in B<psec> will be less | ||
| than the number of seconds per day (3600). Leap seconds are not considered. |
There was a problem hiding this comment.
86400 seconds in a day not 3600.
There was a problem hiding this comment.
Nah... I'm just going to restrict it to an hour... whoops.
|
|
||
| long SSL_CTX_set_timeout(SSL_CTX *ctx, long t); | ||
| long SSL_CTX_get_timeout(SSL_CTX *ctx); | ||
| time_t SSL_CTX_set_timeout_ex(SSL_CTX *ctx, time_t t); |
There was a problem hiding this comment.
The timeout is a duration isn't it. As such, I don't see a need to accept a time_t. long is more than sufficient.
There was a problem hiding this comment.
Duration and let call it "calandar time" are related but distinct concepts. Duration is not fixed in time, whereas a calendar time is. However, calendar time is nothing but a duration from a fixed point in time. So, they really could be the same type. Both are effectively bound by the same constraints, one of which is the size/type of storage. The OSSL_TIME code itself allows for subtraction (which results in a duration) and addition (one of which must be a duration). sleep(3) takes a duration in seconds, as an unsigned int. But I swear there was a type specific for durations, but I can't find it.
There was a problem hiding this comment.
There are more than a few variations documented:
| Call | Type |
|---|---|
alarm(2) |
unsigned int |
clock(2) |
clock_t |
clock_gettime(2) |
struct timespec |
epoll_wait(2) |
int |
| getitimer(2)` | struct timeval |
poll(2) |
int |
sleep(3) |
unsigned int |
usleep(3) |
useconds_t |
I can't locate a specific duration type either.
|
|
||
| time_t SSL_SESSION_get_time_ex(const SSL_SESSION *s); | ||
| time_t SSL_SESSION_set_time_ex(SSL_SESSION *s, time_t tm); | ||
| time_t SSL_SESSION_get_timeout_ex(const SSL_SESSION *s); |
There was a problem hiding this comment.
Again, not sure we need or want timeouts using time_t.
| #include <openssl/ssl.h> | ||
|
|
||
| long SSL_get_default_timeout(const SSL *ssl); | ||
| time_t SSL_get_default_timeout_ex(const SSL *ssl); |
|
Adding new functions with a time_t seems wrong. We should deprecate all public function with a time_t. If time_t is only used internally, we can fix Y2038 problems. |
|
We should not use time_t internally as there are 32-bit builds that will not work in Epoch 1. |
|
To clarify, we should only use time_t when needed to talk to the OS.
Some OSs provide multiple interfaces, and might have one that doesn't
have the Y2038 problem. That might be multiple interfaces that use
time_t. Some OSs will not provide a Y2038 compatible interface, and I'm
not sure if that's up to us to fix or not.
|
Yes, but... the user/application talks to the OS and OpenSSL, and it's likely they already have a |
|
|
||
| SSL_SESSION_get_time_ex(), SSL_SESSION_set_time_ex(), | ||
| SSL_SESSION_get_timeout_ex(), and SSL_SESSION_set_timeout_ex() functions are | ||
| synonyms for the SSL_SESSION_*() (without the "_ex") counterparts. |
There was a problem hiding this comment.
I understand that as: #define SSL_SESSION_get_time_ex SSL_SESSION_get_time
|
It seems to me that most of the functions here actually need a time_t:
- It's about a timeout, which is relative, not some specific time.
- SSL_CTX_flush_sessions also seems to be used relative to the current
time, and maybe it should just take a relative time instead of a
time_t.
The only exception is SSL_SESSION_get_time and related functions, which
take a specific point in time. This can be changed to a type that is
Y2038 compatible, it does not need to be a time_t.
|
|
My view is using something like an |
|
I'm abandoning this, but going to create a PR for the |
This changes internal (libssl) times to use ossl_time.
Replacement public APIs (for backwards compatibility) are introduced to
support time_t in the interface (rather than long).
Checklist