9#ifndef BOTAN_TLS_MESSAGES_H_
10#define BOTAN_TLS_MESSAGES_H_
20#include <botan/pk_keys.h>
21#include <botan/strong_type.h>
22#include <botan/tls_ciphersuite.h>
23#include <botan/tls_extensions.h>
24#include <botan/tls_handshake_msg.h>
25#include <botan/tls_policy.h>
26#include <botan/tls_session.h>
27#include <botan/x509cert.h>
32class Credentials_Manager;
43class Hello_Retry_Request;
48std::vector<uint8_t>
make_hello_random(RandomNumberGenerator& rng, Callbacks& cb,
const Policy& policy);
55 std::vector<uint8_t> serialize()
const override;
59 const std::vector<uint8_t>&
cookie()
const {
return m_cookie; }
64 std::string_view client_identity,
68 std::vector<uint8_t> m_cookie;
71class Client_Hello_Internal;
99 const std::vector<uint8_t>& random() const;
103 const std::vector<uint16_t>& ciphersuites() const;
105 bool offered_suite(uint16_t ciphersuite) const;
117 std::
string sni_hostname() const;
119 bool supports_alpn() const;
121 bool sent_signature_algorithms() const;
123 std::vector<std::
string> next_protocols() const;
125 std::vector<uint16_t> srtp_profiles() const;
127 std::vector<uint8_t> serialize() const override;
129 const std::vector<uint8_t>& cookie() const;
131 std::vector<uint8_t> cookie_input_data() const;
139 explicit
Client_Hello(std::unique_ptr<Client_Hello_Internal> data);
141 const std::vector<uint8_t>& compression_methods() const;
144 std::unique_ptr<Client_Hello_Internal> m_data;
152 m_new_session_version(version), m_hostname(hostname) {}
156 const std::string&
hostname()
const {
return m_hostname; }
160 const std::string m_hostname;
171 const std::vector<uint8_t>& reneg_info,
172 const Settings& client_settings,
173 const std::vector<std::string>& next_protocols);
180 const std::vector<uint8_t>& reneg_info,
182 const std::vector<std::string>& next_protocols);
189 using Client_Hello::compression_methods;
190 using Client_Hello::random;
192 bool prefers_compressed_ec_points()
const;
194 bool secure_renegotiation()
const;
196 std::vector<uint8_t> renegotiation_info()
const;
198 bool supports_session_ticket()
const;
202 std::optional<Session_Handle> session_handle()
const;
204 bool supports_extended_master_secret()
const;
206 bool supports_cert_status_message()
const;
208 bool supports_encrypt_then_mac()
const;
213 void add_tls12_supported_groups_extensions(
const Policy& policy);
216#if defined(BOTAN_HAS_TLS_13)
228 std::string_view hostname,
229 const std::vector<std::string>& next_protocols,
230 std::optional<Session_with_Handle>& session,
231 std::vector<ExternalPSK> psks);
233 static std::variant<Client_Hello_13, Client_Hello_12> parse(
const std::vector<uint8_t>& buf);
245 std::optional<Protocol_Version> highest_supported_version(
const Policy& policy)
const;
269class Server_Hello_Internal;
283 std::vector<uint8_t> serialize() const override;
288 uint16_t ciphersuite() const;
295 explicit
Server_Hello(std::unique_ptr<Server_Hello_Internal> data);
299 const std::vector<uint8_t>& random() const;
300 uint8_t compression_method() const;
304 std::unique_ptr<Server_Hello_Internal> m_data;
313 uint16_t ciphersuite,
314 bool offer_session_ticket) :
315 m_new_session_id(std::move(new_session_id)),
316 m_new_session_version(new_session_version),
317 m_ciphersuite(ciphersuite),
318 m_offer_session_ticket(offer_session_ticket) {}
331 uint16_t m_ciphersuite;
332 bool m_offer_session_ticket;
340 const std::vector<uint8_t>& secure_reneg_info,
342 const Settings& settings,
343 std::string_view next_protocol);
350 const std::vector<uint8_t>& secure_reneg_info,
352 const Session& resumed_session,
353 bool offer_session_ticket,
354 std::string_view next_protocol);
363 using Server_Hello::compression_method;
364 using Server_Hello::extension_types;
365 using Server_Hello::legacy_version;
366 using Server_Hello::random;
373 bool secure_renegotiation()
const;
375 std::vector<uint8_t> renegotiation_info()
const;
377 std::string next_protocol()
const;
379 bool supports_extended_master_secret()
const;
381 bool supports_encrypt_then_mac()
const;
383 bool supports_certificate_status_message()
const;
385 bool supports_session_ticket()
const;
387 uint16_t srtp_profile()
const;
388 bool prefers_compressed_ec_points()
const;
393 std::optional<Protocol_Version> random_signals_downgrade()
const;
396#if defined(BOTAN_HAS_TLS_13)
402 static const struct Server_Hello_Tag {
405 static const struct Hello_Retry_Request_Tag {
406 } as_hello_retry_request;
408 static const struct Hello_Retry_Request_Creation_Tag {
409 } as_new_hello_retry_request;
415 explicit Server_Hello_13(std::unique_ptr<Server_Hello_Internal> data, Server_Hello_Tag tag = as_server_hello);
416 explicit Server_Hello_13(std::unique_ptr<Server_Hello_Internal> data, Hello_Retry_Request_Tag tag);
417 void basic_validation()
const;
422 std::optional<Named_Group> key_exchange_group,
429 explicit Server_Hello_13(std::unique_ptr<Server_Hello_Internal> data, Hello_Retry_Request_Creation_Tag tag);
432 static std::variant<Hello_Retry_Request, Server_Hello_13> create(
const Client_Hello_13& ch,
433 bool hello_retry_request_allowed,
440 static std::variant<Hello_Retry_Request, Server_Hello_13, Server_Hello_12> parse(
const std::vector<uint8_t>& buf);
445 std::optional<Protocol_Version> random_signals_downgrade()
const;
474 std::vector<uint8_t> serialize()
const override;
494 const std::optional<std::string>&
psk_identity()
const {
return m_psk_identity; }
501 std::string_view hostname,
512 std::vector<uint8_t> serialize()
const override {
return m_key_material; }
514 std::vector<uint8_t> m_key_material;
516 std::optional<std::string> m_psk_identity;
526 const std::vector<X509_Certificate>&
cert_chain()
const {
return m_certs; }
528 size_t count()
const {
return m_certs.size(); }
530 bool empty()
const {
return m_certs.empty(); }
536 std::vector<uint8_t> serialize()
const override;
539 std::vector<X509_Certificate> m_certs;
542#if defined(BOTAN_HAS_TLS_13)
544class Certificate_Request_13;
560 std::shared_ptr<const Public_Key> public_key()
const;
562 std::vector<uint8_t> serialize()
const;
569 std::optional<X509_Certificate> m_certificate;
570 std::shared_ptr<Public_Key> m_raw_public_key;
577 std::vector<X509_Certificate> cert_chain()
const;
579 bool has_certificate_chain()
const;
580 bool is_raw_public_key()
const;
582 size_t count()
const {
return m_entries.size(); }
584 bool empty()
const {
return m_entries.empty(); }
586 std::shared_ptr<const Public_Key> public_key()
const;
596 std::string_view hostname,
631 void validate_extensions(
const std::set<Extension_Code>& requested_extensions,
Callbacks& cb)
const;
641 std::string_view hostname,
642 bool use_ocsp)
const;
644 std::vector<uint8_t> serialize()
const override;
647 void setup_entries(std::vector<X509_Certificate> cert_chain,
650 void setup_entry(std::shared_ptr<Public_Key> raw_public_key,
Callbacks& callbacks);
652 void verify_certificate_chain(
Callbacks& callbacks,
655 std::string_view hostname,
660 std::vector<uint8_t> m_request_context;
661 std::vector<Certificate_Entry> m_entries;
676 const std::vector<uint8_t>&
response()
const {
return m_response; }
689 std::vector<uint8_t> serialize()
const override;
692 std::vector<uint8_t> m_response;
702 const std::vector<std::string>& acceptable_cert_types()
const;
704 const std::vector<X509_DN>& acceptable_CAs()
const;
706 const std::vector<Signature_Scheme>& signature_schemes()
const;
711 const std::vector<X509_DN>& allowed_cas);
715 std::vector<uint8_t> serialize()
const override;
718 std::vector<X509_DN> m_names;
719 std::vector<std::string> m_cert_key_types;
720 std::vector<Signature_Scheme> m_schemes;
723#if defined(BOTAN_HAS_TLS_13)
733 static std::optional<Certificate_Request_13> maybe_create(
const Client_Hello_13& sni_hostname,
738 std::vector<X509_DN> acceptable_CAs()
const;
739 const std::vector<Signature_Scheme>& signature_schemes()
const;
740 const std::vector<Signature_Scheme>& certificate_signature_schemes()
const;
744 std::vector<uint8_t> serialize()
const override;
746 const std::vector<uint8_t>&
context()
const {
return m_context; }
752 std::vector<uint8_t> m_context;
767 std::vector<uint8_t> serialize()
const override;
779 using Certificate_Verify::Certificate_Verify;
796#if defined(BOTAN_HAS_TLS_13)
811 const std::vector<Signature_Scheme>& peer_allowed_schemes,
812 std::string_view hostname,
833 explicit Finished(
const std::vector<uint8_t>& buf);
837 std::vector<uint8_t> verify_data()
const;
839 std::vector<uint8_t> serialize()
const override;
842 using Handshake_Message::Handshake_Message;
848 using Finished::Finished;
854#if defined(BOTAN_HAS_TLS_13)
857 using Finished::Finished;
875 std::vector<uint8_t> serialize()
const override;
885 const std::vector<uint8_t>&
params()
const {
return m_params; }
896 const std::optional<Group_Params>&
shared_group()
const {
return m_shared_group; }
911 std::vector<uint8_t> serialize()
const override;
913 std::unique_ptr<PK_Key_Agreement_Key> m_kex_key;
914 std::optional<Group_Params> m_shared_group;
916 std::vector<uint8_t> m_params;
918 std::vector<uint8_t> m_signature;
933 std::vector<uint8_t> serialize()
const override;
950 std::chrono::seconds lifetime);
956 std::vector<uint8_t> serialize()
const override;
959 std::chrono::seconds m_ticket_lifetime_hint;
963#if defined(BOTAN_HAS_TLS_13)
979 std::vector<uint8_t> serialize()
const override;
989 std::chrono::seconds
lifetime_hint()
const {
return m_ticket_lifetime_hint; }
995 std::optional<uint32_t> early_data_byte_limit()
const;
1005 std::chrono::seconds m_ticket_lifetime_hint;
1006 uint32_t m_ticket_age_add;
1021 std::vector<uint8_t>
serialize()
const override {
return std::vector<uint8_t>(1, 1); }
1024#if defined(BOTAN_HAS_TLS_13)
1030 explicit Key_Update(
bool request_peer_update);
1031 explicit Key_Update(
const std::vector<uint8_t>& buf);
1033 std::vector<uint8_t> serialize()
const override;
1038 bool m_update_requested;
1042template <
typename T>
1043struct as_wrapped_references {};
1045template <
typename... AlternativeTs>
1046struct as_wrapped_references<std::variant<AlternativeTs...>> {
1047 using type = std::variant<std::reference_wrapper<AlternativeTs>...>;
1050template <
typename T>
1051using as_wrapped_references_t =
typename as_wrapped_references<T>::type;
Handshake_Type type() const override
const std::vector< X509_Certificate > & cert_chain() const
const Extensions & extensions() const
Extensions & extensions()
bool has_certificate() const
Handshake_Type type() const override
const std::vector< uint8_t > & request_context() const
const Extensions & extensions() const
const std::vector< uint8_t > & context() const
const std::vector< uint8_t > & response() const
Handshake_Type type() const override
Handshake_Type type() const override
Signature_Scheme m_scheme
Certificate_Verify()=default
Signature_Scheme signature_scheme() const
std::vector< uint8_t > m_signature
std::vector< uint8_t > serialize() const override
Handshake_Type type() const override
const std::string & hostname() const
Settings(const Protocol_Version version, std::string_view hostname="")
Protocol_Version protocol_version() const
Client_Hello(Client_Hello &&) noexcept
Client_Hello & operator=(const Client_Hello &)=delete
Client_Hello(const Client_Hello &)=delete
Handshake_Type type() const override
const std::optional< std::string > & psk_identity() const
const secure_vector< uint8_t > & pre_master_secret() const
const Extensions & extensions() const
Handshake_Type type() const override
std::vector< uint8_t > m_verification_data
Handshake_Type type() const override
Handshake_Type type() const override
Handshake_Type wire_type() const override
Handshake_Type type() const override
Handshake_Type type() const override
const std::vector< uint8_t > & cookie() const
bool expects_reciprocation() const
Handshake_Type type() const override
std::chrono::seconds ticket_lifetime_hint() const
Handshake_Type type() const override
const Session_Ticket & ticket() const
Handshake_Type type() const override
std::chrono::seconds lifetime_hint() const
uint32_t ticket_age_add() const
const Ticket_Nonce & nonce() const
const Opaque_Session_Handle & handle() const
const Extensions & extensions() const
uint16_t ciphersuite() const
Protocol_Version protocol_version() const
Settings(Session_ID new_session_id, Protocol_Version new_session_version, uint16_t ciphersuite, bool offer_session_ticket)
const Session_ID & session_id() const
bool offer_session_ticket() const
Handshake_Type type() const override
Server_Hello(const Server_Hello &)=delete
Server_Hello(Server_Hello &&) noexcept
Server_Hello & operator=(const Server_Hello &)=delete
Handshake_Type type() const override
const std::vector< uint8_t > & params() const
const std::optional< Group_Params > & shared_group() const
Helper class to embody a session handle in all protocol versions.
int(* final)(unsigned char *, CTX *)
#define BOTAN_UNSTABLE_API
as_wrapped_references_t< Server_Handshake_13_Message > Server_Handshake_13_Message_Ref
as_wrapped_references_t< Client_Handshake_13_Message > Client_Handshake_13_Message_Ref
std::vector< uint8_t > Transcript_Hash
as_wrapped_references_t< Handshake_Message_13 > Handshake_Message_13_Ref
std::variant< Key_Update > Client_Post_Handshake_13_Message
std::variant< Client_Hello_13, Client_Hello_12, Certificate_13, Certificate_Verify_13, Finished_13 > Client_Handshake_13_Message
std::variant< Server_Hello_13, Server_Hello_12, Hello_Retry_Request, Encrypted_Extensions, Certificate_13, Certificate_Request_13, Certificate_Verify_13, Finished_13 > Server_Handshake_13_Message
std::vector< uint8_t > make_hello_random(RandomNumberGenerator &rng, Callbacks &cb, const Policy &policy)
std::variant< New_Session_Ticket_13, Key_Update > Post_Handshake_Message_13
std::variant< New_Session_Ticket_13, Key_Update > Server_Post_Handshake_13_Message
std::variant< Client_Hello_13, Client_Hello_12, Server_Hello_13, Server_Hello_12, Hello_Retry_Request, Encrypted_Extensions, Certificate_13, Certificate_Request_13, Certificate_Verify_13, Finished_13 > Handshake_Message_13
std::vector< T, secure_allocator< T > > secure_vector