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