Botan 3.11.0
Crypto and TLS for C&
tls_server.h
Go to the documentation of this file.
1/*
2* TLS Server
3* (C) 2004-2011 Jack Lloyd
4* 2016 Matthias Gierlings
5* 2021 Elektrobit Automotive GmbH
6* 2022 René Meusel, Hannes Rantzsch - neXenio GmbH
7*
8* Botan is released under the Simplified BSD License (see license.txt)
9*/
10
11#ifndef BOTAN_TLS_SERVER_H_
12#define BOTAN_TLS_SERVER_H_
13
14#include <botan/credentials_manager.h>
15#include <botan/tls_callbacks.h> // TODO(Botan4) not necessary here, remove
16#include <botan/tls_channel.h>
17#include <botan/tls_policy.h> // TODO(Botan4) not necessary here, remove
18#include <vector>
19
20namespace Botan::TLS {
21
22class Callbacks;
23class Session_Manager;
24class Channel_Impl;
25class Policy;
26
27/**
28* TLS Server
29*/
30class BOTAN_PUBLIC_API(2, 0) Server final : public Channel {
31 public:
32 /**
33 * Server initialization
34 *
35 * The first 5 arguments as well as the final argument
36 * @p reserved_io_buffer_size, are treated similarly to the TLS::Client().
37 *
38 * If a client sends the ALPN extension, the
39 * TLS::Callbacks::tls_server_choose_app_protocol() will be called and the
40 * result sent back to the client. If the empty string is returned, the
41 * server will not send an ALPN response. The function can also throw an
42 * exception to abort the handshake entirely, the ALPN specification says
43 * that if this occurs the alert should be of type
44 * TLS::AlertType::NoApplicationProtocol.
45 *
46 * The optional argument @p is_datagram specifies if this is a TLS or DTLS
47 * server; unlike clients, which know what type of protocol (TLS vs DTLS)
48 * they are negotiating from the start via the @p offer_version, servers
49 * would not until they actually received a client hello.
50 *
51 * @param callbacks contains a set of callback function references required
52 * by the TLS server.
53 *
54 * @param session_manager manages session state
55 *
56 * @param creds manages application/user credentials
57 *
58 * @param policy specifies other connection policy information
59 *
60 * @param rng a random number generator
61 *
62 * @param is_datagram set to true if this server should expect DTLS
63 * connections. Otherwise TLS connections are expected.
64 *
65 * @param reserved_io_buffer_size This many bytes of memory will be
66 * preallocated for the read and write buffers. Smaller values just
67 * mean reallocations and copies are more likely.
68 */
69 Server(const std::shared_ptr<Callbacks>& callbacks,
70 const std::shared_ptr<Session_Manager>& session_manager,
71 const std::shared_ptr<Credentials_Manager>& creds,
72 const std::shared_ptr<const Policy>& policy,
73 const std::shared_ptr<RandomNumberGenerator>& rng,
74 bool is_datagram = false,
75 size_t reserved_io_buffer_size = TLS::Channel::IO_BUF_DEFAULT_SIZE);
76
77 ~Server() override;
78
79 /**
80 * Return the protocol notification set by the client (using the
81 * ALPN extension) for this connection, if any. This value is not
82 * tied to the session and a later renegotiation of the same
83 * session can choose a new protocol.
84 */
85 std::string application_protocol() const override;
86
87 size_t from_peer(std::span<const uint8_t> data) override;
88
89 bool is_handshake_complete() const override;
90
91 bool is_active() const override;
92
93 bool is_closed() const override;
94
95 bool is_closed_for_reading() const override;
96 bool is_closed_for_writing() const override;
97
98 std::vector<X509_Certificate> peer_cert_chain() const override;
99 std::shared_ptr<const Public_Key> peer_raw_public_key() const override;
100 std::optional<std::string> external_psk_identity() const override;
101
102 SymmetricKey key_material_export(std::string_view label, std::string_view context, size_t length) const override;
103
104 void renegotiate(bool force_full_renegotiation = false) override;
105
106 bool new_session_ticket_supported() const;
107 size_t send_new_session_tickets(size_t tickets = 1);
108
109 void update_traffic_keys(bool request_peer_update = false) override;
110
111 bool secure_renegotiation_supported() const override;
112
113 void to_peer(std::span<const uint8_t> data) override;
114
115 void send_alert(const Alert& alert) override;
116
117 void send_warning_alert(Alert::Type type) override;
118
119 void send_fatal_alert(Alert::Type type) override;
120
121 void close() override;
122
123 bool timeout_check() override;
124
125 Server(const Server& other) = delete;
126 Server(Server&& other) = default;
127 Server& operator=(const Server& other) = delete;
128 Server& operator=(Server&& other) = delete;
129
130 private:
131 std::unique_ptr<Channel_Impl> m_impl;
132};
133} // namespace Botan::TLS
134
135#endif
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:21
AlertType Type
Definition tls_alert.h:72
Channel(const Channel &other)=delete
static constexpr size_t IO_BUF_DEFAULT_SIZE
Definition tls_channel.h:37
void update_traffic_keys(bool request_peer_update=false) override
SymmetricKey key_material_export(std::string_view label, std::string_view context, size_t length) const override
~Server() override
bool timeout_check() override
void close() override
bool secure_renegotiation_supported() const override
void send_fatal_alert(Alert::Type type) override
bool is_closed() const override
Server(Server &&other)=default
bool is_closed_for_writing() const override
Server & operator=(const Server &other)=delete
std::string application_protocol() const override
size_t send_new_session_tickets(size_t tickets=1)
Server(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, bool is_datagram=false, size_t reserved_io_buffer_size=TLS::Channel::IO_BUF_DEFAULT_SIZE)
bool is_handshake_complete() const override
Server(const Server &other)=delete
void renegotiate(bool force_full_renegotiation=false) override
std::optional< std::string > external_psk_identity() const override
std::shared_ptr< const Public_Key > peer_raw_public_key() const override
void send_alert(const Alert &alert) override
void send_warning_alert(Alert::Type type) override
bool new_session_ticket_supported() const
std::vector< X509_Certificate > peer_cert_chain() const override
void to_peer(std::span< const uint8_t > data) override
Server & operator=(Server &&other)=delete
bool is_active() const override
size_t from_peer(std::span< const uint8_t > data) override
bool is_closed_for_reading() const override
OctetString SymmetricKey
Definition symkey.h:140