proxygen
wangle::SSLSessionPersistentCacheBase< K > Class Template Referenceabstract

#include <SSLSessionPersistentCache.h>

Inheritance diagram for wangle::SSLSessionPersistentCacheBase< K >:
wangle::SSLSessionCallbacks

Classes

class  TimeUtil
 

Public Member Functions

 SSLSessionPersistentCacheBase (std::shared_ptr< PersistentCache< K, SSLSessionCacheData >> cache)
 
 SSLSessionPersistentCacheBase (std::shared_ptr< folly::Executor > executor, const std::string &filename, std::size_t cacheCapacity, std::chrono::seconds syncInterval)
 
 SSLSessionPersistentCacheBase (const std::string &filename, std::size_t cacheCapacity, std::chrono::seconds syncInterval)
 
void setSSLSession (const std::string &identity, SSLSessionPtr session) noexceptoverride
 
SSLSessionPtr getSSLSession (const std::string &identity) const noexceptoverride
 
bool removeSSLSession (const std::string &identity) noexceptoverride
 
bool supportsPersistence () const noexceptoverride
 
void setTimeUtil (std::unique_ptr< TimeUtil > timeUtil) noexcept
 
size_t size () const override
 
- Public Member Functions inherited from wangle::SSLSessionCallbacks
virtual ~SSLSessionCallbacks ()
 

Protected Member Functions

virtual K getKey (const std::string &identity) const =0
 

Protected Attributes

std::shared_ptr< PersistentCache< K, SSLSessionCacheData > > persistentCache_
 
std::unique_ptr< TimeUtiltimeUtil_
 

Additional Inherited Members

- Static Public Member Functions inherited from wangle::SSLSessionCallbacks
static void attachCallbacksToContext (SSL_CTX *ctx, SSLSessionCallbacks *callbacks)
 
static void detachCallbacksFromContext (SSL_CTX *ctx, SSLSessionCallbacks *callbacks)
 
static SSLSessionCallbacksgetCacheFromContext (SSL_CTX *ctx)
 

Detailed Description

template<typename K>
class wangle::SSLSessionPersistentCacheBase< K >

This cache is as threadsafe as the underlying PersistentCache used. Multiple instances may delegate to the same persistence layer

Definition at line 38 of file SSLSessionPersistentCache.h.

Constructor & Destructor Documentation

template<typename K>
wangle::SSLSessionPersistentCacheBase< K >::SSLSessionPersistentCacheBase ( std::shared_ptr< PersistentCache< K, SSLSessionCacheData >>  cache)
explicit

Definition at line 28 of file SSLSessionPersistentCache-inl.h.

Referenced by wangle::SSLSessionPersistentCacheBase< K >::TimeUtil::now().

29  :
30  persistentCache_(cache),
31  timeUtil_(new TimeUtil()) {}
std::shared_ptr< PersistentCache< K, SSLSessionCacheData > > persistentCache_
TimeUtilGeneric<> TimeUtil
Definition: Time.h:194
template<typename K>
wangle::SSLSessionPersistentCacheBase< K >::SSLSessionPersistentCacheBase ( std::shared_ptr< folly::Executor executor,
const std::string filename,
std::size_t  cacheCapacity,
std::chrono::seconds  syncInterval 
)

Definition at line 34 of file SSLSessionPersistentCache-inl.h.

40  std::make_shared<FilePersistentCache<K, SSLSessionCacheData>>(
42  filename,
43  cacheCapacity,
44  syncInterval,
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
PUSHMI_INLINE_VAR constexpr __adl::get_executor_fn executor
constexpr int DEFAULT_CACHE_SYNC_RETRIES
SSLSessionPersistentCacheBase(std::shared_ptr< PersistentCache< K, SSLSessionCacheData >> cache)
template<typename K>
wangle::SSLSessionPersistentCacheBase< K >::SSLSessionPersistentCacheBase ( const std::string filename,
std::size_t  cacheCapacity,
std::chrono::seconds  syncInterval 
)

Definition at line 48 of file SSLSessionPersistentCache-inl.h.

53  std::make_shared<FilePersistentCache<K, SSLSessionCacheData>>(
54  filename,
55  cacheCapacity,
56  syncInterval)) {}
SSLSessionPersistentCacheBase(std::shared_ptr< PersistentCache< K, SSLSessionCacheData >> cache)

Member Function Documentation

template<typename K >
SSLSessionPtr wangle::SSLSessionPersistentCacheBase< K >::getSSLSession ( const std::string identity) const
overridevirtualnoexcept

Implements wangle::SSLSessionCallbacks.

Definition at line 76 of file SSLSessionPersistentCache-inl.h.

References wangle::SSLSessionPersistentCacheBase< K >::getKey(), wangle::getSessionFromCacheData(), now(), wangle::SSLSessionPersistentCacheBase< K >::persistentCache_, folly::portability::ssl::SSL_SESSION_get_ticket_lifetime_hint(), folly::portability::ssl::SSL_SESSION_has_ticket(), wangle::SSLSessionPersistentCacheBase< K >::timeUtil_, and value.

Referenced by wangle::SSLSessionPersistentCacheBase< K >::TimeUtil::now().

77  {
78  auto key = getKey(identity);
79  auto hit = persistentCache_->get(key);
80  if (!hit) {
81  return nullptr;
82  }
83 
84  // Create a SSL_SESSION and return. In failure it returns nullptr.
85  auto& value = hit.value();
87 
88 #if OPENSSL_TICKETS
89  if (sess &&
90  SSL_SESSION_has_ticket(sess.get()) &&
91  SSL_SESSION_get_ticket_lifetime_hint(sess.get()) > 0) {
92  auto now = timeUtil_->now();
93  auto secsBetween =
94  std::chrono::duration_cast<std::chrono::seconds>(now - value.addedTime);
95  if (secsBetween >= std::chrono::seconds(SSL_SESSION_get_ticket_lifetime_hint(sess.get()))) {
96  return nullptr;
97  }
98  }
99 #endif
100 
101  return sess;
102 }
std::chrono::steady_clock::time_point now()
std::shared_ptr< PersistentCache< K, SSLSessionCacheData > > persistentCache_
std::unique_ptr< SSL_SESSION, SessionDestructor > SSLSessionPtr
Definition: SSLSession.h:32
int SSL_SESSION_has_ticket(const SSL_SESSION *s)
Definition: OpenSSL.cpp:203
SSL_SESSION * getSessionFromCacheData(const SSLSessionCacheData &data)
static const char *const value
Definition: Conv.cpp:50
unsigned long SSL_SESSION_get_ticket_lifetime_hint(const SSL_SESSION *s)
Definition: OpenSSL.cpp:207
virtual K getKey(const std::string &identity) const =0
template<typename K >
bool wangle::SSLSessionPersistentCacheBase< K >::removeSSLSession ( const std::string identity)
overridevirtualnoexcept

Implements wangle::SSLSessionCallbacks.

Definition at line 105 of file SSLSessionPersistentCache-inl.h.

References wangle::SSLSessionPersistentCacheBase< K >::getKey(), and wangle::SSLSessionPersistentCacheBase< K >::persistentCache_.

Referenced by wangle::SSLSessionPersistentCacheBase< K >::TimeUtil::now().

106  {
107  auto key = getKey(identity);
108  return persistentCache_->remove(key);
109 }
std::shared_ptr< PersistentCache< K, SSLSessionCacheData > > persistentCache_
virtual K getKey(const std::string &identity) const =0
template<typename K >
void wangle::SSLSessionPersistentCacheBase< K >::setSSLSession ( const std::string identity,
SSLSessionPtr  session 
)
overridevirtualnoexcept

Implements wangle::SSLSessionCallbacks.

Definition at line 59 of file SSLSessionPersistentCache-inl.h.

References wangle::getCacheDataForSession(), wangle::SSLSessionPersistentCacheBase< K >::getKey(), wangle::SSLSessionPersistentCacheBase< K >::persistentCache_, and wangle::SSLSessionPersistentCacheBase< K >::timeUtil_.

Referenced by wangle::SSLSessionPersistentCacheBase< K >::TimeUtil::now().

60  {
61  if (!session) {
62  return;
63  }
64 
65  // We do not cache the session itself, but cache the session data from it in
66  // order to recreate a new session later.
67  auto sessionCacheData = getCacheDataForSession(session.get());
68  if (sessionCacheData) {
69  auto key = getKey(identity);
70  sessionCacheData->addedTime = timeUtil_->now();
71  persistentCache_->put(key, *sessionCacheData);
72  }
73 }
folly::Optional< SSLSessionCacheData > getCacheDataForSession(SSL_SESSION *sess)
std::shared_ptr< PersistentCache< K, SSLSessionCacheData > > persistentCache_
virtual K getKey(const std::string &identity) const =0
template<typename K>
void wangle::SSLSessionPersistentCacheBase< K >::setTimeUtil ( std::unique_ptr< TimeUtil timeUtil)
inlinenoexcept

Definition at line 86 of file SSLSessionPersistentCache.h.

86  {
87  timeUtil_ = std::move(timeUtil);
88  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
template<typename K >
size_t wangle::SSLSessionPersistentCacheBase< K >::size ( ) const
overridevirtual

Reimplemented from wangle::SSLSessionCallbacks.

Definition at line 112 of file SSLSessionPersistentCache-inl.h.

References wangle::SSLSessionPersistentCacheBase< K >::persistentCache_.

Referenced by wangle::SSLSessionPersistentCacheBase< std::string >::setTimeUtil().

112  {
113  return persistentCache_->size();
114 }
std::shared_ptr< PersistentCache< K, SSLSessionCacheData > > persistentCache_
template<typename K>
bool wangle::SSLSessionPersistentCacheBase< K >::supportsPersistence ( ) const
inlineoverridevirtualnoexcept

Reimplemented from wangle::SSLSessionCallbacks.

Definition at line 82 of file SSLSessionPersistentCache.h.

82  {
83  return true;
84  }

Member Data Documentation


The documentation for this class was generated from the following files: