Botan 3.4.0
Crypto and TLS for C&
tls_client_impl_13.cpp
Go to the documentation of this file.
1/*
2* TLS Client - implementation for TLS 1.3
3* (C) 2022 Jack Lloyd
4* 2021 Elektrobit Automotive GmbH
5* 2022 Hannes Rantzsch, René Meusel - neXenio GmbH
6*
7* Botan is released under the Simplified BSD License (see license.txt)
8*/
9#include <botan/internal/tls_client_impl_13.h>
10
11#include <botan/credentials_manager.h>
12#include <botan/hash.h>
13#include <botan/tls_client.h>
14#include <botan/tls_messages.h>
15#include <botan/types.h>
16#include <botan/internal/stl_util.h>
17#include <botan/internal/tls_channel_impl_13.h>
18#include <botan/internal/tls_cipher_state.h>
19
20#include <iterator>
21#include <utility>
22
23namespace Botan::TLS {
24
25Client_Impl_13::Client_Impl_13(const std::shared_ptr<Callbacks>& callbacks,
26 const std::shared_ptr<Session_Manager>& session_manager,
27 const std::shared_ptr<Credentials_Manager>& creds,
28 const std::shared_ptr<const Policy>& policy,
29 const std::shared_ptr<RandomNumberGenerator>& rng,
31 const std::vector<std::string>& next_protocols) :
32 Channel_Impl_13(callbacks, session_manager, creds, rng, policy, false /* is_server */),
33 m_info(std::move(info)),
34 m_should_send_ccs(false) {
35#if defined(BOTAN_HAS_TLS_12)
36 if(policy->allow_tls12()) {
37 expect_downgrade(m_info, next_protocols);
38 }
39#endif
40
41 if(auto session = find_session_for_resumption()) {
42 if(!session->session.version().is_pre_tls_13()) {
43 m_resumed_session = std::move(session);
44 } else if(expects_downgrade()) {
45 // If we found a session that was created with TLS 1.2, we downgrade
46 // the implementation right away, before even issuing a Client Hello.
47 request_downgrade_for_resumption(std::move(session.value()));
48 return;
49 }
50 }
51
52 auto msg = send_handshake_message(m_handshake_state.sending(
54 *callbacks,
55 *rng,
56 m_info.hostname(),
57 next_protocols,
58 m_resumed_session,
59 creds->find_preshared_keys(m_info.hostname(), Connection_Side::Client))));
60
61 if(expects_downgrade()) {
63 }
64
65 // RFC 8446 Appendix D.4
66 // If not offering early data, the client sends a dummy change_cipher_spec
67 // record [...] immediately before its second flight. This may either be before
68 // its second ClientHello or before its encrypted handshake flight.
69 //
70 // TODO: don't schedule ccs here when early data is used
72 m_should_send_ccs = true;
73 }
74
76}
77
78void Client_Impl_13::process_handshake_msg(Handshake_Message_13 message) {
79 std::visit(
80 [&](auto msg) {
81 // first verify that the message was expected by the state machine...
82 m_transitions.confirm_transition_to(msg.get().type());
83
84 // ... then allow the library user to abort on their discretion
86
87 // ... finally handle the message
88 handle(msg.get());
89 },
90 m_handshake_state.received(std::move(message)));
91}
92
93void Client_Impl_13::process_post_handshake_msg(Post_Handshake_Message_13 message) {
95
96 std::visit([&](auto msg) { handle(msg); }, m_handshake_state.received(std::move(message)));
97}
98
99void Client_Impl_13::process_dummy_change_cipher_spec() {
100 // RFC 8446 5.
101 // If an implementation detects a change_cipher_spec record received before
102 // the first ClientHello message or after the peer's Finished message, it MUST be
103 // treated as an unexpected record type [("unexpected_message" alert)].
104 if(!m_handshake_state.has_client_hello() || m_handshake_state.has_server_finished()) {
105 throw TLS_Exception(Alert::UnexpectedMessage, "Received an unexpected dummy Change Cipher Spec");
106 }
107
108 // RFC 8446 5.
109 // An implementation may receive an unencrypted record of type change_cipher_spec [...]
110 // at any time after the first ClientHello message has been sent or received
111 // and before the peer's Finished message has been received [...]
112 // and MUST simply drop it without further processing.
113 //
114 // ... no further processing.
115}
116
118 return m_handshake_state.handshake_finished();
119}
120
121std::optional<Session_with_Handle> Client_Impl_13::find_session_for_resumption() {
122 // RFC 8446 4.6.1
123 // Clients MUST only resume if the new SNI value is valid for the
124 // server certificate presented in the original session and SHOULD only
125 // resume if the SNI value matches the one used in the original session.
126 //
127 // Below we search sessions based on their SNI value. Assuming that a
128 // 3rd party session manager does not lie to the implementation, we don't
129 // explicitly re-check that the SNI values match.
130 //
131 // Also, the default implementation did verify that very same SNI information
132 // against the server's certificate (via Callbacks::tls_verify_cert_chain())
133 // before storing it in the session.
134 //
135 // We therefore assume that the session returned by the `Session_Manager` is
136 // suitable for resumption in this context.
137 auto sessions = session_manager().find(m_info, callbacks(), policy());
138 if(sessions.empty()) {
139 return std::nullopt;
140 }
141
142 // TODO: TLS 1.3 allows sending more than one ticket (for resumption) in a
143 // Client Hello. Currently, we do not support that. The Session_Manager
144 // does imply otherwise with its API, though.
145 auto& session_to_resume = sessions.front();
146
147 return std::move(session_to_resume);
148}
149
150void Client_Impl_13::handle(const Server_Hello_12& server_hello_msg) {
151 if(m_handshake_state.has_hello_retry_request()) {
152 throw TLS_Exception(Alert::UnexpectedMessage, "Version downgrade received after Hello Retry");
153 }
154
155 // RFC 8446 Appendix D.1
156 // If the version chosen by the server is not supported by the client
157 // (or is not acceptable), the client MUST abort the handshake with a
158 // "protocol_version" alert.
159 if(!expects_downgrade()) {
160 throw TLS_Exception(Alert::ProtocolVersion, "Received an unexpected legacy Server Hello");
161 }
162
163 // RFC 8446 4.1.3
164 // TLS 1.3 has a downgrade protection mechanism embedded in the server's
165 // random value. TLS 1.3 servers which negotiate TLS 1.2 or below in
166 // response to a ClientHello MUST set the last 8 bytes of their Random
167 // value specially in their ServerHello.
168 //
169 // TLS 1.3 clients receiving a ServerHello indicating TLS 1.2 or below
170 // MUST check that the [downgrade indication is not set]. [...] If a match
171 // is found, the client MUST abort the handshake with an
172 // "illegal_parameter" alert.
173 if(server_hello_msg.random_signals_downgrade().has_value()) {
174 throw TLS_Exception(Alert::IllegalParameter, "Downgrade attack detected");
175 }
176
177 // RFC 8446 4.2.1
178 // A server which negotiates a version of TLS prior to TLS 1.3 [...]
179 // MUST NOT send the "supported_versions" extension.
180 //
181 // Note that this condition should never happen, as the Server_Hello parsing
182 // code decides to create a Server_Hello_12 based on the absense of this extension.
183 if(server_hello_msg.extensions().has<Supported_Versions>()) {
184 throw TLS_Exception(Alert::IllegalParameter, "Unexpected extension received");
185 }
186
187 // RFC 8446 Appendix D.1
188 // If the version chosen by the server is not supported by the client
189 // (or is not acceptable), the client MUST abort the handshake with a
190 // "protocol_version" alert.
191 const auto& client_hello_exts = m_handshake_state.client_hello().extensions();
192 BOTAN_ASSERT_NOMSG(client_hello_exts.has<Supported_Versions>());
193 if(!client_hello_exts.get<Supported_Versions>()->supports(server_hello_msg.selected_version())) {
194 throw TLS_Exception(Alert::ProtocolVersion, "Protocol version was not offered");
195 }
196
197 if(policy().tls_13_middlebox_compatibility_mode() &&
198 m_handshake_state.client_hello().session_id() == server_hello_msg.session_id()) {
199 // In compatibility mode, the server will reflect the session ID we sent in the client hello.
200 // However, a TLS 1.2 server that wants to downgrade cannot have found the random session ID
201 // we sent. Therefore, we have to consider this as an attack.
202 // (Thanks BoGo test EchoTLS13CompatibilitySessionID!)
203 throw TLS_Exception(Alert::IllegalParameter, "Unexpected session ID during downgrade");
204 }
205
207
208 // After this, no further messages are expected here because this instance will be replaced
209 // by a Client_Impl_12.
210 m_transitions.set_expected_next({});
211}
212
213namespace {
214// validate Server_Hello_13 and Hello_Retry_Request
215void validate_server_hello_ish(const Client_Hello_13& ch, const Server_Hello_13& sh) {
216 // RFC 8446 4.1.3
217 // A client which receives a legacy_session_id_echo field that does not match what
218 // it sent in the ClientHello MUST abort the handshake with an "illegal_parameter" alert.
219 if(ch.session_id() != sh.session_id()) {
220 throw TLS_Exception(Alert::IllegalParameter, "echoed session id did not match");
221 }
222
223 // RFC 8446 4.1.3
224 // A client which receives a cipher suite that was not offered MUST abort the handshake
225 // with an "illegal_parameter" alert.
226 if(!ch.offered_suite(sh.ciphersuite())) {
227 throw TLS_Exception(Alert::IllegalParameter, "Server replied with ciphersuite we didn't send");
228 }
229
230 // RFC 8446 4.2.1
231 // If the "supported_versions" extension in the ServerHello contains a
232 // version not offered by the client or contains a version prior to
233 // TLS 1.3, the client MUST abort the handshake with an "illegal_parameter" alert.
234 //
235 // Note: Server_Hello_13 parsing checks that its selected version is TLS 1.3
236 BOTAN_ASSERT_NOMSG(ch.extensions().has<Supported_Versions>());
237 if(!ch.extensions().get<Supported_Versions>()->supports(sh.selected_version())) {
238 throw TLS_Exception(Alert::IllegalParameter, "Protocol version was not offered");
239 }
240}
241} // namespace
242
243void Client_Impl_13::handle(const Server_Hello_13& sh) {
244 // Note: Basic checks (that do not require contextual information) were already
245 // performed during the construction of the Server_Hello_13 object.
246
247 const auto& ch = m_handshake_state.client_hello();
248
249 validate_server_hello_ish(ch, sh);
250
251 // RFC 8446 4.2
252 // Implementations MUST NOT send extension responses if the remote
253 // endpoint did not send the corresponding extension requests, [...]. Upon
254 // receiving such an extension, an endpoint MUST abort the handshake
255 // with an "unsupported_extension" alert.
256 if(sh.extensions().contains_other_than(ch.extensions().extension_types())) {
257 throw TLS_Exception(Alert::UnsupportedExtension, "Unsupported extension found in Server Hello");
258 }
259
260 if(m_handshake_state.has_hello_retry_request()) {
261 const auto& hrr = m_handshake_state.hello_retry_request();
262
263 // RFC 8446 4.1.4
264 // Upon receiving the ServerHello, clients MUST check that the cipher suite
265 // supplied in the ServerHello is the same as that in the HelloRetryRequest
266 // and otherwise abort the handshake with an "illegal_parameter" alert.
267 if(hrr.ciphersuite() != sh.ciphersuite()) {
268 throw TLS_Exception(Alert::IllegalParameter, "server changed its chosen ciphersuite");
269 }
270
271 // RFC 8446 4.1.4
272 // The value of selected_version in the HelloRetryRequest "supported_versions"
273 // extension MUST be retained in the ServerHello, and a client MUST abort the
274 // handshake with an "illegal_parameter" alert if the value changes.
275 if(hrr.selected_version() != sh.selected_version()) {
276 throw TLS_Exception(Alert::IllegalParameter, "server changed its chosen protocol version");
277 }
278 }
279
280 auto cipher = Ciphersuite::by_id(sh.ciphersuite());
281 BOTAN_ASSERT_NOMSG(cipher.has_value()); // should work, since we offered this suite
282
283 // RFC 8446 Appendix B.4
284 // Although TLS 1.3 uses the same cipher suite space as previous versions
285 // of TLS [...] cipher suites for TLS 1.2 and lower cannot be used with
286 // TLS 1.3.
287 if(!cipher->usable_in_version(Protocol_Version::TLS_V13)) {
288 throw TLS_Exception(Alert::IllegalParameter,
289 "Server replied using a ciphersuite not allowed in version it offered");
290 }
291
292 // RFC 8446 4.2.11
293 // Clients MUST verify that [...] a server "key_share" extension is present
294 // if required by the ClientHello "psk_key_exchange_modes" extension. If
295 // these values are not consistent, the client MUST abort the handshake
296 // with an "illegal_parameter" alert.
297 //
298 // Currently, we don't support PSK-only mode, hence a key share extension is
299 // considered mandatory.
300 //
301 // TODO: Implement PSK-only mode.
302 if(!sh.extensions().has<Key_Share>()) {
303 throw TLS_Exception(Alert::IllegalParameter, "Server Hello did not contain a key share extension");
304 }
305
306 auto my_keyshare = ch.extensions().get<Key_Share>();
307 auto shared_secret = my_keyshare->decapsulate(*sh.extensions().get<Key_Share>(), policy(), callbacks(), rng());
308
309 m_transcript_hash.set_algorithm(cipher.value().prf_algo());
310
311 if(sh.extensions().has<PSK>()) {
312 std::tie(m_psk_identity, m_cipher_state) =
313 ch.extensions().get<PSK>()->take_selected_psk_info(*sh.extensions().get<PSK>(), cipher.value());
314
315 // If we offered a session for resumption *and* an externally provided PSK
316 // and the latter was chosen by the server over the offered resumption, we
317 // want to invalidate the now-outdated session in m_resumed_session.
318 if(m_psk_identity.has_value() && m_resumed_session.has_value()) {
319 m_resumed_session.reset();
320 }
321
322 // TODO: When implementing early data, `advance_with_client_hello` must
323 // happen _before_ encrypting any early application data.
324 // Same when we want to support early key export.
325 m_cipher_state->advance_with_client_hello(m_transcript_hash.previous());
326 m_cipher_state->advance_with_server_hello(cipher.value(), std::move(shared_secret), m_transcript_hash.current());
327 } else {
328 m_resumed_session.reset(); // might have been set if we attempted a resumption
330 m_side, std::move(shared_secret), cipher.value(), m_transcript_hash.current());
331 }
332
334
336}
337
338void Client_Impl_13::handle(const Hello_Retry_Request& hrr) {
339 // Note: Basic checks (that do not require contextual information) were already
340 // performed during the construction of the Hello_Retry_Request object as
341 // a subclass of Server_Hello_13.
342
343 auto& ch = m_handshake_state.client_hello();
344
345 validate_server_hello_ish(ch, hrr);
346
347 // RFC 8446 4.1.4.
348 // A HelloRetryRequest MUST NOT contain any
349 // extensions that were not first offered by the client in its
350 // ClientHello, with the exception of optionally the "cookie".
351 auto allowed_exts = ch.extensions().extension_types();
352 allowed_exts.insert(Extension_Code::Cookie);
353 if(hrr.extensions().contains_other_than(allowed_exts)) {
354 throw TLS_Exception(Alert::UnsupportedExtension, "Unsupported extension found in Hello Retry Request");
355 }
356
357 auto cipher = Ciphersuite::by_id(hrr.ciphersuite());
358 BOTAN_ASSERT_NOMSG(cipher.has_value()); // should work, since we offered this suite
359
362
363 ch.retry(hrr, m_transcript_hash, callbacks(), rng());
364
366
367 send_handshake_message(std::reference_wrapper(ch));
368
369 // RFC 8446 4.1.4
370 // If a client receives a second HelloRetryRequest in the same connection [...],
371 // it MUST abort the handshake with an "unexpected_message" alert.
373}
374
375void Client_Impl_13::handle(const Encrypted_Extensions& encrypted_extensions_msg) {
376 const auto& exts = encrypted_extensions_msg.extensions();
377
378 // RFC 8446 4.2
379 // Implementations MUST NOT send extension responses if the remote
380 // endpoint did not send the corresponding extension requests, [...]. Upon
381 // receiving such an extension, an endpoint MUST abort the handshake
382 // with an "unsupported_extension" alert.
383 const auto& requested_exts = m_handshake_state.client_hello().extensions().extension_types();
384 if(exts.contains_other_than(requested_exts)) {
385 throw TLS_Exception(Alert::UnsupportedExtension,
386 "Encrypted Extensions contained an extension that was not offered");
387 }
388
389 // Note: As per RFC 6066 3. we can check for an empty SNI extensions to
390 // determine if the server used the SNI we sent here.
391
392 if(exts.has<Record_Size_Limit>() && m_handshake_state.client_hello().extensions().has<Record_Size_Limit>()) {
393 // RFC 8449 4.
394 // The record size limit only applies to records sent toward the
395 // endpoint that advertises the limit. An endpoint can send records
396 // that are larger than the limit it advertises as its own limit.
397 //
398 // Hence, the "outgoing" limit is what the server requested and the
399 // "incoming" limit is what we requested in the Client Hello.
400 const auto outgoing_limit = exts.get<Record_Size_Limit>();
401 const auto incoming_limit = m_handshake_state.client_hello().extensions().get<Record_Size_Limit>();
402 set_record_size_limits(outgoing_limit->limit(), incoming_limit->limit());
403 }
404
405 if(exts.has<Server_Certificate_Type>() &&
406 m_handshake_state.client_hello().extensions().has<Server_Certificate_Type>()) {
407 const auto* server_cert_type = exts.get<Server_Certificate_Type>();
408 const auto* our_server_cert_types = m_handshake_state.client_hello().extensions().get<Server_Certificate_Type>();
409 our_server_cert_types->validate_selection(*server_cert_type);
410
411 // RFC 7250 4.2
412 // With the server_certificate_type extension in the server hello, the
413 // TLS server indicates the certificate type carried in the Certificate
414 // payload.
415 //
416 // Note: TLS 1.3 carries this extension in the Encrypted Extensions
417 // message instead of the Server Hello.
418 set_selected_certificate_type(server_cert_type->selected_certificate_type());
419 }
420
422
423 if(m_handshake_state.server_hello().extensions().has<PSK>()) {
424 // RFC 8446 2.2
425 // As the server is authenticating via a PSK, it does not send a
426 // Certificate or a CertificateVerify message.
428 } else {
430 }
431}
432
433void Client_Impl_13::handle(const Certificate_Request_13& certificate_request_msg) {
434 // RFC 8446 4.3.2
435 // [The 'context' field] SHALL be zero length unless used for the
436 // post-handshake authentication exchanges described in Section 4.6.2.
437 if(!is_handshake_complete() && !certificate_request_msg.context().empty()) {
438 throw TLS_Exception(Alert::DecodeError, "Certificate_Request context must be empty in the main handshake");
439 }
440
442 certificate_request_msg.extensions(), Connection_Side::Server, Handshake_Type::CertificateRequest);
444}
445
446void Client_Impl_13::handle(const Certificate_13& certificate_msg) {
447 // RFC 8446 4.4.2
448 // certificate_request_context: [...] In the case of server authentication,
449 // this field SHALL be zero length.
450 if(!certificate_msg.request_context().empty()) {
451 throw TLS_Exception(Alert::DecodeError, "Received a server certificate message with non-empty request context");
452 }
453
454 // RFC 8446 4.4.2
455 // Extensions in the Certificate message from the server MUST correspond
456 // to ones from the ClientHello message.
457 certificate_msg.validate_extensions(m_handshake_state.client_hello().extensions().extension_types(), callbacks());
458 certificate_msg.verify(callbacks(),
459 policy(),
461 m_info.hostname(),
462 m_handshake_state.client_hello().extensions().has<Certificate_Status_Request>());
463
465}
466
467void Client_Impl_13::handle(const Certificate_Verify_13& certificate_verify_msg) {
468 // RFC 8446 4.4.3
469 // If the CertificateVerify message is sent by a server, the signature
470 // algorithm MUST be one offered in the client's "signature_algorithms"
471 // extension unless no valid certificate chain can be produced without
472 // unsupported algorithms.
473 //
474 // Note: if the server failed to produce a certificate chain without using
475 // an unsupported signature scheme, we opt to abort the handshake.
476 const auto offered = m_handshake_state.client_hello().signature_schemes();
477 if(!value_exists(offered, certificate_verify_msg.signature_scheme())) {
478 throw TLS_Exception(Alert::IllegalParameter,
479 "We did not offer the usage of " + certificate_verify_msg.signature_scheme().to_string() +
480 " as a signature scheme");
481 }
482
483 bool sig_valid = certificate_verify_msg.verify(
485
486 if(!sig_valid) {
487 throw TLS_Exception(Alert::DecryptError, "Server certificate verification failed");
488 }
489
491}
492
493void Client_Impl_13::send_client_authentication(Channel_Impl_13::AggregatedHandshakeMessages& flight) {
494 BOTAN_ASSERT_NOMSG(m_handshake_state.has_certificate_request());
495 const auto& cert_request = m_handshake_state.certificate_request();
496
497 const auto cert_type = [&] {
498 const auto& exts = m_handshake_state.encrypted_extensions().extensions();
499 const auto& chexts = m_handshake_state.client_hello().extensions();
500 if(exts.has<Client_Certificate_Type>() && chexts.has<Client_Certificate_Type>()) {
501 const auto* client_cert_type = exts.get<Client_Certificate_Type>();
502 chexts.get<Client_Certificate_Type>()->validate_selection(*client_cert_type);
503
504 // RFC 7250 4.2
505 // This client_certificate_type extension in the server hello then
506 // indicates the type of certificates the client is requested to
507 // provide in a subsequent certificate payload.
508 //
509 // Note: TLS 1.3 carries this extension in the Encrypted Extensions
510 // message instead of the Server Hello.
511 return client_cert_type->selected_certificate_type();
512 } else {
513 // RFC 8446 4.4.2
514 // If the corresponding certificate type extension [...] was not
515 // negotiated in EncryptedExtensions, [...] then each
516 // CertificateEntry contains a DER-encoded X.509 certificate.
518 }
519 }();
520
521 // RFC 8446 4.4.2
522 // certificate_request_context: If this message is in response to a
523 // CertificateRequest, the value of certificate_request_context in
524 // that message.
525 flight.add(m_handshake_state.sending(
526 Certificate_13(cert_request, m_info.hostname(), credentials_manager(), callbacks(), cert_type)));
527
528 // RFC 8446 4.4.2
529 // If the server requests client authentication but no suitable certificate
530 // is available, the client MUST send a Certificate message containing no
531 // certificates.
532 //
533 // In that case, no Certificate Verify message will be sent.
534 if(!m_handshake_state.client_certificate().empty()) {
535 flight.add(m_handshake_state.sending(Certificate_Verify_13(m_handshake_state.client_certificate(),
536 cert_request.signature_schemes(),
537 m_info.hostname(),
541 policy(),
542 callbacks(),
543 rng())));
544 }
545}
546
547void Client_Impl_13::handle(const Finished_13& finished_msg) {
548 // RFC 8446 4.4.4
549 // Recipients of Finished messages MUST verify that the contents are
550 // correct and if incorrect MUST terminate the connection with a
551 // "decrypt_error" alert.
552 if(!finished_msg.verify(m_cipher_state.get(), m_transcript_hash.previous())) {
553 throw TLS_Exception(Alert::DecryptError, "Finished message didn't verify");
554 }
555
556 // Give the application a chance for a final veto before fully
557 // establishing the connection.
558 callbacks().tls_session_established(Session_Summary(m_handshake_state.server_hello(),
563 m_resumed_session.has_value(),
564 m_info,
565 callbacks().tls_current_timestamp()));
566
567 // Derives the secrets for receiving application data but defers
568 // the derivation of sending application data.
569 m_cipher_state->advance_with_server_finished(m_transcript_hash.current());
570
571 auto flight = aggregate_handshake_messages();
572
573 // RFC 8446 4.4.2
574 // The client MUST send a Certificate message if and only if the server
575 // has requested client authentication via a CertificateRequest message.
576 if(m_handshake_state.has_certificate_request()) {
577 send_client_authentication(flight);
578 }
579
580 // send client finished handshake message (still using handshake traffic secrets)
581 flight.add(m_handshake_state.sending(Finished_13(m_cipher_state.get(), m_transcript_hash.current())));
582
583 flight.send();
584
585 // derives the sending application traffic secrets
586 m_cipher_state->advance_with_client_finished(m_transcript_hash.current());
587
588 // TODO: Create a dummy session object and invoke tls_session_established.
589 // Alternatively, consider changing the expectations described in the
590 // callback's doc string.
591
592 // no more handshake messages expected
593 m_transitions.set_expected_next({});
594
596}
597
598void TLS::Client_Impl_13::handle(const New_Session_Ticket_13& new_session_ticket) {
599 callbacks().tls_examine_extensions(
600 new_session_ticket.extensions(), Connection_Side::Server, Handshake_Type::NewSessionTicket);
601
602 Session session(m_cipher_state->psk(new_session_ticket.nonce()),
603 new_session_ticket.early_data_byte_limit(),
604 new_session_ticket.ticket_age_add(),
605 new_session_ticket.lifetime_hint(),
606 m_handshake_state.server_hello().selected_version(),
607 m_handshake_state.server_hello().ciphersuite(),
609 peer_cert_chain(),
610 peer_raw_public_key(),
611 m_info,
612 callbacks().tls_current_timestamp());
613
614 if(callbacks().tls_should_persist_resumption_information(session)) {
615 session_manager().store(session, new_session_ticket.handle());
616 }
617}
618
619std::vector<X509_Certificate> Client_Impl_13::peer_cert_chain() const {
620 if(m_handshake_state.has_server_certificate_msg() &&
621 m_handshake_state.server_certificate().has_certificate_chain()) {
622 return m_handshake_state.server_certificate().cert_chain();
623 }
624
625 if(m_resumed_session.has_value()) {
626 return m_resumed_session->session.peer_certs();
627 }
628
629 return {};
630}
631
632std::shared_ptr<const Public_Key> Client_Impl_13::peer_raw_public_key() const {
633 if(m_handshake_state.has_server_certificate_msg() && m_handshake_state.server_certificate().is_raw_public_key()) {
634 return m_handshake_state.server_certificate().public_key();
635 }
636
637 if(m_resumed_session.has_value()) {
638 return m_resumed_session->session.peer_raw_public_key();
639 }
640
641 return nullptr;
642}
643
644std::optional<std::string> Client_Impl_13::external_psk_identity() const {
645 return m_psk_identity;
646}
647
648bool Client_Impl_13::prepend_ccs() {
649 return std::exchange(m_should_send_ccs, false); // test-and-set
650}
651
654 const auto& eee = m_handshake_state.encrypted_extensions().extensions();
656 return eee.get<Application_Layer_Protocol_Notification>()->single_protocol();
657 }
658 }
659
660 return "";
661}
662
663} // namespace Botan::TLS
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:59
#define BOTAN_STATE_CHECK(expr)
Definition assert.h:41
virtual void tls_session_established(const Session_Summary &session)
virtual void tls_session_activated()
virtual void tls_examine_extensions(const Extensions &extn, Connection_Side which_side, Handshake_Type which_message)
virtual void tls_inspect_handshake_msg(const Handshake_Message &message)
std::shared_ptr< const Public_Key > public_key() const
std::vector< X509_Certificate > cert_chain() const
const Policy & policy() const
void expect_downgrade(const Server_Information &server_info, const std::vector< std::string > &next_protocols)
AggregatedHandshakeMessages aggregate_handshake_messages()
Credentials_Manager & credentials_manager()
RandomNumberGenerator & rng()
std::vector< uint8_t > send_handshake_message(const std::variant< MsgTs... > &message)
Transcript_Hash_State m_transcript_hash
Session_Manager & session_manager()
std::unique_ptr< Cipher_State > m_cipher_state
void set_selected_certificate_type(Certificate_Type cert_type)
void set_record_size_limits(uint16_t outgoing_limit, uint16_t incoming_limit)
void request_downgrade_for_resumption(Session_with_Handle session)
void preserve_client_hello(std::span< const uint8_t > msg)
static std::unique_ptr< Cipher_State > init_with_server_hello(Connection_Side side, secure_vector< uint8_t > &&shared_secret, const Ciphersuite &cipher, const Transcript_Hash &transcript_hash)
static std::optional< Ciphersuite > by_id(uint16_t suite)
std::vector< Signature_Scheme > signature_schemes() const
const Extensions & extensions() const
const Session_ID & session_id() const
Client_Impl_13(const std::shared_ptr< Callbacks > &callbacks, const std::shared_ptr< Session_Manager > &session_manager, const std::shared_ptr< Credentials_Manager > &creds, const std::shared_ptr< const Policy > &policy, const std::shared_ptr< RandomNumberGenerator > &rng, Server_Information server_info=Server_Information(), const std::vector< std::string > &next_protocols={})
std::optional< std::string > external_psk_identity() const override
std::string application_protocol() const override
std::shared_ptr< const Public_Key > peer_raw_public_key() const override
bool is_handshake_complete() const override
std::vector< X509_Certificate > peer_cert_chain() const override
const Extensions & extensions() const
std::set< Extension_Code > extension_types() const
std::reference_wrapper< MsgT > sending(MsgT msg)
decltype(auto) received(Handshake_Message_13 message)
void confirm_transition_to(Handshake_Type msg_type)
void set_expected_next(Handshake_Type msg_type)
const Hello_Retry_Request & hello_retry_request() const
const Certificate_Request_13 & certificate_request() const
const Encrypted_Extensions & encrypted_extensions() const
virtual bool allow_tls12() const
virtual bool tls_13_middlebox_compatibility_mode() const
const Extensions & extensions() const
virtual std::vector< Session_with_Handle > find(const Server_Information &info, Callbacks &callbacks, const Policy &policy)
Find all sessions that match a given server info.
const Transcript_Hash & current() const
static Transcript_Hash_State recreate_after_hello_retry_request(std::string_view algo_spec, const Transcript_Hash_State &prev_transcript_hash_state)
void set_algorithm(std::string_view algo_spec)
const Transcript_Hash & previous() const
std::variant< New_Session_Ticket_13, Key_Update > Post_Handshake_Message_13
std::variant< Client_Hello_13, Client_Hello_12, Server_Hello_13, Server_Hello_12, Hello_Retry_Request, Encrypted_Extensions, Certificate_13, Certificate_Request_13, Certificate_Verify_13, Finished_13 > Handshake_Message_13
bool value_exists(const std::vector< T > &vec, const OT &val)
Definition stl_util.h:118