GRPC Core  9.0.0
ssl_session.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2018 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPC_CORE_TSI_SSL_SESSION_CACHE_SSL_SESSION_H
20 #define GRPC_CORE_TSI_SSL_SESSION_CACHE_SSL_SESSION_H
21 
23 
25 
26 #include <grpc/slice.h>
27 
28 extern "C" {
29 #include <openssl/ssl.h>
30 }
31 
33 
34 // The main purpose of code here is to provide means to cache SSL sessions
35 // in a way that they can be shared between connections.
36 //
37 // SSL_SESSION stands for single instance of session and is not generally safe
38 // to share between SSL contexts with different lifetimes. It happens because
39 // not all SSL implementations guarantee immutability of SSL_SESSION object.
40 // See SSL_SESSION documentation in BoringSSL and OpenSSL for more details.
41 
42 namespace tsi {
43 
45  void operator()(SSL_SESSION* session) { SSL_SESSION_free(session); }
46 };
47 
48 typedef std::unique_ptr<SSL_SESSION, SslSessionDeleter> SslSessionPtr;
49 
54  public:
55  // Not copyable nor movable.
56  SslCachedSession(const SslCachedSession&) = delete;
58 
60  static std::unique_ptr<SslCachedSession> Create(SslSessionPtr session);
61 
62  virtual ~SslCachedSession() = default;
63 
65  virtual SslSessionPtr CopySession() const = 0;
66 
67  protected:
68  SslCachedSession() = default;
69 };
70 
71 } // namespace tsi
72 
73 #endif /* GRPC_CORE_TSI_SSL_SESSION_CACHE_SSL_SESSION_H */
SslCachedSession is an immutable thread-safe storage for single session representation.
Definition: ssl_session.h:53
virtual SslSessionPtr CopySession() const =0
Returns a copy of previously cached session.
std::unique_ptr< SSL_SESSION, SslSessionDeleter > SslSessionPtr
Definition: ssl_session.h:48
SslCachedSession & operator=(const SslCachedSession &)=delete
void operator()(SSL_SESSION *session)
Definition: ssl_session.h:45
static std::unique_ptr< SslCachedSession > Create(SslSessionPtr session)
Create single cached instance of session.
Definition: ssl_session_openssl.cc:68
virtual ~SslCachedSession()=default
Cache for SSL sessions for sessions resumption.
Definition: ssl_session.h:42
Definition: ssl_session.h:44
SslCachedSession()=default