Botan 3.6.1
Crypto and TLS for C&
Botan::TLS::Server_Hello_12 Class Referencefinal

#include <tls_messages.h>

Inheritance diagram for Botan::TLS::Server_Hello_12:
Botan::TLS::Server_Hello Botan::TLS::Handshake_Message

Classes

class  Settings
 

Public Member Functions

uint16_t ciphersuite () const
 
uint8_t compression_method () const
 
std::set< Extension_Codeextension_types () const
 
const Extensionsextensions () const
 
Protocol_Version legacy_version () const
 
std::string next_protocol () const
 
bool prefers_compressed_ec_points () const
 
const std::vector< uint8_t > & random () const
 
std::optional< Protocol_Versionrandom_signals_downgrade () const
 
std::vector< uint8_t > renegotiation_info () const
 
bool secure_renegotiation () const
 
Protocol_Version selected_version () const override
 
std::vector< uint8_t > serialize () const override
 
 Server_Hello_12 (const std::vector< uint8_t > &buf)
 
 Server_Hello_12 (Handshake_IO &io, Handshake_Hash &hash, const Policy &policy, Callbacks &cb, RandomNumberGenerator &rng, const std::vector< uint8_t > &secure_reneg_info, const Client_Hello_12 &client_hello, const Session &resumed_session, bool offer_session_ticket, std::string_view next_protocol)
 
 Server_Hello_12 (Handshake_IO &io, Handshake_Hash &hash, const Policy &policy, Callbacks &cb, RandomNumberGenerator &rng, const std::vector< uint8_t > &secure_reneg_info, const Client_Hello_12 &client_hello, const Settings &settings, std::string_view next_protocol)
 
const Session_IDsession_id () const
 
uint16_t srtp_profile () const
 
bool supports_certificate_status_message () const
 
bool supports_encrypt_then_mac () const
 
bool supports_extended_master_secret () const
 
bool supports_session_ticket () const
 
Handshake_Type type () const override
 
std::string type_string () const
 
virtual Handshake_Type wire_type () const
 

Protected Member Functions

 Server_Hello_12 (std::unique_ptr< Server_Hello_Internal > data)
 

Protected Attributes

std::unique_ptr< Server_Hello_Internal > m_data
 

Friends

class Server_Hello_13
 

Detailed Description

Definition at line 307 of file tls_messages.h.

Constructor & Destructor Documentation

◆ Server_Hello_12() [1/4]

Botan::TLS::Server_Hello_12::Server_Hello_12 ( Handshake_IO & io,
Handshake_Hash & hash,
const Policy & policy,
Callbacks & cb,
RandomNumberGenerator & rng,
const std::vector< uint8_t > & secure_reneg_info,
const Client_Hello_12 & client_hello,
const Settings & settings,
std::string_view next_protocol )

Definition at line 231 of file msg_server_hello.cpp.

239 :
240 Server_Hello(std::make_unique<Server_Hello_Internal>(
241 server_settings.protocol_version(),
242 server_settings.session_id(),
243 make_server_hello_random(rng, server_settings.protocol_version(), cb, policy),
244 server_settings.ciphersuite(),
245 uint8_t(0))) {
246 if(client_hello.supports_extended_master_secret()) {
247 m_data->extensions().add(new Extended_Master_Secret);
248 }
249
250 // Sending the extension back does not commit us to sending a stapled response
251 if(client_hello.supports_cert_status_message() && policy.support_cert_status_message()) {
252 m_data->extensions().add(new Certificate_Status_Request);
253 }
254
255 if(!next_protocol.empty() && client_hello.supports_alpn()) {
256 m_data->extensions().add(new Application_Layer_Protocol_Notification(next_protocol));
257 }
258
259 const auto c = Ciphersuite::by_id(m_data->ciphersuite());
260
261 if(c && c->cbc_ciphersuite() && client_hello.supports_encrypt_then_mac() && policy.negotiate_encrypt_then_mac()) {
262 m_data->extensions().add(new Encrypt_then_MAC);
263 }
264
265 if(c && c->ecc_ciphersuite() && client_hello.extension_types().contains(Extension_Code::EcPointFormats)) {
266 m_data->extensions().add(new Supported_Point_Formats(policy.use_ecc_point_compression()));
267 }
268
269 if(client_hello.secure_renegotiation()) {
270 m_data->extensions().add(new Renegotiation_Extension(reneg_info));
271 }
272
273 if(client_hello.supports_session_ticket() && server_settings.offer_session_ticket()) {
274 m_data->extensions().add(new Session_Ticket_Extension());
275 }
276
277 if(m_data->legacy_version().is_datagram_protocol()) {
278 const std::vector<uint16_t> server_srtp = policy.srtp_profiles();
279 const std::vector<uint16_t> client_srtp = client_hello.srtp_profiles();
280
281 if(!server_srtp.empty() && !client_srtp.empty()) {
282 uint16_t shared = 0;
283 // always using server preferences for now
284 for(auto s_srtp : server_srtp) {
285 for(auto c_srtp : client_srtp) {
286 if(shared == 0 && s_srtp == c_srtp) {
287 shared = s_srtp;
288 }
289 }
290 }
291
292 if(shared) {
293 m_data->extensions().add(new SRTP_Protection_Profiles(shared));
294 }
295 }
296 }
297
298 cb.tls_modify_extensions(m_data->extensions(), Connection_Side::Server, type());
299
300 hash.update(io.send(*this));
301}
static std::optional< Ciphersuite > by_id(uint16_t suite)
std::string next_protocol() const
Server_Hello(const Server_Hello &)=delete
Handshake_Type type() const override
std::unique_ptr< Server_Hello_Internal > m_data

References Botan::TLS::Ciphersuite::by_id(), Botan::TLS::EcPointFormats, Botan::TLS::Client_Hello::extension_types(), Botan::TLS::Server_Hello::m_data, Botan::TLS::Policy::negotiate_encrypt_then_mac(), next_protocol(), Botan::TLS::Server_Hello_12::Settings::offer_session_ticket(), Botan::TLS::Client_Hello_12::secure_renegotiation(), Botan::TLS::Policy::support_cert_status_message(), Botan::TLS::Client_Hello::supports_alpn(), Botan::TLS::Client_Hello_12::supports_cert_status_message(), Botan::TLS::Client_Hello_12::supports_encrypt_then_mac(), Botan::TLS::Client_Hello_12::supports_extended_master_secret(), and Botan::TLS::Client_Hello_12::supports_session_ticket().

◆ Server_Hello_12() [2/4]

Botan::TLS::Server_Hello_12::Server_Hello_12 ( Handshake_IO & io,
Handshake_Hash & hash,
const Policy & policy,
Callbacks & cb,
RandomNumberGenerator & rng,
const std::vector< uint8_t > & secure_reneg_info,
const Client_Hello_12 & client_hello,
const Session & resumed_session,
bool offer_session_ticket,
std::string_view next_protocol )

Definition at line 304 of file msg_server_hello.cpp.

313 :
314 Server_Hello(std::make_unique<Server_Hello_Internal>(resumed_session.version(),
315 client_hello.session_id(),
316 make_hello_random(rng, cb, policy),
317 resumed_session.ciphersuite_code(),
318 uint8_t(0))) {
319 if(client_hello.supports_extended_master_secret()) {
320 m_data->extensions().add(new Extended_Master_Secret);
321 }
322
323 if(!next_protocol.empty() && client_hello.supports_alpn()) {
324 m_data->extensions().add(new Application_Layer_Protocol_Notification(next_protocol));
325 }
326
327 if(client_hello.supports_encrypt_then_mac() && policy.negotiate_encrypt_then_mac()) {
328 Ciphersuite c = resumed_session.ciphersuite();
329 if(c.cbc_ciphersuite()) {
330 m_data->extensions().add(new Encrypt_then_MAC);
331 }
332 }
333
334 if(resumed_session.ciphersuite().ecc_ciphersuite() &&
335 client_hello.extension_types().contains(Extension_Code::EcPointFormats)) {
336 m_data->extensions().add(new Supported_Point_Formats(policy.use_ecc_point_compression()));
337 }
338
339 if(client_hello.secure_renegotiation()) {
340 m_data->extensions().add(new Renegotiation_Extension(reneg_info));
341 }
342
343 if(client_hello.supports_session_ticket() && offer_session_ticket) {
344 m_data->extensions().add(new Session_Ticket_Extension());
345 }
346
347 cb.tls_modify_extensions(m_data->extensions(), Connection_Side::Server, type());
348
349 hash.update(io.send(*this));
350}
std::vector< uint8_t > make_hello_random(RandomNumberGenerator &rng, Callbacks &cb, const Policy &policy)

References Botan::TLS::make_hello_random(), Botan::TLS::Policy::negotiate_encrypt_then_mac(), next_protocol(), Botan::TLS::Client_Hello::supports_alpn(), Botan::TLS::Client_Hello_12::supports_encrypt_then_mac(), and Botan::TLS::Client_Hello_12::supports_extended_master_secret().

◆ Server_Hello_12() [3/4]

Botan::TLS::Server_Hello_12::Server_Hello_12 ( const std::vector< uint8_t > & buf)
explicit

Definition at line 352 of file msg_server_hello.cpp.

352 :
353 Server_Hello_12(std::make_unique<Server_Hello_Internal>(buf)) {}
Server_Hello_12(Handshake_IO &io, Handshake_Hash &hash, const Policy &policy, Callbacks &cb, RandomNumberGenerator &rng, const std::vector< uint8_t > &secure_reneg_info, const Client_Hello_12 &client_hello, const Settings &settings, std::string_view next_protocol)

◆ Server_Hello_12() [4/4]

Botan::TLS::Server_Hello_12::Server_Hello_12 ( std::unique_ptr< Server_Hello_Internal > data)
explicitprotected

Definition at line 355 of file msg_server_hello.cpp.

355 : Server_Hello(std::move(data)) {
356 if(!m_data->version().is_pre_tls_13()) {
357 throw TLS_Exception(Alert::ProtocolVersion, "Expected server hello of (D)TLS 1.2 or lower");
358 }
359}

References Botan::TLS::Server_Hello::m_data.

Member Function Documentation

◆ ciphersuite()

uint16_t Botan::TLS::Server_Hello::ciphersuite ( ) const
inherited

Definition at line 218 of file msg_server_hello.cpp.

218 {
219 return m_data->ciphersuite();
220}

References Botan::TLS::Server_Hello::m_data.

Referenced by Botan::TLS::Client_Hello_13::retry().

◆ compression_method()

uint8_t Botan::TLS::Server_Hello::compression_method ( ) const

Definition at line 300 of file msg_server_hello.cpp.

210 {
211 return m_data->comp_method();
212}

◆ extension_types()

std::set< Extension_Code > Botan::TLS::Server_Hello::extension_types ( ) const

Definition at line 298 of file msg_server_hello.cpp.

222 {
223 return m_data->extensions().extension_types();
224}

◆ extensions()

◆ legacy_version()

Protocol_Version Botan::TLS::Server_Hello::legacy_version ( ) const

Definition at line 301 of file msg_server_hello.cpp.

202 {
203 return m_data->legacy_version();
204}

Referenced by selected_version().

◆ next_protocol()

std::string Botan::TLS::Server_Hello_12::next_protocol ( ) const

Definition at line 404 of file msg_server_hello.cpp.

404 {
405 if(auto alpn = m_data->extensions().get<Application_Layer_Protocol_Notification>()) {
406 return alpn->single_protocol();
407 }
408 return "";
409}

References Botan::TLS::Server_Hello::m_data.

Referenced by Server_Hello_12(), and Server_Hello_12().

◆ prefers_compressed_ec_points()

bool Botan::TLS::Server_Hello_12::prefers_compressed_ec_points ( ) const

Definition at line 411 of file msg_server_hello.cpp.

411 {
412 if(auto ecc_formats = m_data->extensions().get<Supported_Point_Formats>()) {
413 return ecc_formats->prefers_compressed();
414 }
415 return false;
416}

References Botan::TLS::Server_Hello::m_data.

◆ random()

const std::vector< uint8_t > & Botan::TLS::Server_Hello::random ( ) const

Definition at line 299 of file msg_server_hello.cpp.

206 {
207 return m_data->random();
208}

◆ random_signals_downgrade()

std::optional< Protocol_Version > Botan::TLS::Server_Hello_12::random_signals_downgrade ( ) const

Return desired downgrade version indicated by hello random, if any.

Definition at line 418 of file msg_server_hello.cpp.

418 {
419 const uint64_t last8 = load_be<uint64_t>(m_data->random().data(), 3);
420 if(last8 == DOWNGRADE_TLS11) {
421 return Protocol_Version::TLS_V11;
422 }
423 if(last8 == DOWNGRADE_TLS12) {
424 return Protocol_Version::TLS_V12;
425 }
426
427 return std::nullopt;
428}
constexpr auto load_be(ParamTs &&... params)
Definition loadstor.h:530

References Botan::load_be(), and Botan::TLS::Server_Hello::m_data.

◆ renegotiation_info()

std::vector< uint8_t > Botan::TLS::Server_Hello_12::renegotiation_info ( ) const

Definition at line 369 of file msg_server_hello.cpp.

369 {
370 if(Renegotiation_Extension* reneg = m_data->extensions().get<Renegotiation_Extension>()) {
371 return reneg->renegotiation_info();
372 }
373 return std::vector<uint8_t>();
374}

References Botan::TLS::Server_Hello::m_data.

Referenced by Botan::TLS::Channel_Impl_12::secure_renegotiation_check().

◆ secure_renegotiation()

bool Botan::TLS::Server_Hello_12::secure_renegotiation ( ) const

Definition at line 365 of file msg_server_hello.cpp.

365 {
366 return m_data->extensions().has<Renegotiation_Extension>();
367}

References Botan::TLS::Server_Hello::m_data.

Referenced by Botan::TLS::Channel_Impl_12::secure_renegotiation_check().

◆ selected_version()

Protocol_Version Botan::TLS::Server_Hello_12::selected_version ( ) const
overridevirtual
Returns
the selected version as indicated in the legacy_version field

Implements Botan::TLS::Server_Hello.

Definition at line 361 of file msg_server_hello.cpp.

361 {
362 return legacy_version();
363}
Protocol_Version legacy_version() const

References legacy_version().

◆ serialize()

std::vector< uint8_t > Botan::TLS::Server_Hello::serialize ( ) const
overridevirtualinherited
Returns
DER representation of this message

Implements Botan::TLS::Handshake_Message.

Definition at line 178 of file msg_server_hello.cpp.

178 {
179 std::vector<uint8_t> buf;
180 buf.reserve(1024); // working around GCC warning
181
182 buf.push_back(m_data->legacy_version().major_version());
183 buf.push_back(m_data->legacy_version().minor_version());
184 buf += m_data->random();
185
186 append_tls_length_value(buf, m_data->session_id().get(), 1);
187
188 buf.push_back(get_byte<0>(m_data->ciphersuite()));
189 buf.push_back(get_byte<1>(m_data->ciphersuite()));
190
191 buf.push_back(m_data->comp_method());
192
193 buf += m_data->extensions().serialize(Connection_Side::Server);
194
195 return buf;
196}
void append_tls_length_value(std::vector< uint8_t, Alloc > &buf, const T *vals, size_t vals_size, size_t tag_size)
Definition tls_reader.h:180
constexpr uint8_t get_byte(T input)
Definition loadstor.h:75

References Botan::TLS::append_tls_length_value(), Botan::get_byte(), Botan::TLS::Server_Hello::random(), and Botan::TLS::Server.

◆ session_id()

const Session_ID & Botan::TLS::Server_Hello::session_id ( ) const
inherited

Definition at line 214 of file msg_server_hello.cpp.

214 {
215 return m_data->session_id();
216}

References Botan::TLS::Server_Hello::m_data.

◆ srtp_profile()

uint16_t Botan::TLS::Server_Hello_12::srtp_profile ( ) const

Definition at line 392 of file msg_server_hello.cpp.

392 {
393 if(auto srtp = m_data->extensions().get<SRTP_Protection_Profiles>()) {
394 auto prof = srtp->profiles();
395 if(prof.size() != 1 || prof[0] == 0) {
396 throw Decoding_Error("Server sent malformed DTLS-SRTP extension");
397 }
398 return prof[0];
399 }
400
401 return 0;
402}

References Botan::TLS::Server_Hello::m_data.

◆ supports_certificate_status_message()

bool Botan::TLS::Server_Hello_12::supports_certificate_status_message ( ) const

Definition at line 384 of file msg_server_hello.cpp.

384 {
385 return m_data->extensions().has<Certificate_Status_Request>();
386}

References Botan::TLS::Server_Hello::m_data.

◆ supports_encrypt_then_mac()

bool Botan::TLS::Server_Hello_12::supports_encrypt_then_mac ( ) const

Definition at line 380 of file msg_server_hello.cpp.

380 {
381 return m_data->extensions().has<Encrypt_then_MAC>();
382}

References Botan::TLS::Server_Hello::m_data.

◆ supports_extended_master_secret()

bool Botan::TLS::Server_Hello_12::supports_extended_master_secret ( ) const

Definition at line 376 of file msg_server_hello.cpp.

376 {
377 return m_data->extensions().has<Extended_Master_Secret>();
378}

References Botan::TLS::Server_Hello::m_data.

◆ supports_session_ticket()

bool Botan::TLS::Server_Hello_12::supports_session_ticket ( ) const

Definition at line 388 of file msg_server_hello.cpp.

388 {
389 return m_data->extensions().has<Session_Ticket_Extension>();
390}

References Botan::TLS::Server_Hello::m_data.

◆ type()

Handshake_Type Botan::TLS::Server_Hello::type ( ) const
overridevirtualinherited
Returns
the message type

Implements Botan::TLS::Handshake_Message.

Definition at line 198 of file msg_server_hello.cpp.

References Botan::TLS::ServerHello.

◆ type_string()

std::string Botan::TLS::Handshake_Message::type_string ( ) const
inherited
Returns
string representation of this message type

Definition at line 19 of file tls_handshake_state.cpp.

19 {
21}
virtual Handshake_Type type() const =0
const char * handshake_type_to_string(Handshake_Type type)

References Botan::TLS::handshake_type_to_string(), and Botan::TLS::Handshake_Message::type().

◆ wire_type()

virtual Handshake_Type Botan::TLS::Handshake_Message::wire_type ( ) const
inlinevirtualinherited
Returns
the wire representation of the message's type

Reimplemented in Botan::TLS::Hello_Retry_Request.

Definition at line 39 of file tls_handshake_msg.h.

39 {
40 // Usually equal to the Handshake_Type enum value,
41 // with the exception of TLS 1.3 Hello Retry Request.
42 return type();
43 }

Referenced by Botan::TLS::Stream_Handshake_IO::send().

Friends And Related Symbol Documentation

◆ Server_Hello_13

friend class Server_Hello_13
friend

Definition at line 359 of file tls_messages.h.

Member Data Documentation

◆ m_data


The documentation for this class was generated from the following files: