proxygen
SSLSessionCallbacks.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 
19 #include <wangle/ssl/SSLUtil.h>
22 
23 #include <openssl/ssl.h>
24 
25 #ifdef OPENSSL_NO_TLSEXT
26 #define OPENSSL_TICKETS 0
27 #else
28 #define OPENSSL_TICKETS \
29  OPENSSL_VERSION_NUMBER >= 0x1000105fL
30 #endif
31 
32 namespace wangle {
33 
42  public:
43  // Store the session data of the specified identity in cache. Note that the
44  // implementation must make it's own memory copy of the session data to put
45  // into the cache.
46  virtual void setSSLSession(
47  const std::string& identity, SSLSessionPtr session) noexcept = 0;
48 
49  // Return a SSL session if the cache contained session information for the
50  // specified identity. It is the caller's responsibility to decrement the
51  // reference count of the returned session pointer.
53  const std::string& identity) const noexcept = 0;
54 
55  // Remove session data of the specified identity from cache. Return true if
56  // there was session data associated with the identity before removal, or
57  // false otherwise.
58  virtual bool removeSSLSession(const std::string& identity) noexcept = 0;
59 
60  // Return true if the underlying cache supports persistence
61  virtual bool supportsPersistence() const noexcept {
62  return false;
63  }
64 
65  virtual size_t size() const {
66  return 0;
67  }
68 
69  virtual ~SSLSessionCallbacks() {}
70 
75  static void attachCallbacksToContext(SSL_CTX* ctx,
76  SSLSessionCallbacks* callbacks);
77 
82  static void detachCallbacksFromContext(SSL_CTX* ctx,
83  SSLSessionCallbacks* callbacks);
84 
85  static SSLSessionCallbacks* getCacheFromContext(SSL_CTX* ctx);
86 
87  private:
88 
89  static std::string getSessionKeyFromSSL(SSL* ssl);
90 
91  static int newSessionCallback(SSL* ssl, SSL_SESSION* session);
92 
93  static void removeSessionCallback(SSL_CTX* ctx, SSL_SESSION* session);
94 
95  static int32_t& getCacheIndex() {
96  static int32_t sExDataIndex = -1;
97  return sExDataIndex;
98  }
99 
100 };
101 
102 }
static int newSessionCallback(SSL *ssl, SSL_SESSION *session)
static std::string getSessionKeyFromSSL(SSL *ssl)
virtual bool removeSSLSession(const std::string &identity) noexcept=0
requires E e noexcept(noexcept(s.error(std::move(e))))
virtual size_t size() const
std::unique_ptr< SSL_SESSION, SessionDestructor > SSLSessionPtr
Definition: SSLSession.h:32
virtual bool supportsPersistence() const noexcept
virtual void setSSLSession(const std::string &identity, SSLSessionPtr session) noexcept=0
virtual SSLSessionPtr getSSLSession(const std::string &identity) const noexcept=0
static void attachCallbacksToContext(SSL_CTX *ctx, SSLSessionCallbacks *callbacks)
static int32_t & getCacheIndex()
static void detachCallbacksFromContext(SSL_CTX *ctx, SSLSessionCallbacks *callbacks)
const char * string
Definition: Conv.cpp:212
const
Definition: upload.py:398
static SSLSessionCallbacks * getCacheFromContext(SSL_CTX *ctx)
static void removeSessionCallback(SSL_CTX *ctx, SSL_SESSION *session)