Botan 3.12.0
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_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 final
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 Attributes

std::unique_ptr< Server_Hello_Internalm_data

Detailed Description

Definition at line 89 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,
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 22 of file msg_server_hello_12.cpp.

30 :
31 Server_Hello_12(std::make_unique<Server_Hello_Internal>(
32 server_settings.protocol_version(),
33 server_settings.session_id(),
34 make_server_hello_random(rng, server_settings.protocol_version(), cb, policy),
35 server_settings.ciphersuite(),
36 uint8_t(0))) {
37 // NOLINTBEGIN(*-owning-memory)
38 if(client_hello.supports_extended_master_secret()) {
39 m_data->extensions().add(new Extended_Master_Secret);
40 }
41
42 // Sending the extension back does not commit us to sending a stapled response
43 if(client_hello.supports_cert_status_message() && policy.support_cert_status_message()) {
44 m_data->extensions().add(new Certificate_Status_Request);
45 }
46
47 if(!next_protocol.empty() && client_hello.supports_alpn()) {
48 m_data->extensions().add(new Application_Layer_Protocol_Notification(next_protocol));
49 }
50
51 const auto c = Ciphersuite::by_id(m_data->ciphersuite());
52
53 if(c && c->cbc_ciphersuite() && client_hello.supports_encrypt_then_mac() && policy.negotiate_encrypt_then_mac()) {
54 m_data->extensions().add(new Encrypt_then_MAC);
55 }
56
57 if(c && c->ecc_ciphersuite() && client_hello.extension_types().contains(Extension_Code::EcPointFormats)) {
58 m_data->extensions().add(new Supported_Point_Formats(policy.use_ecc_point_compression()));
59 }
60
61 if(client_hello.secure_renegotiation()) {
62 m_data->extensions().add(new Renegotiation_Extension(reneg_info));
63 }
64
65 if(client_hello.supports_session_ticket() && server_settings.offer_session_ticket()) {
66 m_data->extensions().add(new Session_Ticket_Extension());
67 }
68
69 if(m_data->legacy_version().is_datagram_protocol()) {
70 const std::vector<uint16_t> server_srtp = policy.srtp_profiles();
71 const std::vector<uint16_t> client_srtp = client_hello.srtp_profiles();
72
73 if(!server_srtp.empty() && !client_srtp.empty()) {
74 uint16_t shared = 0;
75 // always using server preferences for now
76 for(auto s_srtp : server_srtp) {
77 for(auto c_srtp : client_srtp) {
78 if(shared == 0 && s_srtp == c_srtp) {
79 shared = s_srtp;
80 }
81 }
82 }
83
84 if(shared != 0) {
85 m_data->extensions().add(new SRTP_Protection_Profiles(shared));
86 }
87 }
88 }
89 // NOLINTEND(*-owning-memory)
90
91 cb.tls_modify_extensions(m_data->extensions(), Connection_Side::Server, type());
92
93 hash.update(io.send(*this));
94}
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, const std::vector< uint8_t > &secure_reneg_info, const Client_Hello_12 &client_hello, const Settings &settings, std::string_view next_protocol)
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)

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

106 :
108 std::make_unique<Server_Hello_Internal>(resumed_session.version(),
109 client_hello.session_id(),
110 make_server_hello_random(rng, resumed_session.version(), cb, policy),
111 resumed_session.ciphersuite_code(),
112 uint8_t(0))) {
113 // NOLINTBEGIN(*-owning-memory)
114 if(client_hello.supports_extended_master_secret()) {
115 m_data->extensions().add(new Extended_Master_Secret);
116 }
117
118 if(!next_protocol.empty() && client_hello.supports_alpn()) {
119 m_data->extensions().add(new Application_Layer_Protocol_Notification(next_protocol));
120 }
121
122 if(client_hello.supports_encrypt_then_mac() && policy.negotiate_encrypt_then_mac()) {
123 const Ciphersuite c = resumed_session.ciphersuite();
124 if(c.cbc_ciphersuite()) {
125 m_data->extensions().add(new Encrypt_then_MAC);
126 }
127 }
128
129 if(resumed_session.ciphersuite().ecc_ciphersuite() &&
130 client_hello.extension_types().contains(Extension_Code::EcPointFormats)) {
131 m_data->extensions().add(new Supported_Point_Formats(policy.use_ecc_point_compression()));
132 }
133
134 if(client_hello.secure_renegotiation()) {
135 m_data->extensions().add(new Renegotiation_Extension(reneg_info));
136 }
137
138 if(client_hello.supports_session_ticket() && offer_session_ticket) {
139 m_data->extensions().add(new Session_Ticket_Extension());
140 }
141 // NOLINTEND(*-owning-memory)
142
143 cb.tls_modify_extensions(m_data->extensions(), Connection_Side::Server, type());
144
145 hash.update(io.send(*this));
146}

References Botan::TLS::make_server_hello_random(), Botan::TLS::Policy::negotiate_encrypt_then_mac(), next_protocol(), Server_Hello_12(), Botan::TLS::Server_Hello::session_id(), 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/3]

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

Definition at line 148 of file msg_server_hello_12.cpp.

148 :
149 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

Definition at line 144 of file msg_server_hello.cpp.

144 {
145 return m_data->ciphersuite();
146}

References m_data.

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

◆ compression_method()

Definition at line 198 of file msg_server_hello.cpp.

136 {
137 return m_data->comp_method();
138}

◆ extension_types()

Definition at line 196 of file msg_server_hello.cpp.

148 {
149 return m_data->extensions().extension_types();
150}

◆ extensions()

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

◆ legacy_version()

Definition at line 199 of file msg_server_hello.cpp.

128 {
129 return m_data->legacy_version();
130}

◆ next_protocol()

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

Definition at line 192 of file msg_server_hello_12.cpp.

192 {
193 if(auto* alpn = m_data->extensions().get<Application_Layer_Protocol_Notification>()) {
194 return alpn->single_protocol();
195 }
196 return "";
197}

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

199 {
200 if(auto* ecc_formats = m_data->extensions().get<Supported_Point_Formats>()) {
201 return ecc_formats->prefers_compressed();
202 }
203 return false;
204}

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.

132 {
133 return m_data->random();
134}

◆ 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 170 of file msg_server_hello.cpp.

170 {
171 const uint64_t last8 = load_be<uint64_t>(m_data->random().data(), 3);
172 if(last8 == DOWNGRADE_TLS11) {
173 return Protocol_Version::TLS_V11;
174 }
175 if(last8 == DOWNGRADE_TLS12) {
176 return Protocol_Version::TLS_V12;
177 }
178
179 return std::nullopt;
180}
constexpr uint64_t DOWNGRADE_TLS12
Definition tls_magic.h:118
constexpr uint64_t DOWNGRADE_TLS11
Definition tls_magic.h:107
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 157 of file msg_server_hello_12.cpp.

157 {
158 if(const Renegotiation_Extension* reneg = m_data->extensions().get<Renegotiation_Extension>()) {
159 return reneg->renegotiation_info();
160 }
161 return std::vector<uint8_t>();
162}

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

153 {
154 return m_data->extensions().has<Renegotiation_Extension>();
155}

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

166 {
167 return legacy_version();
168}
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
Returns
DER representation of this message

Implements Botan::TLS::Handshake_Message.

Definition at line 104 of file msg_server_hello.cpp.

104 {
105 std::vector<uint8_t> buf;
106 buf.reserve(1024); // working around GCC warning
107
108 buf.push_back(m_data->legacy_version().major_version());
109 buf.push_back(m_data->legacy_version().minor_version());
110 buf += m_data->random();
111
112 append_tls_length_value(buf, m_data->session_id().get(), 1);
113
114 buf.push_back(get_byte<0>(m_data->ciphersuite()));
115 buf.push_back(get_byte<1>(m_data->ciphersuite()));
116
117 buf.push_back(m_data->comp_method());
118
119 buf += m_data->extensions().serialize(Connection_Side::Server);
120
121 return buf;
122}
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:177
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 180 of file msg_server_hello_12.cpp.

180 {
181 if(auto* srtp = m_data->extensions().get<SRTP_Protection_Profiles>()) {
182 auto prof = srtp->profiles();
183 if(prof.size() != 1 || prof[0] == 0) {
184 throw Decoding_Error("Server sent malformed DTLS-SRTP extension");
185 }
186 return prof[0];
187 }
188
189 return 0;
190}

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

172 {
173 return m_data->extensions().has<Certificate_Status_Request>();
174}

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

168 {
169 return m_data->extensions().has<Encrypt_then_MAC>();
170}

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

164 {
165 return m_data->extensions().has<Extended_Master_Secret>();
166}

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

◆ supports_session_ticket()

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

Definition at line 176 of file msg_server_hello_12.cpp.

176 {
177 return m_data->extensions().has<Session_Ticket_Extension>();
178}

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 124 of file msg_server_hello.cpp.

References Botan::TLS::ServerHello.

Referenced by ~Server_Hello().

◆ type_string()

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

Definition at line 21 of file tls_handshake_state.cpp.

21 {
23}
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
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 }

References type().

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

Member Data Documentation

◆ m_data


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