Botan 3.6.1
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/mutex.h>
13#include <botan/tls_session.h>
14#include <botan/tls_session_manager.h>
15
16#include <deque>
17#include <map>
18
19namespace Botan {
20
21class RandomNumberGenerator;
22
23namespace TLS {
24
25/**
26 * A thread-safe Session_Manager that stores TLS sessions in memory.
27 *
28 * The Session_Handle objects emitted by this manager when establishing a new
29 * session (i.e in the TLS server) will never contain a Session_Ticket but only a
30 * Session_ID. Storing received sessions (i.e. in the TLS client) under either
31 * a Session_ID or a Session_Ticket will however echo them back.
32 *
33 * In other words, this manager _will_ support ticket-based resumption in a
34 * TLS client but it won't issue tickets on a TLS server.
35 *
36 * For applications that implement a TLS client and that do not want to persist
37 * sessions to non-volatile memory, this is typically a good default option.
38 */
40 public:
41 /**
42 * @param rng a RNG used for generating session key and for
43 * session encryption
44 * @param max_sessions a hint on the maximum number of sessions
45 * to keep in memory at any one time. (If zero, don't cap)
46 */
47 Session_Manager_In_Memory(const std::shared_ptr<RandomNumberGenerator>& rng, 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
Helper class to embody a session handle in all protocol versions.
Definition tls_session.h:64
#define BOTAN_PUBLIC_API(maj, min)
Definition compiler.h:31