|
Botan
1.11.15
|
#include <tls_session_manager.h>
Public Member Functions | |
| bool | load_from_server_info (const Server_Information &info, Session &session) override |
| bool | load_from_session_id (const std::vector< byte > &session_id, Session &session) override |
| void | remove_entry (const std::vector< byte > &session_id) override |
| void | save (const Session &session_data) override |
| std::chrono::seconds | session_lifetime () const override |
| Session_Manager_In_Memory (RandomNumberGenerator &rng, size_t max_sessions=1000, std::chrono::seconds session_lifetime=std::chrono::seconds(7200)) | |
An implementation of Session_Manager that saves values in memory.
Definition at line 101 of file tls_session_manager.h.
| Botan::TLS::Session_Manager_In_Memory::Session_Manager_In_Memory | ( | RandomNumberGenerator & | rng, |
| size_t | max_sessions = 1000, |
||
| std::chrono::seconds | session_lifetime = std::chrono::seconds(7200) |
||
| ) |
| max_sessions | a hint on the maximum number of sessions to keep in memory at any one time. (If zero, don't cap) |
| session_lifetime | sessions are expired after this many seconds have elapsed from initial handshake. |
Definition at line 16 of file tls_session_manager_memory.cpp.
: m_max_sessions(max_sessions), m_session_lifetime(session_lifetime), m_rng(rng), m_session_key(m_rng, 32) {}
| bool Botan::TLS::Session_Manager_In_Memory::load_from_server_info | ( | const Server_Information & | info, |
| Session & | session | ||
| ) | [override, virtual] |
Try to load a saved session (using info about server)
| info | the information about the server |
| session | will be set to the saved session data (if found), or not modified if not found |
Implements Botan::TLS::Session_Manager.
Definition at line 65 of file tls_session_manager_memory.cpp.
{
std::lock_guard<std::mutex> lock(m_mutex);
auto i = m_info_sessions.find(info);
if(i == m_info_sessions.end())
return false;
if(load_from_session_str(i->second, session))
return true;
/*
* It existed at one point but was removed from the sessions map,
* remove m_info_sessions entry as well
*/
m_info_sessions.erase(i);
return false;
}
| bool Botan::TLS::Session_Manager_In_Memory::load_from_session_id | ( | const std::vector< byte > & | session_id, |
| Session & | session | ||
| ) | [override, virtual] |
Try to load a saved session (using session ID)
| session_id | the session identifier we are trying to resume |
| session | will be set to the saved session data (if found), or not modified if not found |
Implements Botan::TLS::Session_Manager.
Definition at line 57 of file tls_session_manager_memory.cpp.
References Botan::hex_encode().
{
std::lock_guard<std::mutex> lock(m_mutex);
return load_from_session_str(hex_encode(session_id), session);
}
| void Botan::TLS::Session_Manager_In_Memory::remove_entry | ( | const std::vector< byte > & | session_id | ) | [override, virtual] |
Remove this session id from the cache, if it exists
Implements Botan::TLS::Session_Manager.
Definition at line 87 of file tls_session_manager_memory.cpp.
References Botan::hex_encode().
{
std::lock_guard<std::mutex> lock(m_mutex);
auto i = m_sessions.find(hex_encode(session_id));
if(i != m_sessions.end())
m_sessions.erase(i);
}
| void Botan::TLS::Session_Manager_In_Memory::save | ( | const Session & | session | ) | [override, virtual] |
Save a session on a best effort basis; the manager may not in fact be able to save the session for whatever reason; this is not an error. Caller cannot assume that calling save followed immediately by load_from_* will result in a successful lookup.
| session | to save |
Implements Botan::TLS::Session_Manager.
Definition at line 98 of file tls_session_manager_memory.cpp.
References Botan::TLS::CLIENT, Botan::TLS::Server_Information::empty(), Botan::TLS::Session::encrypt(), Botan::hex_encode(), Botan::TLS::Session::server_info(), Botan::TLS::Session::session_id(), and Botan::TLS::Session::side().
{
std::lock_guard<std::mutex> lock(m_mutex);
if(m_max_sessions != 0)
{
/*
We generate new session IDs with the first 4 bytes being a
timestamp, so this actually removes the oldest sessions first.
*/
while(m_sessions.size() >= m_max_sessions)
m_sessions.erase(m_sessions.begin());
}
const std::string session_id_str = hex_encode(session.session_id());
m_sessions[session_id_str] = session.encrypt(m_session_key, m_rng);
if(session.side() == CLIENT && !session.server_info().empty())
m_info_sessions[session.server_info()] = session_id_str;
}
| std::chrono::seconds Botan::TLS::Session_Manager_In_Memory::session_lifetime | ( | ) | const [inline, override, virtual] |
Return the allowed lifetime of a session; beyond this time, sessions are not resumed. Returns 0 if unknown/no explicit expiration policy.
Implements Botan::TLS::Session_Manager.
Definition at line 125 of file tls_session_manager.h.
{ return m_session_lifetime; }
1.7.6.1