Botan 3.9.0
Crypto and TLS for C&
Botan::TLS::Server_Name_Indicator Class Referencefinal

#include <tls_extensions.h>

Inheritance diagram for Botan::TLS::Server_Name_Indicator:
Botan::TLS::Extension

Public Member Functions

bool empty () const override
std::string host_name () const
virtual bool is_implemented () const
std::vector< uint8_t > serialize (Connection_Side whoami) const override
 Server_Name_Indicator (std::string_view host_name)
 Server_Name_Indicator (TLS_Data_Reader &reader, uint16_t extension_size)
Extension_Code type () const override

Static Public Member Functions

static Extension_Code static_type ()

Detailed Description

Server Name Indicator extension (RFC 3546)

Definition at line 123 of file tls_extensions.h.

Constructor & Destructor Documentation

◆ Server_Name_Indicator() [1/2]

Botan::TLS::Server_Name_Indicator::Server_Name_Indicator ( std::string_view host_name)
inlineexplicit

Definition at line 129 of file tls_extensions.h.

129: m_sni_host_name(host_name) {}

References host_name().

◆ Server_Name_Indicator() [2/2]

Botan::TLS::Server_Name_Indicator::Server_Name_Indicator ( TLS_Data_Reader & reader,
uint16_t extension_size )

Definition at line 244 of file tls_extensions.cpp.

244 {
245 /*
246 * This is used by the server to confirm that it knew the name
247 */
248 if(extension_size == 0) {
249 return;
250 }
251
252 uint16_t name_bytes = reader.get_uint16_t();
253
254 if(name_bytes + 2 != extension_size) {
255 throw Decoding_Error("Bad encoding of SNI extension");
256 }
257
258 while(name_bytes > 0) {
259 uint8_t name_type = reader.get_byte();
260 name_bytes--;
261
262 if(name_type == 0) {
263 // DNS
264 m_sni_host_name = reader.get_string(2, 1, 65535);
265 name_bytes -= static_cast<uint16_t>(2 + m_sni_host_name.size());
266 } else {
267 // some other unknown name type, which we will ignore
268 reader.discard_next(name_bytes);
269 name_bytes = 0;
270 }
271 }
272}

References Botan::TLS::TLS_Data_Reader::discard_next(), Botan::TLS::TLS_Data_Reader::get_byte(), Botan::TLS::TLS_Data_Reader::get_string(), and Botan::TLS::TLS_Data_Reader::get_uint16_t().

Member Function Documentation

◆ empty()

bool Botan::TLS::Server_Name_Indicator::empty ( ) const
inlineoverridevirtual
Returns
if we should encode this extension or not

Implements Botan::TLS::Extension.

Definition at line 137 of file tls_extensions.h.

137{ return false; }

◆ host_name()

std::string Botan::TLS::Server_Name_Indicator::host_name ( ) const
inline

Definition at line 133 of file tls_extensions.h.

133{ return m_sni_host_name; }

Referenced by Server_Name_Indicator().

◆ is_implemented()

virtual bool Botan::TLS::Extension::is_implemented ( ) const
inlinevirtualinherited
Returns
true if this extension is known and implemented by Botan

Reimplemented in Botan::TLS::Unknown_Extension.

Definition at line 115 of file tls_extensions.h.

115{ return true; }

◆ serialize()

std::vector< uint8_t > Botan::TLS::Server_Name_Indicator::serialize ( Connection_Side whoami) const
overridevirtual
Returns
serialized binary for the extension

Implements Botan::TLS::Extension.

Definition at line 274 of file tls_extensions.cpp.

274 {
275 // RFC 6066
276 // [...] the server SHALL include an extension of type "server_name" in
277 // the (extended) server hello. The "extension_data" field of this
278 // extension SHALL be empty.
279 if(whoami == Connection_Side::Server) {
280 return {};
281 }
282
283 std::vector<uint8_t> buf;
284
285 size_t name_len = m_sni_host_name.size();
286
287 buf.push_back(get_byte<0>(static_cast<uint16_t>(name_len + 3)));
288 buf.push_back(get_byte<1>(static_cast<uint16_t>(name_len + 3)));
289 buf.push_back(0); // DNS
290
291 buf.push_back(get_byte<0>(static_cast<uint16_t>(name_len)));
292 buf.push_back(get_byte<1>(static_cast<uint16_t>(name_len)));
293
294 buf += as_span_of_bytes(m_sni_host_name);
295
296 return buf;
297}
constexpr uint8_t get_byte(T input)
Definition loadstor.h:79
std::span< const uint8_t > as_span_of_bytes(const char *s, size_t len)
Definition mem_utils.h:28

References Botan::as_span_of_bytes(), Botan::get_byte(), and Botan::TLS::Server.

◆ static_type()

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

Definition at line 125 of file tls_extensions.h.

References Botan::TLS::ServerNameIndication.

Referenced by type().

◆ type()

Extension_Code Botan::TLS::Server_Name_Indicator::type ( ) const
inlineoverridevirtual
Returns
code number of the extension

Implements Botan::TLS::Extension.

Definition at line 127 of file tls_extensions.h.

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

References static_type().


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