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

#include <tls_messages_12.h>

Inheritance diagram for Botan::TLS::Server_Hello_12:
Botan::TLS::Server_Hello_12_Shim 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_Code > extension_types () const
const Extensions & extensions () 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_Version > random_signals_downgrade () const
std::vector< uint8_t > renegotiation_info () const
bool secure_renegotiation () const
Protocol_Version selected_version () const final
std::vector< uint8_t > serialize () const override
 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 Session &resumed_session, bool offer_session_ticket, std::string_view next_protocol, TLS_Flavor flavor)
 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_12 (std::span< const uint8_t > buf)
const Session_ID & session_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 Attributes

std::unique_ptr< Server_Hello_Internal > m_data

Detailed Description

Definition at line 101 of file tls_messages_12.h.

Constructor & Destructor Documentation

◆ Server_Hello_12() [1/3]

Botan::TLS::Server_Hello_12::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 )

Definition at line 23 of file msg_server_hello_12.cpp.

32 :
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}
static std::optional< Ciphersuite > by_id(uint16_t suite)
virtual Handshake_Type type() const =0
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)
std::unique_ptr< Server_Hello_Internal > m_data
std::vector< uint8_t > make_server_hello_random(RandomNumberGenerator &rng, Protocol_Version offered_version, Callbacks &cb, const Policy &policy, TLS_Flavor flavor)

References Botan::TLS::Ciphersuite::by_id(), Botan::TLS::Server_Hello::ciphersuite(), Botan::TLS::EcPointFormats, Botan::TLS::Client_Hello::extension_types(), Botan::TLS::Server_Hello::m_data, Botan::TLS::make_server_hello_random(), 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(), Server_Hello_12(), Botan::TLS::Server_Hello::session_id(), 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().

Referenced by Server_Hello_12(), Server_Hello_12(), and Server_Hello_12().

◆ Server_Hello_12() [2/3]

Botan::TLS::Server_Hello_12::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 Session & resumed_session,
bool offer_session_ticket,
std::string_view next_protocol,
TLS_Flavor flavor )

Definition at line 99 of file msg_server_hello_12.cpp.

109 :
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
156 cb.tls_modify_extensions(m_data->extensions(), Connection_Side::Server, type());
157
158 hash.update(io.send(*this));
159}
bool value_exists(const std::vector< T > &vec, const V &val)
Definition stl_util.h:44

References Botan::TLS::Ciphersuite::cbc_ciphersuite(), Botan::TLS::Session_Base::ciphersuite(), Botan::TLS::Session_Base::dtls_srtp_profile(), Botan::TLS::Ciphersuite::ecc_ciphersuite(), Botan::TLS::EcPointFormats, Botan::TLS::Client_Hello::extension_types(), Botan::TLS::Server_Hello::m_data, Botan::TLS::make_server_hello_random(), next_protocol(), Botan::TLS::Client_Hello_12::secure_renegotiation(), Botan::TLS::Handshake_IO::send(), Botan::TLS::Server, Server_Hello_12(), Botan::TLS::Server_Hello::session_id(), Botan::TLS::Client_Hello::srtp_profiles(), Botan::TLS::Client_Hello::supports_alpn(), Botan::TLS::Client_Hello_12::supports_encrypt_then_mac(), Botan::TLS::Session_Base::supports_encrypt_then_mac(), Botan::TLS::Client_Hello_12::supports_extended_master_secret(), Botan::TLS::Client_Hello_12::supports_session_ticket(), Botan::TLS::Callbacks::tls_modify_extensions(), Botan::TLS::Server_Hello::type(), Botan::TLS::Handshake_Hash::update(), and Botan::value_exists().

◆ Server_Hello_12() [3/3]

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

Definition at line 161 of file msg_server_hello_12.cpp.

161 :
162 Server_Hello_12(std::make_unique<Server_Hello_Internal>(buf)) {}

References Server_Hello_12().

Member Function Documentation

◆ ciphersuite()

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

◆ compression_method()

Definition at line 198 of file msg_server_hello.cpp.

139 {
140 return m_data->comp_method();
141}

◆ extension_types()

Definition at line 196 of file msg_server_hello.cpp.

151 {
152 return m_data->extensions().extension_types();
153}

◆ extensions()

const Extensions & Botan::TLS::Server_Hello::extensions ( ) const
inherited

◆ legacy_version()

Definition at line 199 of file msg_server_hello.cpp.

131 {
132 return m_data->legacy_version();
133}

◆ next_protocol()

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

Definition at line 203 of file msg_server_hello_12.cpp.

203 {
204 if(const auto* alpn = m_data->extensions().get<Application_Layer_Protocol_Notification>()) {
205 return alpn->single_protocol();
206 }
207 return "";
208}

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 210 of file msg_server_hello_12.cpp.

210 {
211 if(const auto* ecc_formats = m_data->extensions().get<Supported_Point_Formats>()) {
212 return ecc_formats->prefers_compressed();
213 }
214 return false;
215}

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

◆ random()

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

Definition at line 197 of file msg_server_hello.cpp.

135 {
136 return m_data->random();
137}

◆ random_signals_downgrade()

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

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

Definition at line 173 of file msg_server_hello.cpp.

173 {
174 const uint64_t last8 = load_be<uint64_t>(m_data->random().data(), 3);
175 if(last8 == DOWNGRADE_TLS11) {
176 return Protocol_Version::TLS_V11;
177 }
178 if(last8 == DOWNGRADE_TLS12) {
179 return Protocol_Version::TLS_V12;
180 }
181
182 return std::nullopt;
183}
constexpr uint64_t DOWNGRADE_TLS12
Definition tls_magic.h:130
constexpr uint64_t DOWNGRADE_TLS11
Definition tls_magic.h:119
constexpr auto load_be(ParamTs &&... params)
Definition loadstor.h:504

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

Referenced by Server_Hello_13.

◆ renegotiation_info()

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

Definition at line 170 of file msg_server_hello_12.cpp.

170 {
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}

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 166 of file msg_server_hello_12.cpp.

166 {
167 return m_data->extensions().has<Renegotiation_Extension>();
168}

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_Shim::selected_version ( ) const
finalvirtualinherited
Returns
the selected version as indicated in the legacy_version field

Implements Botan::TLS::Server_Hello.

Definition at line 169 of file msg_server_hello.cpp.

169 {
170 return legacy_version();
171}
Protocol_Version legacy_version() const

References Botan::TLS::Server_Hello::legacy_version().

Referenced by Server_Hello_13.

◆ serialize()

std::vector< uint8_t > Botan::TLS::Server_Hello::serialize ( ) const
overridevirtualinherited

Serialize this handshake message

Implements Botan::TLS::Handshake_Message.

Definition at line 107 of file msg_server_hello.cpp.

107 {
108 std::vector<uint8_t> buf;
109 buf.reserve(1024); // working around GCC warning
110
111 buf.push_back(m_data->legacy_version().major_version());
112 buf.push_back(m_data->legacy_version().minor_version());
113 buf += m_data->random();
114
115 append_tls_length_value(buf, m_data->session_id().get(), 1);
116
117 buf.push_back(get_byte<0>(m_data->ciphersuite()));
118 buf.push_back(get_byte<1>(m_data->ciphersuite()));
119
120 buf.push_back(m_data->comp_method());
121
122 buf += m_data->extensions().serialize(Connection_Side::Server);
123
124 return buf;
125}
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:182
constexpr uint8_t get_byte(T input)
Definition loadstor.h:79

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

Referenced by serialize(), and ~Server_Hello().

◆ session_id()

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

◆ srtp_profile()

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

Definition at line 193 of file msg_server_hello_12.cpp.

193 {
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}
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:82

References BOTAN_ASSERT_NOMSG, and Botan::TLS::Server_Hello::m_data.

◆ supports_certificate_status_message()

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

Definition at line 185 of file msg_server_hello_12.cpp.

185 {
186 return m_data->extensions().has<Certificate_Status_Request>();
187}

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 181 of file msg_server_hello_12.cpp.

181 {
182 return m_data->extensions().has<Encrypt_then_MAC>();
183}

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

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

◆ supports_extended_master_secret()

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

Definition at line 177 of file msg_server_hello_12.cpp.

177 {
178 return m_data->extensions().has<Extended_Master_Secret>();
179}

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

◆ supports_session_ticket()

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

Definition at line 189 of file msg_server_hello_12.cpp.

189 {
190 return m_data->extensions().has<Session_Ticket_Extension>();
191}

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

◆ type()

Handshake_Type Botan::TLS::Server_Hello::type ( ) const
overridevirtualinherited

Return the TLS handshake type code

Returns
the message type

Implements Botan::TLS::Handshake_Message.

Definition at line 127 of file msg_server_hello.cpp.

References Botan::TLS::ServerHello.

Referenced by Botan::TLS::Server_Hello_12::Server_Hello_12(), and ~Server_Hello().

◆ type_string()

std::string Botan::TLS::Handshake_Message::type_string ( ) const
inherited

Return a free-form string describing this message type

Returns
string representation of this message type

Definition at line 22 of file tls_handshake_state.cpp.

22 {
24}
const char * handshake_type_to_string(Handshake_Type type)
Definition tls_magic.cpp:15

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

◆ wire_type()

virtual Handshake_Type Botan::TLS::Handshake_Message::wire_type ( ) const
inlinevirtualinherited

Return the wire encoding of the message type code

Note
This is usually equal to type with the exception of a TLS 1.3 Helloy Retry Request.
Returns
the wire representation of the message's type

Reimplemented in Botan::TLS::Hello_Retry_Request.

Definition at line 47 of file tls_handshake_msg.h.

47{ return type(); }

References type().

Referenced by Botan::TLS::Stream_Handshake_IO::send(), and Botan::TLS::Handshake_Layer::update_transcript_for_psk_binder_calc().

Member Data Documentation

◆ m_data


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