Botan 2.19.5 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:

## Public Member Functions
bool | empty () const override
std::string | host_name () const
std::vector< uint8_t > | serialize (Connection_Side whoami) 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 81 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 | ) |
| inline explicit

Definition at line 89 of file tls_extensions.h.

89 :
90 m_sni_host_name(host_name) {}
Botan::TLS::Server_Name_Indicator::host_name
std::string host_name() const
Definition: tls_extensions.h:95

## ◆ Server_Name_Indicator() [2/2]

Botan::TLS::Server_Name_Indicator::Server_Name_Indicator | ( | TLS_Data_Reader & | reader,
|  | uint16_t | extension_size
| ) |  |

Definition at line 164 of file tls_extensions.cpp.

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

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
| inline override virtual

Returns
  if we should encode this extension or not

Implements Botan::TLS::Extension.

Definition at line 99 of file tls_extensions.h.

99{ return m_sni_host_name.empty(); }

## ◆ host_name()

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

Definition at line 95 of file tls_extensions.h.

95{ return m_sni_host_name; }

## ◆ serialize()

std::vector< uint8_t > Botan::TLS::Server_Name_Indicator::serialize | ( | Connection_Side | whoami | ) | const
| override virtual

Returns
  serialized binary for the extension

Implements Botan::TLS::Extension.

Definition at line 196 of file tls_extensions.cpp.

197 {
198 std::vector<uint8_t> buf;
199
200 size_t name_len = m_sni_host_name.size();
201
202 buf.push_back(get_byte(0, static_cast<uint16_t>(name_len+3)));
203 buf.push_back(get_byte(1, static_cast<uint16_t>(name_len+3)));
204 buf.push_back(0); // DNS
205
206 buf.push_back(get_byte(0, static_cast<uint16_t>(name_len)));
207 buf.push_back(get_byte(1, static_cast<uint16_t>(name_len)));
208
209 buf += std::make_pair(
210 cast_char_ptr_to_uint8(m_sni_host_name.data()),
211 m_sni_host_name.size());
212
213 return buf;
214 }
Botan::get_byte
constexpr uint8_t get_byte(size_t byte_num, T input)
Definition: loadstor.h:41
Botan::cast_char_ptr_to_uint8
const uint8_t * cast_char_ptr_to_uint8(const char *s)
Definition: mem_ops.h:190

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

## ◆ static_type()

static Handshake_Extension_Type Botan::TLS::Server_Name_Indicator::static_type | ( |  | ) |
| inline static

Definition at line 84 of file tls_extensions.h.

85 { return TLSEXT_SERVER_NAME_INDICATION; }
Botan::TLS::TLSEXT_SERVER_NAME_INDICATION
@ TLSEXT_SERVER_NAME_INDICATION
Definition: tls_extensions.h:33

References Botan::TLS::TLSEXT_SERVER_NAME_INDICATION.

## ◆ type()

Handshake_Extension_Type Botan::TLS::Server_Name_Indicator::type | ( |  | ) | const
| inline override virtual

Returns
  code number of the extension

Implements Botan::TLS::Extension.

Definition at line 87 of file tls_extensions.h.

87{ return static_type(); }
Botan::TLS::Server_Name_Indicator::static_type
static Handshake_Extension_Type static_type()
Definition: tls_extensions.h:84

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

- src/lib/tls/tls_extensions.h
- src/lib/tls/tls_extensions.cpp