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/loadstor.h>
16#include <botan/pubkey.h>
19#include <botan/ecdh.h>
21#if defined(BOTAN_HAS_CURVE_25519)
22 #include <botan/curve25519.h>
25#if defined(BOTAN_HAS_CECPQ1)
26 #include <botan/cecpq1.h>
29#if defined(BOTAN_HAS_SRP6)
30 #include <botan/srp6.h>
47 const std::string hostname = state.
client_hello()->sni_hostname();
52 std::string identity_hint =
60 const std::vector<Group_Params> dh_groups = state.
client_hello()->supported_dh_groups();
80 "Could not agree on a DH group with the client");
90 m_kex_key.reset(dh.release());
94 const std::vector<Group_Params> ec_groups = state.
client_hello()->supported_ecc_curves();
97 throw Internal_Error(
"Client sent no ECC extension but we negotiated ECDH");
104 std::vector<uint8_t> ecdh_public_val;
108#if defined(BOTAN_HAS_CURVE_25519)
110 ecdh_public_val = x25519->public_value();
111 m_kex_key.reset(x25519.release());
113 throw Internal_Error(
"Negotiated X25519 somehow, but it is disabled");
123 std::unique_ptr<ECDH_PrivateKey> ecdh(
new ECDH_PrivateKey(rng, ec_group));
126 ecdh_public_val = ecdh->public_value(
130 m_kex_key.reset(ecdh.release());
133 const uint16_t named_curve_id =
static_cast<uint16_t
>(shared_group);
134 m_params.push_back(3);
135 m_params.push_back(
get_byte(0, named_curve_id));
136 m_params.push_back(
get_byte(1, named_curve_id));
140#if defined(BOTAN_HAS_SRP6)
143 const std::string srp_identifier = state.
client_hello()->srp_identifier();
145 std::string group_id;
147 std::vector<uint8_t> salt;
149 const bool found = creds.
srp_verifier(
"tls-server", hostname,
156 "Unknown SRP user " + srp_identifier);
160 BigInt B = m_srp_params->step1(v, group_id,
171#if defined(BOTAN_HAS_CECPQ1)
176 CECPQ1_offer(cecpq1_offer.data(), m_cecpq1_key.get(), rng);
190 std::pair<std::string, Signature_Format> format =
193 std::vector<uint8_t> buf = state.
client_hello()->random();
200 format.first, format.second, buf);
231 for(
size_t i = 0; i != 3; ++i)
257 throw Decoding_Error(
"Server_Key_Exchange: Unsupported kex type " +
260 m_params.assign(buf.data(), buf.data() + reader.
read_so_far());
269 m_signature = reader.
get_range<uint8_t>(2, 0, 65535);
278std::vector<uint8_t> Server_Key_Exchange::serialize()
const
280 std::vector<uint8_t> buf =
params();
282 if(m_signature.size())
286 const uint16_t scheme_code =
static_cast<uint16_t
>(m_scheme);
287 buf.push_back(
get_byte(0, scheme_code));
288 buf.push_back(
get_byte(1, scheme_code));
302 const Policy& policy)
const
306 std::pair<std::string, Signature_Format> format =
309 std::vector<uint8_t> buf = state.
client_hello()->random();
314 const bool signature_valid =
318#if defined(BOTAN_UNSAFE_FUZZER_MODE)
322 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 bool srp_verifier(const std::string &type, const std::string &context, const std::string &identifier, std::string &group_name, BigInt &verifier, std::vector< uint8_t > &salt, bool generate_fake_on_unknown)
const BigInt & get_p() const
const BigInt & get_g() const
virtual std::string tls_decode_group_param(Group_Params group_param)
virtual bool tls_verify_message(const Public_Key &key, const std::string &emsa, Signature_Format format, const std::vector< uint8_t > &msg, const std::vector< uint8_t > &sig)
virtual std::vector< uint8_t > tls_sign_message(const Private_Key &key, RandomNumberGenerator &rng, const std::string &emsa, Signature_Format format, const std::vector< uint8_t > &msg)
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
Callbacks & callbacks() const
std::pair< std::string, Signature_Format > parse_sig_format(const Public_Key &key, Signature_Scheme scheme, bool for_client_auth, const Policy &policy) const
void client_hello(Client_Hello *client_hello)
const Ciphersuite & ciphersuite() const
void server_hello(Server_Hello *server_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 bool hide_unknown_users() const
virtual Group_Params choose_key_exchange_group(const std::vector< Group_Params > &peer_groups) const
virtual Group_Params default_dh_group() const
bool supports_negotiable_signature_algorithms() 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)
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)
void CECPQ1_offer(uint8_t send[CECPQ1_OFFER_BYTES], CECPQ1_key *offer_key_output, RandomNumberGenerator &rng)
constexpr uint8_t get_byte(size_t byte_num, T input)