Botan  2.8.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 157 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 171 of file tls_extensions.h.

171  :
172  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 177 of file tls_extensions.h.

177  :
178  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 242 of file tls_extensions.cpp.

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

244  {
245  if(extension_size == 0)
246  return; // empty extension
247 
248  const uint16_t name_bytes = reader.get_uint16_t();
249 
250  size_t bytes_remaining = extension_size - 2;
251 
252  if(name_bytes != bytes_remaining)
253  throw Decoding_Error("Bad encoding of ALPN extension, bad length field");
254 
255  while(bytes_remaining)
256  {
257  const std::string p = reader.get_string(1, 0, 255);
258 
259  if(bytes_remaining < p.size() + 1)
260  throw Decoding_Error("Bad encoding of ALPN, length field too long");
261 
262  bytes_remaining -= (p.size() + 1);
263 
264  m_protocols.push_back(p);
265  }
266  }

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

185 { return m_protocols.empty(); }

◆ protocols()

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

Definition at line 164 of file tls_extensions.h.

164 { 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 277 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.

278  {
279  std::vector<uint8_t> buf(2);
280 
281  for(auto&& p: m_protocols)
282  {
283  if(p.length() >= 256)
284  throw TLS_Exception(Alert::INTERNAL_ERROR, "ALPN name too long");
285  if(p != "")
287  cast_char_ptr_to_uint8(p.data()),
288  p.size(),
289  1);
290  }
291 
292  buf[0] = get_byte(0, static_cast<uint16_t>(buf.size()-2));
293  buf[1] = get_byte(1, static_cast<uint16_t>(buf.size()-2));
294 
295  return buf;
296  }
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
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 268 of file tls_extensions.cpp.

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

269  {
270  if(m_protocols.size() != 1)
271  throw TLS_Exception(Alert::HANDSHAKE_FAILURE,
272  "Server sent " + std::to_string(m_protocols.size()) +
273  " protocols in ALPN extension response");
274  return m_protocols[0];
275  }
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:210

◆ static_type()

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

Definition at line 160 of file tls_extensions.h.

References Botan::TLS::TLSEXT_ALPN.

Referenced by type().

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

References static_type().

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

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