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

#include <tls_messages_13.h>

Inheritance diagram for Botan::TLS::Client_Hello_13:
Botan::TLS::Client_Hello Botan::TLS::Handshake_Message

Public Member Functions

std::vector< Signature_Scheme > certificate_signature_schemes () const
const std::vector< uint16_t > & ciphersuites () const
 Client_Hello_13 (const Policy &policy, Callbacks &cb, RandomNumberGenerator &rng, std::string_view hostname, std::vector< std::string > next_protocols, std::optional< Session_with_Handle > &session, std::vector< ExternalPSK > psks, TLS_Flavor flavor)
const std::vector< uint8_t > & cookie () const
std::vector< uint8_t > cookie_input_data () const
std::set< Extension_Code > extension_types () const
const Extensions & extensions () const
std::optional< Protocol_Version > highest_supported_version (const Policy &policy) const
Protocol_Version legacy_version () const
std::vector< std::string > next_protocols () const
bool offered_suite (uint16_t ciphersuite) const
bool offered_tls13 () const
const std::vector< uint8_t > & random () const
void retry (const Hello_Retry_Request &hrr, const Transcript_Hash_State &transcript_hash_state, Callbacks &cb, RandomNumberGenerator &rng)
bool sent_signature_algorithms () const
std::vector< uint8_t > serialize () const override
const Session_ID & session_id () const
std::vector< Signature_Scheme > signature_schemes () const
std::string sni_hostname () const
std::vector< uint16_t > srtp_profiles () const
std::vector< Group_Params > supported_dh_groups () const
std::vector< Group_Params > supported_ecc_curves () const
std::vector< Protocol_Version > supported_versions () const
bool supports_alpn () const
Handshake_Type type () const override
std::string type_string () const
void validate_updates (const Client_Hello_13 &new_ch)
virtual Handshake_Type wire_type () const

Static Public Member Functions

static std::variant< Client_Hello_13, Client_Hello_12_Shim > parse (std::span< const uint8_t > buf)

Protected Member Functions

const std::vector< uint8_t > & compression_methods () const

Protected Attributes

std::unique_ptr< Client_Hello_Internal > m_data

Detailed Description

Definition at line 30 of file tls_messages_13.h.

Constructor & Destructor Documentation

◆ Client_Hello_13()

Botan::TLS::Client_Hello_13::Client_Hello_13 ( const Policy & policy,
Callbacks & cb,
RandomNumberGenerator & rng,
std::string_view hostname,
std::vector< std::string > next_protocols,
std::optional< Session_with_Handle > & session,
std::vector< ExternalPSK > psks,
TLS_Flavor flavor )

Creates a client hello which might optionally use the passed-in session for resumption. In that case, this will "extract" the master secret from the passed-in session.

Definition at line 154 of file msg_client_hello_13.cpp.

161 {
162 // RFC 8446 4.1.2
163 // In TLS 1.3, the client indicates its version preferences in the
164 // "supported_versions" extension (Section 4.2.1) and the
165 // legacy_version field MUST be set to 0x0303, which is the version
166 // number for TLS 1.2.
167 m_data->m_legacy_version = Protocol_Version::TLS_V12;
168 m_data->m_random = make_hello_random(rng, cb, policy);
169 m_data->m_suites = policy.ciphersuite_list(Protocol_Version::TLS_V13);
170
171 if(policy.allow_tls12()) {
172 // Note: DTLS 1.3 is NYI, hence dtls_12 is not checked
173 const auto legacy_suites = policy.ciphersuite_list(Protocol_Version::TLS_V12);
174 m_data->m_suites.insert(m_data->m_suites.end(), legacy_suites.cbegin(), legacy_suites.cend());
175 }
176
177 if(policy.tls_13_middlebox_compatibility_mode()) {
178 // RFC 8446 4.1.2
179 // In compatibility mode (see Appendix D.4), this field MUST be non-empty,
180 // so a client not offering a pre-TLS 1.3 session MUST generate a new
181 // 32-byte value.
182 //
183 // Note: we won't ever offer a TLS 1.2 session. In such a case we would
184 // have instantiated a TLS 1.2 client in the first place.
185 m_data->m_session_id = Session_ID(make_hello_random(rng, cb, policy));
186 }
187
188 // NOLINTBEGIN(*-owning-memory)
190 m_data->extensions().add(new Server_Name_Indicator(hostname));
191 }
192
193 // Groups only defined for TLS 1.2 are offered only if TLS 1.2 is offered as well
194 if(policy.allow_tls12()) {
195 m_data->extensions().add(new Supported_Groups(policy.key_exchange_groups()));
196 } else {
197 m_data->extensions().add(
198 new Supported_Groups(groups_usable_in_version(policy.key_exchange_groups(), Protocol_Version::TLS_V13)));
199 }
200
201 m_data->extensions().add(new Key_Share(policy, cb, rng));
202
203 m_data->extensions().add(new Supported_Versions(Protocol_Version::TLS_V13, policy));
204
205 m_data->extensions().add(new Signature_Algorithms(policy.acceptable_signature_schemes()));
206 if(auto cert_signing_prefs = policy.acceptable_certificate_signature_schemes()) {
207 // RFC 8446 4.2.3
208 // Implementations which have the same policy in both cases MAY omit
209 // the "signature_algorithms_cert" extension.
210 m_data->extensions().add(new Signature_Algorithms_Cert(std::move(cert_signing_prefs.value())));
211 }
212
213 // TODO: Support for PSK-only mode without a key exchange.
214 // This should be configurable in TLS::Policy and should allow no PSK
215 // support at all (e.g. to disable support for session resumption).
216 m_data->extensions().add(new PSK_Key_Exchange_Modes({PSK_Key_Exchange_Mode::PSK_DHE_KE}));
217
218 if(policy.support_cert_status_message()) {
219 m_data->extensions().add(new Certificate_Status_Request({}, {}));
220 }
221
222 // We currently support "record_size_limit" for TLS 1.3 exclusively. Hence,
223 // when TLS 1.2 is advertised as a supported protocol, we must not offer this
224 // extension.
225 if(policy.record_size_limit().has_value() && !policy.allow_tls12()) {
226 m_data->extensions().add(new Record_Size_Limit(policy.record_size_limit().value()));
227 }
228
229 /*
230 * Right now raw public key support is not implemented for TLS 1.2, so we only offer
231 * certificate_types (which is used to request raw public key) if additionally TLS 1.2
232 * support is disabled. Otherwise a peer might reply with a 1.2 server hello + a certificate_type
233 * extension indicating it wishes to use RPK, which would lead to errors later.
234 */
235 if(!policy.allow_tls12()) {
236 m_data->extensions().add(new Client_Certificate_Type(policy.accepted_client_certificate_types()));
237 m_data->extensions().add(new Server_Certificate_Type(policy.accepted_server_certificate_types()));
238 }
239
240 if(!next_protocols.empty()) {
241 m_data->extensions().add(new Application_Layer_Protocol_Notification(std::move(next_protocols)));
242 }
243
244#if defined(BOTAN_HAS_TLS_12)
245 if(policy.allow_tls12()) {
246 m_data->extensions().add(new Renegotiation_Extension());
247 m_data->extensions().add(new Session_Ticket_Extension());
248
249 // EMS must always be used with TLS 1.2, regardless of the policy
250 m_data->extensions().add(new Extended_Master_Secret);
251
252 if(policy.negotiate_encrypt_then_mac()) {
253 m_data->extensions().add(new Encrypt_then_MAC);
254 }
255
256 if(m_data->extensions().has<Supported_Groups>() &&
257 !m_data->extensions().get<Supported_Groups>()->ec_groups().empty()) {
258 m_data->extensions().add(new Supported_Point_Formats(policy.use_ecc_point_compression()));
259 }
260 }
261#endif
262
263 if(session.has_value() || !psks.empty()) {
264 m_data->extensions().add(new PSK(session, std::move(psks), cb));
265 }
266 // NOLINTEND(*-owning-memory)
267
268 cb.tls_modify_extensions(m_data->extensions(), Connection_Side::Client, type());
269
270 // The application's tls_modify_extensions callback could have stripped
271 // Supported_Groups or Key_Share, which must be there.
272 if(!m_data->extensions().has<Supported_Groups>()) {
273 throw TLS_Exception(Alert::InternalError,
274 "Application tls_modify_extensions callback removed Supported_Groups from the ClientHello");
275 }
276 if(!m_data->extensions().has<Key_Share>()) {
277 throw TLS_Exception(Alert::InternalError,
278 "Application tls_modify_extensions callback removed Key_Share from the ClientHello");
279 }
280
281 if(m_data->extensions().has<PSK>()) {
282 // RFC 8446 4.2.11
283 // The "pre_shared_key" extension MUST be the last extension in the
284 // ClientHello (this facilitates implementation [...]).
285 if(m_data->extensions().last_added() != Extension_Code::PresharedKey) {
286 throw TLS_Exception(Alert::InternalError,
287 "Application modified extensions of Client Hello, PSK is not last anymore");
288 }
289 calculate_psk_binders(Transcript_Hash_State(flavor));
290 }
291}
std::unique_ptr< Client_Hello_Internal > m_data
std::vector< std::string > next_protocols() const
virtual Handshake_Type type() const =0
static bool hostname_acceptable_for_sni(std::string_view hostname)
std::vector< uint8_t > make_hello_random(RandomNumberGenerator &rng, Callbacks &cb, const Policy &policy)
std::vector< Group_Params > groups_usable_in_version(std::span< const Group_Params > groups, Protocol_Version version)
Strong< std::vector< uint8_t >, struct Session_ID_ > Session_ID
holds a TLS 1.2 session ID for stateful resumption

References Botan::TLS::Policy::acceptable_certificate_signature_schemes(), Botan::TLS::Policy::acceptable_signature_schemes(), Botan::TLS::Policy::accepted_client_certificate_types(), Botan::TLS::Policy::accepted_server_certificate_types(), Botan::TLS::Policy::allow_tls12(), Botan::TLS::Policy::ciphersuite_list(), Botan::TLS::Client, Client_Hello_13(), Botan::TLS::Supported_Groups::ec_groups(), Botan::TLS::groups_usable_in_version(), Botan::TLS::Server_Name_Indicator::hostname_acceptable_for_sni(), Botan::TLS::Policy::key_exchange_groups(), Botan::TLS::Client_Hello::m_data, Botan::TLS::make_hello_random(), Botan::TLS::Policy::negotiate_encrypt_then_mac(), Botan::TLS::Client_Hello::next_protocols(), Botan::TLS::PresharedKey, Botan::TLS::PSK_DHE_KE, Botan::TLS::Policy::record_size_limit(), Botan::TLS::Policy::support_cert_status_message(), Botan::TLS::Policy::tls_13_middlebox_compatibility_mode(), Botan::TLS::Callbacks::tls_modify_extensions(), Botan::TLS::Client_Hello::type(), and Botan::TLS::Policy::use_ecc_point_compression().

Referenced by Client_Hello_13(), parse(), and validate_updates().

Member Function Documentation

◆ certificate_signature_schemes()

std::vector< Signature_Scheme > Botan::TLS::Client_Hello::certificate_signature_schemes ( ) const
inherited

Definition at line 236 of file msg_client_hello.cpp.

236 {
237 // RFC 8446 4.2.3
238 // If no "signature_algorithms_cert" extension is present, then the
239 // "signature_algorithms" extension also applies to signatures appearing
240 // in certificates.
241 if(const Signature_Algorithms_Cert* sigs = m_data->extensions().get<Signature_Algorithms_Cert>()) {
242 return sigs->supported_schemes();
243 } else {
244 return signature_schemes();
245 }
246}
std::vector< Signature_Scheme > signature_schemes() const

References m_data, and signature_schemes().

Referenced by Botan::TLS::Certificate_13::Certificate_13(), and ~Client_Hello().

◆ ciphersuites()

const std::vector< uint16_t > & Botan::TLS::Client_Hello::ciphersuites ( ) const
inherited

Definition at line 172 of file msg_client_hello.cpp.

172 {
173 return m_data->ciphersuites();
174}

References m_data.

Referenced by ~Client_Hello().

◆ compression_methods()

const std::vector< uint8_t > & Botan::TLS::Client_Hello::compression_methods ( ) const
protectedinherited

Definition at line 168 of file msg_client_hello.cpp.

168 {
169 return m_data->comp_methods();
170}

References m_data.

Referenced by ~Client_Hello().

◆ cookie()

const std::vector< uint8_t > & Botan::TLS::Client_Hello::cookie ( ) const
inherited

Definition at line 312 of file msg_client_hello.cpp.

312 {
313 return m_data->hello_cookie();
314}

References m_data.

Referenced by ~Client_Hello().

◆ cookie_input_data()

std::vector< uint8_t > Botan::TLS::Client_Hello::cookie_input_data ( ) const
inherited

Definition at line 215 of file msg_client_hello.cpp.

215 {
216 BOTAN_STATE_CHECK(!m_data->hello_cookie_input_bits().empty());
217
218 return m_data->hello_cookie_input_bits();
219}
#define BOTAN_STATE_CHECK(expr)
Definition assert.h:49

References BOTAN_STATE_CHECK, and m_data.

Referenced by ~Client_Hello().

◆ extension_types()

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

Definition at line 176 of file msg_client_hello.cpp.

176 {
177 return m_data->extensions().extension_types();
178}

References m_data.

Referenced by Botan::TLS::Server_Hello_12::Server_Hello_12(), Botan::TLS::Server_Hello_12::Server_Hello_12(), Botan::TLS::Client_Hello_13::validate_updates(), and ~Client_Hello().

◆ extensions()

◆ highest_supported_version()

std::optional< Protocol_Version > Botan::TLS::Client_Hello_13::highest_supported_version ( const Policy & policy) const

Select the highest protocol version from the list of versions supported by the client. If no such version can be determined this returns std::nullopt.

Definition at line 513 of file msg_client_hello_13.cpp.

513 {
514 // RFC 8446 4.2.1
515 // The "supported_versions" extension is used by the client to indicate
516 // which versions of TLS it supports and by the server to indicate which
517 // version it is using. The extension contains a list of supported
518 // versions in preference order, with the most preferred version first.
519 const auto* const supvers = m_data->extensions().get<Supported_Versions>();
520 BOTAN_ASSERT_NONNULL(supvers);
521
522 std::optional<Protocol_Version> result;
523
524 for(const auto& v : supvers->versions()) {
525 // RFC 8446 4.2.1
526 // Servers MUST only select a version of TLS present in that extension
527 // and MUST ignore any unknown versions that are present in that
528 // extension.
529 if(!v.known_version() || !policy.acceptable_protocol_version(v)) {
530 continue;
531 }
532
533 result = (result.has_value()) ? std::optional(std::max(result.value(), v)) : std::optional(v);
534 }
535
536 return result;
537}
#define BOTAN_ASSERT_NONNULL(ptr)
Definition assert.h:121

References Botan::TLS::Policy::acceptable_protocol_version(), BOTAN_ASSERT_NONNULL, highest_supported_version(), and Botan::TLS::Client_Hello::m_data.

Referenced by highest_supported_version().

◆ legacy_version()

Protocol_Version Botan::TLS::Client_Hello::legacy_version ( ) const
inherited

Return the version indicated in the ClientHello. This may differ from the version indicated in the supported_versions extension.

See RFC 8446 4.1.2: TLS 1.3, the client indicates its version preferences in the "supported_versions" extension (Section 4.2.1) and the legacy_version field MUST be set to 0x0303, which is the version number for TLS 1.2.

Definition at line 156 of file msg_client_hello.cpp.

156 {
157 return m_data->legacy_version();
158}

References m_data.

Referenced by ~Client_Hello().

◆ next_protocols()

std::vector< std::string > Botan::TLS::Client_Hello::next_protocols ( ) const
inherited

Definition at line 298 of file msg_client_hello.cpp.

298 {
299 if(const auto* alpn = m_data->extensions().get<Application_Layer_Protocol_Notification>()) {
300 return alpn->protocols();
301 }
302 return {};
303}

References m_data.

Referenced by Botan::TLS::Client_Hello_12::Client_Hello_12(), Botan::TLS::Client_Hello_12::Client_Hello_12(), Botan::TLS::Client_Hello_13::Client_Hello_13(), and ~Client_Hello().

◆ offered_suite()

bool Botan::TLS::Client_Hello::offered_suite ( uint16_t ciphersuite) const
inherited

Definition at line 224 of file msg_client_hello.cpp.

224 {
225 return std::find(m_data->ciphersuites().cbegin(), m_data->ciphersuites().cend(), ciphersuite) !=
226 m_data->ciphersuites().cend();
227}

References m_data.

Referenced by ~Client_Hello().

◆ offered_tls13()

bool Botan::TLS::Client_Hello::offered_tls13 ( ) const
inherited

Definition at line 269 of file msg_client_hello.cpp.

269 {
270 // RFC 9846 4.2.2
271 // TLS 1.3 ClientHellos are identified as having a legacy_version of
272 // 0x0303 and a "supported_versions" extension present with 0x0304 as the
273 // highest version indicated therein.
274 const auto* versions = m_data->extensions().get<Supported_Versions>();
275 if(versions == nullptr) {
276 return false;
277 }
278
279 return versions->supports(Protocol_Version::TLS_V13) || //
280 versions->supports(Protocol_Version::DTLS_V13);
281}

References m_data, and Botan::TLS::Supported_Versions::supports().

Referenced by ~Client_Hello().

◆ parse()

std::variant< Client_Hello_13, Client_Hello_12_Shim > Botan::TLS::Client_Hello_13::parse ( std::span< const uint8_t > buf)
static

Definition at line 293 of file msg_client_hello_13.cpp.

293 {
294 auto data = std::make_unique<Client_Hello_Internal>(buf);
295 const auto version = data->version();
296
297 if(version.is_pre_tls_13()) {
298 return Client_Hello_12_Shim(std::move(data));
299 } else {
300 return Client_Hello_13(std::move(data));
301 }
302}
Client_Hello_13(const Policy &policy, Callbacks &cb, RandomNumberGenerator &rng, std::string_view hostname, std::vector< std::string > next_protocols, std::optional< Session_with_Handle > &session, std::vector< ExternalPSK > psks, TLS_Flavor flavor)

References Client_Hello_13(), and parse().

Referenced by parse(), and Botan::TLS::Handshake_Layer::parse_handshake_message().

◆ random()

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

Definition at line 160 of file msg_client_hello.cpp.

160 {
161 return m_data->random();
162}

References m_data.

Referenced by ~Client_Hello().

◆ retry()

void Botan::TLS::Client_Hello_13::retry ( const Hello_Retry_Request & hrr,
const Transcript_Hash_State & transcript_hash_state,
Callbacks & cb,
RandomNumberGenerator & rng )

Definition at line 304 of file msg_client_hello_13.cpp.

307 {
308 BOTAN_STATE_CHECK(m_data->extensions().has<Supported_Groups>());
309 BOTAN_STATE_CHECK(m_data->extensions().has<Key_Share>());
310
311 const auto* hrr_ks = hrr.extensions().get<Key_Share>();
312 const auto& supported_groups = m_data->extensions().get<Supported_Groups>()->groups();
313
314 if(hrr.extensions().has<Key_Share>()) {
315 m_data->extensions().get<Key_Share>()->retry_offer(*hrr_ks, supported_groups, cb, rng);
316 }
317
318 // RFC 8446 4.2.2
319 // When sending the new ClientHello, the client MUST copy
320 // the contents of the extension received in the HelloRetryRequest into
321 // a "cookie" extension in the new ClientHello.
322 //
323 // RFC 8446 4.2.2
324 // Clients MUST NOT use cookies in their initial ClientHello in subsequent
325 // connections.
326 if(hrr.extensions().has<Cookie>()) {
327 BOTAN_STATE_CHECK(!m_data->extensions().has<Cookie>());
328 m_data->extensions().add(new Cookie(hrr.extensions().get<Cookie>()->get_cookie())); // NOLINT(*-owning-memory)
329 }
330
331 // Note: the consumer of the TLS implementation won't be able to distinguish
332 // invocations to this callback due to the first Client_Hello or the
333 // retried Client_Hello after receiving a Hello_Retry_Request. We assume
334 // that the user keeps and detects this state themselves.
335 cb.tls_modify_extensions(m_data->extensions(), Connection_Side::Client, type());
336
337 // Same invariants as in the constructor: the callback must not strip
338 // Supported_Groups or Key_Share
339 if(!m_data->extensions().has<Supported_Groups>()) {
340 throw TLS_Exception(
341 Alert::InternalError,
342 "Application tls_modify_extensions callback removed Supported_Groups from the retried ClientHello");
343 }
344 if(!m_data->extensions().has<Key_Share>()) {
345 throw TLS_Exception(Alert::InternalError,
346 "Application tls_modify_extensions callback removed Key_Share from the retried ClientHello");
347 }
348
349 auto* psk = m_data->extensions().get<PSK>();
350 if(psk != nullptr) {
351 // RFC 8446 4.2.11
352 // The "pre_shared_key" extension MUST be the last extension in the
353 // ClientHello (this facilitates implementation [...]).
354 m_data->extensions().reorder(std::array{Extension_Code::PresharedKey});
355
356 // Cipher suite should always be a known suite as this is checked upstream
357 const auto cipher = Ciphersuite::by_id(hrr.ciphersuite());
358 BOTAN_ASSERT_NOMSG(cipher.has_value());
359
360 // RFC 8446 4.1.4
361 // In [...] its updated ClientHello, the client SHOULD NOT offer
362 // any pre-shared keys associated with a hash other than that of the
363 // selected cipher suite.
364 psk->filter(cipher.value());
365
366 // RFC 8446 4.2.11.2
367 // If the server responds with a HelloRetryRequest and the client
368 // then sends ClientHello2, its binder will be computed over: [...].
369 calculate_psk_binders(transcript_hash_state.clone());
370 }
371}
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:82
static std::optional< Ciphersuite > by_id(uint16_t suite)

References BOTAN_ASSERT_NOMSG, BOTAN_STATE_CHECK, Botan::TLS::Ciphersuite::by_id(), Botan::TLS::Server_Hello::ciphersuite(), Botan::TLS::Client, Botan::TLS::Transcript_Hash_State::clone(), Botan::TLS::Server_Hello::extensions(), Botan::TLS::Extensions::get(), Botan::TLS::Cookie::get_cookie(), Botan::TLS::Extensions::has(), Botan::TLS::Client_Hello::m_data, Botan::TLS::PresharedKey, retry(), Botan::TLS::Callbacks::tls_modify_extensions(), and Botan::TLS::Client_Hello::type().

Referenced by retry().

◆ sent_signature_algorithms()

bool Botan::TLS::Client_Hello::sent_signature_algorithms ( ) const
inherited

Definition at line 294 of file msg_client_hello.cpp.

294 {
295 return m_data->extensions().has<Signature_Algorithms>();
296}

References m_data.

Referenced by ~Client_Hello().

◆ serialize()

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

Serialize this handshake message

Implements Botan::TLS::Handshake_Message.

Definition at line 187 of file msg_client_hello.cpp.

187 {
188 std::vector<uint8_t> buf;
189 buf.reserve(1024); // working around GCC warning
190
191 buf.push_back(m_data->legacy_version().major_version());
192 buf.push_back(m_data->legacy_version().minor_version());
193 buf += m_data->random();
194
195 append_tls_length_value(buf, m_data->session_id().get(), 1);
196
197 if(m_data->legacy_version().is_datagram_protocol()) {
198 append_tls_length_value(buf, m_data->hello_cookie(), 1);
199 }
200
201 append_tls_length_value(buf, m_data->ciphersuites(), 2);
202 append_tls_length_value(buf, m_data->comp_methods(), 1);
203
204 /*
205 * May not want to send extensions at all in some cases. If so,
206 * should include SCSV value (if reneg info is empty, if not we are
207 * renegotiating with a modern server)
208 */
209
210 buf += m_data->extensions().serialize(Connection_Side::Client);
211
212 return buf;
213}
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

References Botan::TLS::append_tls_length_value(), Botan::TLS::Client, and m_data.

Referenced by ~Client_Hello().

◆ session_id()

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

Definition at line 164 of file msg_client_hello.cpp.

164 {
165 return m_data->session_id();
166}

References m_data.

Referenced by Botan::TLS::Client_Hello_12::session_handle(), and ~Client_Hello().

◆ signature_schemes()

std::vector< Signature_Scheme > Botan::TLS::Client_Hello::signature_schemes ( ) const
inherited

Definition at line 229 of file msg_client_hello.cpp.

229 {
230 if(const Signature_Algorithms* sigs = m_data->extensions().get<Signature_Algorithms>()) {
231 return sigs->supported_schemes();
232 }
233 return {};
234}

References m_data.

Referenced by Botan::TLS::Certificate_13::Certificate_13(), certificate_signature_schemes(), Botan::TLS::Handshake_State::choose_sig_format(), and ~Client_Hello().

◆ sni_hostname()

std::string Botan::TLS::Client_Hello::sni_hostname ( ) const
inherited

Definition at line 262 of file msg_client_hello.cpp.

262 {
263 if(const Server_Name_Indicator* sni = m_data->extensions().get<Server_Name_Indicator>()) {
264 return sni->host_name();
265 }
266 return "";
267}

References m_data.

Referenced by Botan::TLS::Certificate_13::Certificate_13(), Botan::TLS::Certificate_Request_13::maybe_create(), and ~Client_Hello().

◆ srtp_profiles()

std::vector< uint16_t > Botan::TLS::Client_Hello::srtp_profiles ( ) const
inherited

Definition at line 305 of file msg_client_hello.cpp.

305 {
306 if(const SRTP_Protection_Profiles* srtp = m_data->extensions().get<SRTP_Protection_Profiles>()) {
307 return srtp->profiles();
308 }
309 return {};
310}

References m_data.

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

◆ supported_dh_groups()

std::vector< Group_Params > Botan::TLS::Client_Hello::supported_dh_groups ( ) const
inherited

Definition at line 255 of file msg_client_hello.cpp.

255 {
256 if(const Supported_Groups* groups = m_data->extensions().get<Supported_Groups>()) {
257 return groups->dh_groups();
258 }
259 return std::vector<Group_Params>();
260}

References m_data.

Referenced by ~Client_Hello().

◆ supported_ecc_curves()

std::vector< Group_Params > Botan::TLS::Client_Hello::supported_ecc_curves ( ) const
inherited

Definition at line 248 of file msg_client_hello.cpp.

248 {
249 if(const Supported_Groups* groups = m_data->extensions().get<Supported_Groups>()) {
250 return groups->ec_groups();
251 }
252 return {};
253}

References m_data.

Referenced by ~Client_Hello().

◆ supported_versions()

std::vector< Protocol_Version > Botan::TLS::Client_Hello::supported_versions ( ) const
inherited

Definition at line 283 of file msg_client_hello.cpp.

283 {
284 if(const Supported_Versions* versions = m_data->extensions().get<Supported_Versions>()) {
285 return versions->versions();
286 }
287 return {};
288}

References m_data.

Referenced by ~Client_Hello().

◆ supports_alpn()

bool Botan::TLS::Client_Hello::supports_alpn ( ) const
inherited

Definition at line 290 of file msg_client_hello.cpp.

290 {
291 return m_data->extensions().has<Application_Layer_Protocol_Notification>();
292}

References m_data.

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

◆ type()

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

◆ 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().

◆ validate_updates()

void Botan::TLS::Client_Hello_13::validate_updates ( const Client_Hello_13 & new_ch)

This validates that a Client Hello received after sending a Hello Retry Request was updated in accordance with RFC 8446 4.1.2. If issues are found, this method throws accordingly.

Definition at line 373 of file msg_client_hello_13.cpp.

373 {
374 // RFC 8446 4.1.2
375 // The client will also send a ClientHello when the server has responded
376 // to its ClientHello with a HelloRetryRequest. In that case, the client
377 // MUST send the same ClientHello without modification, except as follows:
378
379 if(m_data->legacy_version() != new_ch.m_data->legacy_version() ||
380 m_data->session_id() != new_ch.m_data->session_id() || m_data->random() != new_ch.m_data->random() ||
381 m_data->ciphersuites() != new_ch.m_data->ciphersuites() ||
382 m_data->comp_methods() != new_ch.m_data->comp_methods()) {
383 throw TLS_Exception(Alert::IllegalParameter, "Client Hello core values changed after Hello Retry Request");
384 }
385
386 const auto oldexts = extension_types();
387 const auto newexts = new_ch.extension_types();
388
389 // Check that extension omissions are justified. RFC 8446 4.1.2 lists the
390 // only mutations the client may make between CH1 and CH2; any other
391 // extension removal is an illegal parameter regardless of whether the
392 // extension is one this implementation recognizes.
393 for(const auto oldext : oldexts) {
394 if(!newexts.contains(oldext)) {
395 // RFC 8446 4.1.2
396 // Removing the "early_data" extension (Section 4.2.10) if one was
397 // present. Early data is not permitted after a HelloRetryRequest.
398 if(oldext == EarlyDataIndication::static_type()) {
399 continue;
400 }
401
402 // RFC 8446 4.1.2
403 // Optionally adding, removing, or changing the length of the
404 // "padding" extension.
405 if(oldext == Extension_Code::Padding) {
406 continue;
407 }
408
409 // RFC 8446 4.1.2
410 // Updating the "pre_shared_key" extension if present by
411 // recomputing the "obfuscated_ticket_age" and binder values
412 // and (optionally) removing any PSKs which are incompatible
413 // with the server's indicated cipher suite.
414 //
415 // If all PSKs are removed then so is the extension
416 if(oldext == Extension_Code::PresharedKey) {
417 continue;
418 }
419
420 throw TLS_Exception(Alert::IllegalParameter, "Extension removed in updated Client Hello");
421 }
422 }
423
424 // Check that extension additions are justified. Same reasoning: only the
425 // RFC-listed mutations are allowed, including for unknown extension codes.
426 for(const auto newext : newexts) {
427 if(!oldexts.contains(newext)) {
428 // RFC 8446 4.1.2
429 // Including a "cookie" extension if one was provided in the
430 // HelloRetryRequest.
431 if(newext == Cookie::static_type()) {
432 continue;
433 }
434
435 // RFC 8446 4.1.2
436 // Optionally adding, removing, or changing the length of the
437 // "padding" extension.
438 if(newext == Extension_Code::Padding) {
439 continue;
440 }
441
442 throw TLS_Exception(Alert::UnsupportedExtension, "Added an extension in updated Client Hello");
443 }
444 }
445
446 // RFC 8446 4.1.2
447 // Removing the "early_data" extension (Section 4.2.10) if one was
448 // present. Early data is not permitted after a HelloRetryRequest.
449 if(new_ch.extensions().has<EarlyDataIndication>()) {
450 throw TLS_Exception(Alert::IllegalParameter, "Updated Client Hello indicates early data");
451 }
452
453 // RFC 8446 4.1.2
454 // The client MUST send the same ClientHello without modification,
455 // except as follows: [key_share, pre_shared_key, early_data, cookie, padding]
456 //
457 // Verify that extensions whose content must not change between the
458 // initial and retried Client Hello have identical wire encodings.
459 const std::set<Extension_Code> extensions_allowed_to_change = {
465 };
466
467 // As quoted above, PSKs may only be removed. Their identities must
468 // otherwise be retained in the same order.
469 const auto* old_psk = extensions().get<PSK>();
470 const auto* new_psk = new_ch.extensions().get<PSK>();
471 if(old_psk != nullptr && new_psk != nullptr) {
472 old_psk->validate_updates(*new_psk);
473 }
474
475 for(const auto ext_type : oldexts) {
476 if(extensions_allowed_to_change.contains(ext_type)) {
477 continue;
478 }
479
480 const auto old_bytes = extensions().extension_raw_bytes(ext_type);
481 const auto new_bytes = new_ch.extensions().extension_raw_bytes(ext_type);
482
483 // Both Client Hellos validated here are received from the peer and went
484 // through Extensions::deserialize, which records raw bytes for every
485 // parsed extension. A missing raw_bytes on either side would mean an
486 // extension was added by us programmatically - which shouldn't happen
487 BOTAN_ASSERT_NOMSG(old_bytes.has_value() && new_bytes.has_value());
488 if(old_bytes.value() != new_bytes.value()) {
489 throw TLS_Exception(Alert::IllegalParameter, "Extension content changed in updated Client Hello");
490 }
491 }
492}
const Extensions & extensions() const
std::set< Extension_Code > extension_types() const
static Extension_Code static_type()
static Extension_Code static_type()
std::optional< std::vector< uint8_t > > extension_raw_bytes(Extension_Code type) const

References BOTAN_ASSERT_NOMSG, Client_Hello_13(), Botan::TLS::Cookie, Botan::TLS::EarlyData, Botan::TLS::Extensions::extension_raw_bytes(), Botan::TLS::Client_Hello::extension_types(), Botan::TLS::Client_Hello::extensions(), Botan::TLS::Extensions::get(), Botan::TLS::Extensions::has(), Botan::TLS::KeyShare, Botan::TLS::Client_Hello::m_data, Botan::TLS::Padding, Botan::TLS::PresharedKey, Botan::TLS::Cookie::static_type(), Botan::TLS::EarlyDataIndication::static_type(), and validate_updates().

Referenced by validate_updates().

◆ 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: