proxygen
ServerSSLContext.cpp
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  */
17 
18 #include <folly/Memory.h>
24 
25 using folly::SSLContext;
26 using folly::EventBase;
27 
28 namespace wangle {
29 
31  : folly::SSLContext(version) {
32  setSessionCacheContext("ServerSSLContext");
33 }
34 
36  const TLSTicketKeySeeds* ticketSeeds,
37  const SSLContextConfig& ctxConfig,
38  SSLStats* stats) {
39 #ifdef SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB
40  if (ticketSeeds && ctxConfig.sessionTicketEnabled) {
41  ticketManager_ = std::make_unique<TLSTicketKeyManager>(this, stats);
42  ticketManager_->setTLSTicketKeySeeds(
43  ticketSeeds->oldSeeds,
44  ticketSeeds->currentSeeds,
45  ticketSeeds->newSeeds);
46  } else {
47  setOptions(SSL_OP_NO_TICKET);
48  ticketManager_.reset();
49  }
50 #else
51  if (ticketSeeds && ctxConfig.sessionTicketEnabled) {
52  OPENSSL_MISSING_FEATURE(TLSTicket);
53  }
54 #endif
55 }
56 
58  const SSLContextConfig& ctxConfig,
59  const SSLCacheOptions& cacheOptions,
60  const std::shared_ptr<SSLCacheProvider>& externalCache,
61  const std::string& sessionIdContext,
62  SSLStats* stats) {
63  // the internal cache never does what we want (per-thread-per-vip).
64  // Disable it. SSLSessionCacheManager will set it appropriately.
65  SSL_CTX_set_session_cache_mode(getSSLCtx(), SSL_SESS_CACHE_OFF);
66  SSL_CTX_set_timeout(getSSLCtx(), cacheOptions.sslCacheTimeout.count());
67  if (ctxConfig.sessionCacheEnabled &&
68  cacheOptions.maxSSLCacheSize > 0 &&
69  cacheOptions.sslCacheFlushSize > 0) {
70  sessionCacheManager_ = std::make_unique<SSLSessionCacheManager>(
71  cacheOptions.maxSSLCacheSize,
72  cacheOptions.sslCacheFlushSize,
73  this,
74  sessionIdContext,
75  stats,
76  externalCache);
77  } else {
78  sessionCacheManager_.reset();
79  }
80 }
81 
82 }
std::vector< std::string > newSeeds
void setupSessionCache(const SSLContextConfig &ctxConfig, const SSLCacheOptions &cacheOptions, const std::shared_ptr< SSLCacheProvider > &externalCache, const std::string &sessionIdContext, SSLStats *stats)
std::vector< std::string > currentSeeds
void setupTicketManager(const TLSTicketKeySeeds *ticketSeeds, const SSLContextConfig &ctxConfig, SSLStats *stats)
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
void setOptions(long options)
Definition: SSLContext.cpp:590
ProtocolVersion version
SSL_CTX * getSSLCtx() const
Definition: SSLContext.h:503
#define OPENSSL_MISSING_FEATURE(name)
ServerSSLContext(SSLVersion version=TLSv1)
std::chrono::seconds sslCacheTimeout
void setSessionCacheContext(const std::string &context)
Definition: SSLContext.cpp:526
const char * string
Definition: Conv.cpp:212
std::vector< std::string > oldSeeds
std::unique_ptr< TLSTicketKeyManager > ticketManager_
std::unique_ptr< SSLSessionCacheManager > sessionCacheManager_