diff --git a/iocore/net/SSLSessionCache.cc b/iocore/net/SSLSessionCache.cc index fd8c56e2957..93051a35c7f 100644 --- a/iocore/net/SSLSessionCache.cc +++ b/iocore/net/SSLSessionCache.cc @@ -326,22 +326,8 @@ SSLOriginSessionCache::insert_session(const std::string &lookup_key, SSL_SESSION Debug("ssl.origin_session_cache", "insert session: %s = %p", lookup_key.c_str(), sess); } - size_t len = i2d_SSL_SESSION(sess, nullptr); - - Ptr buf; - Ptr buf_exdata; - size_t len_exdata = sizeof(ssl_session_cache_exdata); - buf = new_IOBufferData(buffer_size_to_index(len, MAX_BUFFER_SIZE_INDEX), MEMALIGNED); - ink_release_assert(static_cast(buf->block_size()) >= len); - unsigned char *loc = reinterpret_cast(buf->data()); - i2d_SSL_SESSION(sess, &loc); - buf_exdata = new_IOBufferData(buffer_size_to_index(len, MAX_BUFFER_SIZE_INDEX), MEMALIGNED); - ink_release_assert(static_cast(buf_exdata->block_size()) >= len_exdata); - ssl_session_cache_exdata *exdata = reinterpret_cast(buf_exdata->data()); - // This could be moved to a function in charge of populating exdata - exdata->curve = (ssl == nullptr) ? 0 : SSLGetCurveNID(ssl); - - ats_scoped_obj ssl_orig_session(new SSLOriginSession(lookup_key, buf, len, buf_exdata)); + ssl_curve_id curve = (ssl == nullptr) ? 0 : SSLGetCurveNID(ssl); + ats_scoped_obj ssl_orig_session(new SSLOriginSession(lookup_key, sess, curve)); auto new_node = ssl_orig_session.release(); std::unique_lock lock(mutex); @@ -360,7 +346,7 @@ SSLOriginSessionCache::insert_session(const std::string &lookup_key, SSL_SESSION } bool -SSLOriginSessionCache::get_session(const std::string &lookup_key, SSL_SESSION **sess, ssl_session_cache_exdata **data) +SSLOriginSessionCache::get_session(const std::string &lookup_key, SSL_SESSION **sess, ssl_curve_id *curve) { if (is_debug_tag_set("ssl.origin_session_cache")) { Debug("ssl.origin_session_cache", "get session: %s", lookup_key.c_str()); @@ -372,11 +358,9 @@ SSLOriginSessionCache::get_session(const std::string &lookup_key, SSL_SESSION ** return false; } - const unsigned char *loc = reinterpret_cast(entry->second->asn1_data->data()); - *sess = d2i_SSL_SESSION(nullptr, &loc, entry->second->len_asn1_data); - if (data != nullptr) { - ssl_session_cache_exdata *exdata = reinterpret_cast(entry->second->extra_data->data()); - *data = exdata; + *sess = entry->second->session; + if (curve != nullptr) { + *curve = entry->second->curve_id; } return true; } diff --git a/iocore/net/SSLSessionCache.h b/iocore/net/SSLSessionCache.h index 2fa44a50312..fdf99660867 100644 --- a/iocore/net/SSLSessionCache.h +++ b/iocore/net/SSLSessionCache.h @@ -187,16 +187,16 @@ class SSLOriginSession { public: std::string key; - Ptr asn1_data; /* this is the ASN1 representation of the SSL_CTX */ - size_t len_asn1_data; - Ptr extra_data; + SSL_SESSION *session; + ssl_curve_id curve_id; - SSLOriginSession(const std::string &lookup_key, const Ptr &ssl_asn1_data, size_t len_asn1, - Ptr &exdata) - : key(lookup_key), asn1_data(ssl_asn1_data), len_asn1_data(len_asn1), extra_data(exdata) + SSLOriginSession(const std::string &lookup_key, SSL_SESSION *sess, ssl_curve_id curve) + : key(lookup_key), session(sess), curve_id(curve) { } + ~SSLOriginSession() { SSL_SESSION_free(session); } + LINK(SSLOriginSession, link); }; @@ -207,7 +207,7 @@ class SSLOriginSessionCache ~SSLOriginSessionCache(); void insert_session(const std::string &lookup_key, SSL_SESSION *sess, SSL *ssl); - bool get_session(const std::string &lookup_key, SSL_SESSION **sess, ssl_session_cache_exdata **data); + bool get_session(const std::string &lookup_key, SSL_SESSION **sess, ssl_curve_id *curve); private: void remove_oldest_session(const std::unique_lock &lock); diff --git a/iocore/net/TLSSessionResumptionSupport.cc b/iocore/net/TLSSessionResumptionSupport.cc index b36633929c1..e4aa162c980 100644 --- a/iocore/net/TLSSessionResumptionSupport.cc +++ b/iocore/net/TLSSessionResumptionSupport.cc @@ -175,11 +175,10 @@ TLSSessionResumptionSupport::getSession(SSL *ssl, const unsigned char *id, int l SSL_SESSION * TLSSessionResumptionSupport::getOriginSession(SSL *ssl, const std::string &lookup_key) { - SSL_SESSION *session = nullptr; - ssl_session_cache_exdata *exdata = nullptr; - if (origin_sess_cache->get_session(lookup_key, &session, &exdata)) { + SSL_SESSION *session = nullptr; + ssl_curve_id curve = 0; + if (origin_sess_cache->get_session(lookup_key, &session, &curve)) { ink_assert(session); - ink_assert(exdata); // Double check the timeout if (is_ssl_session_timed_out(session)) { @@ -188,7 +187,7 @@ TLSSessionResumptionSupport::getOriginSession(SSL *ssl, const std::string &looku } else { SSL_INCREMENT_DYN_STAT(ssl_origin_session_cache_hit); this->_setSSLSessionCacheHit(true); - this->_setSSLCurveNID(exdata->curve); + this->_setSSLCurveNID(curve); } } else { SSL_INCREMENT_DYN_STAT(ssl_origin_session_cache_miss);