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";
100 m_handshake_io(
std::move(io)),
101 m_version(m_handshake_io->initial_record_version())
114 m_client_hello->update_hello_cookie(hello_verify);
124 m_client_hello.reset();
215 if(!m_ciphersuite.has_value())
219 return m_ciphersuite.value();
234 m_session_keys =
Session_Keys(
this, resume_master_secret,
true);
252std::pair<Handshake_Type, std::vector<uint8_t>>
270 if(prf_algo ==
"MD5" || prf_algo ==
"SHA-1")
276std::pair<std::string, Signature_Format>
279 bool for_client_auth,
280 const Policy& policy)
const
282 const std::string sig_algo = key.
algo_name();
286 std::vector<Signature_Scheme> requested =
291 if(!scheme.is_available())
296 if(scheme.algorithm_name() == sig_algo)
298 if(std::find(requested.begin(), requested.end(), scheme) != requested.end())
300 chosen_scheme = scheme;
311 "Policy refuses to accept signing with any hash supported by peer");
314 if(!chosen_scheme.
format().has_value())
315 {
throw Invalid_Argument(sig_algo +
" is invalid/unknown for TLS signatures"); }
322bool supported_algos_include(
323 const std::vector<Signature_Scheme>& schemes,
324 const std::string& key_type,
325 const std::string& hash_type)
329 if(scheme.is_available() &&
330 hash_type == scheme.hash_function_name() &&
331 key_type == scheme.algorithm_name())
342std::pair<std::string, Signature_Format>
345 const std::vector<Signature_Scheme>& offered_schemes,
346 bool for_client_auth,
347 const Policy& policy)
const
349 const std::string key_type = key.
algo_name();
354 "Rejecting " + key_type +
" signature");
360 "Peer sent unknown signature scheme");
364 {
throw Decoding_Error(
"Counterparty sent inconsistent key and sig types"); }
369 "No certificate verify set");
377 const std::vector<Signature_Scheme> supported_algos =
386 if(!supported_algos_include(supported_algos, key_type,
hash_algo))
389 "TLS signature extension did not allow for " +
390 key_type +
"/" +
hash_algo +
" signature");
393 if(!scheme.
format().has_value())
394 {
throw Invalid_Argument(key_type +
" is invalid/unknown for TLS signatures"); }
static std::unique_ptr< KDF > create_or_throw(const std::string &algo_spec, const std::string &provider="")
virtual std::string algo_name() const =0
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
std::vector< uint8_t > 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
std::vector< uint8_t > session_ticket() 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
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 std::vector< uint8_t > & ticket() const
virtual std::vector< Signature_Scheme > allowed_signature_schemes() const
bool allowed_signature_method(const std::string &sig_method) const
bool allowed_signature_hash(const std::string &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
std::string to_string(const BER_Object &obj)
const char * handshake_type_to_string(Handshake_Type type)
std::vector< T, secure_allocator< T > > secure_vector
AlgorithmIdentifier hash_algo