Skip to content

Commit 0d8f683

Browse files
committed
TLS curve/group name logging for Ticket Resumption
This applies to the cqssu (curve) and cqssg (group name) TLS log fields. This does two things: * Updates server session caching logic to provide the TLS group name on resumption. * Updates the logging of the curve and group name for ticket resumption logic so that the TLS curve and group names are properly retrieved from the SSL object. For ticket resumption, there is no curve/group name stored to retrieve. It is properly retrieved from the SSL object. Before this change: (1) the SSL group was always retrieved from the SSL object when it should have been retrieved from the server session cache ex_data for session cache resumption and (2) the curve value for cqssu was alway "-" for TLS ticket resumption because there was no cached value to retrieve like there is with server session caching. Fixes: #12398
1 parent 3d04702 commit 0d8f683

17 files changed

+252
-68
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,10 @@ check_symbol_exists(SSL_set1_verify_cert_store "openssl/ssl.h" TS_HAS_VERIFY_CER
476476
check_symbol_exists(SSL_get_shared_curve "openssl/ssl.h" HAVE_SSL_GET_SHARED_CURVE)
477477
check_symbol_exists(SSL_get_curve_name "openssl/ssl.h" HAVE_SSL_GET_CURVE_NAME)
478478
check_symbol_exists(SSL_get0_group_name "openssl/ssl.h" HAVE_SSL_GET0_GROUP_NAME)
479+
check_symbol_exists(SSL_get_negotiated_group "openssl/ssl.h" HAVE_SSL_GET_NEGOTIATED_GROUP)
479480
check_symbol_exists(SSL_get_group_id "openssl/ssl.h" HAVE_SSL_GET_GROUP_ID)
480481
check_symbol_exists(SSL_get_group_name "openssl/ssl.h" HAVE_SSL_GET_GROUP_NAME)
482+
check_symbol_exists(SSL_group_to_name "openssl/ssl.h" HAVE_SSL_GROUP_TO_NAME)
481483
check_symbol_exists(SSL_set_max_early_data "openssl/ssl.h" HAVE_SSL_SET_MAX_EARLY_DATA)
482484
check_symbol_exists(SSL_read_early_data "openssl/ssl.h" HAVE_SSL_READ_EARLY_DATA)
483485
check_symbol_exists(SSL_write_early_data "openssl/ssl.h" HAVE_SSL_WRITE_EARLY_DATA)

include/iocore/net/TLSBasicSupport.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#pragma once
2626

2727
#include <string>
28+
#include <string_view>
2829

2930
#include <openssl/ssl.h>
3031

@@ -43,13 +44,13 @@ class TLSBasicSupport
4344
static void bind(SSL *ssl, TLSBasicSupport *srs);
4445
static void unbind(SSL *ssl);
4546

46-
TLSHandle get_tls_handle() const;
47-
const char *get_tls_protocol_name() const;
48-
const char *get_tls_cipher_suite() const;
49-
const char *get_tls_curve() const;
50-
const char *get_tls_group() const;
51-
ink_hrtime get_tls_handshake_begin_time() const;
52-
ink_hrtime get_tls_handshake_end_time() const;
47+
TLSHandle get_tls_handle() const;
48+
const char *get_tls_protocol_name() const;
49+
const char *get_tls_cipher_suite() const;
50+
const char *get_tls_curve() const;
51+
std::string_view get_tls_group() const;
52+
ink_hrtime get_tls_handshake_begin_time() const;
53+
ink_hrtime get_tls_handshake_end_time() const;
5354
/**
5455
* Returns a certificate that need to be verified.
5556
*
@@ -80,8 +81,9 @@ class TLSBasicSupport
8081
protected:
8182
void clear();
8283

83-
virtual SSL *_get_ssl_object() const = 0;
84-
virtual ssl_curve_id _get_tls_curve() const = 0;
84+
virtual SSL *_get_ssl_object() const = 0;
85+
virtual ssl_curve_id _get_tls_curve() const = 0;
86+
virtual std::string_view _get_tls_group() const = 0;
8587

8688
void _record_tls_handshake_begin_time();
8789
void _record_tls_handshake_end_time();

include/iocore/net/TLSSessionResumptionSupport.h

Lines changed: 76 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/** @file
22
33
TLSSessionResumptionSupport implements common methods and members to
4-
support TLS Ssssion Resumption
4+
support TLS Ssssion Resumption, either via server session caching or
5+
TLS session tickets.
56
67
@section license License
78
@@ -25,6 +26,7 @@
2526
#pragma once
2627

2728
#include <openssl/ssl.h>
29+
#include <string_view>
2830

2931
#include "tscore/ink_inet.h"
3032
#include "iocore/net/SSLTypes.h"
@@ -36,36 +38,98 @@ class TLSSessionResumptionSupport
3638
public:
3739
virtual ~TLSSessionResumptionSupport() = default;
3840

41+
// ---------------------------------------------------------------------------
42+
// Binding of the TLSSessionResumptionSupport object to the SSL object
43+
// ---------------------------------------------------------------------------
44+
3945
static void initialize();
4046
static TLSSessionResumptionSupport *getInstance(SSL *ssl);
4147
static void bind(SSL *ssl, TLSSessionResumptionSupport *srs);
4248
static void unbind(SSL *ssl);
4349

50+
// ---------------------------------------------------------------------------
51+
// TLS Session Resumption Support Via Session Tickets
52+
// ---------------------------------------------------------------------------
53+
54+
/** Handles TLS session ticket processing for session resumption.
55+
*
56+
* This function is called by OpenSSL to either encrypt (create) or decrypt (resume) a session ticket,
57+
* depending on the value of the @p enc parameter. It selects the appropriate ticket key block based on
58+
* the local endpoint and certificate context, and then either generates a new session ticket or attempts
59+
* to decrypt and validate an existing one.
60+
*
61+
* @param[in] ssl The SSL connection object.
62+
* @param[out] keyname Buffer for the session ticket key name.
63+
* @param[out] iv Buffer for the initialization vector.
64+
* @param[in,out] cipher_ctx Cipher context for encryption/decryption.
65+
* @param[in,out] hctx HMAC or MAC context for integrity protection.
66+
* @param[in] enc Indicates operation: 1 for encrypt (create ticket), 0 for decrypt (resume session).
67+
* @return 1 on success, 0 if key not found, negative value on error, or 2 if ticket should be renewed.
68+
*/
4469
#ifdef HAVE_SSL_CTX_SET_TLSEXT_TICKET_KEY_EVP_CB
4570
int processSessionTicket(SSL *ssl, unsigned char *keyname, unsigned char *iv, EVP_CIPHER_CTX *cipher_ctx, EVP_MAC_CTX *hctx,
4671
int enc);
4772
#else
4873
int processSessionTicket(SSL *ssl, unsigned char *keyname, unsigned char *iv, EVP_CIPHER_CTX *cipher_ctx, HMAC_CTX *hctx,
4974
int enc);
5075
#endif
51-
bool getSSLSessionCacheHit() const;
52-
bool getSSLOriginSessionCacheHit() const;
53-
ssl_curve_id getSSLCurveNID() const;
5476

55-
SSL_SESSION *getSession(SSL *ssl, const unsigned char *id, int len, int *copy);
77+
// ---------------------------------------------------------------------------
78+
// TLS Session Resumption Support Via Server Session Caching
79+
// ---------------------------------------------------------------------------
80+
81+
/** Retrieves a cached SSL session from the session cache.
82+
*
83+
* This function is used to retrieve a cached SSL session from the session cache.
84+
*
85+
* @param[in] ssl The SSL connection object.
86+
* @param[in] id The session ID to lookup.
87+
* @param[in] len The length of the session ID.
88+
* @param[out] copy Pointer to an integer indicating if the session ID should be copied.
89+
* @return A pointer to the cached SSL session, or nullptr if not found.
90+
*/
91+
SSL_SESSION *getSession(SSL *ssl, const unsigned char *id, int len, int *copy);
92+
93+
/**
94+
* @brief Retrieves a cached SSL session from the origin session cache.
95+
*
96+
* This function is used to retrieve a cached SSL session from the origin session cache.
97+
*
98+
* @param[in] lookup_key The key to lookup the session in the cache.
99+
* @return A pointer to the cached SSL session, or nullptr if not found.
100+
*/
56101
std::shared_ptr<SSL_SESSION> getOriginSession(const std::string &lookup_key);
57102

103+
// ---------------------------------------------------------------------------
104+
// Getters used for both ticket and session caching
105+
// ---------------------------------------------------------------------------
106+
107+
bool getIsResumedSSLSession() const;
108+
bool getIsResumedOriginSSLSession() const;
109+
bool getIsResumedFromSessionCache() const;
110+
bool getIsResumedFromSessionTicket() const;
111+
ssl_curve_id getSSLCurveNID() const;
112+
std::string_view getSSLGroupName() const;
113+
58114
protected:
59115
void clear();
60116
virtual const IpEndpoint &_getLocalEndpoint() = 0;
61117

62118
private:
119+
enum class ResumptionType {
120+
NOT_RESUMED,
121+
RESUMED_FROM_SESSION_CACHE,
122+
RESUMED_FROM_SESSION_TICKET,
123+
};
124+
63125
static int _ex_data_index;
64126

65-
bool _sslSessionCacheHit = false;
66-
bool _sslOriginSessionCacheHit = false;
67-
int _sslCurveNID = NID_undef;
127+
ResumptionType _resumptionType = ResumptionType::NOT_RESUMED;
128+
bool _isResumedOriginSession = false;
129+
int _sslCurveNID = NID_undef;
130+
std::string _sslGroupName;
68131

132+
private:
69133
#ifdef HAVE_SSL_CTX_SET_TLSEXT_TICKET_KEY_EVP_CB
70134
int _setSessionInformation(ssl_ticket_key_block *keyblock, unsigned char *keyname, unsigned char *iv, EVP_CIPHER_CTX *cipher_ctx,
71135
EVP_MAC_CTX *hctx);
@@ -78,7 +142,8 @@ class TLSSessionResumptionSupport
78142
EVP_CIPHER_CTX *cipher_ctx, HMAC_CTX *hctx);
79143
#endif
80144

81-
void _setSSLSessionCacheHit(bool state);
82-
void _setSSLOriginSessionCacheHit(bool state);
83-
void _setSSLCurveNID(ssl_curve_id curve_nid);
145+
constexpr static bool IS_RESUMED_ORIGIN_SESSION = true;
146+
void _setResumptionType(ResumptionType type, bool isOrigin);
147+
void _setSSLCurveNID(ssl_curve_id curve_nid);
148+
void _setSSLGroupName(std::string_view group_name);
84149
};

include/proxy/http/HttpUserAgent.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ HttpUserAgent::set_txn(ProxyTransaction *txn, TransactionMilestones &milestones)
169169
m_conn_info.curve = "-";
170170
}
171171

172-
if (auto group{tbs->get_tls_group()}; group) {
173-
m_conn_info.security_group = group;
172+
if (auto group{tbs->get_tls_group()}; !group.empty()) {
173+
m_conn_info.security_group = group.data();
174174
} else {
175175
m_conn_info.security_group = "-";
176176
}
@@ -187,7 +187,7 @@ HttpUserAgent::set_txn(ProxyTransaction *txn, TransactionMilestones &milestones)
187187
}
188188

189189
if (auto tsrs = netvc->get_service<TLSSessionResumptionSupport>()) {
190-
m_conn_info.ssl_reused = tsrs->getSSLSessionCacheHit();
190+
m_conn_info.ssl_reused = tsrs->getIsResumedSSLSession();
191191
}
192192

193193
if (auto protocol_str{txn->get_protocol_string()}; protocol_str) {

include/tscore/ink_config.h.cmake.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,10 @@ const int DEFAULT_STACKSIZE = @DEFAULT_STACK_SIZE@;
176176
#cmakedefine01 HAVE_SSL_GET_SHARED_CURVE
177177
#cmakedefine01 HAVE_SSL_GET_CURVE_NAME
178178
#cmakedefine01 HAVE_SSL_GET0_GROUP_NAME
179+
#cmakedefine01 HAVE_SSL_GET_NEGOTIATED_GROUP
179180
#cmakedefine01 HAVE_SSL_GET_GROUP_ID
180181
#cmakedefine01 HAVE_SSL_GET_GROUP_NAME
182+
#cmakedefine01 HAVE_SSL_GROUP_TO_NAME
181183
#cmakedefine01 HAVE_SSL_ERROR_DESCRIPTION
182184
#cmakedefine01 HAVE_OSSL_PARAM_CONSTRUCT_END
183185
#cmakedefine01 TS_USE_TLS_SET_CIPHERSUITES

src/api/InkAPI.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5436,7 +5436,7 @@ TSVConnIsSslReused(TSVConn sslp)
54365436
NetVConnection *vc = reinterpret_cast<NetVConnection *>(sslp);
54375437
SSLNetVConnection *ssl_vc = dynamic_cast<SSLNetVConnection *>(vc);
54385438

5439-
return ssl_vc ? ssl_vc->getSSLSessionCacheHit() : 0;
5439+
return ssl_vc ? ssl_vc->getIsResumedSSLSession() : 0;
54405440
}
54415441

54425442
const char *

src/iocore/net/P_QUICNetVConnection.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,10 @@ class QUICNetVConnection : public UnixNetVConnection,
157157
bool _isReadyToTransferData() const override;
158158

159159
// TLSBasicSupport
160-
SSL *_get_ssl_object() const override;
161-
ssl_curve_id _get_tls_curve() const override;
162-
int _verify_certificate(X509_STORE_CTX *ctx) override;
160+
SSL *_get_ssl_object() const override;
161+
ssl_curve_id _get_tls_curve() const override;
162+
std::string_view _get_tls_group() const override;
163+
int _verify_certificate(X509_STORE_CTX *ctx) override;
163164

164165
// TLSSNISupport
165166
in_port_t _get_local_port() override;

src/iocore/net/P_SSLNetVConnection.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,9 @@ class SSLNetVConnection : public UnixNetVConnection,
319319
{
320320
return this->ssl;
321321
}
322-
ssl_curve_id _get_tls_curve() const override;
323-
int _verify_certificate(X509_STORE_CTX *ctx) override;
322+
ssl_curve_id _get_tls_curve() const override;
323+
std::string_view _get_tls_group() const override;
324+
int _verify_certificate(X509_STORE_CTX *ctx) override;
324325

325326
// TLSSessionResumptionSupport
326327
const IpEndpoint &

src/iocore/net/P_SSLUtils.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,12 @@ class SSLNetVConnection;
3636

3737
using ssl_error_t = int;
3838

39-
// Return the SSL Curve ID associated to the specified SSL connection
39+
/// Return the SSL Curve ID associated with the specified SSL connection
4040
ssl_curve_id SSLGetCurveNID(SSL *ssl);
4141

42+
/// Return the TLS Group Name associated with the specified SSL connection.
43+
std::string_view SSLGetGroupName(SSL *ssl);
44+
4245
SSL_SESSION *SSLSessionDup(SSL_SESSION *sess);
4346

4447
enum class SSLCertContextType;

src/iocore/net/QUICNetVConnection.cc

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,13 +808,29 @@ QUICNetVConnection::_get_ssl_object() const
808808
ssl_curve_id
809809
QUICNetVConnection::_get_tls_curve() const
810810
{
811-
if (getSSLSessionCacheHit()) {
811+
// For resumed server side session caching, we have to retrieve the curve/group
812+
// from our stored data. For non-resumed sessions or from ticket based resumption,
813+
// simply query the SSL object.
814+
if (getIsResumedFromSessionCache()) {
812815
return getSSLCurveNID();
813816
} else {
814817
return SSLGetCurveNID(this->_ssl);
815818
}
816819
}
817820

821+
std::string_view
822+
QUICNetVConnection::_get_tls_group() const
823+
{
824+
// For resumed server side session caching, we have to retrieve the curve/group
825+
// from our stored data. For non-resumed sessions or from ticket based resumption,
826+
// simply query the SSL object.
827+
if (getIsResumedFromSessionCache()) {
828+
return getSSLGroupName();
829+
} else {
830+
return SSLGetGroupName(this->_ssl);
831+
}
832+
}
833+
818834
int
819835
QUICNetVConnection::_verify_certificate(X509_STORE_CTX * /* ctx ATS_UNUSED */)
820836
{

0 commit comments

Comments
 (0)