1
1
/* * @file
2
2
3
3
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.
5
6
6
7
@section license License
7
8
25
26
#pragma once
26
27
27
28
#include < openssl/ssl.h>
29
+ #include < string_view>
28
30
29
31
#include " tscore/ink_inet.h"
30
32
#include " iocore/net/SSLTypes.h"
@@ -36,36 +38,98 @@ class TLSSessionResumptionSupport
36
38
public:
37
39
virtual ~TLSSessionResumptionSupport () = default ;
38
40
41
+ // ---------------------------------------------------------------------------
42
+ // Binding of the TLSSessionResumptionSupport object to the SSL object
43
+ // ---------------------------------------------------------------------------
44
+
39
45
static void initialize ();
40
46
static TLSSessionResumptionSupport *getInstance (SSL *ssl);
41
47
static void bind (SSL *ssl, TLSSessionResumptionSupport *srs);
42
48
static void unbind (SSL *ssl);
43
49
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
+ */
44
69
#ifdef HAVE_SSL_CTX_SET_TLSEXT_TICKET_KEY_EVP_CB
45
70
int processSessionTicket (SSL *ssl, unsigned char *keyname, unsigned char *iv, EVP_CIPHER_CTX *cipher_ctx, EVP_MAC_CTX *hctx,
46
71
int enc);
47
72
#else
48
73
int processSessionTicket (SSL *ssl, unsigned char *keyname, unsigned char *iv, EVP_CIPHER_CTX *cipher_ctx, HMAC_CTX *hctx,
49
74
int enc);
50
75
#endif
51
- bool getSSLSessionCacheHit () const ;
52
- bool getSSLOriginSessionCacheHit () const ;
53
- ssl_curve_id getSSLCurveNID () const ;
54
76
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
+ */
56
101
std::shared_ptr<SSL_SESSION> getOriginSession (const std::string &lookup_key);
57
102
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
+
58
114
protected:
59
115
void clear ();
60
116
virtual const IpEndpoint &_getLocalEndpoint () = 0;
61
117
62
118
private:
119
+ enum class ResumptionType {
120
+ NOT_RESUMED,
121
+ RESUMED_FROM_SESSION_CACHE,
122
+ RESUMED_FROM_SESSION_TICKET,
123
+ };
124
+
63
125
static int _ex_data_index;
64
126
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;
68
131
132
+ private:
69
133
#ifdef HAVE_SSL_CTX_SET_TLSEXT_TICKET_KEY_EVP_CB
70
134
int _setSessionInformation (ssl_ticket_key_block *keyblock, unsigned char *keyname, unsigned char *iv, EVP_CIPHER_CTX *cipher_ctx,
71
135
EVP_MAC_CTX *hctx);
@@ -78,7 +142,8 @@ class TLSSessionResumptionSupport
78
142
EVP_CIPHER_CTX *cipher_ctx, HMAC_CTX *hctx);
79
143
#endif
80
144
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);
84
149
};
0 commit comments