13#ifndef BOTAN_TLS_EXTENSIONS_H_
14#define BOTAN_TLS_EXTENSIONS_H_
16#include <botan/credentials_manager.h>
17#include <botan/pkix_types.h>
18#include <botan/secmem.h>
19#include <botan/tls_algos.h>
20#include <botan/tls_magic.h>
21#include <botan/tls_session.h>
22#include <botan/tls_signature_scheme.h>
23#include <botan/tls_version.h>
35class RandomNumberGenerator;
36class Credentials_Manager;
40#if defined(BOTAN_HAS_TLS_13)
45class Transcript_Hash_State;
78#if defined(BOTAN_HAS_TLS_13)
134 std::string
host_name()
const {
return m_sni_host_name; }
138 bool empty()
const override {
return false; }
141 std::string m_sni_host_name;
163 bool empty()
const override {
return false; }
166 std::vector<uint8_t> m_reneg_data;
178 const std::vector<std::string>&
protocols()
const {
return m_protocols; }
180 std::string single_protocol()
const;
186 m_protocols(1, std::string(protocol)) {}
192 m_protocols(protocols) {}
198 bool empty()
const override {
return m_protocols.empty(); }
201 std::vector<std::string> m_protocols;
226 const std::vector<Certificate_Type>& server_preference);
241 return m_from == Connection_Side::Client && m_certificate_types.size() == 1 &&
242 m_certificate_types.front() == Certificate_Type::X509;
246 std::vector<Certificate_Type> m_certificate_types;
252 using Certificate_Type_Base::Certificate_Type_Base;
266 using Certificate_Type_Base::Certificate_Type_Base;
309 bool empty()
const override {
return false; }
324 const std::vector<Group_Params>& groups()
const;
327 std::vector<Group_Params> ec_groups()
const;
330 std::vector<Group_Params> dh_groups()
const;
338 bool empty()
const override {
return m_groups.empty(); }
341 std::vector<Group_Params> m_groups;
354 ANSIX962_COMPRESSED_PRIME = 1,
355 ANSIX962_COMPRESSED_CHAR2 = 2,
368 bool empty()
const override {
return false; }
373 bool m_prefers_compressed =
false;
389 bool empty()
const override {
return m_schemes.empty(); }
396 std::vector<Signature_Scheme> m_schemes;
422 bool empty()
const override {
return m_schemes.empty(); }
429 std::vector<Signature_Scheme> m_schemes;
441 const std::vector<uint16_t>&
profiles()
const {
return m_pp; }
445 bool empty()
const override {
return m_pp.empty(); }
454 std::vector<uint16_t> m_pp;
468 bool empty()
const override {
return false; }
486 bool empty()
const override {
return false; }
493class Certificate_Status_Request_Internal;
506 bool empty()
const override {
return false; }
510 const std::vector<uint8_t>& get_ocsp_response()
const;
517 std::vector<std::vector<uint8_t>> ocsp_key_ids);
523 uint16_t extension_size,
530 std::unique_ptr<Certificate_Status_Request_Internal> m_impl;
544 bool empty()
const override {
return m_versions.empty(); }
554 const std::vector<Protocol_Version>&
versions()
const {
return m_versions; }
557 std::vector<Protocol_Version> m_versions;
577 uint16_t
limit()
const {
return m_limit; }
581 bool empty()
const override {
return m_limit == 0; }
589#if defined(BOTAN_HAS_TLS_13)
601 bool empty()
const override {
return m_cookie.empty(); }
603 const std::vector<uint8_t>&
get_cookie()
const {
return m_cookie; }
605 explicit Cookie(
const std::vector<uint8_t>& cookie);
610 std::vector<uint8_t> m_cookie;
624 bool empty()
const override {
return m_modes.empty(); }
626 const std::vector<PSK_Key_Exchange_Mode>&
modes()
const {
return m_modes; }
633 std::vector<PSK_Key_Exchange_Mode> m_modes;
647 bool empty()
const override {
return m_distinguished_names.empty(); }
655 std::vector<X509_DN> m_distinguished_names;
680 std::pair<std::optional<std::string>, std::unique_ptr<Cipher_State>> take_selected_psk_info(
688 std::unique_ptr<PSK> select_offered_psk(std::string_view host,
706 std::variant<Session, ExternalPSK> take_session_to_resume_or_psk();
708 bool empty()
const override;
724 PSK(std::optional<Session_with_Handle>& session_to_resume, std::vector<ExternalPSK> psks,
Callbacks& callbacks);
729 bool validate_binder(
const PSK& server_psk,
const std::vector<uint8_t>& binder)
const;
742 PSK(
Session session_to_resume, uint16_t psk_index);
755 std::unique_ptr<PSK_Internal> m_impl;
769 bool empty()
const override;
779 static std::unique_ptr<Key_Share> create_as_encapsulation(
Group_Params selected_group,
803 void retry_offer(
const Key_Share& retry_request_keyshare,
804 const std::vector<Named_Group>& supported_groups,
811 std::vector<Named_Group> offered_groups()
const;
848 class Key_Share_Impl;
849 std::unique_ptr<Key_Share_Impl> m_impl;
863 bool empty()
const override;
875 m_max_early_data_size(std::move(max_early_data_size)) {}
878 std::optional<uint32_t> m_max_early_data_size;
892 const std::vector<uint8_t>&
value() {
return m_value; }
894 bool empty()
const override {
return false; }
902 std::vector<uint8_t> m_value;
910 std::set<Extension_Code> extension_types()
const;
912 const std::vector<std::unique_ptr<Extension>>&
all()
const {
return m_extensions; }
914 template <
typename T>
916 return dynamic_cast<T*
>(get(T::static_type()));
919 template <
typename T>
921 return get<T>() !=
nullptr;
926 size_t size()
const {
return m_extensions.size(); }
928 bool empty()
const {
return m_extensions.empty(); }
930 void add(std::unique_ptr<Extension> extn);
935 const auto i = std::find_if(
936 m_extensions.cbegin(), m_extensions.cend(), [type](
const auto& ext) { return ext->type() == type; });
938 return (i != m_extensions.end()) ? i->get() :
nullptr;
950 bool contains_other_than(
const std::set<Extension_Code>& allowed_extensions,
951 bool allow_unknown_extensions =
false)
const;
959 return contains_other_than(allowed_extensions,
true);
966 template <
typename T>
970 auto ext = take(T::static_type());
972 out_ptr.reset(
dynamic_cast<T*
>(ext.get()));
1002 deserialize(reader, side, message_type);
1006 std::vector<std::unique_ptr<Extension>> m_extensions;
#define BOTAN_ASSERT_NOMSG(expr)
Application_Layer_Protocol_Notification(std::string_view protocol)
const std::vector< std::string > & protocols() const
Application_Layer_Protocol_Notification(const std::vector< std::string > &protocols)
Extension_Code type() const override
bool empty() const override
static Extension_Code static_type()
static Extension_Code static_type()
Extension_Code type() const override
bool empty() const override
const std::vector< X509_DN > & distinguished_names() const
const std::vector< uint8_t > & get_request_extensions() const
~Certificate_Status_Request() override
const std::vector< uint8_t > & get_responder_id_list() const
static Extension_Code static_type()
Extension_Code type() const override
bool empty() const override
bool empty() const override
Extension_Code type() const override
static Extension_Code static_type()
bool empty() const override
const std::vector< uint8_t > & get_cookie() const
static Extension_Code static_type()
Extension_Code type() const override
std::optional< uint32_t > max_early_data_size() const
EarlyDataIndication(std::optional< uint32_t > max_early_data_size=std::nullopt)
Extension_Code type() const override
static Extension_Code static_type()
Extension_Code type() const override
Encrypt_then_MAC()=default
static Extension_Code static_type()
bool empty() const override
static Extension_Code static_type()
Extension_Code type() const override
Extended_Master_Secret()=default
bool empty() const override
virtual std::vector< uint8_t > serialize(Connection_Side whoami) const =0
virtual bool is_implemented() const
virtual Extension_Code type() const =0
virtual bool empty() const =0
virtual ~Extension()=default
Extensions(Extensions &&)=default
void add(Extension *extn)
Extension * get(Extension_Code type) const
bool contains_implemented_extensions_other_than(const std::set< Extension_Code > &allowed_extensions) const
Extensions & operator=(const Extensions &)=delete
Extensions(const Extensions &)=delete
Extensions(TLS_Data_Reader &reader, Connection_Side side, Handshake_Type message_type)
Extensions & operator=(Extensions &&)=default
bool remove_extension(Extension_Code type)
bool has(Extension_Code type) const
const std::vector< std::unique_ptr< Extension > > & all() const
static Extension_Code static_type()
Extension_Code type() const override
Extension_Code type() const override
static Extension_Code static_type()
const std::vector< PSK_Key_Exchange_Mode > & modes() const
PSK_Key_Exchange_Modes(std::vector< PSK_Key_Exchange_Mode > modes)
bool empty() const override
Extension_Code type() const override
static Extension_Code static_type()
Extension_Code type() const override
static Extension_Code static_type()
bool empty() const override
static Extension_Code static_type()
Renegotiation_Extension(const std::vector< uint8_t > &bits)
bool empty() const override
Extension_Code type() const override
Renegotiation_Extension()=default
const std::vector< uint8_t > & renegotiation_info() const
Extension_Code type() const override
SRTP_Protection_Profiles(uint16_t pp)
bool empty() const override
SRTP_Protection_Profiles(const std::vector< uint16_t > &pp)
const std::vector< uint16_t > & profiles() const
static Extension_Code static_type()
static Extension_Code static_type()
Extension_Code type() const override
static Extension_Code static_type()
Extension_Code type() const override
std::string host_name() const
bool empty() const override
Server_Name_Indicator(std::string_view host_name)
Session_Ticket_Extension()=default
static Extension_Code static_type()
Extension_Code type() const override
Session_Ticket_Extension(Session_Ticket session_ticket)
std::vector< uint8_t > serialize(Connection_Side) const override
bool empty() const override
const Session_Ticket & contents() const
static Extension_Code static_type()
bool empty() const override
Signature_Algorithms_Cert(std::vector< Signature_Scheme > schemes)
const std::vector< Signature_Scheme > & supported_schemes() const
Extension_Code type() const override
Signature_Algorithms(std::vector< Signature_Scheme > schemes)
const std::vector< Signature_Scheme > & supported_schemes() const
bool empty() const override
static Extension_Code static_type()
Extension_Code type() const override
bool empty() const override
Extension_Code type() const override
static Extension_Code static_type()
static Extension_Code static_type()
const std::vector< Protocol_Version > & versions() const
bool empty() const override
Supported_Versions(Protocol_Version version)
Extension_Code type() const override
bool empty() const override
const std::vector< uint8_t > & value()
bool is_implemented() const override
Extension_Code type() const override
int(* final)(unsigned char *, CTX *)
#define BOTAN_UNSTABLE_API
std::string certificate_type_to_string(Certificate_Type type)
@ CertSignatureAlgorithms
@ ApplicationLayerProtocolNegotiation
@ CertificateStatusRequest
Certificate_Type certificate_type_from_string(const std::string &type_str)
constexpr auto out_ptr(T &outptr) noexcept
std::vector< T, secure_allocator< T > > secure_vector