blob: 05a09242604ce8f56eac0091582c408310e57821 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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;
}
}
|