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

#include <tls_version.h>

Public Member Functions

bool is_datagram_protocol () const
bool is_pre_tls_13 () const
bool is_tls_13_or_later () const
bool known_version () const
uint8_t major_version () const
uint8_t minor_version () const
bool operator!= (const Protocol_Version &other) const
bool operator< (const Protocol_Version &other) const
bool operator<= (const Protocol_Version &other) const
bool operator== (const Protocol_Version &other) const
bool operator> (const Protocol_Version &other) const
bool operator>= (const Protocol_Version &other) const
 Protocol_Version ()
 Protocol_Version (uint16_t code)
 Protocol_Version (uint8_t major, uint8_t minor)
 Protocol_Version (Version_Code named_version)
std::string to_string () const
bool valid () const
uint16_t version_code () const

Static Public Member Functions

static Protocol_Version latest_dtls_version ()
static Protocol_Version latest_tls_version ()

Detailed Description

TLS Protocol Version

Definition at line 38 of file tls_version.h.

Constructor & Destructor Documentation

◆ Protocol_Version() [1/4]

Botan::TLS::Protocol_Version::Protocol_Version ( )
inline

◆ Protocol_Version() [2/4]

Botan::TLS::Protocol_Version::Protocol_Version ( uint16_t code)
inlineexplicit

Definition at line 60 of file tls_version.h.

60: m_version(code) {}

◆ Protocol_Version() [3/4]

Botan::TLS::Protocol_Version::Protocol_Version ( Version_Code named_version)
inline
Parameters
named_versiona specific named version of the protocol

Definition at line 65 of file tls_version.h.

65 : // NOLINT(*-explicit-conversions,*-explicit-constructor)
66 Protocol_Version(static_cast<uint16_t>(named_version)) {}

References Protocol_Version().

◆ Protocol_Version() [4/4]

Botan::TLS::Protocol_Version::Protocol_Version ( uint8_t major,
uint8_t minor )
inline
Parameters
majorthe major version
minorthe minor version

Definition at line 72 of file tls_version.h.

72 :
73 Protocol_Version(static_cast<uint16_t>((static_cast<uint16_t>(major) << 8) | minor)) {}

References Protocol_Version().

Member Function Documentation

◆ is_datagram_protocol()

bool Botan::TLS::Protocol_Version::is_datagram_protocol ( ) const

◆ is_pre_tls_13()

bool Botan::TLS::Protocol_Version::is_pre_tls_13 ( ) const
Returns
true if this version indicates (D)TLS 1.2 or older

Definition at line 58 of file tls_version.cpp.

58 {
59 return (!is_datagram_protocol() && *this <= Protocol_Version::TLS_V12) ||
60 (is_datagram_protocol() && *this <= Protocol_Version::DTLS_V12);
61}

References is_datagram_protocol().

Referenced by Botan::TLS::Policy::ciphersuite_list(), Botan::TLS::Session_Manager_Hybrid::establish(), Botan::TLS::group_usable_in_version(), Botan::TLS::make_server_hello_random(), Botan::TLS::Callbacks::tls_should_persist_resumption_information(), and Botan::TLS::Ciphersuite::usable_in_version().

◆ is_tls_13_or_later()

bool Botan::TLS::Protocol_Version::is_tls_13_or_later ( ) const
Returns
true if this version indicates a (D)TLS newer than 1.3

Definition at line 63 of file tls_version.cpp.

63 {
64 return (!is_datagram_protocol() && *this >= Protocol_Version::TLS_V13) ||
65 (is_datagram_protocol() && *this >= Protocol_Version::DTLS_V13);
66}

References is_datagram_protocol().

◆ known_version()

bool Botan::TLS::Protocol_Version::known_version ( ) const
Returns
true if this is a protocol version we know about

Definition at line 103 of file tls_version.cpp.

103 {
104#if defined(BOTAN_HAS_TLS_13)
105 if(m_version == static_cast<uint16_t>(Protocol_Version::TLS_V13)) {
106 return true;
107 }
108#endif
109
110#if defined(BOTAN_HAS_TLS_12)
111 if(m_version == static_cast<uint16_t>(Protocol_Version::TLS_V12)) {
112 return true;
113 }
114 if(m_version == static_cast<uint16_t>(Protocol_Version::DTLS_V12)) {
115 return true;
116 }
117#endif
118
119 return false;
120}

◆ latest_dtls_version()

Protocol_Version Botan::TLS::Protocol_Version::latest_dtls_version ( )
static

Returns the latest version of the DTLS protocol known to the library and available in the current build.

Returns
latest known DTLS version

Definition at line 26 of file tls_version.cpp.

26 {
27#if defined(BOTAN_HAS_TLS_12)
28 return Protocol_Version::DTLS_V12;
29#else
30 throw Not_Implemented("This build contains no usable DTLS version");
31#endif
32}

References Protocol_Version().

◆ latest_tls_version()

Protocol_Version Botan::TLS::Protocol_Version::latest_tls_version ( )
static

Returns the latest version of the TLS protocol known to the library and available in the current build.

Returns
latest known TLS version

Definition at line 16 of file tls_version.cpp.

16 {
17#if defined(BOTAN_HAS_TLS_13)
18 return Protocol_Version::TLS_V13;
19#elif defined(BOTAN_HAS_TLS_12)
20 return Protocol_Version::TLS_V12;
21#else
22 throw Not_Implemented("This build contains no usable TLS version");
23#endif
24}

References Protocol_Version().

◆ major_version()

uint8_t Botan::TLS::Protocol_Version::major_version ( ) const
inline

◆ minor_version()

uint8_t Botan::TLS::Protocol_Version::minor_version ( ) const
inline
Returns
minor version of the protocol version

Definition at line 93 of file tls_version.h.

93{ return static_cast<uint8_t>(m_version & 0xFF); }

Referenced by Botan::TLS::Client_Key_Exchange::Client_Key_Exchange(), Botan::TLS::Connection_Cipher_State::format_ad(), Botan::TLS::Hello_Verify_Request::serialize(), to_string(), and valid().

◆ operator!=()

bool Botan::TLS::Protocol_Version::operator!= ( const Protocol_Version & other) const
inline
Returns
if this version is not equal to other

Definition at line 132 of file tls_version.h.

132{ return (m_version != other.m_version); }

References Protocol_Version().

◆ operator<()

bool Botan::TLS::Protocol_Version::operator< ( const Protocol_Version & other) const
inline
Returns
if this version is earlier to other

Definition at line 147 of file tls_version.h.

147{ return !(*this >= other); }

References Protocol_Version().

◆ operator<=()

bool Botan::TLS::Protocol_Version::operator<= ( const Protocol_Version & other) const
inline
Returns
if this version is earlier than or equal to other

Definition at line 152 of file tls_version.h.

152{ return (*this == other || *this < other); }

References Protocol_Version().

◆ operator==()

bool Botan::TLS::Protocol_Version::operator== ( const Protocol_Version & other) const
inline
Returns
if this version is equal to other

Definition at line 127 of file tls_version.h.

127{ return (m_version == other.m_version); }

References Protocol_Version().

◆ operator>()

bool Botan::TLS::Protocol_Version::operator> ( const Protocol_Version & other) const
Returns
if this version is later than other

Definition at line 68 of file tls_version.cpp.

68 {
69 if(this->is_datagram_protocol() != other.is_datagram_protocol()) {
70 throw TLS_Exception(Alert::ProtocolVersion, "Version comparing " + to_string() + " with " + other.to_string());
71 }
72
73 if(this->is_datagram_protocol()) {
74 return m_version < other.m_version; // goes backwards
75 }
76
77 return m_version > other.m_version;
78}
std::string to_string() const

References is_datagram_protocol(), Protocol_Version(), and to_string().

◆ operator>=()

bool Botan::TLS::Protocol_Version::operator>= ( const Protocol_Version & other) const
inline
Returns
if this version is later than or equal to other

Definition at line 142 of file tls_version.h.

142{ return (*this == other || *this > other); }

References Protocol_Version().

◆ to_string()

std::string Botan::TLS::Protocol_Version::to_string ( ) const

Generate a human readable version string.

for instance "TLS v1.1" or "DTLS v1.0".

Returns
human-readable description of this version

Definition at line 34 of file tls_version.cpp.

34 {
35 const uint8_t maj = major_version();
36 const uint8_t min = minor_version();
37
38 if(maj == 3 && min == 0) {
39 return "SSL v3";
40 }
41
42 if(maj == 3 && min >= 1) { // TLS v1.x
43 return "TLS v1." + std::to_string(min - 1);
44 }
45
46 if(maj == 254) { // DTLS 1.x
47 return "DTLS v1." + std::to_string(255 - min);
48 }
49
50 // Some very new or very old protocol (or bogus data)
51 return "Unknown " + std::to_string(maj) + "." + std::to_string(min);
52}
uint8_t minor_version() const
Definition tls_version.h:93

References major_version(), and minor_version().

Referenced by Botan::TLS::Channel_Impl_12::create_handshake_state(), and operator>().

◆ valid()

bool Botan::TLS::Protocol_Version::valid ( ) const
Returns
true if this is a valid protocol version

Definition at line 80 of file tls_version.cpp.

80 {
81 const uint8_t maj = major_version();
82 const uint8_t min = minor_version();
83
84 if(maj == 3 && min <= 4) {
85 // 3.0: SSLv3
86 // 3.1: TLS 1.0
87 // 3.2: TLS 1.1
88 // 3.3: TLS 1.2
89 // 3.4: TLS 1.3
90 return true;
91 }
92
93 if(maj == 254 && (min == 252 || min == 253 || min == 255)) {
94 // 254.252: DTLS 1.3
95 // 254.253: DTLS 1.2
96 // 254.255: DTLS 1.0
97 return true;
98 }
99
100 return false;
101}

References major_version(), and minor_version().

◆ version_code()

uint16_t Botan::TLS::Protocol_Version::version_code ( ) const
inline
Returns
the version code

Definition at line 98 of file tls_version.h.

98{ return m_version; }

Referenced by Botan::TLS::PSKImporter::derive_imported_psk().


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