Botan  2.8.0
Crypto and TLS for C++11
Public Types | Public Member Functions | List of all members
Botan::TLS::Stream_Handshake_IO Class Referencefinal

#include <tls_handshake_io.h>

Inheritance diagram for Botan::TLS::Stream_Handshake_IO:
Botan::TLS::Handshake_IO

Public Types

typedef std::function< void(uint8_t, const std::vector< uint8_t > &)> writer_fn
 

Public Member Functions

void add_record (const std::vector< uint8_t > &record, Record_Type type, uint64_t sequence_number) override
 
std::vector< uint8_t > format (const std::vector< uint8_t > &handshake_msg, Handshake_Type handshake_type) const override
 
std::pair< Handshake_Type, std::vector< uint8_t > > get_next_record (bool expecting_ccs) override
 
Protocol_Version initial_record_version () const override
 
std::vector< uint8_t > send (const Handshake_Message &msg) override
 
 Stream_Handshake_IO (writer_fn writer)
 
bool timeout_check () override
 

Detailed Description

Handshake IO for stream-based handshakes

Definition at line 64 of file tls_handshake_io.h.

Member Typedef Documentation

◆ writer_fn

typedef std::function<void (uint8_t, const std::vector<uint8_t>&)> Botan::TLS::Stream_Handshake_IO::writer_fn

Definition at line 67 of file tls_handshake_io.h.

Constructor & Destructor Documentation

◆ Stream_Handshake_IO()

Botan::TLS::Stream_Handshake_IO::Stream_Handshake_IO ( writer_fn  writer)
inlineexplicit

Definition at line 69 of file tls_handshake_io.h.

69 : m_send_hs(writer) {}

Member Function Documentation

◆ add_record()

void Botan::TLS::Stream_Handshake_IO::add_record ( const std::vector< uint8_t > &  record,
Record_Type  type,
uint64_t  sequence_number 
)
overridevirtual

Implements Botan::TLS::Handshake_IO.

Definition at line 61 of file tls_handshake_io.cpp.

References Botan::TLS::CHANGE_CIPHER_SPEC, Botan::TLS::HANDSHAKE, Botan::TLS::HANDSHAKE_CCS, and Botan::ASN1::to_string().

63  {
64  if(record_type == HANDSHAKE)
65  {
66  m_queue.insert(m_queue.end(), record.begin(), record.end());
67  }
68  else if(record_type == CHANGE_CIPHER_SPEC)
69  {
70  if(record.size() != 1 || record[0] != 1)
71  throw Decoding_Error("Invalid ChangeCipherSpec");
72 
73  // Pretend it's a regular handshake message of zero length
74  const uint8_t ccs_hs[] = { HANDSHAKE_CCS, 0, 0, 0 };
75  m_queue.insert(m_queue.end(), ccs_hs, ccs_hs + sizeof(ccs_hs));
76  }
77  else
78  throw Decoding_Error("Unknown message type " + std::to_string(record_type) + " in handshake processing");
79  }
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:210

◆ format()

std::vector< uint8_t > Botan::TLS::Stream_Handshake_IO::format ( const std::vector< uint8_t > &  handshake_msg,
Handshake_Type  handshake_type 
) const
overridevirtual

Implements Botan::TLS::Handshake_IO.

Definition at line 105 of file tls_handshake_io.cpp.

References Botan::copy_mem(), and type.

Referenced by send().

107  {
108  std::vector<uint8_t> send_buf(4 + msg.size());
109 
110  const size_t buf_size = msg.size();
111 
112  send_buf[0] = type;
113 
114  store_be24(&send_buf[1], buf_size);
115 
116  if (msg.size() > 0)
117  {
118  copy_mem(&send_buf[4], msg.data(), msg.size());
119  }
120 
121  return send_buf;
122  }
MechanismType type
void copy_mem(T *out, const T *in, size_t n)
Definition: mem_ops.h:108

◆ get_next_record()

std::pair< Handshake_Type, std::vector< uint8_t > > Botan::TLS::Stream_Handshake_IO::get_next_record ( bool  expecting_ccs)
overridevirtual

Returns (HANDSHAKE_NONE, std::vector<>()) if no message currently available

Implements Botan::TLS::Handshake_IO.

Definition at line 82 of file tls_handshake_io.cpp.

References Botan::TLS::HANDSHAKE_NONE, Botan::make_uint32(), and type.

83  {
84  if(m_queue.size() >= 4)
85  {
86  const size_t length = 4 + make_uint32(0, m_queue[1], m_queue[2], m_queue[3]);
87 
88  if(m_queue.size() >= length)
89  {
90  Handshake_Type type = static_cast<Handshake_Type>(m_queue[0]);
91 
92  std::vector<uint8_t> contents(m_queue.begin() + 4,
93  m_queue.begin() + length);
94 
95  m_queue.erase(m_queue.begin(), m_queue.begin() + length);
96 
97  return std::make_pair(type, contents);
98  }
99  }
100 
101  return std::make_pair(HANDSHAKE_NONE, std::vector<uint8_t>());
102  }
MechanismType type
uint32_t make_uint32(uint8_t i0, uint8_t i1, uint8_t i2, uint8_t i3)
Definition: loadstor.h:65

◆ initial_record_version()

Protocol_Version Botan::TLS::Stream_Handshake_IO::initial_record_version ( ) const
overridevirtual

◆ send()

std::vector< uint8_t > Botan::TLS::Stream_Handshake_IO::send ( const Handshake_Message msg)
overridevirtual

Implements Botan::TLS::Handshake_IO.

Definition at line 124 of file tls_handshake_io.cpp.

References Botan::TLS::CHANGE_CIPHER_SPEC, format(), Botan::TLS::HANDSHAKE, Botan::TLS::HANDSHAKE_CCS, Botan::TLS::Handshake_Message::serialize(), and Botan::TLS::Handshake_Message::type().

125  {
126  const std::vector<uint8_t> msg_bits = msg.serialize();
127 
128  if(msg.type() == HANDSHAKE_CCS)
129  {
130  m_send_hs(CHANGE_CIPHER_SPEC, msg_bits);
131  return std::vector<uint8_t>(); // not included in handshake hashes
132  }
133 
134  const std::vector<uint8_t> buf = format(msg_bits, msg.type());
135  m_send_hs(HANDSHAKE, buf);
136  return buf;
137  }
std::vector< uint8_t > format(const std::vector< uint8_t > &handshake_msg, Handshake_Type handshake_type) const override

◆ timeout_check()

bool Botan::TLS::Stream_Handshake_IO::timeout_check ( )
inlineoverridevirtual

Implements Botan::TLS::Handshake_IO.

Definition at line 73 of file tls_handshake_io.h.

73 { return false; }

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