9#include <botan/internal/tls_server_impl_12.h>
11#include <botan/certstor.h>
12#include <botan/ec_group.h>
13#include <botan/ecc_key.h>
14#include <botan/ocsp.h>
15#include <botan/tls_callbacks.h>
16#include <botan/tls_magic.h>
17#include <botan/tls_messages_12.h>
18#include <botan/tls_policy.h>
19#include <botan/tls_version.h>
20#include <botan/internal/ct_utils.h>
21#include <botan/internal/stl_util.h>
22#include <botan/internal/tls_handshake_state.h>
23#include <botan/internal/tls_messages_internal.h>
27#include <unordered_set>
34 Server_Handshake_State(std::unique_ptr<Handshake_IO> io, Callbacks& cb) :
Handshake_State(std::move(io), cb) {}
36 Private_Key* server_rsa_kex_key() {
return m_server_rsa_kex_key.get(); }
38 void set_server_rsa_kex_key(std::shared_ptr<Private_Key> key) { m_server_rsa_kex_key = std::move(key); }
40 bool allow_session_resumption()
const {
return m_allow_session_resumption; }
42 void set_allow_session_resumption(
bool allow_session_resumption) {
43 m_allow_session_resumption = allow_session_resumption;
46 const std::vector<X509_Certificate>& resume_peer_certs()
const {
return m_resume_peer_certs; }
48 void set_resume_certs(
const std::vector<X509_Certificate>& certs) { m_resume_peer_certs = certs; }
50 void mark_as_resumption() { m_is_a_resumption =
true; }
53 void mark_as_server_initiated() { m_server_initiated =
true; }
55 bool is_server_initiated()
const {
return m_server_initiated; }
57 bool is_a_resumption()
const {
return m_is_a_resumption; }
59 void set_resumption_summary(Session_Summary summary) { m_resumption_summary = std::move(summary); }
61 std::optional<Session_Summary> take_resumption_summary() {
return std::exchange(m_resumption_summary, {}); }
64 if(!m_resume_peer_certs.empty()) {
65 return m_resume_peer_certs;
75 std::shared_ptr<Private_Key> m_server_rsa_kex_key;
81 bool m_allow_session_resumption =
true;
83 bool m_is_a_resumption =
false;
85 bool m_server_initiated =
false;
87 std::vector<X509_Certificate> m_resume_peer_certs;
90 std::optional<Session_Summary> m_resumption_summary;
99uint32_t ticket_lifetime_hint(
const Policy& policy) {
100 const auto lifetime = policy.session_ticket_lifetime().count();
104 return static_cast<uint32_t
>(std::min<std::chrono::seconds::rep>(lifetime, std::numeric_limits<uint32_t>::max()));
107std::optional<Session> check_for_resume(
const Session_Handle& handle_to_resume,
112 auto session = session_manager.retrieve(handle_to_resume, cb, policy);
113 if(!session.has_value()) {
123 "Session manager returned a session stored by a TLS client for server-side resumption");
127 if(client_hello->legacy_version() != session->version()) {
132 if(!
value_exists(client_hello->ciphersuites(), session->ciphersuite_code())) {
137 if(!
value_exists(policy.ciphersuite_list(session->version()), session->ciphersuite_code())) {
142 if(!client_hello->sni_hostname().empty() && client_hello->sni_hostname() != session->server_info().hostname()) {
149 if(policy.require_client_certificate_authentication() && !session->peer_credential_type().has_value()) {
154 if(client_hello->supports_extended_master_secret() != session->supports_extended_master_secret()) {
155 if(!session->supports_extended_master_secret()) {
162 throw TLS_Exception(Alert::HandshakeFailure,
"Client resumed extended ms session without sending extension");
167 if(!client_hello->supports_encrypt_then_mac() && session->supports_encrypt_then_mac()) {
172 throw TLS_Exception(Alert::HandshakeFailure,
"Client resumed Encrypt-then-MAC session without sending extension");
177 if(
const uint16_t srtp_profile = session->dtls_srtp_profile()) {
178 if(!
value_exists(client_hello->srtp_profiles(), srtp_profile) ||
190uint16_t choose_ciphersuite(
const Policy& policy,
192 const std::map<std::string, std::vector<X509_Certificate>>& cert_chains,
194 const bool our_choice = policy.server_uses_own_ciphersuite_preferences();
195 const std::vector<uint16_t>& client_suites = client_hello.ciphersuites();
196 const std::vector<uint16_t> server_suites = policy.ciphersuite_list(version);
198 if(server_suites.empty()) {
199 throw TLS_Exception(Alert::HandshakeFailure,
"Policy forbids us from negotiating any ciphersuite");
202 const bool have_shared_ecc_curve =
203 (policy.choose_key_exchange_group(
212 const bool client_supports_ecdsa_cert_curve = [&] {
213 const auto chain = cert_chains.find(
"ECDSA");
214 if(chain == cert_chains.end() || chain->second.empty()) {
217 const auto key = chain->second.front().subject_public_key();
218 const auto* ec_key =
dynamic_cast<const EC_PublicKey*
>(key.get());
219 if(ec_key ==
nullptr) {
224 if(!group.has_value()) {
227 return value_exists(client_hello.supported_ecc_curves(), group.value());
230 const bool client_supports_ffdhe_groups = !client_hello.supported_dh_groups().empty();
232 const bool have_shared_dh_group =
233 (policy.choose_key_exchange_group(client_hello.supported_dh_groups(), {}) != Group_Params::NONE);
235 const std::unordered_set<uint16_t> client_suite_set(client_suites.begin(), client_suites.end());
239 const bool require_client_cert = policy.require_client_certificate_authentication();
241 const std::vector<Signature_Scheme> allowed_sig_schemes = policy.allowed_signature_schemes();
242 const std::vector<Signature_Scheme> client_sig_methods = client_hello.signature_schemes();
246 const std::unordered_set<std::string> client_sig_algs = [&] {
247 std::unordered_set<uint16_t> allowed_codes;
248 allowed_codes.reserve(allowed_sig_schemes.size());
249 for(
const auto s : allowed_sig_schemes) {
250 allowed_codes.insert(
static_cast<uint16_t
>(s.wire_code()));
252 std::unordered_set<std::string> result;
254 if(!scheme.is_available() || !scheme.is_compatible_with(Protocol_Version::TLS_V12)) {
257 if(!allowed_codes.contains(
static_cast<uint16_t
>(scheme.wire_code()))) {
260 if(!policy.allowed_signature_hash(scheme.hash_function_name())) {
263 result.insert(scheme.algorithm_name());
271 const std::vector<uint16_t>& pref_list = our_choice ? server_suites : client_suites;
273 const auto in_other_list = [&](uint16_t suite_id) {
275 return our_choice ? client_suite_set.contains(suite_id) :
value_exists(server_suites, suite_id);
278 for(
const auto suite_id : pref_list) {
279 if(!in_other_list(suite_id)) {
285 if(!suite.has_value() || !suite->valid()) {
289 if(have_shared_ecc_curve ==
false && suite->ecc_ciphersuite()) {
293 if(suite->kex_method() ==
Kex_Algo::DH && client_supports_ffdhe_groups && !have_shared_dh_group) {
297 if(require_client_cert && !suite->is_certificate_required()) {
302 if(suite->is_certificate_required()) {
303 const std::string cert_algo = suite->signature_used() ? suite->sig_algo() :
"RSA";
306 if(!cert_chains.contains(cert_algo)) {
310 if(cert_algo ==
"ECDSA" && !client_supports_ecdsa_cert_curve) {
315 if(suite->signature_used()) {
322 if(!client_sig_algs.contains(suite->sig_algo())) {
336 if(client_supports_ffdhe_groups && !have_shared_dh_group) {
337 throw TLS_Exception(Alert::InsufficientSecurity,
"Can't agree on a sufficiently strong ciphersuite with client");
340 throw TLS_Exception(Alert::HandshakeFailure,
"Can't agree on a ciphersuite with client");
343std::map<std::string, std::vector<X509_Certificate>> get_server_certs(
344 std::string_view hostname,
const std::vector<Signature_Scheme>& cert_sig_schemes, Credentials_Manager& creds) {
345 const std::vector<std::string> cert_types = {
"RSA",
"ECDSA"};
347 std::map<std::string, std::vector<X509_Certificate>> cert_chains;
349 for(
const auto& cert_type : cert_types) {
350 const std::vector<X509_Certificate> certs = creds.cert_chain_single_type(
354 if(!certs.empty() && certs.front().subject_public_key()->algo_name() == cert_type) {
355 cert_chains[cert_type] = certs;
365 return creds.psk(
"tls-server",
"dtls-cookie-secret",
"").bits_of();
371 if(cookie_secret.empty()) {
375 "Since Botan 3.13 DTLS server requires setting a non-empty cookie secret. "
376 "Either override Credentials_Manager::dtls_cookie_secret() or disable the "
377 "cookie exchange using TLS::Policy::dtls_server_require_cookie_exchange(), "
378 "if you understand the security implications of doing so.");
381 return cookie_secret;
388 const std::shared_ptr<Credentials_Manager>& creds,
389 const std::shared_ptr<const Policy>&
policy,
390 const std::shared_ptr<RandomNumberGenerator>&
rng,
392 size_t reserved_io_buffer_size)
394 auto self = std::make_shared<Server_Impl_12>(
401 load_dtls_cookie_secret(*self->m_creds);
416std::unique_ptr<Handshake_State> Server_Impl_12::new_handshake_state(std::unique_ptr<Handshake_IO> io) {
417 auto state = std::make_unique<Server_Handshake_State>(std::move(io),
callbacks());
425void Server_Impl_12::initiate_handshake(Handshake_State& state,
bool force_full_renegotiation) {
426 auto& server_state =
dynamic_cast<Server_Handshake_State&
>(state);
427 server_state.set_allow_session_resumption(!force_full_renegotiation);
428 server_state.mark_as_server_initiated();
430 const Hello_Request hello_req(state.handshake_io());
442 const std::vector<Protocol_Version>& supported_versions) {
444 const bool initial_handshake = (active_version.valid() ==
false);
446 if(!supported_versions.empty()) {
449 return Protocol_Version::DTLS_V12;
451 throw TLS_Exception(Alert::ProtocolVersion,
"No shared DTLS version");
454 return Protocol_Version::TLS_V12;
456 throw TLS_Exception(Alert::ProtocolVersion,
"No shared TLS version");
460 if(!initial_handshake) {
468 if(active_version > client_offer) {
470 Alert::ProtocolVersion,
471 "Client negotiated " + active_version.to_string() +
" then renegotiated with " + client_offer.to_string());
473 return active_version;
478 if(policy.allow_dtls12() && client_offer >= Protocol_Version::DTLS_V12) {
479 return Protocol_Version::DTLS_V12;
482 if(policy.allow_tls12() && client_offer >= Protocol_Version::TLS_V12) {
483 return Protocol_Version::TLS_V12;
488 "Client version " + client_offer.to_string() +
" is unacceptable by policy");
495void Server_Impl_12::process_client_hello_msg(Server_Handshake_State& pending_state,
496 const std::vector<uint8_t>& contents,
497 bool epoch0_restart) {
500 const bool initial_handshake = epoch0_restart || !
active_state().has_value();
503 if(initial_handshake ==
false && !pending_state.is_server_initiated() &&
504 policy().allow_client_initiated_renegotiation() ==
false) {
505 if(
policy().abort_connection_on_undesired_renegotiation()) {
506 throw TLS_Exception(Alert::NoRenegotiation,
"Server policy prohibits renegotiation");
518 if(pending_state.handshake_io().have_more_data()) {
526 throw TLS_Exception(Alert::UnexpectedMessage,
"Have data remaining in buffer after ClientHello");
529 pending_state.client_hello(std::make_unique<Client_Hello_12>(contents));
530 const Protocol_Version client_offer = pending_state.client_hello().legacy_version();
531 const bool datagram = client_offer.is_datagram_protocol();
534 if(peer_flavor !=
flavor()) {
535 throw TLS_Exception(Alert::ProtocolVersion,
"Client offered a version of the wrong protocol type");
539 if(client_offer.major_version() == 0xFF) {
540 throw TLS_Exception(Alert::ProtocolVersion,
"Client offered DTLS version with major version 0xFF");
543 if(client_offer.major_version() < 3) {
544 throw TLS_Exception(Alert::ProtocolVersion,
"Client offered TLS version with major version under 3");
546 if(client_offer.major_version() == 3 && client_offer.minor_version() == 0) {
547 throw TLS_Exception(Alert::ProtocolVersion,
"Client offered SSLv3 which is not supported");
561 const Protocol_Version negotiated_version =
565 pending_state.client_hello().supported_versions());
567 pending_state.set_version(negotiated_version);
569 const auto compression_methods = pending_state.client_hello().compression_methods();
571 throw TLS_Exception(Alert::IllegalParameter,
"Client did not offer NULL compression");
574 if(initial_handshake && datagram &&
policy().dtls_server_require_cookie_exchange()) {
576 const auto cookie_secret = load_dtls_cookie_secret(*m_creds);
579 if(client_identity.empty()) {
587 "Since Botan 3.13 DTLS server requires tls_peer_network_identity() return a non-empty value");
589 const Hello_Verify_Request verify(
590 pending_state.client_hello().cookie_input_data(), client_identity, cookie_secret);
594 pending_state.handshake_io().send_under_epoch(verify, 0);
596 pending_state.handshake_io().send(verify);
604 pending_state.client_hello(
nullptr);
622 if(
policy().require_extended_master_secret() && !pending_state.client_hello().supports_extended_master_secret()) {
623 throw TLS_Exception(Alert::HandshakeFailure,
624 "Policy requires the Extended Master Secret extension but the client did not send it");
640 if(
const auto& active =
active_state(); active && !epoch0_restart) {
641 const bool ems_pending = pending_state.client_hello().supports_extended_master_secret();
642 if(active->supports_extended_master_secret() ==
true && ems_pending ==
false) {
643 throw TLS_Exception(Alert::HandshakeFailure,
644 "Renegotiation ClientHello dropped the Extended Master Secret extension");
651 const auto session_handle = pending_state.client_hello().session_handle();
653 std::optional<Session> session_info;
654 if(pending_state.allow_session_resumption() && session_handle.has_value()) {
655 session_info = check_for_resume(
659 m_next_protocol =
"";
660 if(!initial_handshake && !pending_state.client_hello().supports_alpn()) {
663 m_next_protocol =
active_state()->application_protocol();
664 }
else if(pending_state.client_hello().supports_alpn()) {
665 const auto offered = pending_state.client_hello().next_protocols();
670 if(!m_next_protocol.empty() && !
value_exists(offered, m_next_protocol)) {
671 throw TLS_Exception(Alert::InternalError,
"Application chose an ALPN protocol that the client did not offer");
682 if(session_info.has_value()) {
683 this->session_resume(pending_state, {session_info.value(), session_handle.value()}, epoch0_restart);
686 this->session_create(pending_state, epoch0_restart);
695void Server_Impl_12::process_certificate_msg(Server_Handshake_State& pending_state,
696 const std::vector<uint8_t>& contents) {
697 pending_state.client_certs(std::make_unique<Certificate_12>(contents,
policy()));
700 if(pending_state.client_certs().empty() &&
policy().require_client_certificate_authentication()) {
701 throw TLS_Exception(Alert::HandshakeFailure,
"Policy requires client send a certificate, but it did not");
707void Server_Impl_12::process_client_key_exchange_msg(Server_Handshake_State& pending_state,
708 const std::vector<uint8_t>& contents) {
709 if(pending_state.has_client_certs() && !pending_state.client_certs().empty()) {
715 pending_state.client_kex(std::make_unique<Client_Key_Exchange>(
716 contents, pending_state, pending_state.server_rsa_kex_key(), *m_creds,
policy(),
rng()));
718 pending_state.compute_session_keys();
719 if(
policy().allow_ssl_key_log_file()) {
725 "CLIENT_RANDOM", pending_state.client_hello().random(), pending_state.session_keys().master_secret());
729void Server_Impl_12::process_change_cipher_spec_msg(Server_Handshake_State& pending_state) {
734void Server_Impl_12::process_certificate_verify_msg(Server_Handshake_State& pending_state,
736 const std::vector<uint8_t>& contents) {
737 pending_state.client_verify(std::make_unique<Certificate_Verify_12>(contents));
739 const std::vector<X509_Certificate>& client_certs = pending_state.client_certs().cert_chain();
741 if(client_certs.empty()) {
742 throw TLS_Exception(Alert::DecodeError,
"No client certificate sent");
745 const auto cert_constraints = client_certs[0].constraints();
746 if(!cert_constraints.empty()) {
748 throw TLS_Exception(Alert::BadCertificate,
"Client certificate does not support signing");
755 const std::string sni_hostname = pending_state.client_hello().sni_hostname();
756 const auto trusted_CAs = m_creds->trusted_certificate_authorities(
"tls-server", sni_hostname);
764 }
catch(TLS_Exception&) {
766 }
catch(std::exception& e) {
767 throw TLS_Exception(Alert::BadCertificate, e.what());
770 const bool sig_valid = pending_state.client_verify().verify(client_certs[0], pending_state,
policy());
772 pending_state.hash().update(pending_state.handshake_io().format(contents, type));
780 throw TLS_Exception(Alert::DecryptError,
"Client cert verify failed");
786void Server_Impl_12::process_finished_msg(Server_Handshake_State& pending_state,
788 const std::vector<uint8_t>& contents) {
791 if(pending_state.handshake_io().have_more_data()) {
792 throw TLS_Exception(Alert::UnexpectedMessage,
"Have data remaining in buffer after Finished");
795 pending_state.client_finished(std::make_unique<Finished_12>(contents));
798 throw TLS_Exception(Alert::DecryptError,
"Finished message didn't verify");
801 if(!pending_state.has_server_finished()) {
804 pending_state.hash().update(pending_state.handshake_io().format(contents, type));
806 Session session_info(pending_state.session_keys().master_secret(),
807 pending_state.server_hello().legacy_version(),
808 pending_state.server_hello().ciphersuite(),
810 pending_state.server_hello().supports_extended_master_secret(),
811 pending_state.server_hello().supports_encrypt_then_mac(),
812 pending_state.peer_cert_chain(),
813 Server_Information(pending_state.client_hello().sni_hostname()),
814 pending_state.server_hello().srtp_profile(),
820 Session_Summary summary(session_info, pending_state.is_a_resumption(), pending_state.psk_identity());
821 summary.set_session_id(pending_state.server_hello().session_id());
825 if(
callbacks().tls_should_persist_resumption_information(session_info)) {
827 pending_state.server_hello().session_id(),
828 !pending_state.server_hello().supports_session_ticket());
830 if(pending_state.server_hello().supports_session_ticket() && handle.has_value() && handle->is_ticket()) {
831 pending_state.new_session_ticket(std::make_unique<New_Session_Ticket_12>(pending_state.handshake_io(),
832 pending_state.hash(),
833 handle->ticket().value(),
834 ticket_lifetime_hint(
policy())));
840 if(!pending_state.has_new_session_ticket() && pending_state.server_hello().supports_session_ticket()) {
841 pending_state.new_session_ticket(
842 std::make_unique<New_Session_Ticket_12>(pending_state.handshake_io(), pending_state.hash()));
845 pending_state.handshake_io().send(Change_Cipher_Spec());
849 pending_state.server_finished(
851 }
else if(
auto summary = pending_state.take_resumption_summary()) {
865 const std::vector<uint8_t>& contents,
866 bool epoch0_restart) {
867 Server_Handshake_State& state =
dynamic_cast<Server_Handshake_State&
>(state_base);
868 state.confirm_transition_to(type);
879 state.hash().update(state.handshake_io().format(contents, type));
884 return this->process_client_hello_msg(state, contents, epoch0_restart);
887 return this->process_certificate_msg(state, contents);
890 return this->process_client_key_exchange_msg(state, contents);
893 return this->process_certificate_verify_msg(state, type, contents);
896 return this->process_change_cipher_spec_msg(state);
899 return this->process_finished_msg(state, type, contents);
902 throw Unexpected_Message(
"Unknown handshake message received");
906void Server_Impl_12::session_resume(Server_Handshake_State& pending_state,
908 bool epoch0_restart) {
912 const bool offer_new_session_ticket = pending_state.client_hello().supports_session_ticket() &&
913 pending_state.client_hello().session_ticket().empty() &&
922 pending_state.server_hello(std::make_unique<Server_Hello_12>(pending_state.handshake_io(),
923 pending_state.hash(),
928 pending_state.client_hello(),
930 offer_new_session_ticket,
936 pending_state.mark_as_resumption();
937 pending_state.compute_session_keys(session.session.master_secret());
938 if(
policy().allow_ssl_key_log_file()) {
944 "CLIENT_RANDOM", pending_state.client_hello().random(), pending_state.session_keys().master_secret());
946 pending_state.set_resume_certs(session.session.peer_certs());
950 pending_state.set_resumption_summary([&] {
951 Session_Summary summary(session.session, pending_state.is_a_resumption(), pending_state.psk_identity());
952 summary.set_session_id(pending_state.server_hello().session_id());
953 if(
auto ticket = session.handle.ticket()) {
954 summary.set_session_ticket(std::move(ticket.value()));
959 auto new_handle = [&,
this]() -> std::optional<Session_Handle> {
960 if(!
callbacks().tls_should_persist_resumption_information(session.session)) {
970 if(pending_state.server_hello().supports_session_ticket()) {
971 if(new_handle.has_value() && new_handle->is_ticket()) {
972 pending_state.new_session_ticket(std::make_unique<New_Session_Ticket_12>(pending_state.handshake_io(),
973 pending_state.hash(),
974 new_handle->ticket().value(),
975 ticket_lifetime_hint(
policy())));
977 pending_state.new_session_ticket(
978 std::make_unique<New_Session_Ticket_12>(pending_state.handshake_io(), pending_state.hash()));
982 pending_state.handshake_io().send(Change_Cipher_Spec());
986 pending_state.server_finished(
991void Server_Impl_12::session_create(Server_Handshake_State& pending_state,
bool epoch0_restart) {
992 std::map<std::string, std::vector<X509_Certificate>> cert_chains;
994 const std::string sni_hostname = pending_state.client_hello().sni_hostname();
1002 const auto cert_signature_schemes = pending_state.client_hello().certificate_signature_schemes();
1003 cert_chains = get_server_certs(sni_hostname, cert_signature_schemes, *m_creds);
1005 if(!sni_hostname.empty() && cert_chains.empty()) {
1006 cert_chains = get_server_certs(
"", cert_signature_schemes, *m_creds);
1015 if(!cert_chains.empty()) {
1020 const uint16_t ciphersuite =
1021 choose_ciphersuite(
policy(), pending_state.version(), cert_chains, pending_state.client_hello());
1024 pending_state.version(),
1035 if(epoch0_restart) {
1039 pending_state.server_hello(std::make_unique<Server_Hello_12>(pending_state.handshake_io(),
1040 pending_state.hash(),
1045 pending_state.client_hello(),
1052 const Ciphersuite& pending_suite = pending_state.ciphersuite();
1054 std::shared_ptr<Private_Key> private_key;
1056 if(pending_suite.is_certificate_required()) {
1057 const std::string algo_used = pending_suite.signature_used() ? pending_suite.sig_algo() :
"RSA";
1059 BOTAN_ASSERT(!cert_chains[algo_used].empty(),
"Attempting to send empty certificate chain");
1061 pending_state.server_certs(
1062 std::make_unique<Certificate_12>(pending_state.handshake_io(), pending_state.hash(), cert_chains[algo_used]));
1069 if(pending_state.client_hello().supports_cert_status_message() &&
1070 pending_state.server_hello().supports_certificate_status_message() &&
1071 pending_state.is_a_resumption() ==
false) {
1072 const auto* csr = pending_state.client_hello().extensions().get<Certificate_Status_Request>();
1076 if(!resp_bytes.empty()) {
1077 pending_state.server_cert_status(
1078 std::make_unique<Certificate_Status_12>(pending_state.handshake_io(), pending_state.hash(), resp_bytes));
1082 private_key = m_creds->private_key_for(pending_state.server_certs().cert_chain()[0],
"tls-server", sni_hostname);
1085 throw Internal_Error(
"No private key located for associated server cert");
1093 const bool omit_psk_server_kex =
1095 m_creds->psk_identity_hint(
"tls-server", pending_state.client_hello().sni_hostname()).empty();
1098 pending_state.set_server_rsa_kex_key(private_key);
1099 }
else if(omit_psk_server_kex) {
1102 pending_state.server_kex(std::make_unique<Server_Key_Exchange>(
1103 pending_state.handshake_io(), pending_state,
policy(), *m_creds,
rng(), private_key.get()));
1106 const auto trusted_CAs = m_creds->trusted_certificate_authorities(
"tls-server", sni_hostname);
1108 std::vector<X509_DN> client_auth_CAs;
1110 for(
const auto* store : trusted_CAs) {
1111 auto subjects = store->all_subjects();
1112 client_auth_CAs.insert(client_auth_CAs.end(), subjects.begin(), subjects.end());
1117 const bool request_cert =
1123 const bool can_request_cert = std::ranges::any_of(
policy().acceptable_signature_schemes(),
1124 [](
const Signature_Scheme& scheme) {
1125 return scheme.is_compatible_with(Protocol_Version::TLS_V12);
1127 pending_state.ciphersuite().is_certificate_required();
1129 if(require_cert && !can_request_cert) {
1130 throw TLS_Exception(Alert::HandshakeFailure,
1131 "Policy requires client certificate authentication but no CertificateRequest can be sent");
1134 if(request_cert && can_request_cert) {
1135 pending_state.cert_req(std::make_unique<Certificate_Request_12>(
1136 pending_state.handshake_io(), pending_state.hash(),
policy(), client_auth_CAs));
1148 pending_state.server_hello_done(
1149 std::make_unique<Server_Hello_Done>(pending_state.handshake_io(), pending_state.hash()));
#define BOTAN_ASSERT_NOMSG(expr)
#define BOTAN_ASSERT_NONNULL(ptr)
#define BOTAN_ASSERT_IMPLICATION(expr1, expr2, msg)
#define BOTAN_ASSERT(expr, assertion_made)
virtual std::vector< uint8_t > tls_provide_cert_status(const std::vector< X509_Certificate > &chain, const Certificate_Status_Request &csr)
virtual std::string tls_peer_network_identity()
virtual std::string tls_server_choose_app_protocol(const std::vector< std::string > &client_protos)
virtual void tls_examine_extensions(const Extensions &extn, Connection_Side which_side, Handshake_Type which_message)
virtual void tls_session_established(const Session_Summary &session)
virtual void tls_verify_cert_chain(const std::vector< X509_Certificate > &cert_chain, const std::vector< std::optional< OCSP::Response > > &ocsp_responses, const std::vector< Certificate_Store * > &trusted_roots, Usage_Type usage, std::string_view hostname, const TLS::Policy &policy)
virtual void tls_ssl_key_log_data(std::string_view label, std::span< const uint8_t > client_random, std::span< const uint8_t > secret) const
const std::vector< X509_Certificate > & cert_chain() const
RandomNumberGenerator & rng()
void change_cipher_spec_reader(Connection_Side side)
void maybe_arm_dtls_retransmission_timer(TimerGeneration generation_policy=TimerGeneration::Advance)
std::vector< uint8_t > secure_renegotiation_data_for_server_hello() const
Callbacks & callbacks() const
virtual bool dtls_epoch0_restart_enabled() const
TLS_Flavor flavor() const
Session_Manager & session_manager()
const Policy & policy() const
void note_resumption_handle(std::optional< Session_Handle > handle)
void change_cipher_spec_writer(Connection_Side side)
void secure_renegotiation_check(const Client_Hello_12 *client_hello, bool fresh_handshake_mode=false)
const std::optional< Active_Connection_State_12 > & active_state() const
void reset_active_association_state()
bool secure_renegotiation_supported() const override
void send_warning_alert(Alert::Type type)
static std::optional< Ciphersuite > by_id(uint16_t suite)
static std::optional< Group_Params > from_string(std::string_view group_name)
bool has_client_certs() const
Handshake_State(std::unique_ptr< Handshake_IO > io, Callbacks &callbacks)
const Certificate_12 & client_certs() const
virtual std::vector< X509_Certificate > peer_cert_chain() const =0
virtual bool require_client_certificate_authentication() const
virtual bool allow_dtls_epoch0_restart() const
virtual bool request_client_certificate_authentication() const
virtual bool dtls_server_require_cookie_exchange() const
bool is_datagram_protocol() const
static std::shared_ptr< Server_Impl_12 > create(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, TLS_Flavor flavor=TLS_Flavor::TLS, size_t reserved_io_buffer_size=TLS::Channel::IO_BUF_DEFAULT_SIZE)
Helper class to embody a session handle in all protocol versions.
virtual size_t remove(const Session_Handle &handle)=0
virtual std::optional< Session_Handle > establish(const Session &session, const std::optional< Session_ID > &id=std::nullopt, bool tls12_no_ticket=false)
Save a new Session and assign a Session_Handle (TLS Server).
virtual bool emits_session_tickets()
constexpr CT::Mask< T > is_equal(const T x[], const T y[], size_t len)
std::vector< AlgorithmIdentifier > to_algorithm_identifiers(const std::vector< Signature_Scheme > &schemes)
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
bool value_exists(const std::vector< T > &vec, const V &val)
std::vector< T, secure_allocator< T > > secure_vector