9#include <botan/tls_messages.h>
10#include <botan/tls_extensions.h>
11#include <botan/internal/tls_reader.h>
12#include <botan/internal/tls_handshake_io.h>
13#include <botan/internal/tls_handshake_state.h>
14#include <botan/credentials_manager.h>
15#include <botan/internal/loadstor.h>
16#include <botan/pubkey.h>
18#include <botan/dl_group.h>
20#include <botan/ecdh.h>
22#if defined(BOTAN_HAS_CURVE_25519)
23 #include <botan/curve25519.h>
38 const std::string hostname = state.
client_hello()->sni_hostname();
43 std::string identity_hint =
51 const std::vector<Group_Params> dh_groups = state.
client_hello()->supported_dh_groups();
71 "Could not agree on a DH group with the client");
79 throw TLS_Exception(Alert::InternalError,
"Application did not provide a Diffie-Hellman key");
88 const std::vector<Group_Params> ec_groups = state.
client_hello()->supported_ecc_curves();
91 throw Internal_Error(
"Client sent no ECC extension but we negotiated ECDH");
96 throw TLS_Exception(Alert::HandshakeFailure,
"No shared ECC group with client");
98 std::vector<uint8_t> ecdh_public_val;
106 "Application did not provide a X25519 key");
108 ecdh_public_val = m_kex_key->public_value();
116 throw TLS_Exception(Alert::InternalError,
"Application did not provide a EC-Diffie-Hellman key");
120 ecdh_public_val = ecdh->public_value(
125 const uint16_t named_curve_id =
static_cast<uint16_t
>(shared_group);
126 m_params.push_back(3);
127 m_params.push_back(get_byte<0>(named_curve_id));
128 m_params.push_back(get_byte<1>(named_curve_id));
142 std::pair<std::string, Signature_Format> format =
145 std::vector<uint8_t> buf = state.
client_hello()->random();
152 format.first, format.second, buf);
184 for(
size_t i = 0; i != 3; ++i)
196 throw Decoding_Error(
"Server_Key_Exchange: Unsupported kex type " +
199 m_params.assign(buf.data(), buf.data() + reader.
read_so_far());
204 m_signature = reader.
get_range<uint8_t>(2, 0, 65535);
213std::vector<uint8_t> Server_Key_Exchange::serialize()
const
215 std::vector<uint8_t> buf =
params();
217 if(!m_signature.empty())
221 buf.push_back(get_byte<0>(m_scheme.
wire_code()));
222 buf.push_back(get_byte<1>(m_scheme.
wire_code()));
236 const Policy& policy)
const
240 std::pair<std::string, Signature_Format> format =
243 std::vector<uint8_t> buf = state.
client_hello()->random();
248 const bool signature_valid =
252#if defined(BOTAN_UNSAFE_FUZZER_MODE)
256 return signature_valid;
#define BOTAN_UNUSED(...)
#define BOTAN_ASSERT_NONNULL(ptr)
#define BOTAN_ASSERT(expr, assertion_made)
static std::vector< uint8_t > encode(const BigInt &n)
virtual std::string psk_identity_hint(const std::string &type, const std::string &context)
virtual std::vector< uint8_t > tls_sign_message(const Private_Key &key, RandomNumberGenerator &rng, std::string_view padding, Signature_Format format, const std::vector< uint8_t > &msg)
virtual std::unique_ptr< PK_Key_Agreement_Key > tls_generate_ephemeral_key(const std::variant< TLS::Group_Params, DL_Group > &group, RandomNumberGenerator &rng)
virtual bool tls_verify_message(const Public_Key &key, std::string_view padding, Signature_Format format, const std::vector< uint8_t > &msg, const std::vector< uint8_t > &sig)
bool signature_used() const
Kex_Algo kex_method() const
void update(const uint8_t in[], size_t length)
virtual std::vector< uint8_t > send(const Handshake_Message &msg)=0
std::pair< std::string, Signature_Format > parse_sig_format(const Public_Key &key, Signature_Scheme scheme, const std::vector< Signature_Scheme > &offered_schemes, bool for_client_auth, const Policy &policy) const
void server_hello(Server_Hello_12 *server_hello)
Callbacks & callbacks() const
const Ciphersuite & ciphersuite() const
void client_hello(Client_Hello_12 *client_hello)
std::pair< std::string, Signature_Format > choose_sig_format(const Private_Key &key, Signature_Scheme &scheme, bool for_client_auth, const Policy &policy) const
virtual void check_peer_key_acceptable(const Public_Key &public_key) const
virtual Group_Params default_dh_group() 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
bool verify(const Public_Key &server_key, const Handshake_State &state, const Policy &policy) const
const std::vector< uint8_t > & params() const
const Private_Key & server_kex_key() const
Server_Key_Exchange(Handshake_IO &io, Handshake_State &state, const Policy &policy, Credentials_Manager &creds, RandomNumberGenerator &rng, const Private_Key *signing_key=nullptr)
Signature_Scheme::Code wire_code() const noexcept
bool is_set() const noexcept
std::string get_string(size_t len_bytes, size_t min_bytes, size_t max_bytes)
size_t read_so_far() const
std::vector< T > get_range(size_t len_bytes, size_t min_elems, size_t max_elems)
void append_tls_length_value(std::vector< uint8_t, Alloc > &buf, const T *vals, size_t vals_size, size_t tag_size)
std::string kex_method_to_string(Kex_Algo method)
bool group_param_is_dh(Group_Params group)