24 void SSLSessionCallbacks::attachCallbacksToContext(
27 SSL_CTX_set_session_cache_mode(
29 SSL_SESS_CACHE_NO_INTERNAL | SSL_SESS_CACHE_CLIENT |
30 SSL_SESS_CACHE_NO_AUTO_CLEAR);
32 SSLUtil::getSSLCtxExIndex(&getCacheIndex());
33 SSL_CTX_set_ex_data(ctx, getCacheIndex(), callbacks);
34 SSL_CTX_sess_set_new_cb(ctx, SSLSessionCallbacks::newSessionCallback);
35 SSL_CTX_sess_set_remove_cb(ctx, SSLSessionCallbacks::removeSessionCallback);
39 void SSLSessionCallbacks::detachCallbacksFromContext(
42 auto sslSessionCache = getCacheFromContext(ctx);
43 if (sslSessionCache != callbacks) {
48 SSL_CTX_set_ex_data(ctx, getCacheIndex(),
nullptr);
49 SSL_CTX_sess_set_new_cb(ctx,
nullptr);
50 SSL_CTX_sess_set_remove_cb(ctx,
nullptr);
56 SSL_CTX_get_ex_data(ctx, getCacheIndex()));
60 std::string SSLSessionCallbacks::getSessionKeyFromSSL(SSL* ssl) {
62 return sock ? sock->getSessionKey() :
"";
66 int SSLSessionCallbacks::newSessionCallback(SSL* ssl, SSL_SESSION* session) {
68 SSL_CTX* ctx = SSL_get_SSL_CTX(ssl);
69 auto sslSessionCache = getCacheFromContext(ctx);
71 if (sessionKey.empty()) {
73 sessionKey = name ? name :
"";
75 if (!sessionKey.empty()) {
77 sslSessionCache->setSSLSession(sessionKey,
std::move(sessionPtr));
84 void SSLSessionCallbacks::removeSessionCallback(
86 SSL_SESSION* session) {
87 auto sslSessionCache = getCacheFromContext(ctx);
89 if (identity && !identity->empty()) {
90 sslSessionCache->removeSSLSession(*identity);
96 sslSessionCache->removeSSLSession(
std::string(hostname));
bool setSessionServiceIdentity(SSL_SESSION *session, const std::string &str)
static const char * getSSLServerNameFromSSL(SSL *ssl)
folly::Optional< std::string > getSessionServiceIdentity(SSL_SESSION *session)
constexpr detail::Map< Move > move
std::unique_ptr< SSL_SESSION, SessionDestructor > SSLSessionPtr
const char * SSL_SESSION_get0_hostname(const SSL_SESSION *s)
static AsyncSSLSocket * getFromSSL(const SSL *ssl)