Botan  2.4.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 73 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 81 of file tls_extensions.h.

81  :
82  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 135 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().

137  {
138  /*
139  * This is used by the server to confirm that it knew the name
140  */
141  if(extension_size == 0)
142  return;
143 
144  uint16_t name_bytes = reader.get_uint16_t();
145 
146  if(name_bytes + 2 != extension_size)
147  throw Decoding_Error("Bad encoding of SNI extension");
148 
149  while(name_bytes)
150  {
151  uint8_t name_type = reader.get_byte();
152  name_bytes--;
153 
154  if(name_type == 0) // DNS
155  {
156  m_sni_host_name = reader.get_string(2, 1, 65535);
157  name_bytes -= static_cast<uint16_t>(2 + m_sni_host_name.size());
158  }
159  else // some other unknown name type
160  {
161  reader.discard_next(name_bytes);
162  name_bytes = 0;
163  }
164  }
165  }

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

References Botan::TLS::Extension::empty(), Botan::TLS::Extension::serialize(), Botan::TLS::TLSEXT_SRP_IDENTIFIER, and Botan::TLS::Extension::type().

91 { return m_sni_host_name.empty(); }

◆ host_name()

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

Definition at line 87 of file tls_extensions.h.

References Botan::TLS::Extension::serialize().

87 { 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 167 of file tls_extensions.cpp.

References Botan::TLS::append_tls_length_value(), Botan::cast_char_ptr_to_uint8(), Botan::get_byte(), and Botan::TLS::TLS_Data_Reader::get_string().

168  {
169  std::vector<uint8_t> buf;
170 
171  size_t name_len = m_sni_host_name.size();
172 
173  buf.push_back(get_byte(0, static_cast<uint16_t>(name_len+3)));
174  buf.push_back(get_byte(1, static_cast<uint16_t>(name_len+3)));
175  buf.push_back(0); // DNS
176 
177  buf.push_back(get_byte(0, static_cast<uint16_t>(name_len)));
178  buf.push_back(get_byte(1, static_cast<uint16_t>(name_len)));
179 
180  buf += std::make_pair(
181  cast_char_ptr_to_uint8(m_sni_host_name.data()),
182  m_sni_host_name.size());
183 
184  return buf;
185  }
const uint8_t * cast_char_ptr_to_uint8(const char *s)
Definition: mem_ops.h:120
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 79 of file tls_extensions.h.

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

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