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