Botan 3.11.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 bool hostname_acceptable_for_sni (std::string_view hostname)
static Extension_Code static_type ()

Detailed Description

Server Name Indicator extension (RFC 3546)

Definition at line 103 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 109 of file tls_extensions.h.

109: 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 266 of file tls_extensions.cpp.

266 {
267 /*
268 * This is used by the server to confirm that it knew the name
269 */
270 if(extension_size == 0) {
271 return;
272 }
273
274 uint16_t name_bytes = reader.get_uint16_t();
275
276 if(name_bytes + 2 != extension_size) {
277 throw Decoding_Error("Bad encoding of SNI extension");
278 }
279
280 while(name_bytes > 0) {
281 const uint8_t name_type = reader.get_byte();
282 name_bytes--;
283
284 if(name_type == 0) {
285 // DNS
286 m_sni_host_name = reader.get_string(2, 1, 65535);
287 name_bytes -= static_cast<uint16_t>(2 + m_sni_host_name.size());
288 } else {
289 // some other unknown name type, which we will ignore
290 reader.discard_next(name_bytes);
291 name_bytes = 0;
292 }
293 }
294}

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 117 of file tls_extensions.h.

117{ return false; }

◆ host_name()

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

Definition at line 113 of file tls_extensions.h.

113{ return m_sni_host_name; }

Referenced by Server_Name_Indicator().

◆ hostname_acceptable_for_sni()

bool Botan::TLS::Server_Name_Indicator::hostname_acceptable_for_sni ( std::string_view hostname)
static

Definition at line 321 of file tls_extensions.cpp.

321 {
322 // Avoid sending an IPv4/IPv6 address in SNI as this is prohibited
323
324 if(hostname.empty()) {
325 return false;
326 }
327
328 if(string_to_ipv4(hostname).has_value()) {
329 return false;
330 }
331
332 // IPv6? Anyway ':' is not valid in DNS
333 if(hostname.find(':') != std::string_view::npos) {
334 return false;
335 }
336
337 return true;
338}
std::optional< uint32_t > string_to_ipv4(std::string_view str)
Definition parsing.cpp:156

References Botan::string_to_ipv4().

Referenced by Botan::TLS::Client_Hello_12::Client_Hello_12(), Botan::TLS::Client_Hello_12::Client_Hello_12(), and Botan::TLS::Client_Hello_13::Client_Hello_13().

◆ 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 95 of file tls_extensions.h.

95{ 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 296 of file tls_extensions.cpp.

296 {
297 // RFC 6066
298 // [...] the server SHALL include an extension of type "server_name" in
299 // the (extended) server hello. The "extension_data" field of this
300 // extension SHALL be empty.
301 if(whoami == Connection_Side::Server) {
302 return {};
303 }
304
305 std::vector<uint8_t> buf;
306
307 const size_t name_len = m_sni_host_name.size();
308
309 buf.push_back(get_byte<0>(static_cast<uint16_t>(name_len + 3)));
310 buf.push_back(get_byte<1>(static_cast<uint16_t>(name_len + 3)));
311 buf.push_back(0); // DNS
312
313 buf.push_back(get_byte<0>(static_cast<uint16_t>(name_len)));
314 buf.push_back(get_byte<1>(static_cast<uint16_t>(name_len)));
315
316 buf += as_span_of_bytes(m_sni_host_name);
317
318 return buf;
319}
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:59

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 105 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 107 of file tls_extensions.h.

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

References static_type().


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