Botan  2.4.0
Crypto and TLS for C++11
Public Member Functions | Static Public Member Functions | List of all members
Botan::TLS::Application_Layer_Protocol_Notification Class Referencefinal

#include <tls_extensions.h>

Inheritance diagram for Botan::TLS::Application_Layer_Protocol_Notification:
Botan::TLS::Extension

Public Member Functions

 Application_Layer_Protocol_Notification (const std::string &protocol)
 
 Application_Layer_Protocol_Notification (const std::vector< std::string > &protocols)
 
 Application_Layer_Protocol_Notification (TLS_Data_Reader &reader, uint16_t extension_size)
 
bool empty () const override
 
const std::vector< std::string > & protocols () const
 
std::vector< uint8_t > serialize () const override
 
const std::string & single_protocol () const
 
Handshake_Extension_Type type () const override
 

Static Public Member Functions

static Handshake_Extension_Type static_type ()
 

Detailed Description

ALPN (RFC 7301)

Definition at line 156 of file tls_extensions.h.

Constructor & Destructor Documentation

◆ Application_Layer_Protocol_Notification() [1/3]

Botan::TLS::Application_Layer_Protocol_Notification::Application_Layer_Protocol_Notification ( const std::string &  protocol)
inlineexplicit

Single protocol, used by server

Definition at line 170 of file tls_extensions.h.

170  :
171  m_protocols(1, protocol) {}

◆ Application_Layer_Protocol_Notification() [2/3]

Botan::TLS::Application_Layer_Protocol_Notification::Application_Layer_Protocol_Notification ( const std::vector< std::string > &  protocols)
inlineexplicit

List of protocols, used by client

Definition at line 176 of file tls_extensions.h.

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

176  :
177  m_protocols(protocols) {}
const std::vector< std::string > & protocols() const

◆ Application_Layer_Protocol_Notification() [3/3]

Botan::TLS::Application_Layer_Protocol_Notification::Application_Layer_Protocol_Notification ( TLS_Data_Reader reader,
uint16_t  extension_size 
)

Definition at line 222 of file tls_extensions.cpp.

References Botan::TLS::TLS_Data_Reader::get_string(), and Botan::TLS::TLS_Data_Reader::get_uint16_t().

224  {
225  if(extension_size == 0)
226  return; // empty extension
227 
228  const uint16_t name_bytes = reader.get_uint16_t();
229 
230  size_t bytes_remaining = extension_size - 2;
231 
232  if(name_bytes != bytes_remaining)
233  throw Decoding_Error("Bad encoding of ALPN extension, bad length field");
234 
235  while(bytes_remaining)
236  {
237  const std::string p = reader.get_string(1, 0, 255);
238 
239  if(bytes_remaining < p.size() + 1)
240  throw Decoding_Error("Bad encoding of ALPN, length field too long");
241 
242  bytes_remaining -= (p.size() + 1);
243 
244  m_protocols.push_back(p);
245  }
246  }

Member Function Documentation

◆ empty()

bool Botan::TLS::Application_Layer_Protocol_Notification::empty ( ) const
inlineoverridevirtual
Returns
if we should encode this extension or not

Implements Botan::TLS::Extension.

Definition at line 184 of file tls_extensions.h.

184 { return m_protocols.empty(); }

◆ protocols()

const std::vector<std::string>& Botan::TLS::Application_Layer_Protocol_Notification::protocols ( ) const
inline

Definition at line 163 of file tls_extensions.h.

163 { return m_protocols; }

◆ serialize()

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

Implements Botan::TLS::Extension.

Definition at line 257 of file tls_extensions.cpp.

References Botan::TLS::append_tls_length_value(), Botan::cast_char_ptr_to_uint8(), Botan::get_byte(), and Botan::TLS::Alert::INTERNAL_ERROR.

258  {
259  std::vector<uint8_t> buf(2);
260 
261  for(auto&& p: m_protocols)
262  {
263  if(p.length() >= 256)
264  throw TLS_Exception(Alert::INTERNAL_ERROR, "ALPN name too long");
265  if(p != "")
267  cast_char_ptr_to_uint8(p.data()),
268  p.size(),
269  1);
270  }
271 
272  buf[0] = get_byte(0, static_cast<uint16_t>(buf.size()-2));
273  buf[1] = get_byte(1, static_cast<uint16_t>(buf.size()-2));
274 
275  return buf;
276  }
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
void append_tls_length_value(std::vector< uint8_t, Alloc > &buf, const T *vals, size_t vals_size, size_t tag_size)
Definition: tls_reader.h:185

◆ single_protocol()

const std::string & Botan::TLS::Application_Layer_Protocol_Notification::single_protocol ( ) const

Definition at line 248 of file tls_extensions.cpp.

References Botan::TLS::Alert::HANDSHAKE_FAILURE, and Botan::ASN1::to_string().

249  {
250  if(m_protocols.size() != 1)
251  throw TLS_Exception(Alert::HANDSHAKE_FAILURE,
252  "Server sent " + std::to_string(m_protocols.size()) +
253  " protocols in ALPN extension response");
254  return m_protocols[0];
255  }
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:108

◆ static_type()

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

Definition at line 159 of file tls_extensions.h.

References Botan::TLS::TLSEXT_ALPN.

◆ type()

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

Implements Botan::TLS::Extension.

Definition at line 161 of file tls_extensions.h.

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

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