Botan 2.19.3
Crypto and TLS for C&
tls_session_manager_sql.h
Go to the documentation of this file.
1/*
2* TLS Session Manager storing to encrypted SQL db table
3* (C) 2012,2014 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#ifndef BOTAN_TLS_SQL_SESSION_MANAGER_H_
9#define BOTAN_TLS_SQL_SESSION_MANAGER_H_
10
11#include <botan/tls_session_manager.h>
12#include <botan/database.h>
13
14namespace Botan {
15
16class RandomNumberGenerator;
17
18namespace TLS {
19
20/**
21* An implementation of Session_Manager that saves values in a SQL
22* database file, with the session data encrypted using a passphrase.
23*
24* @warning For clients, the hostnames associated with the saved
25* sessions are stored in the database in plaintext. This may be a
26* serious privacy risk in some situations.
27*/
29 {
30 public:
31 /**
32 * @param db A connection to the database to use
33 The table names botan_tls_sessions and
34 botan_tls_sessions_metadata will be used
35 * @param passphrase used to encrypt the session data
36 * @param rng a random number generator
37 * @param max_sessions a hint on the maximum number of sessions
38 * to keep in memory at any one time. (If zero, don't cap)
39 * @param session_lifetime sessions are expired after this many
40 * seconds have elapsed from initial handshake.
41 */
42 Session_Manager_SQL(std::shared_ptr<SQL_Database> db,
43 const std::string& passphrase,
45 size_t max_sessions = 1000,
46 std::chrono::seconds session_lifetime = std::chrono::seconds(7200));
47
49
51
52 bool load_from_session_id(const std::vector<uint8_t>& session_id,
53 Session& session) override;
54
55 bool load_from_server_info(const Server_Information& info,
56 Session& session) override;
57
58 void remove_entry(const std::vector<uint8_t>& session_id) override;
59
60 size_t remove_all() override;
61
62 void save(const Session& session_data) override;
63
64 std::chrono::seconds session_lifetime() const override
65 { return m_session_lifetime; }
66
67 private:
68 void prune_session_cache();
69
70 std::shared_ptr<SQL_Database> m_db;
71 secure_vector<uint8_t> m_session_key;
73 size_t m_max_sessions;
74 std::chrono::seconds m_session_lifetime;
75 };
76
77}
78
79}
80
81#endif
Session_Manager_SQL & operator=(const Session_Manager_SQL &)=delete
Session_Manager_SQL(const Session_Manager_SQL &)=delete
std::chrono::seconds session_lifetime() const override
#define BOTAN_PUBLIC_API(maj, min)
Definition compiler.h:31
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:65