Botan 3.14.1
Crypto and TLS for C&
tls_server_impl_12.h
Go to the documentation of this file.
1/*
2* TLS Server - implementation for TLS 1.2
3* (C) 2004-2011 Jack Lloyd
4* 2016 Matthias Gierlings
5*
6* Botan is released under the Simplified BSD License (see license.txt)
7*/
8
9#ifndef BOTAN_TLS_SERVER_IMPL_12_H_
10#define BOTAN_TLS_SERVER_IMPL_12_H_
11
12#include <botan/credentials_manager.h>
13#include <botan/internal/tls_channel_impl_12.h>
14#include <vector>
15
16namespace Botan::TLS {
17
18class Policy;
19class Server_Handshake_State;
20
21/**
22* SSL/TLS Server 1.2 implementation
23*/
24class Server_Impl_12 final : public Channel_Impl_12 {
25 public:
26 /**
27 * Server initialization
28 *
29 * @param callbacks contains a set of callback function references
30 * required by the TLS server.
31 *
32 * @param session_manager manages session state
33 *
34 * @param creds manages application/user credentials
35 *
36 * @param policy specifies other connection policy information
37 *
38 * @param rng a random number generator
39 *
40 * @param flavor specifies the TLS flavor (TLS or DTLS)
41 *
42 * @param reserved_io_buffer_size This many bytes of memory will
43 * be preallocated for the read and write buffers. Smaller
44 * values just mean reallocations and copies are more likely.
45 */
46 static std::shared_ptr<Server_Impl_12> create(const std::shared_ptr<Callbacks>& callbacks,
47 const std::shared_ptr<Session_Manager>& session_manager,
48 const std::shared_ptr<Credentials_Manager>& creds,
49 const std::shared_ptr<const Policy>& policy,
50 const std::shared_ptr<RandomNumberGenerator>& rng,
52 size_t reserved_io_buffer_size = TLS::Channel::IO_BUF_DEFAULT_SIZE);
53
54 Server_Impl_12([[maybe_unused]] Private dont_call_me,
55 const std::shared_ptr<Callbacks>& callbacks,
56 const std::shared_ptr<Session_Manager>& session_manager,
57 const std::shared_ptr<Credentials_Manager>& creds,
58 const std::shared_ptr<const Policy>& policy,
59 const std::shared_ptr<RandomNumberGenerator>& rng,
61 size_t reserved_io_buffer_size = TLS::Channel::IO_BUF_DEFAULT_SIZE) :
62 Channel_Impl_12(callbacks, session_manager, rng, policy, true, flavor, reserved_io_buffer_size),
63 m_creds(creds) {}
64
65#if defined(BOTAN_HAS_TLS_DOWNGRADE_SUPPORT)
66
67 static std::shared_ptr<Server_Impl_12> create_for_downgrade(
68 const Channel_Impl::Downgrade_Information& downgrade_info) {
69 return std::make_shared<Server_Impl_12>(Private{}, downgrade_info);
70 }
71
72 Server_Impl_12([[maybe_unused]] Private dont_call_me, const Channel_Impl::Downgrade_Information& downgrade_info) :
73 Channel_Impl_12(downgrade_info.callbacks,
74 downgrade_info.session_manager,
75 downgrade_info.rng,
76 downgrade_info.policy,
77 true /* is_server*/,
78 downgrade_info.flavor,
79 downgrade_info.io_buffer_size),
80 m_creds(downgrade_info.creds) {}
81
82#endif
83
84 private:
85 /**
86 * Return the protocol notification set by the client (using the
87 * ALPN extension) for this connection, if any. This value is not
88 * tied to the session and a later renegotiation of the same
89 * session can choose a new protocol.
90 */
91 std::string application_protocol() const override {
92 // A renegotiation in progress does not affect the active connection
93 if(active_state().has_value()) {
94 return active_state()->application_protocol();
95 }
96 return m_next_protocol;
97 }
98
99 std::string negotiated_application_protocol() const override { return m_next_protocol; }
100
101 void initiate_handshake(Handshake_State& state, bool force_full_renegotiation) override;
102
103 void process_handshake_msg(Handshake_State& pending_state,
104 Handshake_Type type,
105 const std::vector<uint8_t>& contents,
106 bool epoch0_restart) override;
107
108 void process_client_hello_msg(Server_Handshake_State& pending_state,
109 const std::vector<uint8_t>& contents,
110 bool epoch0_restart);
111
112 void process_certificate_msg(Server_Handshake_State& pending_state, const std::vector<uint8_t>& contents);
113
114 void process_client_key_exchange_msg(Server_Handshake_State& pending_state, const std::vector<uint8_t>& contents);
115
116 void process_change_cipher_spec_msg(Server_Handshake_State& pending_state);
117
118 void process_certificate_verify_msg(Server_Handshake_State& pending_state,
119 Handshake_Type type,
120 const std::vector<uint8_t>& contents);
121
122 void process_finished_msg(Server_Handshake_State& pending_state,
123 Handshake_Type type,
124 const std::vector<uint8_t>& contents);
125
126 void session_resume(Server_Handshake_State& pending_state,
127 const Session_with_Handle& session_info,
128 bool epoch0_restart);
129
130 void session_create(Server_Handshake_State& pending_state, bool epoch0_restart);
131
132 std::unique_ptr<Handshake_State> new_handshake_state(std::unique_ptr<Handshake_IO> io) override;
133
134 bool dtls_epoch0_restart_enabled() const override;
135
136 std::shared_ptr<Credentials_Manager> m_creds;
137 std::string m_next_protocol;
138};
139
140} // namespace Botan::TLS
141
142#endif
RandomNumberGenerator & rng()
virtual std::string negotiated_application_protocol() const =0
virtual bool dtls_epoch0_restart_enabled() const
Channel_Impl_12(const std::shared_ptr< Callbacks > &callbacks, const std::shared_ptr< Session_Manager > &session_manager, const std::shared_ptr< RandomNumberGenerator > &rng, const std::shared_ptr< const Policy > &policy, bool is_server, TLS_Flavor flavor, size_t io_buf_sz=TLS::Channel::IO_BUF_DEFAULT_SIZE)
Session_Manager & session_manager()
const Policy & policy() const
const std::optional< Active_Connection_State_12 > & active_state() const
virtual std::string application_protocol() const =0
static constexpr size_t IO_BUF_DEFAULT_SIZE
Definition tls_channel.h:38
static std::shared_ptr< Server_Impl_12 > create(const std::shared_ptr< Callbacks > &callbacks, const std::shared_ptr< Session_Manager > &session_manager, const std::shared_ptr< Credentials_Manager > &creds, const std::shared_ptr< const Policy > &policy, const std::shared_ptr< RandomNumberGenerator > &rng, TLS_Flavor flavor=TLS_Flavor::TLS, size_t reserved_io_buffer_size=TLS::Channel::IO_BUF_DEFAULT_SIZE)
Server_Impl_12(Private dont_call_me, const std::shared_ptr< Callbacks > &callbacks, const std::shared_ptr< Session_Manager > &session_manager, const std::shared_ptr< Credentials_Manager > &creds, const std::shared_ptr< const Policy > &policy, const std::shared_ptr< RandomNumberGenerator > &rng, TLS_Flavor flavor=TLS_Flavor::TLS, size_t reserved_io_buffer_size=TLS::Channel::IO_BUF_DEFAULT_SIZE)