@@ -97,6 +97,12 @@ static DbgCtl dbg_ctl_ssl_session_cache{"ssl.session_cache"};
9797static DbgCtl dbg_ctl_ssl_error{" ssl.error" };
9898static DbgCtl dbg_ctl_ssl_verify{" ssl_verify" };
9999
100+ #if TS_HAS_TLS_SESSION_TICKET
101+ static bool ssl_context_enable_ticket_callback (SSL_CTX *ctx);
102+ static bool ssl_apply_sni_session_ticket_properties (SSL *ssl);
103+ static bool ssl_set_session_ticket_number (SSL *ssl, size_t num_tickets);
104+ #endif
105+
100106/* Using pthread thread ID and mutex functions directly, instead of
101107 * ATS this_ethread / ProxyMutex, so that other linked libraries
102108 * may use pthreads and openssl without confusing us here. (TS-2271).
@@ -304,15 +310,8 @@ ssl_cert_callback(SSL *ssl, [[maybe_unused]] void *arg)
304310 setClientCertCACerts (ssl, sslnetvc->get_ca_cert_file (), sslnetvc->get_ca_cert_dir ());
305311 }
306312
307- // Reset the ticket callback if needed
308- SSL_CTX *ctx = SSL_get_SSL_CTX (ssl);
309- shared_SSLMultiCertConfigParams sslMultiCertSettings = std::make_shared<SSLMultiCertConfigParams>();
310- if (sslMultiCertSettings->session_ticket_enabled != 0 ) {
311- #ifdef HAVE_SSL_CTX_SET_TLSEXT_TICKET_KEY_EVP_CB
312- SSL_CTX_set_tlsext_ticket_key_evp_cb (ctx, ssl_callback_session_ticket);
313- #else
314- SSL_CTX_set_tlsext_ticket_key_cb (ctx, ssl_callback_session_ticket);
315- #endif
313+ if (!ssl_apply_sni_session_ticket_properties (ssl)) {
314+ retval = 0 ;
316315 }
317316 }
318317#endif
@@ -493,6 +492,77 @@ ssl_context_enable_dhe(const char *dhparams_file, SSL_CTX *ctx)
493492 return ctx;
494493}
495494
495+ #if TS_HAS_TLS_SESSION_TICKET
496+ static bool
497+ ssl_context_enable_ticket_callback (SSL_CTX *ctx)
498+ {
499+ #ifdef HAVE_SSL_CTX_SET_TLSEXT_TICKET_KEY_EVP_CB
500+ if (SSL_CTX_set_tlsext_ticket_key_evp_cb (ctx, ssl_callback_session_ticket) == 0 ) {
501+ #else
502+ if (SSL_CTX_set_tlsext_ticket_key_cb (ctx, ssl_callback_session_ticket) == 0 ) {
503+ #endif
504+ Error (" failed to set session ticket callback" );
505+ return false ;
506+ }
507+ return true ;
508+ }
509+
510+ static bool
511+ ssl_set_session_ticket_number (SSL *ssl, size_t num_tickets)
512+ {
513+ #if defined(OPENSSL_IS_BORINGSSL)
514+ // BoringSSL only exposes SSL_CTX_set_num_tickets(), so the per-connection
515+ // sni.yaml override is not available here.
516+ (void )ssl;
517+ (void )num_tickets;
518+ return true ;
519+ #else
520+ return SSL_set_num_tickets (ssl, num_tickets) == 1 ;
521+ #endif
522+ }
523+
524+ static bool
525+ ssl_apply_sni_session_ticket_properties (SSL *ssl)
526+ {
527+ auto snis = TLSSNISupport::getInstance (ssl);
528+ if (snis == nullptr ) {
529+ return true ;
530+ }
531+
532+ auto const &hints = snis->hints_from_sni ;
533+ if (!hints.ssl_ticket_enabled .has_value () && !hints.ssl_ticket_number .has_value ()) {
534+ return true ;
535+ }
536+
537+ std::optional<size_t > num_tickets;
538+
539+ if (hints.ssl_ticket_enabled .has_value ()) {
540+ if (hints.ssl_ticket_enabled .value () != 0 ) {
541+ SSL_clear_options (ssl, SSL_OP_NO_TICKET);
542+ Dbg (dbg_ctl_ssl_load, " Enabled session tickets due to sni.yaml override" );
543+ } else {
544+ SSL_set_options (ssl, SSL_OP_NO_TICKET);
545+ num_tickets = 0 ;
546+ Dbg (dbg_ctl_ssl_load, " Disabled session tickets due to sni.yaml override" );
547+ }
548+ }
549+
550+ if ((!hints.ssl_ticket_enabled .has_value () || hints.ssl_ticket_enabled .value () != 0 ) && hints.ssl_ticket_number .has_value ()) {
551+ num_tickets = hints.ssl_ticket_number .value () > 0 ? static_cast <size_t >(hints.ssl_ticket_number .value ()) : 0 ;
552+ }
553+
554+ if (num_tickets.has_value ()) {
555+ if (!ssl_set_session_ticket_number (ssl, num_tickets.value ())) {
556+ Error (" failed to set session ticket number from sni.yaml" );
557+ return false ;
558+ }
559+ Dbg (dbg_ctl_ssl_load, " Set session ticket number from sni.yaml to %zu" , num_tickets.value ());
560+ }
561+
562+ return true ;
563+ }
564+ #endif
565+
496566static ssl_ticket_key_block *
497567ssl_context_enable_tickets (SSL_CTX *ctx, const char *ticket_key_path)
498568{
@@ -509,12 +579,7 @@ ssl_context_enable_tickets(SSL_CTX *ctx, const char *ticket_key_path)
509579 // Setting the callback can only fail if OpenSSL does not recognize the
510580 // SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB constant. we set the callback first
511581 // so that we don't leave a ticket_key pointer attached if it fails.
512- #ifdef HAVE_SSL_CTX_SET_TLSEXT_TICKET_KEY_EVP_CB
513- if (SSL_CTX_set_tlsext_ticket_key_evp_cb (ctx, ssl_callback_session_ticket) == 0 ) {
514- #else
515- if (SSL_CTX_set_tlsext_ticket_key_cb (ctx, ssl_callback_session_ticket) == 0 ) {
516- #endif
517- Error (" failed to set session ticket callback" );
582+ if (!ssl_context_enable_ticket_callback (ctx)) {
518583 ticket_block_free (keyblock);
519584 return nullptr ;
520585 }
@@ -1179,6 +1244,12 @@ SSLMultiCertConfigLoader::init_server_ssl_ctx(CertLoadData const &data, const SS
11791244 }
11801245 }
11811246
1247+ #if TS_HAS_TLS_SESSION_TICKET
1248+ if (!ssl_context_enable_ticket_callback (ctx)) {
1249+ goto fail;
1250+ }
1251+ #endif
1252+
11821253 if (!this ->_setup_client_cert_verification (ctx)) {
11831254 goto fail;
11841255 }
0 commit comments