9#include <botan/internal/tls_handshake_state.h>
10#include <botan/internal/tls_record.h>
11#include <botan/tls_messages.h>
12#include <botan/tls_signature_scheme.h>
28 return "hello_verify_request";
31 return "hello_request";
34 return "client_hello";
37 return "server_hello";
40 return "hello_retry_request";
46 return "certificate_url";
49 return "certificate_status";
52 return "server_key_exchange";
55 return "certificate_request";
58 return "server_hello_done";
61 return "certificate_verify";
64 return "client_key_exchange";
67 return "new_session_ticket";
70 return "change_cipher_spec";
76 return "end_of_early_data";
79 return "encrypted_extensions";
89 "Unknown TLS handshake message type " +
90 std::to_string(
static_cast<size_t>(type)));
101 m_handshake_io(
std::move(io)),
102 m_version(m_handshake_io->initial_record_version())
115 m_client_hello->update_hello_cookie(hello_verify);
125 m_client_hello.reset();
216 if(!m_ciphersuite.has_value())
220 return m_ciphersuite.value();
235 m_session_keys =
Session_Keys(
this, resume_master_secret,
true);
253std::pair<Handshake_Type, std::vector<uint8_t>>
271 if(prf_algo ==
"MD5" || prf_algo ==
"SHA-1")
277std::pair<std::string, Signature_Format>
280 bool for_client_auth,
281 const Policy& policy)
const
283 const std::string sig_algo = key.
algo_name();
287 std::vector<Signature_Scheme> requested =
292 if(!scheme.is_available())
297 if(scheme.algorithm_name() == sig_algo)
299 if(std::find(requested.begin(), requested.end(), scheme) != requested.end())
301 chosen_scheme = scheme;
312 "Policy refuses to accept signing with any hash supported by peer");
315 if(!chosen_scheme.
format().has_value())
316 {
throw Invalid_Argument(sig_algo +
" is invalid/unknown for TLS signatures"); }
323bool supported_algos_include(
324 const std::vector<Signature_Scheme>& schemes,
325 std::string_view key_type,
326 std::string_view hash_type)
330 if(scheme.is_available() &&
331 hash_type == scheme.hash_function_name() &&
332 key_type == scheme.algorithm_name())
343std::pair<std::string, Signature_Format>
346 const std::vector<Signature_Scheme>& offered_schemes,
347 bool for_client_auth,
348 const Policy& policy)
const
350 const std::string key_type = key.
algo_name();
355 "Rejecting " + key_type +
" signature");
361 "Peer sent unknown signature scheme");
365 {
throw Decoding_Error(
"Counterparty sent inconsistent key and sig types"); }
370 "No certificate verify set");
378 const std::vector<Signature_Scheme> supported_algos =
385 {
throw TLS_Exception(Alert::IllegalParameter,
"Peer sent unexceptable signature scheme"); }
387 if(!supported_algos_include(supported_algos, key_type, hash_algo))
390 "TLS signature extension did not allow for " +
391 key_type +
"/" + hash_algo +
" signature");
394 if(!scheme.
format().has_value())
395 {
throw Invalid_Argument(key_type +
" is invalid/unknown for TLS signatures"); }
virtual std::string algo_name() const =0
static std::unique_ptr< KDF > create_or_throw(std::string_view algo_spec, std::string_view provider="")
virtual void tls_inspect_handshake_msg(const Handshake_Message &message)
const std::vector< Signature_Scheme > & signature_schemes() const
static std::optional< Ciphersuite > by_id(uint16_t suite)
std::string prf_algo() const
Session_Ticket session_ticket() const
std::vector< Signature_Scheme > signature_schemes() const
void update(const uint8_t in[], size_t length)
std::string type_string() const
virtual Handshake_Type type() const =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
std::pair< Handshake_Type, std::vector< uint8_t > > get_next_handshake_msg()
const Server_Hello_Done * server_hello_done() const
void hello_verify_request(const Hello_Verify_Request &hello_verify)
void set_expected_next(Handshake_Type msg_type)
void note_message(const Handshake_Message &msg)
const Server_Key_Exchange * server_kex() const
virtual ~Handshake_State()
const Certificate_Status * server_cert_status() const
const Certificate_Verify_12 * server_verify() const
Handshake_State(std::unique_ptr< Handshake_IO > io, Callbacks &callbacks)
Handshake_IO & handshake_io()
const Certificate_Verify_12 * client_verify() const
const Finished_12 * server_finished() const
const Client_Hello_12 * client_hello() const
const Client_Key_Exchange * client_kex() const
void confirm_transition_to(Handshake_Type msg_type)
void set_version(const Protocol_Version &version)
const Certificate_12 * server_certs() const
const Certificate_12 * client_certs() const
const Finished_12 * client_finished() const
const Certificate_Request_12 * cert_req() const
void compute_session_keys()
const Ciphersuite & ciphersuite() const
Session_Ticket session_ticket() const
const Server_Hello_12 * server_hello() const
bool received_handshake_msg(Handshake_Type msg_type) const
std::unique_ptr< KDF > protocol_specific_prf() const
const New_Session_Ticket_12 * new_session_ticket() const
std::pair< std::string, Signature_Format > choose_sig_format(const Private_Key &key, Signature_Scheme &scheme, bool for_client_auth, const Policy &policy) const
Protocol_Version version() const
void confirm_transition_to(Handshake_Type msg_type)
bool received_handshake_msg(Handshake_Type msg_type) const
void set_expected_next(Handshake_Type msg_type)
bool change_cipher_spec_expected() const
const Session_Ticket & ticket() const
virtual std::vector< Signature_Scheme > allowed_signature_schemes() const
bool allowed_signature_method(std::string_view sig_method) const
bool allowed_signature_hash(std::string_view hash) const
std::string hash_function_name() const noexcept
bool is_compatible_with(const Protocol_Version &protocol_version) const noexcept
std::optional< Signature_Format > format() const noexcept
std::string padding_string() const noexcept
bool is_available() const noexcept
std::string algorithm_name() const noexcept
const char * handshake_type_to_string(Handshake_Type type)
std::vector< T, secure_allocator< T > > secure_vector