Botan  2.8.0
Crypto and TLS for C++11
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
 
std::vector< uint8_t > serialize () const override
 
 Server_Name_Indicator (const std::string &host_name)
 
 Server_Name_Indicator (TLS_Data_Reader &reader, uint16_t extension_size)
 
Handshake_Extension_Type type () const override
 

Static Public Member Functions

static Handshake_Extension_Type static_type ()
 

Detailed Description

Server Name Indicator extension (RFC 3546)

Definition at line 74 of file tls_extensions.h.

Constructor & Destructor Documentation

◆ Server_Name_Indicator() [1/2]

Botan::TLS::Server_Name_Indicator::Server_Name_Indicator ( const std::string &  host_name)
inlineexplicit

Definition at line 82 of file tls_extensions.h.

82  :
83  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 155 of file tls_extensions.cpp.

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().

157  {
158  /*
159  * This is used by the server to confirm that it knew the name
160  */
161  if(extension_size == 0)
162  return;
163 
164  uint16_t name_bytes = reader.get_uint16_t();
165 
166  if(name_bytes + 2 != extension_size)
167  throw Decoding_Error("Bad encoding of SNI extension");
168 
169  while(name_bytes)
170  {
171  uint8_t name_type = reader.get_byte();
172  name_bytes--;
173 
174  if(name_type == 0) // DNS
175  {
176  m_sni_host_name = reader.get_string(2, 1, 65535);
177  name_bytes -= static_cast<uint16_t>(2 + m_sni_host_name.size());
178  }
179  else // some other unknown name type
180  {
181  reader.discard_next(name_bytes);
182  name_bytes = 0;
183  }
184  }
185  }

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

92 { return m_sni_host_name.empty(); }

◆ host_name()

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

Definition at line 88 of file tls_extensions.h.

88 { return m_sni_host_name; }

◆ serialize()

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

Implements Botan::TLS::Extension.

Definition at line 187 of file tls_extensions.cpp.

References Botan::cast_char_ptr_to_uint8(), and Botan::get_byte().

188  {
189  std::vector<uint8_t> buf;
190 
191  size_t name_len = m_sni_host_name.size();
192 
193  buf.push_back(get_byte(0, static_cast<uint16_t>(name_len+3)));
194  buf.push_back(get_byte(1, static_cast<uint16_t>(name_len+3)));
195  buf.push_back(0); // DNS
196 
197  buf.push_back(get_byte(0, static_cast<uint16_t>(name_len)));
198  buf.push_back(get_byte(1, static_cast<uint16_t>(name_len)));
199 
200  buf += std::make_pair(
201  cast_char_ptr_to_uint8(m_sni_host_name.data()),
202  m_sni_host_name.size());
203 
204  return buf;
205  }
const uint8_t * cast_char_ptr_to_uint8(const char *s)
Definition: mem_ops.h:131
uint8_t get_byte(size_t byte_num, T input)
Definition: loadstor.h:39

◆ static_type()

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

◆ type()

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

Implements Botan::TLS::Extension.

Definition at line 80 of file tls_extensions.h.

References static_type().

80 { return static_type(); }
static Handshake_Extension_Type static_type()

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