Botan  1.11.15
Public Types | Public Member Functions
Botan::TLS::Stream_Handshake_IO Class Reference

#include <tls_handshake_io.h>

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

List of all members.

Public Types

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

Public Member Functions

void add_record (const std::vector< byte > &record, Record_Type type, u64bit sequence_number) override
std::vector< byteformat (const std::vector< byte > &handshake_msg, Handshake_Type handshake_type) const override
std::pair< Handshake_Type,
std::vector< byte > > 
get_next_record (bool expecting_ccs) override
Protocol_Version initial_record_version () const override
std::vector< bytesend (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 65 of file tls_handshake_io.h.


Member Typedef Documentation

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

Definition at line 68 of file tls_handshake_io.h.


Constructor & Destructor Documentation

Definition at line 70 of file tls_handshake_io.h.

: m_send_hs(writer) {}

Member Function Documentation

void Botan::TLS::Stream_Handshake_IO::add_record ( const std::vector< byte > &  record,
Record_Type  type,
u64bit  sequence_number 
) [override, virtual]

Implements Botan::TLS::Handshake_IO.

Definition at line 43 of file tls_handshake_io.cpp.

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

   {
   if(record_type == HANDSHAKE)
      {
      m_queue.insert(m_queue.end(), record.begin(), record.end());
      }
   else if(record_type == CHANGE_CIPHER_SPEC)
      {
      if(record.size() != 1 || record[0] != 1)
         throw Decoding_Error("Invalid ChangeCipherSpec");

      // Pretend it's a regular handshake message of zero length
      const byte ccs_hs[] = { HANDSHAKE_CCS, 0, 0, 0 };
      m_queue.insert(m_queue.end(), ccs_hs, ccs_hs + sizeof(ccs_hs));
      }
   else
      throw Decoding_Error("Unknown message type " + std::to_string(record_type) + " in handshake processing");
   }
std::vector< byte > Botan::TLS::Stream_Handshake_IO::format ( const std::vector< byte > &  handshake_msg,
Handshake_Type  handshake_type 
) const [override, virtual]

Implements Botan::TLS::Handshake_IO.

Definition at line 87 of file tls_handshake_io.cpp.

References Botan::copy_mem().

Referenced by send().

   {
   std::vector<byte> send_buf(4 + msg.size());

   const size_t buf_size = msg.size();

   send_buf[0] = type;

   store_be24(&send_buf[1], buf_size);

   copy_mem(&send_buf[4], &msg[0], msg.size());

   return send_buf;
   }
std::pair< Handshake_Type, std::vector< byte > > Botan::TLS::Stream_Handshake_IO::get_next_record ( bool  expecting_ccs) [override, virtual]

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

Implements Botan::TLS::Handshake_IO.

Definition at line 64 of file tls_handshake_io.cpp.

References Botan::TLS::HANDSHAKE_NONE, and Botan::make_u32bit().

   {
   if(m_queue.size() >= 4)
      {
      const size_t length = make_u32bit(0, m_queue[1], m_queue[2], m_queue[3]);

      if(m_queue.size() >= length + 4)
         {
         Handshake_Type type = static_cast<Handshake_Type>(m_queue[0]);

         std::vector<byte> contents(m_queue.begin() + 4,
                                    m_queue.begin() + 4 + length);

         m_queue.erase(m_queue.begin(), m_queue.begin() + 4 + length);

         return std::make_pair(type, contents);
         }
      }

   return std::make_pair(HANDSHAKE_NONE, std::vector<byte>());
   }
std::vector< byte > Botan::TLS::Stream_Handshake_IO::send ( const Handshake_Message msg) [override, virtual]

Implements Botan::TLS::Handshake_IO.

Definition at line 103 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().

   {
   const std::vector<byte> msg_bits = msg.serialize();

   if(msg.type() == HANDSHAKE_CCS)
      {
      m_send_hs(CHANGE_CIPHER_SPEC, msg_bits);
      return std::vector<byte>(); // not included in handshake hashes
      }

   const std::vector<byte> buf = format(msg_bits, msg.type());
   m_send_hs(HANDSHAKE, buf);
   return buf;
   }
bool Botan::TLS::Stream_Handshake_IO::timeout_check ( ) [inline, override, virtual]

Implements Botan::TLS::Handshake_IO.

Definition at line 74 of file tls_handshake_io.h.

{ return false; }

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