Botan 3.14.1
Crypto and TLS for C&
Botan::TLS::Client_Hello_Internal Class Reference

#include <tls_messages_internal.h>

Public Member Functions

const std::vector< uint16_t > & ciphersuites () const
 Client_Hello_Internal ()
 Client_Hello_Internal (std::span< const uint8_t > buf)
const std::vector< uint8_t > & comp_methods () const
Extensions & extensions ()
const Extensions & extensions () const
const std::vector< uint8_t > & hello_cookie () const
const std::vector< uint8_t > & hello_cookie_input_bits () const
Protocol_Version legacy_version () const
const std::vector< uint8_t > & random () const
const Session_ID & session_id () const
Protocol_Version version () const

Public Attributes

std::vector< uint8_t > m_comp_methods
std::vector< uint8_t > m_cookie_input_bits
Extensions m_extensions
std::vector< uint8_t > m_hello_cookie
Protocol_Version m_legacy_version
std::vector< uint8_t > m_random
Session_ID m_session_id
std::vector< uint16_t > m_suites

Detailed Description

Version-agnostic internal client hello data container that allows parsing Client_Hello messages without prior knowledge of the contained protocol version.

Definition at line 97 of file tls_messages_internal.h.

Constructor & Destructor Documentation

◆ Client_Hello_Internal() [1/2]

Botan::TLS::Client_Hello_Internal::Client_Hello_Internal ( )
inline

Definition at line 99 of file tls_messages_internal.h.

99: m_comp_methods({0}) {}

References m_comp_methods.

◆ Client_Hello_Internal() [2/2]

Botan::TLS::Client_Hello_Internal::Client_Hello_Internal ( std::span< const uint8_t > buf)
explicit

Definition at line 61 of file msg_client_hello.cpp.

61 {
62 /*
63 Minimum possible client hello
64
65 version: 2 bytes
66 random: 32 bytes
67 session_id len: 1 byte
68 ciphersuite_len: 2
69 ciphersuite (single): 2
70 compression_len: 1
71 compression (single): 1
72 */
73
74 constexpr size_t MinimumClientHelloBytes = 2 + 32 + 1 + 2 + 2 + 1 + 1;
75 if(buf.size() < MinimumClientHelloBytes) {
76 throw Decoding_Error("Client_Hello: Packet corrupted");
77 }
78
79 TLS_Data_Reader reader("ClientHello", buf);
80
81 const uint8_t major_version = reader.get_byte();
82 const uint8_t minor_version = reader.get_byte();
83
84 m_legacy_version = Protocol_Version(major_version, minor_version);
85
86 // DTLS has an additional 1 byte cookie length field
87 if(m_legacy_version.is_datagram_protocol() && buf.size() < MinimumClientHelloBytes + 1) {
88 throw Decoding_Error("Client_Hello: DTLS packet corrupted");
89 }
90
91 m_random = reader.get_fixed<uint8_t>(32);
92 m_session_id = Session_ID(reader.get_range<uint8_t>(1, 0, 32));
93
94 if(m_legacy_version.is_datagram_protocol()) {
95 auto sha256 = HashFunction::create_or_throw("SHA-256");
96 sha256->update(reader.get_data_read_so_far());
97
98 m_hello_cookie = reader.get_range<uint8_t>(1, 0, 255);
99
100 sha256->update(reader.get_remaining());
101 m_cookie_input_bits = sha256->final_stdvec();
102 }
103
104 m_suites = reader.get_range_vector<uint16_t>(2, 1, 32767);
105 m_comp_methods = reader.get_range_vector<uint8_t>(1, 1, 255);
106
108}
static std::unique_ptr< HashFunction > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition hash.cpp:311
Strong< std::vector< uint8_t >, struct Session_ID_ > Session_ID
holds a TLS 1.2 session ID for stateful resumption

References Botan::HashFunction::create_or_throw(), Botan::TLS::TLS_Data_Reader::get_byte(), Botan::TLS::TLS_Data_Reader::get_data_read_so_far(), Botan::TLS::TLS_Data_Reader::get_fixed(), Botan::TLS::TLS_Data_Reader::get_range(), Botan::TLS::TLS_Data_Reader::get_remaining(), m_hello_cookie, m_legacy_version, m_random, and m_session_id.

Member Function Documentation

◆ ciphersuites()

const std::vector< uint16_t > & Botan::TLS::Client_Hello_Internal::ciphersuites ( ) const
inline

Definition at line 120 of file tls_messages_internal.h.

120{ return m_suites; }

References m_suites.

◆ comp_methods()

const std::vector< uint8_t > & Botan::TLS::Client_Hello_Internal::comp_methods ( ) const
inline

Definition at line 122 of file tls_messages_internal.h.

122{ return m_comp_methods; }

References m_comp_methods.

◆ extensions() [1/2]

Extensions & Botan::TLS::Client_Hello_Internal::extensions ( )
inline

Definition at line 130 of file tls_messages_internal.h.

130{ return m_extensions; }

References m_extensions.

◆ extensions() [2/2]

const Extensions & Botan::TLS::Client_Hello_Internal::extensions ( ) const
inline

Definition at line 128 of file tls_messages_internal.h.

128{ return m_extensions; }

References m_extensions.

Referenced by version().

◆ hello_cookie()

const std::vector< uint8_t > & Botan::TLS::Client_Hello_Internal::hello_cookie ( ) const
inline

Definition at line 124 of file tls_messages_internal.h.

124{ return m_hello_cookie; }

References m_hello_cookie.

◆ hello_cookie_input_bits()

const std::vector< uint8_t > & Botan::TLS::Client_Hello_Internal::hello_cookie_input_bits ( ) const
inline

Definition at line 126 of file tls_messages_internal.h.

126{ return m_cookie_input_bits; }

References m_cookie_input_bits.

◆ legacy_version()

Protocol_Version Botan::TLS::Client_Hello_Internal::legacy_version ( ) const
inline

Definition at line 114 of file tls_messages_internal.h.

114{ return m_legacy_version; }

References m_legacy_version.

◆ random()

const std::vector< uint8_t > & Botan::TLS::Client_Hello_Internal::random ( ) const
inline

Definition at line 118 of file tls_messages_internal.h.

118{ return m_random; }

References m_random.

◆ session_id()

const Session_ID & Botan::TLS::Client_Hello_Internal::session_id ( ) const
inline

Definition at line 116 of file tls_messages_internal.h.

116{ return m_session_id; }

References m_session_id.

◆ version()

Protocol_Version Botan::TLS::Client_Hello_Internal::version ( ) const

This distinguishes between a TLS 1.3 compliant Client Hello (containing the "supported_version" extension) and legacy Client Hello messages.

Returns
TLS 1.3 if the Client Hello contains "supported_versions", or the content of the "legacy_version" version field if it indicates (D)TLS 1.2 or older, or (D)TLS 1.2 if the "legacy_version" was some other odd value.

Definition at line 110 of file msg_client_hello.cpp.

110 {
111 // RFC 8446 4.2.1
112 // If [the "supported_versions"] extension is not present, servers
113 // which are compliant with this specification and which also support
114 // TLS 1.2 MUST negotiate TLS 1.2 or prior as specified in [RFC5246],
115 // even if ClientHello.legacy_version is 0x0304 or later.
116 //
117 // RFC 8446 4.2.1
118 // Servers MUST be prepared to receive ClientHellos that include
119 // [the supported_versions] extension but do not include 0x0304 in
120 // the list of versions.
121 //
122 // RFC 8446 4.1.2
123 // TLS 1.3 ClientHellos are identified as having a legacy_version of
124 // 0x0303 and a supported_versions extension present with 0x0304 as
125 // the highest version indicated therein.
126 if(!extensions().has<Supported_Versions>() ||
127 !extensions().get<Supported_Versions>()->supports(Protocol_Version::TLS_V13)) {
128 // The exact legacy_version is ignored we just inspect it to
129 // distinguish TLS and DTLS.
130 return (m_legacy_version.is_datagram_protocol()) ? Protocol_Version::DTLS_V12 : Protocol_Version::TLS_V12;
131 }
132
133 // Note: The Client_Hello_13 class will make sure that legacy_version
134 // is exactly 0x0303 (aka ossified TLS 1.2)
135 return Protocol_Version::TLS_V13;
136}
const Extensions & extensions() const

References extensions(), and m_legacy_version.

Member Data Documentation

◆ m_comp_methods

std::vector<uint8_t> Botan::TLS::Client_Hello_Internal::m_comp_methods

Definition at line 137 of file tls_messages_internal.h.

Referenced by Client_Hello_Internal(), and comp_methods().

◆ m_cookie_input_bits

std::vector<uint8_t> Botan::TLS::Client_Hello_Internal::m_cookie_input_bits

Definition at line 142 of file tls_messages_internal.h.

Referenced by hello_cookie_input_bits().

◆ m_extensions

Extensions Botan::TLS::Client_Hello_Internal::m_extensions

Definition at line 138 of file tls_messages_internal.h.

Referenced by extensions(), and extensions().

◆ m_hello_cookie

std::vector<uint8_t> Botan::TLS::Client_Hello_Internal::m_hello_cookie

Definition at line 141 of file tls_messages_internal.h.

Referenced by Client_Hello_Internal(), and hello_cookie().

◆ m_legacy_version

Protocol_Version Botan::TLS::Client_Hello_Internal::m_legacy_version

Definition at line 133 of file tls_messages_internal.h.

Referenced by Client_Hello_Internal(), legacy_version(), and version().

◆ m_random

std::vector<uint8_t> Botan::TLS::Client_Hello_Internal::m_random

Definition at line 135 of file tls_messages_internal.h.

Referenced by Client_Hello_Internal(), and random().

◆ m_session_id

Session_ID Botan::TLS::Client_Hello_Internal::m_session_id

Definition at line 134 of file tls_messages_internal.h.

Referenced by Client_Hello_Internal(), and session_id().

◆ m_suites

std::vector<uint16_t> Botan::TLS::Client_Hello_Internal::m_suites

Definition at line 136 of file tls_messages_internal.h.

Referenced by ciphersuites().


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