diff options
author | lloyd <[email protected]> | 2011-12-30 20:35:27 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2011-12-30 20:35:27 +0000 |
commit | 2920f1be500d53414b863ec61ca9c2008336479f (patch) | |
tree | fb2dd5c855016521c69d2b1885a7f081e7d3ea8f /src/tls/tls_session_manager.cpp | |
parent | deb92d7f6d43206c04f332625d6b1e1a2abc444d (diff) |
Rename the session type to 'TLS_Session'. Split the manager out into
its own file. Rename tls_state to tls_handshake_state.
Diffstat (limited to 'src/tls/tls_session_manager.cpp')
-rw-r--r-- | src/tls/tls_session_manager.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/tls/tls_session_manager.cpp b/src/tls/tls_session_manager.cpp new file mode 100644 index 000000000..05a092426 --- /dev/null +++ b/src/tls/tls_session_manager.cpp @@ -0,0 +1,66 @@ +/* +* TLS Session Management +* (C) 2011 Jack Lloyd +* +* Released under the terms of the Botan license +*/ + +#include <botan/tls_session_manager.h> +#include <botan/hex.h> +#include <botan/time.h> + +namespace Botan { + +bool TLS_Session_Manager_In_Memory::find(const MemoryVector<byte>& session_id, + TLS_Session& params) + { + std::map<std::string, TLS_Session>::iterator i = + sessions.find(hex_encode(session_id)); + + if(i == sessions.end()) + return false; + + // session has expired, remove it + const u64bit now = system_time(); + if(i->second.start_time() + session_lifetime >= now) + { + sessions.erase(i); + return false; + } + + params = i->second; + return true; + } + +bool TLS_Session_Manager_In_Memory::find(const std::string& hostname, u16bit port, + TLS_Session& params) + { + return false; + } + +void TLS_Session_Manager_In_Memory::prohibit_resumption( + const MemoryVector<byte>& session_id) + { + std::map<std::string, TLS_Session>::iterator i = + sessions.find(hex_encode(session_id)); + + if(i != sessions.end()) + sessions.erase(i); + } + +void TLS_Session_Manager_In_Memory::save(const TLS_Session& session_data) + { + if(max_sessions != 0) + { + /* + This removes randomly based on ordering of session ids. + Instead, remove oldest first? + */ + while(sessions.size() >= max_sessions) + sessions.erase(sessions.begin()); + } + + sessions[hex_encode(session_data.session_id())] = session_data; + } + +} |