Botan 3.6.1
Crypto and TLS for C&
|
#include <tls_session_manager.h>
Public Member Functions | |
virtual std::optional< std::pair< Session, uint16_t > > | choose_from_offered_tickets (const std::vector< PskIdentity > &tickets, std::string_view hash_function, Callbacks &callbacks, const Policy &policy) |
virtual bool | emits_session_tickets () |
virtual std::optional< Session_Handle > | establish (const Session &session, const std::optional< Session_ID > &id=std::nullopt, bool tls12_no_ticket=false) |
Save a new Session and assign a Session_Handle (TLS Server) | |
virtual std::vector< Session_with_Handle > | find (const Server_Information &info, Callbacks &callbacks, const Policy &policy) |
Find all sessions that match a given server info . | |
virtual size_t | remove (const Session_Handle &handle)=0 |
virtual size_t | remove_all ()=0 |
virtual std::optional< Session > | retrieve (const Session_Handle &handle, Callbacks &callbacks, const Policy &policy) |
Retrieves a specific session given a handle . | |
Session_Manager (const std::shared_ptr< RandomNumberGenerator > &rng) | |
virtual void | store (const Session &session, const Session_Handle &handle)=0 |
Save a Session under a Session_Handle (TLS Client) | |
virtual | ~Session_Manager ()=default |
Protected Member Functions | |
virtual std::vector< Session_with_Handle > | find_some (const Server_Information &info, size_t max_sessions_hint)=0 |
Internal retrieval function to find sessions to resume. | |
recursive_mutex_type & | mutex () |
virtual std::optional< Session > | retrieve_one (const Session_Handle &handle)=0 |
Internal retrieval function for a single session. | |
Protected Attributes | |
std::shared_ptr< RandomNumberGenerator > | m_rng |
Session_Manager is an interface to systems which can save session parameters for supporting session resumption.
Saving sessions is done on a best-effort basis; an implementation is allowed to drop sessions due to space constraints or other issues.
Implementations should strive to be thread safe. This base class provides a recursive mutex (via Session_Manager::mutex()). Derived classes may simply reuse this for their own locking.
Definition at line 45 of file tls_session_manager.h.
Botan::TLS::Session_Manager::Session_Manager | ( | const std::shared_ptr< RandomNumberGenerator > & | rng | ) |
Definition at line 17 of file tls_session_manager.cpp.
References BOTAN_ASSERT_NONNULL, and m_rng.
|
virtualdefault |
|
virtual |
Lets the server application choose a PSK to use for a new TLS connection. Implementers must make sure that the PSK's associated hash function is equal to the passed hash_function
.
RFC 8446 4.2.11 The server MUST ensure that it selects a compatible PSK (if any) and cipher suite.
The default implementation simply tries to retrieve all tickets in the order offered by the peer and picks the first that is found and features a matching hash algorithm.
This method is called only by TLS 1.3 servers.
tickets | a list of tickets that were offered by the client |
hash_function | the hash algorithm name we are going to use for the to-be-negotiated connection |
callbacks | callbacks to be used for session policy decisions |
policy | policy to be used for session policy decisions |
Definition at line 206 of file tls_session_manager.cpp.
Referenced by Botan::TLS::PSK::select_offered_psk().
|
inlinevirtual |
Declares whether the given Session_Manager implementation may emit session tickets. Note that this does not mean that the implementation must always emit tickets.
Concrete implementations should declare this, to allow the TLS implementations to act accordingly. E.g. to advertise support for session tickets in their Server Hello.
Reimplemented in Botan::TLS::Session_Manager_Hybrid, Botan::TLS::Session_Manager_In_Memory, Botan::TLS::Session_Manager_SQL, and Botan::TLS::Session_Manager_Stateless.
Definition at line 214 of file tls_session_manager.h.
|
virtual |
Save a new Session and assign a Session_Handle (TLS Server)
Save a new session on a best effort basis; the manager may not in fact be able to save the session for whatever reason; this is not an error. Callers cannot assume that calling establish() followed immediately by retrieve() or choose_from_offered_tickets() will result in a successful lookup. In case no session was stored, std::nullopt is returned.
This method is only called on TLS servers.
Note that implementations will silently refrain from sending session tickets to the client when this method returns std::nullopt.
session | to save |
id | to use (instead of an ID chosen by the manager) |
tls12_no_ticket | disable tickets for this establishment (set when TLS 1.2 client does not support them) |
Reimplemented in Botan::TLS::Session_Manager_Hybrid, Botan::TLS::Session_Manager_Noop, and Botan::TLS::Session_Manager_Stateless.
Definition at line 21 of file tls_session_manager.cpp.
References BOTAN_ASSERT, BOTAN_UNUSED, m_rng, Botan::TLS::Server, Botan::TLS::Session_Base::side(), and store().
|
virtual |
Find all sessions that match a given server info
.
TLS clients use this to obtain session resumption information for a server they are wishing to handshake with. Typically, session info will have been received in prior connections to that same server and stored using Session_Manager::store().
The default implementation will invoke Session_Manager::find_some() and filter the result against a policy. Most notably an expiry check. Expired sessions will be removed via Session_Manager::remove().
The TLS client implementations will query the session manager exactly once per handshake attempt. If no reuse is desired, the session manager may remove the sessions internally when handing them out to the client. The default implementation adheres to Policy::reuse_session_tickets().
For TLS 1.2 the client implementation will attempt a resumption with the first session in the returned list. For TLS 1.3, it will offer all found sessions to the server.
Applications that wish to implement their own Session_Manager may override the default implementation to add further policy checks. Though, typically implementing Session_Manager::find_some() and relying on the default implementation is enough.
info | the info about the server we want to handshake with |
callbacks | callbacks to be used for session policy decisions |
policy | policy to be used for session policy decisions |
Reimplemented in Botan::TLS::Session_Manager_Hybrid.
Definition at line 161 of file tls_session_manager.cpp.
References BOTAN_ASSERT_NOMSG, Botan::TLS::Policy::maximum_session_tickets_per_client_hello(), and Botan::TLS::Policy::reuse_session_tickets().
|
protectedpure virtual |
Internal retrieval function to find sessions to resume.
Try to find saved sessions using info about the server we're planning to connect to. It should return a list of sessions in preference order of the session manager.
Applications that wish to implement their own Session_Manager will have to provide an implementation for it.
Note that the TLS client implementations do not perform any checks on the validity of the session for a given info
. Particularly, it is the Session_Manager's responsibility to ensure the restrictions posed in RFC 8446 4.6.1 regarding server certificate validity for the given info
.
This is called for TLS clients only.
info | the information about the server |
max_sessions_hint | a non-binding guideline for an upper bound of sessions to return from this method (will be at least 1 but potentially more) |
Implemented in Botan::TLS::Session_Manager_Hybrid, Botan::TLS::Session_Manager_In_Memory, Botan::TLS::Session_Manager_Noop, Botan::TLS::Session_Manager_SQL, and Botan::TLS::Session_Manager_Stateless.
|
inlineprotected |
Returns the base class' recursive mutex for reuse in derived classes
Definition at line 267 of file tls_session_manager.h.
Referenced by Botan::TLS::Session_Manager_In_Memory::find_some(), Botan::TLS::Session_Manager_SQL::find_some(), Botan::TLS::Session_Manager_In_Memory::remove(), Botan::TLS::Session_Manager_SQL::remove(), Botan::TLS::Session_Manager_In_Memory::remove_all(), Botan::TLS::Session_Manager_SQL::remove_all(), Botan::TLS::Session_Manager_In_Memory::retrieve_one(), Botan::TLS::Session_Manager_SQL::retrieve_one(), Botan::TLS::Session_Manager_In_Memory::store(), and Botan::TLS::Session_Manager_SQL::store().
|
pure virtual |
Remove a specific session from the cache, if it exists. The handle might contain either a session ID or a ticket.
handle | a Session_Handle of the session to be removed |
Implemented in Botan::TLS::Session_Manager_Hybrid, Botan::TLS::Session_Manager_In_Memory, Botan::TLS::Session_Manager_Noop, Botan::TLS::Session_Manager_SQL, and Botan::TLS::Session_Manager_Stateless.
Referenced by retrieve(), and Botan::TLS::Channel_Impl_12::send_alert().
|
pure virtual |
Remove all sessions from the cache
Implemented in Botan::TLS::Session_Manager_Hybrid, Botan::TLS::Session_Manager_In_Memory, Botan::TLS::Session_Manager_Noop, Botan::TLS::Session_Manager_SQL, and Botan::TLS::Session_Manager_Stateless.
|
virtual |
Retrieves a specific session given a handle
.
This is typically used by TLS servers to obtain resumption information for a previous call to Session_Manager::establish() when a client requested resumption using the handle
.
Even if the session is found successfully, it is returned only if it passes policy validations. Most notably an expiry check. If the expiry check fails, the default implementation calls Session_Manager::remove() for the provided handle
.
Applications that wish to implement their own Session_Manager may override the default implementation to add further policy checks. Though, typically implementing Session_Manager::retrieve_one() and relying on the default implementation is enough.
handle | the Session_Handle to be retrieved |
callbacks | callbacks to be used for session policy decisions |
policy | policy to be used for session policy decisions |
Reimplemented in Botan::TLS::Session_Manager_Hybrid.
Definition at line 36 of file tls_session_manager.cpp.
References remove(), retrieve_one(), Botan::TLS::Policy::session_ticket_lifetime(), and Botan::TLS::Callbacks::tls_current_timestamp().
|
protectedpure virtual |
Internal retrieval function for a single session.
Try to obtain a Session from a Session_Handle that contains either a session ID or a session ticket. This method should not apply any policy decision (such as ticket expiry) but simply be a storage interface.
Applications that wish to implement their own Session_Manager will have to provide an implementation for it.
This method is called only by servers.
handle | a Session_Handle containing either an ID or a ticket |
Implemented in Botan::TLS::Session_Manager_Hybrid, Botan::TLS::Session_Manager_In_Memory, Botan::TLS::Session_Manager_Noop, Botan::TLS::Session_Manager_SQL, and Botan::TLS::Session_Manager_Stateless.
Referenced by retrieve().
|
pure virtual |
Save a Session under a Session_Handle (TLS Client)
Save a session on a best effort basis; the manager may not in fact be able to save the session for whatever reason; this is not an error. Callers cannot assume that calling store() followed immediately by find() will result in a successful lookup.
In contrast to establish(), this stores sessions that were created by the server along with a Session_Handle also coined by the server.
This method is only called on TLS clients.
session | to save |
handle | a Session_Handle on which this session shoud by stored |
Implemented in Botan::TLS::Session_Manager_Hybrid, Botan::TLS::Session_Manager_In_Memory, Botan::TLS::Session_Manager_Noop, Botan::TLS::Session_Manager_SQL, and Botan::TLS::Session_Manager_Stateless.
Referenced by establish().
|
protected |
Definition at line 275 of file tls_session_manager.h.
Referenced by establish(), Botan::TLS::Session_Manager_Stateless::establish(), Session_Manager(), Botan::TLS::Session_Manager_In_Memory::store(), and Botan::TLS::Session_Manager_SQL::store().