Botan 3.3.0
Crypto and TLS for C&
Public Member Functions | Static Public Member Functions | List of all members
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 124 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 130 of file tls_extensions.h.

130: m_sni_host_name(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 233 of file tls_extensions.cpp.

233 {
234 /*
235 * This is used by the server to confirm that it knew the name
236 */
237 if(extension_size == 0) {
238 return;
239 }
240
241 uint16_t name_bytes = reader.get_uint16_t();
242
243 if(name_bytes + 2 != extension_size) {
244 throw Decoding_Error("Bad encoding of SNI extension");
245 }
246
247 while(name_bytes) {
248 uint8_t name_type = reader.get_byte();
249 name_bytes--;
250
251 if(name_type == 0) // DNS
252 {
253 m_sni_host_name = reader.get_string(2, 1, 65535);
254 name_bytes -= static_cast<uint16_t>(2 + m_sni_host_name.size());
255 } else // some other unknown name type
256 {
257 reader.discard_next(name_bytes);
258 name_bytes = 0;
259 }
260 }
261}

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

138{ return false; }

◆ host_name()

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

Definition at line 134 of file tls_extensions.h.

134{ return m_sni_host_name; }

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

116{ 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 263 of file tls_extensions.cpp.

263 {
264 // RFC 6066
265 // [...] the server SHALL include an extension of type "server_name" in
266 // the (extended) server hello. The "extension_data" field of this
267 // extension SHALL be empty.
268 if(whoami == Connection_Side::Server) {
269 return {};
270 }
271
272 std::vector<uint8_t> buf;
273
274 size_t name_len = m_sni_host_name.size();
275
276 buf.push_back(get_byte<0>(static_cast<uint16_t>(name_len + 3)));
277 buf.push_back(get_byte<1>(static_cast<uint16_t>(name_len + 3)));
278 buf.push_back(0); // DNS
279
280 buf.push_back(get_byte<0>(static_cast<uint16_t>(name_len)));
281 buf.push_back(get_byte<1>(static_cast<uint16_t>(name_len)));
282
283 buf += std::make_pair(cast_char_ptr_to_uint8(m_sni_host_name.data()), m_sni_host_name.size());
284
285 return buf;
286}
const uint8_t * cast_char_ptr_to_uint8(const char *s)
Definition mem_ops.h:272

References Botan::cast_char_ptr_to_uint8(), and Botan::TLS::Server.

◆ static_type()

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

Definition at line 126 of file tls_extensions.h.

◆ type()

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

Implements Botan::TLS::Extension.

Definition at line 128 of file tls_extensions.h.

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

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