Skip to content

Commit 2579056

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 2579056

15 files changed

+240
-68
lines changed

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) {

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
{

src/iocore/net/SSLNetVConnection.cc

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2055,13 +2055,29 @@ SSLNetVConnection::_migrateFromSSL()
20552055
ssl_curve_id
20562056
SSLNetVConnection::_get_tls_curve() const
20572057
{
2058-
if (getSSLSessionCacheHit()) {
2058+
// For resumed server side session caching, we have to retrieve the curve/group
2059+
// from our stored data. For non-resumed sessions or from ticket based resumption,
2060+
// simply query the SSL object.
2061+
if (getIsResumedFromSessionCache()) {
20592062
return getSSLCurveNID();
20602063
} else {
20612064
return SSLGetCurveNID(ssl);
20622065
}
20632066
}
20642067

2068+
std::string_view
2069+
SSLNetVConnection::_get_tls_group() const
2070+
{
2071+
// For resumed server side session caching, we have to retrieve the curve/group
2072+
// from our stored data. For non-resumed sessions or from ticket based resumption,
2073+
// simply query the SSL object.
2074+
if (getIsResumedFromSessionCache()) {
2075+
return getSSLGroupName();
2076+
} else {
2077+
return SSLGetGroupName(ssl);
2078+
}
2079+
}
2080+
20652081
int
20662082
SSLNetVConnection::_verify_certificate(X509_STORE_CTX * /* ctx ATS_UNUSED */)
20672083
{

src/iocore/net/SSLSessionCache.cc

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,14 @@ SSLSessionBucket::insertSession(const SSLSessionID &id, SSL_SESSION *sess, SSL *
174174
// This could be moved to a function in charge of populating exdata
175175
exdata->curve = (ssl == nullptr) ? 0 : SSLGetCurveNID(ssl);
176176

177+
if (ssl == nullptr) {
178+
exdata->group_name[0] = '\0';
179+
} else {
180+
std::string_view group_name = SSLGetGroupName(ssl);
181+
ink_release_assert(group_name.size() < sizeof(exdata->group_name));
182+
strcpy(exdata->group_name, group_name.data());
183+
}
184+
177185
std::unique_ptr<SSLSession> ssl_session(new SSLSession(id, buf, len, buf_exdata));
178186

179187
std::unique_lock w_lock(mutex, std::try_to_lock);
@@ -352,9 +360,11 @@ SSLOriginSessionCache::insert_session(const std::string &lookup_key, SSL_SESSION
352360

353361
Dbg(dbg_ctl_ssl_origin_session_cache, "insert session: %s = %p", lookup_key.c_str(), sess_ptr);
354362

355-
ssl_curve_id curve = (ssl == nullptr) ? 0 : SSLGetCurveNID(ssl);
363+
ssl_curve_id curve = (ssl == nullptr) ? 0 : SSLGetCurveNID(ssl);
364+
std::string group_name = (ssl == nullptr) ? "" : std::string{SSLGetGroupName(ssl)};
365+
356366
std::unique_ptr<SSLOriginSession> ssl_orig_session(
357-
new SSLOriginSession(lookup_key, curve, std::shared_ptr<SSL_SESSION>{sess_ptr, SSLSessDeleter}));
367+
new SSLOriginSession(lookup_key, curve, group_name, std::shared_ptr<SSL_SESSION>{sess_ptr, SSLSessDeleter}));
358368
auto new_node = ssl_orig_session.release();
359369

360370
std::unique_lock lock(mutex);
@@ -376,7 +386,7 @@ SSLOriginSessionCache::insert_session(const std::string &lookup_key, SSL_SESSION
376386
}
377387

378388
std::shared_ptr<SSL_SESSION>
379-
SSLOriginSessionCache::get_session(const std::string &lookup_key, ssl_curve_id *curve)
389+
SSLOriginSessionCache::get_session(const std::string &lookup_key, ssl_curve_id *curve, std::string &group_name)
380390
{
381391
Dbg(dbg_ctl_ssl_origin_session_cache, "get session: %s", lookup_key.c_str());
382392

@@ -390,6 +400,8 @@ SSLOriginSessionCache::get_session(const std::string &lookup_key, ssl_curve_id *
390400
*curve = entry->second->curve_id;
391401
}
392402

403+
group_name = entry->second->group_name;
404+
393405
return entry->second->shared_sess;
394406
}
395407

0 commit comments

Comments
 (0)