Botan 3.11.0
Crypto and TLS for C&
tls_session_manager_memory.h
Go to the documentation of this file.
1/**
2 * TLS Session Manager in Memory
3 * (C) 2011 Jack Lloyd
4 * (C) 2023 René Meusel - Rohde & Schwarz Cybersecurity
5 *
6 * Botan is released under the Simplified BSD License (see license.txt)
7 */
8
9#ifndef BOTAN_TLS_SESSION_MANAGER_IN_MEMORY_H_
10#define BOTAN_TLS_SESSION_MANAGER_IN_MEMORY_H_
11
12#include <botan/tls_session.h>
13#include <botan/tls_session_manager.h>
14
15#include <deque>
16#include <map>
17
18namespace Botan {
19
21
22namespace TLS {
23
24/**
25 * A thread-safe Session_Manager that stores TLS sessions in memory.
26 *
27 * The Session_Handle objects emitted by this manager when establishing a new
28 * session (i.e in the TLS server) will never contain a Session_Ticket but only a
29 * Session_ID. Storing received sessions (i.e. in the TLS client) under either
30 * a Session_ID or a Session_Ticket will however echo them back.
31 *
32 * In other words, this manager _will_ support ticket-based resumption in a
33 * TLS client but it won't issue tickets on a TLS server.
34 *
35 * For applications that implement a TLS client and that do not want to persist
36 * sessions to non-volatile memory, this is typically a good default option.
37 */
39 public:
40 /**
41 * @param rng a RNG used for generating session key and for
42 * session encryption
43 * @param max_sessions a hint on the maximum number of sessions
44 * to keep in memory at any one time. (If zero, don't cap)
45 */
46 BOTAN_FUTURE_EXPLICIT Session_Manager_In_Memory(const std::shared_ptr<RandomNumberGenerator>& rng,
47 size_t max_sessions = 1000);
48
49 void store(const Session& session, const Session_Handle& handle) override;
50 size_t remove(const Session_Handle& handle) override;
51 size_t remove_all() override;
52
53 size_t capacity() const { return m_max_sessions; }
54
55 bool emits_session_tickets() override { return false; }
56
57 protected:
58 std::optional<Session> retrieve_one(const Session_Handle& handle) override;
59 std::vector<Session_with_Handle> find_some(const Server_Information& info, size_t max_sessions_hint) override;
60
61 private:
62 size_t remove_internal(const Session_Handle& handle);
63
64 private:
65 size_t m_max_sessions;
66
67 std::map<Session_ID, Session_with_Handle> m_sessions;
68 std::optional<std::deque<Session_ID>> m_fifo;
69};
70
71} // namespace TLS
72
73} // namespace Botan
74
75#endif
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:21
#define BOTAN_FUTURE_EXPLICIT
Definition api.h:52
Helper class to embody a session handle in all protocol versions.
void store(const Session &session, const Session_Handle &handle) override
Save a Session under a Session_Handle (TLS Client).
BOTAN_FUTURE_EXPLICIT Session_Manager_In_Memory(const std::shared_ptr< RandomNumberGenerator > &rng, size_t max_sessions=1000)
size_t remove(const Session_Handle &handle) override
BOTAN_FUTURE_EXPLICIT Session_Manager(const std::shared_ptr< RandomNumberGenerator > &rng)