Botan 2.19.5 Crypto and TLS for C&

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:

## 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 (Connection_Side whoami) 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 164 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 | ) |
| inline explicit

Single protocol, used by server

Definition at line 178 of file tls_extensions.h.

178 :
179 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 | ) |
| inline explicit

List of protocols, used by client

Definition at line 184 of file tls_extensions.h.

184 :
185 m_protocols(protocols) {}
Botan::TLS::Application_Layer_Protocol_Notification::protocols
const std::vector< std::string > & protocols() const
Definition: tls_extensions.h:171

## ◆ 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 251 of file tls_extensions.cpp.

253 {
254 if(extension_size == 0)
255 return; // empty extension
256
257 const uint16_t name_bytes = reader.get_uint16_t();
258
259 size_t bytes_remaining = extension_size - 2;
260
261 if(name_bytes != bytes_remaining)
262 throw Decoding_Error("Bad encoding of ALPN extension, bad length field");
263
264 while(bytes_remaining)
265 {
266 const std::string p = reader.get_string(1, 0, 255);
267
268 if(bytes_remaining < p.size() + 1)
269 throw Decoding_Error("Bad encoding of ALPN, length field too long");
270
271 if(p.empty())
272 throw Decoding_Error("Empty ALPN protocol not allowed");
273
274 bytes_remaining -= (p.size() + 1);
275
276 m_protocols.push_back(p);
277 }
278 }

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

## Member Function Documentation

## ◆ empty()

bool Botan::TLS::Application_Layer_Protocol_Notification::empty | ( |  | ) | const
| inline override virtual

Returns
  if we should encode this extension or not

Implements Botan::TLS::Extension.

Definition at line 192 of file tls_extensions.h.

192{ return m_protocols.empty(); }

## ◆ protocols()

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

Definition at line 171 of file tls_extensions.h.

171{ return m_protocols; }

## ◆ serialize()

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

Returns
  serialized binary for the extension

Implements Botan::TLS::Extension.

Definition at line 289 of file tls_extensions.cpp.

290 {
291 std::vector<uint8_t> buf(2);
292
293 for(auto&& p: m_protocols)
294 {
295 if(p.length() >= 256)
296 throw TLS_Exception(Alert::INTERNAL_ERROR, "ALPN name too long");
297 if(p != "")
298 append_tls_length_value(buf,
299 cast_char_ptr_to_uint8(p.data()),
300 p.size(),
301 1);
302 }
303
304 buf[0] = get_byte(0, static_cast<uint16_t>(buf.size()-2));
305 buf[1] = get_byte(1, static_cast<uint16_t>(buf.size()-2));
306
307 return buf;
308 }
Botan::TLS::Alert::INTERNAL_ERROR
@ INTERNAL_ERROR
Definition: tls_alert.h:49
Botan::TLS::append_tls_length_value
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
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::TLS::append_tls_length_value(), Botan::cast_char_ptr_to_uint8(), Botan::get_byte(), and Botan::TLS::Alert::INTERNAL_ERROR.

## ◆ single_protocol()

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

Definition at line 280 of file tls_extensions.cpp.

281 {
282 if(m_protocols.size() != 1)
283 throw TLS_Exception(Alert::HANDSHAKE_FAILURE,
284 "Server sent " + std::to_string(m_protocols.size()) +
285 " protocols in ALPN extension response");
286 return m_protocols[0];
287 }
Botan::TLS::Alert::HANDSHAKE_FAILURE
@ HANDSHAKE_FAILURE
Definition: tls_alert.h:34
Botan::ASN1::to_string
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:213

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

## ◆ static_type()

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

Definition at line 167 of file tls_extensions.h.

167{ return TLSEXT_ALPN; }
Botan::TLS::TLSEXT_ALPN
@ TLSEXT_ALPN
Definition: tls_extensions.h:42

References Botan::TLS::TLSEXT_ALPN.

## ◆ type()

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

Returns
  code number of the extension

Implements Botan::TLS::Extension.

Definition at line 169 of file tls_extensions.h.

169{ return static_type(); }
Botan::TLS::Application_Layer_Protocol_Notification::static_type
static Handshake_Extension_Type static_type()
Definition: tls_extensions.h:167

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

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