11#include <botan/tls_messages_13.h>
13#include <botan/tls_alert.h>
14#include <botan/tls_callbacks.h>
15#include <botan/tls_exceptn.h>
16#include <botan/tls_extensions_13.h>
17#include <botan/tls_policy.h>
18#include <botan/internal/loadstor.h>
19#include <botan/internal/stl_util.h>
20#include <botan/internal/tls_messages_internal.h>
29 bool hello_retry_request_allowed,
45 const auto& offered_by_client = exts.get<
Key_Share>()->offered_groups();
52 if(selected_group == Named_Group::NONE) {
53 throw TLS_Exception(Alert::HandshakeFailure,
"Client did not offer any acceptable group");
60 throw TLS_Exception(Alert::InternalError,
"Application selected a group that is not supported by the client");
80 return Server_Hello_13(ch, selected_group, session_mgr, credentials_mgr, rng, cb, policy);
85 const std::vector<uint8_t>& buf) {
86 auto data = std::make_unique<Server_Hello_Internal>(buf);
87 const auto version = data->version();
90 if(version.is_pre_tls_13()) {
95 if(version == Protocol_Version::TLS_V13) {
96 if(data->is_hello_retry_request()) {
103 throw TLS_Exception(Alert::ProtocolVersion,
"unexpected server hello version: " + version.to_string());
136 throw TLS_Exception(Alert::DecodeError,
"compression is not supported in TLS 1.3");
142 throw TLS_Exception(Alert::MissingExtension,
"server hello did not contain 'supported version' extension");
150 throw TLS_Exception(Alert::IllegalParameter,
"TLS 1.3 Server Hello selected a different version");
155 Server_Hello_13::Server_Hello_Tag ) :
171 const std::set<Extension_Code> allowed = {
179 if(exts.contains_other_than(allowed)) {
180 throw TLS_Exception(Alert::UnsupportedExtension,
"Server Hello contained an extension that is not allowed");
188 throw TLS_Exception(Alert::MissingExtension,
"server hello must contain key exchange information");
193 Server_Hello_13::Hello_Retry_Request_Tag ) :
205 const std::set<Extension_Code> allowed = {
213 if(exts.contains_other_than(allowed)) {
215 "Hello Retry Request contained an extension that is not allowed");
222 throw TLS_Exception(Alert::IllegalParameter,
"Hello Retry Request does not request any changes to Client Hello");
227 Hello_Retry_Request_Creation_Tag ) :
238 std::swap(pref_list, other_list);
241 for(
auto suite_id : pref_list) {
272 throw TLS_Exception(Alert::HandshakeFailure,
"Can't agree on a ciphersuite with client");
277 std::optional<Named_Group> key_exchange_group,
287 choose_ciphersuite(ch, policy),
300 if(key_exchange_group.has_value()) {
301 BOTAN_ASSERT_NOMSG(ch.extensions().has<Key_Share>());
302 m_data->extensions().add(Key_Share::create_as_encapsulation(
303 key_exchange_group.value(), *ch.extensions().get<Key_Share>(), policy, cb, rng));
308 if(ch_exts.has<
PSK>()) {
309 const auto cs = Ciphersuite::by_id(m_data->ciphersuite());
310 BOTAN_ASSERT_NOMSG(cs);
317 auto* const psk_modes = ch_exts.get<PSK_Key_Exchange_Modes>();
318 BOTAN_ASSERT_NONNULL(psk_modes);
322 if(value_exists(psk_modes->modes(), PSK_Key_Exchange_Mode::PSK_DHE_KE)) {
323 if(auto server_psk = ch_exts.get<PSK>()->select_offered_psk(
324 ch.sni_hostname(), cs.value(), session_mgr, credentials_mgr, cb, policy)) {
328 m_data->extensions().add(std::move(server_psk));
339 return Protocol_Version::TLS_V11;
342 return Protocol_Version::TLS_V12;
351 const auto& versions = versions_ext->versions();
353 return versions.front();
367 choose_ciphersuite(ch, policy),
#define BOTAN_ASSERT_NOMSG(expr)
#define BOTAN_STATE_CHECK(expr)
virtual void tls_modify_extensions(Extensions &extn, Connection_Side which_side, Handshake_Type which_message)
const Extensions & extensions() const
const std::vector< uint16_t > & ciphersuites() const
friend class Server_Hello_13
Hello_Retry_Request(std::unique_ptr< Server_Hello_Internal > data)
Handshake_Type type() const override
std::vector< Named_Group > offered_groups() const
virtual std::vector< uint16_t > ciphersuite_list(Protocol_Version version) const
virtual bool server_uses_own_ciphersuite_preferences() const
virtual Group_Params choose_key_exchange_group(const std::vector< Group_Params > &supported_by_peer, const std::vector< Group_Params > &offered_by_peer) const
static std::variant< Hello_Retry_Request, Server_Hello_13, Server_Hello_12_Shim > parse(const std::vector< uint8_t > &buf)
static const struct Botan::TLS::Server_Hello_13::Hello_Retry_Request_Tag as_hello_retry_request
static const struct Botan::TLS::Server_Hello_13::Hello_Retry_Request_Creation_Tag as_new_hello_retry_request
Server_Hello_13(std::unique_ptr< Server_Hello_Internal > data, Server_Hello_Tag tag=as_server_hello)
std::optional< Protocol_Version > random_signals_downgrade() const
void basic_validation() const
static std::variant< Hello_Retry_Request, Server_Hello_13 > create(const Client_Hello_13 &ch, bool hello_retry_request_allowed, Session_Manager &session_mgr, Credentials_Manager &credentials_mgr, RandomNumberGenerator &rng, const Policy &policy, Callbacks &cb)
Protocol_Version selected_version() const final
static const struct Botan::TLS::Server_Hello_13::Server_Hello_Tag as_server_hello
Server_Hello(const Server_Hello &)=delete
const Session_ID & session_id() const
uint8_t compression_method() const
std::unique_ptr< Server_Hello_Internal > m_data
const Extensions & extensions() const
Protocol_Version legacy_version() const
constexpr uint64_t DOWNGRADE_TLS12
std::vector< uint8_t > make_server_hello_random(RandomNumberGenerator &rng, Protocol_Version offered_version, Callbacks &cb, const Policy &policy)
constexpr uint64_t DOWNGRADE_TLS11
constexpr std::array< uint8_t, 32 > HELLO_RETRY_REQUEST_MARKER
bool value_exists(const std::vector< T > &vec, const V &val)
std::string to_string(ErrorType type)
Convert an ErrorType to string.
constexpr auto load_be(ParamTs &&... params)