Skip to content

Commit 9ab25bc

Browse files
committed
SSL: usage of SSL_SESSION_get_time_ex() with OpenSSL 3.3+.
In OpenSSL, SSL_SESSION_get_time() and SSL_SESSION_set_time() functions use "long" to store seconds since the Epoch, which makes these functions problematic after Y2038 on 32-bit platforms, and, more importantly, on 64-bit platforms with 32-bit long (notably Windows). Note that there is no such problem in BoringSSL, which uses uint64_t instead of "long". LibreSSL also uses "long", but it does not support TLSv1.3 session resumption anyway, hence this is not an issue. Fix is to use SSL_SESSION_get_time_ex() and SSL_SESSION_set_time_ex() functions introduced in OpenSSL 3.3 when these are available. Prodded by MSVC with C4244 warnings (conversion from 'type1' to 'type2', possible loss of data) enabled.
1 parent 44484ef commit 9ab25bc

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/event/ngx_event_openssl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,7 @@ ngx_ssl_info_callback(const ngx_ssl_conn_t *ssl_conn, int where, int ret)
11901190

11911191
} else {
11921192
SSL_SESSION_set_time(sess, now);
1193-
SSL_SESSION_set_timeout(sess, timeout - (now - time));
1193+
SSL_SESSION_set_timeout(sess, (long) (timeout - (now - time)));
11941194
}
11951195
}
11961196
}

src/event/ngx_event_openssl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@
8383
#endif
8484

8585

86+
#if (OPENSSL_VERSION_NUMBER > 0x30300000L)
87+
#define SSL_SESSION_get_time(s) SSL_SESSION_get_time_ex(s)
88+
#define SSL_SESSION_set_time(s, t) SSL_SESSION_set_time_ex(s, t)
89+
#endif
90+
91+
8692
typedef struct ngx_ssl_ocsp_s ngx_ssl_ocsp_t;
8793

8894

0 commit comments

Comments
 (0)