Botan 2.19.5 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
14 namespace Botan {
15
16 class RandomNumberGenerator;
17
18 namespace 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*/
28 class BOTAN_PUBLIC_API(2,0) Session_Manager_SQL : public Session_Manager
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,
44 RandomNumberGenerator& rng,
45 size_t max_sessions = 1000,
46 std::chrono::seconds session_lifetime = std::chrono::seconds(7200));
47
48 Session_Manager_SQL(const Session_Manager_SQL&) = delete;
49
50 Session_Manager_SQL& operator=(const Session_Manager_SQL&) = delete;
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;
72 RandomNumberGenerator& m_rng;
73 size_t m_max_sessions;
74 std::chrono::seconds m_session_lifetime;
75 };
76
77}
78
79}
80
81#endif
Botan::RandomNumberGenerator
Definition: rng.h:26
Botan::TLS::Server_Information
Definition: tls_server_info.h:22
Botan::TLS::Session_Manager_SQL
Definition: tls_session_manager_sql.h:29
Botan::TLS::Session_Manager_SQL::operator=
Session_Manager_SQL & operator=(const Session_Manager_SQL &)=delete
Botan::TLS::Session_Manager_SQL::Session_Manager_SQL
Session_Manager_SQL(const Session_Manager_SQL &)=delete
Botan::TLS::Session_Manager_SQL::session_lifetime
std::chrono::seconds session_lifetime() const override
Definition: tls_session_manager_sql.h:64
Botan::TLS::Session_Manager
Definition: tls_session_manager.h:30
Botan::TLS::Session
Definition: tls_session.h:28
BOTAN_PUBLIC_API
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
Botan
Definition: alg_id.cpp:13
Botan::secure_vector
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:65