Botan 3.9.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/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
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 BOTAN_FUTURE_EXPLICIT Session_Manager_In_Memory(const std::shared_ptr<RandomNumberGenerator>& rng,
48 size_t max_sessions = 1000);
49
50 void store(const Session& session, const Session_Handle& handle) override;
51 size_t remove(const Session_Handle& handle) override;
52 size_t remove_all() override;
53
54 size_t capacity() const { return m_max_sessions; }
55
56 bool emits_session_tickets() override { return false; }
57
58 protected:
59 std::optional<Session> retrieve_one(const Session_Handle& handle) override;
60 std::vector<Session_with_Handle> find_some(const Server_Information& info, size_t max_sessions_hint) override;
61
62 private:
63 size_t remove_internal(const Session_Handle& handle);
64
65 private:
66 size_t m_max_sessions;
67
68 std::map<Session_ID, Session_with_Handle> m_sessions;
69 std::optional<std::deque<Session_ID>> m_fifo;
70};
71
72} // namespace TLS
73
74} // namespace Botan
75
76#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.
Definition tls_session.h:63
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)