Botan 3.10.0
Crypto and TLS for C&
tls_server.cpp
Go to the documentation of this file.
1/*
2* TLS Server
3* (C) 2004-2011,2012,2016 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#include <botan/tls_server.h>
12
13#include <botan/tls_messages.h>
14#include <botan/internal/tls_handshake_state.h>
15
16#include <botan/internal/tls_server_impl_12.h>
17#if defined(BOTAN_HAS_TLS_13)
18 #include <botan/internal/tls_server_impl_13.h>
19#endif
20
21namespace Botan::TLS {
22
23/*
24* TLS Server Constructor
25*/
26Server::Server(const std::shared_ptr<Callbacks>& callbacks,
27 const std::shared_ptr<Session_Manager>& session_manager,
28 const std::shared_ptr<Credentials_Manager>& creds,
29 const std::shared_ptr<const Policy>& policy,
30 const std::shared_ptr<RandomNumberGenerator>& rng,
31 bool is_datagram,
32 size_t io_buf_sz) {
33 const auto max_version = policy->latest_supported_version(is_datagram);
34
35 if(!max_version.is_pre_tls_13()) {
36#if defined(BOTAN_HAS_TLS_13)
37 m_impl = std::make_unique<Server_Impl_13>(callbacks, session_manager, creds, policy, rng);
38
39 if(m_impl->expects_downgrade()) {
40 m_impl->set_io_buffer_size(io_buf_sz);
41 }
42#else
43 throw Not_Implemented("TLS 1.3 server is not available in this build");
44#endif
45 } else {
46 m_impl = std::make_unique<Server_Impl_12>(callbacks, session_manager, creds, policy, rng, is_datagram, io_buf_sz);
47 }
48}
49
50Server::~Server() = default;
51
52size_t Server::from_peer(std::span<const uint8_t> data) {
53 auto read = m_impl->from_peer(data);
54
55 if(m_impl->is_downgrading()) {
56 auto info = m_impl->extract_downgrade_info();
57 m_impl = std::make_unique<Server_Impl_12>(*info);
58
59 // replay peer data received so far
60 read = m_impl->from_peer(info->peer_transcript);
61 }
62
63 return read;
64}
65
67 return m_impl->is_handshake_complete();
68}
69
70bool Server::is_active() const {
71 return m_impl->is_active();
72}
73
74bool Server::is_closed() const {
75 return m_impl->is_closed();
76}
77
79 return m_impl->is_closed_for_reading();
80}
81
83 return m_impl->is_closed_for_writing();
84}
85
86std::vector<X509_Certificate> Server::peer_cert_chain() const {
87 return m_impl->peer_cert_chain();
88}
89
90std::shared_ptr<const Public_Key> Server::peer_raw_public_key() const {
91 return m_impl->peer_raw_public_key();
92}
93
94std::optional<std::string> Server::external_psk_identity() const {
95 return m_impl->external_psk_identity();
96}
97
98SymmetricKey Server::key_material_export(std::string_view label, std::string_view context, size_t length) const {
99 return m_impl->key_material_export(label, context, length);
100}
101
102void Server::renegotiate(bool force_full_renegotiation) {
103 m_impl->renegotiate(force_full_renegotiation);
104}
105
107 return m_impl->new_session_ticket_supported();
108}
109
110size_t Server::send_new_session_tickets(const size_t tickets) {
111 return m_impl->send_new_session_tickets(tickets);
112}
113
114void Server::update_traffic_keys(bool request_peer_update) {
115 m_impl->update_traffic_keys(request_peer_update);
116}
117
119 return m_impl->secure_renegotiation_supported();
120}
121
122void Server::to_peer(std::span<const uint8_t> data) {
123 m_impl->to_peer(data);
124}
125
126void Server::send_alert(const Alert& alert) {
127 m_impl->send_alert(alert);
128}
129
131 m_impl->send_warning_alert(type);
132}
133
135 m_impl->send_fatal_alert(type);
136}
137
139 m_impl->close();
140}
141
143 return m_impl->timeout_check();
144}
145
146std::string Server::application_protocol() const {
147 return m_impl->application_protocol();
148}
149} // namespace Botan::TLS
AlertType Type
Definition tls_alert.h:71
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
bool is_closed_for_writing() const override
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
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
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