Botan 3.14.1
Crypto and TLS for C&
msg_server_hello_12.cpp
Go to the documentation of this file.
1/*
2* TLS Server Hello and Server Hello Done
3* (C) 2004-2011,2015,2016,2019 Jack Lloyd
4* 2016 Matthias Gierlings
5* 2017 Harry Reimann, Rohde & Schwarz Cybersecurity
6*
7* Botan is released under the Simplified BSD License (see license.txt)
8*/
9
10#include <botan/tls_messages_12.h>
11
12#include <botan/tls_callbacks.h>
13#include <botan/tls_extensions_12.h>
14#include <botan/tls_policy.h>
15#include <botan/internal/stl_util.h>
16#include <botan/internal/tls_handshake_hash.h>
17#include <botan/internal/tls_handshake_io.h>
18#include <botan/internal/tls_messages_internal.h>
19
20namespace Botan::TLS {
21
22// New session case
24 Handshake_Hash& hash,
25 const Policy& policy,
26 Callbacks& cb,
28 std::vector<uint8_t> reneg_info,
29 const Client_Hello_12& client_hello,
30 const Server_Hello_12::Settings& server_settings,
31 std::string_view next_protocol,
32 TLS_Flavor flavor) :
33 Server_Hello_12(std::make_unique<Server_Hello_Internal>(
34 server_settings.protocol_version(),
35 server_settings.session_id(),
36 make_server_hello_random(rng, server_settings.protocol_version(), cb, policy, flavor),
37 server_settings.ciphersuite(),
38 uint8_t(0))) {
39 // NOLINTBEGIN(*-owning-memory)
40 if(client_hello.supports_extended_master_secret()) {
41 m_data->extensions().add(new Extended_Master_Secret);
42 }
43
44 // Sending the extension back does not commit us to sending a stapled response
45 if(client_hello.supports_cert_status_message() && policy.support_cert_status_message()) {
46 m_data->extensions().add(new Certificate_Status_Request);
47 }
48
49 if(!next_protocol.empty() && client_hello.supports_alpn()) {
50 m_data->extensions().add(new Application_Layer_Protocol_Notification(next_protocol));
51 }
52
53 const auto c = Ciphersuite::by_id(m_data->ciphersuite());
54
55 if(c && c->cbc_ciphersuite() && client_hello.supports_encrypt_then_mac() && policy.negotiate_encrypt_then_mac()) {
56 m_data->extensions().add(new Encrypt_then_MAC);
57 }
58
59 if(c && c->ecc_ciphersuite() && client_hello.extension_types().contains(Extension_Code::EcPointFormats)) {
60 m_data->extensions().add(new Supported_Point_Formats(policy.use_ecc_point_compression()));
61 }
62
63 if(client_hello.secure_renegotiation()) {
64 m_data->extensions().add(new Renegotiation_Extension(std::move(reneg_info)));
65 }
66
67 if(client_hello.supports_session_ticket() && server_settings.offer_session_ticket()) {
68 m_data->extensions().add(new Session_Ticket_Extension());
69 }
70
71 if(m_data->legacy_version().is_datagram_protocol()) {
72 const std::vector<uint16_t> server_srtp = policy.srtp_profiles();
73 const std::vector<uint16_t> client_srtp = client_hello.srtp_profiles();
74
75 if(!server_srtp.empty() && !client_srtp.empty()) {
76 uint16_t shared = 0;
77 // always using server preferences for now
78 for(const auto s_srtp : server_srtp) {
79 for(const auto c_srtp : client_srtp) {
80 if(shared == 0 && s_srtp == c_srtp) {
81 shared = s_srtp;
82 }
83 }
84 }
85
86 if(shared != 0) {
87 m_data->extensions().add(new SRTP_Protection_Profiles(shared));
88 }
89 }
90 }
91 // NOLINTEND(*-owning-memory)
92
93 cb.tls_modify_extensions(m_data->extensions(), Connection_Side::Server, type());
94
95 hash.update(io.send(*this));
96}
97
98// Resuming
100 Handshake_Hash& hash,
101 const Policy& policy,
102 Callbacks& cb,
104 std::vector<uint8_t> reneg_info,
105 const Client_Hello_12& client_hello,
106 const Session& resumed_session,
107 bool offer_session_ticket,
108 std::string_view next_protocol,
109 TLS_Flavor flavor) :
110 Server_Hello_12(std::make_unique<Server_Hello_Internal>(
111 resumed_session.version(),
112 client_hello.session_id(),
113 make_server_hello_random(rng, resumed_session.version(), cb, policy, flavor),
114 resumed_session.ciphersuite_code(),
115 uint8_t(0))) {
116 // NOLINTBEGIN(*-owning-memory)
117 if(client_hello.supports_extended_master_secret()) {
118 m_data->extensions().add(new Extended_Master_Secret);
119 }
120
121 if(!next_protocol.empty() && client_hello.supports_alpn()) {
122 m_data->extensions().add(new Application_Layer_Protocol_Notification(next_protocol));
123 }
124
125 // RFC 7366 3.1
126 // Implementations SHOULD retain the current session state across all
127 // rehandshakes for that session.
128 //
129 // The client's offer was checked against the session in check_for_resume
130 if(resumed_session.supports_encrypt_then_mac() && client_hello.supports_encrypt_then_mac() &&
131 resumed_session.ciphersuite().cbc_ciphersuite()) {
132 m_data->extensions().add(new Encrypt_then_MAC);
133 }
134
135 if(resumed_session.ciphersuite().ecc_ciphersuite() &&
136 client_hello.extension_types().contains(Extension_Code::EcPointFormats)) {
137 m_data->extensions().add(new Supported_Point_Formats(policy.use_ecc_point_compression()));
138 }
139
140 if(client_hello.secure_renegotiation()) {
141 m_data->extensions().add(new Renegotiation_Extension(std::move(reneg_info)));
142 }
143
144 if(client_hello.supports_session_ticket() && offer_session_ticket) {
145 m_data->extensions().add(new Session_Ticket_Extension());
146 }
147
148 // Echo the SRTP profile from the resumed session when the client re-offers
149 // it, so the abbreviated handshake keeps DTLS-SRTP keying (RFC 5764).
150 if(m_data->legacy_version().is_datagram_protocol() && resumed_session.dtls_srtp_profile() != 0 &&
151 value_exists(client_hello.srtp_profiles(), resumed_session.dtls_srtp_profile())) {
152 m_data->extensions().add(new SRTP_Protection_Profiles(resumed_session.dtls_srtp_profile()));
153 }
154 // NOLINTEND(*-owning-memory)
155
157
158 hash.update(io.send(*this));
159}
160
161Server_Hello_12::Server_Hello_12(std::span<const uint8_t> buf) :
162 Server_Hello_12(std::make_unique<Server_Hello_Internal>(buf)) {}
163
164Server_Hello_12::Server_Hello_12(std::unique_ptr<Server_Hello_Internal> data) : Server_Hello_12_Shim(std::move(data)) {}
165
167 return m_data->extensions().has<Renegotiation_Extension>();
168}
169
170std::vector<uint8_t> Server_Hello_12::renegotiation_info() const {
171 if(const Renegotiation_Extension* reneg = m_data->extensions().get<Renegotiation_Extension>()) {
172 return reneg->renegotiation_info();
173 }
174 return std::vector<uint8_t>();
175}
176
178 return m_data->extensions().has<Extended_Master_Secret>();
179}
180
182 return m_data->extensions().has<Encrypt_then_MAC>();
183}
184
188
190 return m_data->extensions().has<Session_Ticket_Extension>();
191}
192
194 if(const auto* srtp = m_data->extensions().get<SRTP_Protection_Profiles>()) {
195 const auto& prof = srtp->profiles();
196 BOTAN_ASSERT_NOMSG(prof.size() == 1 && prof[0] != 0);
197 return prof[0];
198 }
199
200 return 0;
201}
202
204 if(const auto* alpn = m_data->extensions().get<Application_Layer_Protocol_Notification>()) {
205 return alpn->single_protocol();
206 }
207 return "";
208}
209
211 if(const auto* ecc_formats = m_data->extensions().get<Supported_Point_Formats>()) {
212 return ecc_formats->prefers_compressed();
213 }
214 return false;
215}
216
217/*
218* Create a new Server Hello Done message
219*/
223
224/*
225* Deserialize a Server Hello Done message
226*/
227Server_Hello_Done::Server_Hello_Done(std::span<const uint8_t> buf) {
228 if(!buf.empty()) {
229 throw Decoding_Error("Server_Hello_Done: Must be empty, and is not");
230 }
231}
232
233/*
234* Serialize a Server Hello Done message
235*/
236std::vector<uint8_t> Server_Hello_Done::serialize() const {
237 return std::vector<uint8_t>();
238}
239
240} // namespace Botan::TLS
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:82
virtual void tls_modify_extensions(Extensions &extn, Connection_Side which_side, Handshake_Type which_message)
static std::optional< Ciphersuite > by_id(uint16_t suite)
std::set< Extension_Code > extension_types() const
std::vector< uint16_t > srtp_profiles() const
void update(const uint8_t in[], size_t length)
virtual std::vector< uint8_t > send(const Handshake_Message &msg)=0
virtual std::vector< uint8_t > serialize() const =0
virtual bool negotiate_encrypt_then_mac() const
virtual bool support_cert_status_message() const
std::vector< uint8_t > renegotiation_info() const
Server_Hello_12(Handshake_IO &io, Handshake_Hash &hash, const Policy &policy, Callbacks &cb, RandomNumberGenerator &rng, std::vector< uint8_t > secure_reneg_info, const Client_Hello_12 &client_hello, const Settings &settings, std::string_view next_protocol, TLS_Flavor flavor)
Server_Hello_Done(Handshake_IO &io, Handshake_Hash &hash)
Handshake_Type type() const override
const Session_ID & session_id() const
std::unique_ptr< Server_Hello_Internal > m_data
uint16_t dtls_srtp_profile() const
Definition tls_session.h:94
bool supports_encrypt_then_mac() const
Ciphersuite ciphersuite() const
std::vector< uint8_t > make_server_hello_random(RandomNumberGenerator &rng, Protocol_Version offered_version, Callbacks &cb, const Policy &policy, TLS_Flavor flavor)
bool value_exists(const std::vector< T > &vec, const V &val)
Definition stl_util.h:44