2 * Copyright 2017 Facebook, Inc.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <folly/Memory.h>
20 #include <folly/portability/OpenSSL.h>
21 #include <folly/ssl/detail/SSLSessionImpl.h>
28 // Holds and takes ownership of an SSL_SESSION object by incrementing refcount
29 explicit SSLSession(SSL_SESSION* session, bool takeOwnership = true)
30 : impl_(folly::make_unique<detail::SSLSessionImpl>(
34 // Deserialize from a string
35 explicit SSLSession(const std::string& serializedSession)
36 : impl_(folly::make_unique<detail::SSLSessionImpl>(serializedSession)) {}
38 // Serialize to a string that is suitable to store in a persistent cache
39 std::string serialize() const {
40 return impl_->serialize();
43 // Get Session ID. Returns an empty container if session isn't set
44 std::string getSessionID() const {
45 return impl_->getSessionID();
48 // Get a const raw SSL_SESSION ptr without incrementing referecnce count
49 // (Warning: do not use)
50 const SSL_SESSION* getRawSSLSession() const {
51 return impl_->getRawSSLSession();
54 // Get raw SSL_SESSION pointer
55 // Warning: do not use unless you know what you're doing - caller needs to
56 // decrement refcount using SSL_SESSION_free or this will leak
57 SSL_SESSION* getRawSSLSessionDangerous() {
58 return impl_->getRawSSLSessionDangerous();
62 std::unique_ptr<detail::SSLSessionImpl> impl_;