proxygen
folly::ssl::detail::SSLSessionImpl Class Reference

#include <SSLSessionImpl.h>

Public Member Functions

 SSLSessionImpl (SSL_SESSION *session, bool takeOwnership=true)
 
 SSLSessionImpl (const std::string &serializedSession)
 
virtual ~SSLSessionImpl ()
 
std::string serialize () const
 
std::string getSessionID () const
 
const SSL_SESSION * getRawSSLSession () const
 
SSL_SESSION * getRawSSLSessionDangerous ()
 

Private Member Functions

void upRef ()
 
void downRef ()
 

Private Attributes

SSL_SESSION * session_ {nullptr}
 

Detailed Description

Definition at line 29 of file SSLSessionImpl.h.

Constructor & Destructor Documentation

folly::ssl::detail::SSLSessionImpl::SSLSessionImpl ( SSL_SESSION *  session,
bool  takeOwnership = true 
)
explicit

Definition at line 29 of file SSLSessionImpl.cpp.

References session_, and upRef().

30  : session_(session) {
31  if (session_ == nullptr) {
32  throw std::runtime_error("SSL_SESSION is null");
33  }
34  // If we're not given ownership, we need to up the refcount so the SSL_SESSION
35  // object won't be freed while SSLSessionImpl is alive
36  if (!takeOwnership) {
37  upRef();
38  }
39 }
folly::ssl::detail::SSLSessionImpl::SSLSessionImpl ( const std::string serializedSession)
explicit

Definition at line 41 of file SSLSessionImpl.cpp.

References session_.

41  {
42  auto sessionData =
43  reinterpret_cast<const unsigned char*>(serializedSession.data());
44  auto longLen = long(serializedSession.length());
45  if ((session_ = d2i_SSL_SESSION(nullptr, &sessionData, longLen)) == nullptr) {
46  throw std::runtime_error("Cannot deserialize SSLSession string");
47  }
48 }
folly::ssl::detail::SSLSessionImpl::~SSLSessionImpl ( )
virtual

Definition at line 50 of file SSLSessionImpl.cpp.

References downRef().

50  {
51  downRef();
52 }

Member Function Documentation

void folly::ssl::detail::SSLSessionImpl::downRef ( )
private

Definition at line 99 of file SSLSessionImpl.cpp.

References session_.

Referenced by ~SSLSessionImpl().

99  {
100  if (session_) {
101  SSL_SESSION_free(session_);
102  }
103 }
const SSL_SESSION * folly::ssl::detail::SSLSessionImpl::getRawSSLSession ( ) const

Definition at line 84 of file SSLSessionImpl.cpp.

References session_.

84  {
85  return const_cast<SSL_SESSION*>(session_);
86 }
SSL_SESSION * folly::ssl::detail::SSLSessionImpl::getRawSSLSessionDangerous ( )

Definition at line 88 of file SSLSessionImpl.cpp.

References session_, and upRef().

88  {
89  upRef();
90  return session_;
91 }
std::string folly::ssl::detail::SSLSessionImpl::getSessionID ( ) const

Definition at line 73 of file SSLSessionImpl.cpp.

References ptr, session_, and string.

73  {
74  std::string ret;
75  if (session_) {
76  const unsigned char* ptr = nullptr;
77  unsigned int len = 0;
78  ptr = SSL_SESSION_get_id(session_, &len);
79  ret.assign(ptr, ptr + len);
80  }
81  return ret;
82 }
void * ptr
const char * string
Definition: Conv.cpp:212
std::string folly::ssl::detail::SSLSessionImpl::serialize ( ) const

Definition at line 54 of file SSLSessionImpl.cpp.

References session_, and string.

54  {
55  std::string ret;
56 
57  // Get the length first, then we know how much space to allocate.
58  auto len = i2d_SSL_SESSION(session_, nullptr);
59 
60  if (len > 0) {
61  std::unique_ptr<unsigned char[]> uptr(new unsigned char[size_t(len)]);
62  auto p = uptr.get();
63  auto written = i2d_SSL_SESSION(session_, &p);
64  if (written <= 0) {
65  VLOG(2) << "Could not serialize SSL_SESSION!";
66  } else {
67  ret.assign(uptr.get(), uptr.get() + written);
68  }
69  }
70  return ret;
71 }
const char * string
Definition: Conv.cpp:212
void folly::ssl::detail::SSLSessionImpl::upRef ( )
private

Definition at line 93 of file SSLSessionImpl.cpp.

References session_.

Referenced by getRawSSLSessionDangerous(), and SSLSessionImpl().

93  {
94  if (session_) {
95  SSL_SESSION_up_ref(session_);
96  }
97 }

Member Data Documentation

SSL_SESSION* folly::ssl::detail::SSLSessionImpl::session_ {nullptr}
private

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