Botan 3.14.1
Crypto and TLS for C&
Botan::TLS::Supported_Versions Class Referencefinal

#include <tls_extensions.h>

Inheritance diagram for Botan::TLS::Supported_Versions:
Botan::TLS::Extension

Public Member Functions

bool empty () const override
virtual bool is_implemented () const
std::vector< uint8_t > serialize (Connection_Side whoami) const override
 Supported_Versions (Protocol_Version version)
 Supported_Versions (Protocol_Version version, const Policy &policy)
 Supported_Versions (TLS_Data_Reader &reader, uint16_t extension_size, Connection_Side from)
bool supports (Protocol_Version version) const
Extension_Code type () const override
const std::vector< Protocol_Version > & versions () const

Static Public Member Functions

static Extension_Code static_type ()

Detailed Description

Supported Versions from RFC 8446

Definition at line 408 of file tls_extensions.h.

Constructor & Destructor Documentation

◆ Supported_Versions() [1/3]

Botan::TLS::Supported_Versions::Supported_Versions ( Protocol_Version version,
const Policy & policy )

Definition at line 902 of file tls_extensions.cpp.

902 {
903 // RFC 8446 4.2.1
904 // The extension contains a list of supported versions in preference order,
905 // with the most preferred version first. Implementations [...] MUST send
906 // this extension in the ClientHello containing all versions of TLS which
907 // they are prepared to negotiate.
908 //
909 // We simply assume that we always want the newest available TLS version.
910#if defined(BOTAN_HAS_TLS_13)
911 if(!offer.is_datagram_protocol()) {
912 if(offer >= Protocol_Version::TLS_V13 && policy.allow_tls13()) {
913 m_versions.push_back(Protocol_Version::TLS_V13);
914 }
915 }
916#endif
917
918#if defined(BOTAN_HAS_TLS_12)
919 if(offer.is_datagram_protocol()) {
920 if(offer >= Protocol_Version::DTLS_V12 && policy.allow_dtls12()) {
921 m_versions.push_back(Protocol_Version::DTLS_V12);
922 }
923 } else {
924 if(offer >= Protocol_Version::TLS_V12 && policy.allow_tls12()) {
925 m_versions.push_back(Protocol_Version::TLS_V12);
926 }
927 }
928#endif
929
930 // if no versions are supported, the input variables are not used
931 BOTAN_UNUSED(offer, policy);
932}
#define BOTAN_UNUSED
Definition assert.h:151

References Botan::TLS::Policy::allow_dtls12(), Botan::TLS::Policy::allow_tls12(), Botan::TLS::Policy::allow_tls13(), BOTAN_UNUSED, and Botan::TLS::Protocol_Version::is_datagram_protocol().

◆ Supported_Versions() [2/3]

Botan::TLS::Supported_Versions::Supported_Versions ( Protocol_Version version)
inlineexplicit

Definition at line 420 of file tls_extensions.h.

420{ m_versions.push_back(version); }

◆ Supported_Versions() [3/3]

Botan::TLS::Supported_Versions::Supported_Versions ( TLS_Data_Reader & reader,
uint16_t extension_size,
Connection_Side from )

Definition at line 934 of file tls_extensions.cpp.

934 {
935 if(from == Connection_Side::Server) {
936 if(extension_size != 2) {
937 throw Decoding_Error("Server sent invalid supported_versions extension");
938 }
939 m_versions.push_back(Protocol_Version(reader.get_uint16_t()));
940 } else {
941 const auto versions = reader.get_range<uint16_t>(1, 1, 127);
942
943 for(const auto v : versions) {
944 m_versions.push_back(Protocol_Version(v));
945 }
946
947 if(extension_size != 1 + 2 * versions.size()) {
948 throw Decoding_Error("Client sent invalid supported_versions extension");
949 }
950 }
951}
const std::vector< Protocol_Version > & versions() const

References Botan::TLS::TLS_Data_Reader::get_range(), Botan::TLS::TLS_Data_Reader::get_uint16_t(), Botan::TLS::Server, and versions().

Member Function Documentation

◆ empty()

bool Botan::TLS::Supported_Versions::empty ( ) const
inlineoverridevirtual

Predicate if a TLS extension should be included or not

Returns
true if this extension should be encoded, otherwise false

Implements Botan::TLS::Extension.

Definition at line 416 of file tls_extensions.h.

416{ return m_versions.empty(); }

◆ is_implemented()

virtual bool Botan::TLS::Extension::is_implemented ( ) const
inlinevirtualinherited

Predicate if the extension is known/implemented

Note
this exists primarily to support unknown extension handling and doesn't need to be overridden even in the custom extension case.
Returns
true if this extension is known

Reimplemented in Botan::TLS::Unknown_Extension.

Definition at line 113 of file tls_extensions.h.

113{ return true; }

◆ serialize()

std::vector< uint8_t > Botan::TLS::Supported_Versions::serialize ( Connection_Side whoami) const
overridevirtual

Serialize a TLS extension

Parameters
whoamiwhich peer we are acting as in the protocol
Returns
serialized binary for the extension

Implements Botan::TLS::Extension.

Definition at line 878 of file tls_extensions.cpp.

878 {
879 std::vector<uint8_t> buf;
880
881 if(whoami == Connection_Side::Server) {
882 BOTAN_ASSERT_NOMSG(m_versions.size() == 1);
883 buf.push_back(m_versions[0].major_version());
884 buf.push_back(m_versions[0].minor_version());
885 } else {
886 // RFC 8446 4.2.1: ProtocolVersion versions<2..254>; - up to 127 entries.
887 BOTAN_ASSERT_NOMSG(!m_versions.empty());
888 BOTAN_ASSERT_NOMSG(m_versions.size() <= 127);
889 const uint8_t len = static_cast<uint8_t>(m_versions.size() * 2);
890
891 buf.push_back(len);
892
893 for(const Protocol_Version version : m_versions) {
894 buf.push_back(version.major_version());
895 buf.push_back(version.minor_version());
896 }
897 }
898
899 return buf;
900}
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:82

References BOTAN_ASSERT_NOMSG, and Botan::TLS::Server.

◆ static_type()

Extension_Code Botan::TLS::Supported_Versions::static_type ( )
inlinestatic

Definition at line 410 of file tls_extensions.h.

References Botan::TLS::SupportedVersions.

Referenced by type().

◆ supports()

bool Botan::TLS::Supported_Versions::supports ( Protocol_Version version) const

Definition at line 953 of file tls_extensions.cpp.

953 {
954 for(const auto v : m_versions) {
955 if(version == v) {
956 return true;
957 }
958 }
959 return false;
960}

Referenced by Botan::TLS::Client_Hello::offered_tls13().

◆ type()

Extension_Code Botan::TLS::Supported_Versions::type ( ) const
inlineoverridevirtual

Return TLS extension code

Returns
code number of the extension

Implements Botan::TLS::Extension.

Definition at line 412 of file tls_extensions.h.

412{ return static_type(); }
static Extension_Code static_type()

References static_type().

◆ versions()

const std::vector< Protocol_Version > & Botan::TLS::Supported_Versions::versions ( ) const
inline

Definition at line 426 of file tls_extensions.h.

426{ return m_versions; }

Referenced by Supported_Versions().


The documentation for this class was generated from the following files: