Botan 3.0.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 121 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 :
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 250 of file tls_extensions.cpp.

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

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

139{ return false; }

◆ host_name()

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

Definition at line 135 of file tls_extensions.h.

135{ 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 113 of file tls_extensions.h.

113{ 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 282 of file tls_extensions.cpp.

283 {
284 // RFC 6066
285 // [...] the server SHALL include an extension of type "server_name" in
286 // the (extended) server hello. The "extension_data" field of this
287 // extension SHALL be empty.
288 if(whoami == Connection_Side::Server)
289 {
290 return {};
291 }
292
293 std::vector<uint8_t> buf;
294
295 size_t name_len = m_sni_host_name.size();
296
297 buf.push_back(get_byte<0>(static_cast<uint16_t>(name_len+3)));
298 buf.push_back(get_byte<1>(static_cast<uint16_t>(name_len+3)));
299 buf.push_back(0); // DNS
300
301 buf.push_back(get_byte<0>(static_cast<uint16_t>(name_len)));
302 buf.push_back(get_byte<1>(static_cast<uint16_t>(name_len)));
303
304 buf += std::make_pair(
305 cast_char_ptr_to_uint8(m_sni_host_name.data()),
306 m_sni_host_name.size());
307
308 return buf;
309 }
const uint8_t * cast_char_ptr_to_uint8(const char *s)
Definition: mem_ops.h:183

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

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

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