Botan 2.19.2
Crypto and TLS for C&
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 uint8_t record[], size_t record_len, 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
 
std::vector< uint8_t > send_under_epoch (const Handshake_Message &msg, uint16_t epoch) override
 
 Stream_Handshake_IO (writer_fn writer)
 
bool timeout_check () override
 

Detailed Description

Handshake IO for stream-based handshakes

Definition at line 67 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 70 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 72 of file tls_handshake_io.h.

72: m_send_hs(writer) {}

Member Function Documentation

◆ add_record()

void Botan::TLS::Stream_Handshake_IO::add_record ( const uint8_t  record[],
size_t  record_len,
Record_Type  type,
uint64_t  sequence_number 
)
overridevirtual

Implements Botan::TLS::Handshake_IO.

Definition at line 50 of file tls_handshake_io.cpp.

53 {
54 if(record_type == HANDSHAKE)
55 {
56 m_queue.insert(m_queue.end(), record, record + record_len);
57 }
58 else if(record_type == CHANGE_CIPHER_SPEC)
59 {
60 if(record_len != 1 || record[0] != 1)
61 throw Decoding_Error("Invalid ChangeCipherSpec");
62
63 // Pretend it's a regular handshake message of zero length
64 const uint8_t ccs_hs[] = { HANDSHAKE_CCS, 0, 0, 0 };
65 m_queue.insert(m_queue.end(), ccs_hs, ccs_hs + sizeof(ccs_hs));
66 }
67 else
68 throw Decoding_Error("Unknown message type " + std::to_string(record_type) + " in handshake processing");
69 }
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:213
@ HANDSHAKE_CCS
Definition: tls_magic.h:62
@ CHANGE_CIPHER_SPEC
Definition: tls_magic.h:36

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

◆ 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 98 of file tls_handshake_io.cpp.

100 {
101 std::vector<uint8_t> send_buf(4 + msg.size());
102
103 const size_t buf_size = msg.size();
104
105 send_buf[0] = static_cast<uint8_t>(type);
106
107 store_be24(&send_buf[1], buf_size);
108
109 if (msg.size() > 0)
110 {
111 copy_mem(&send_buf[4], msg.data(), msg.size());
112 }
113
114 return send_buf;
115 }
void copy_mem(T *out, const T *in, size_t n)
Definition: mem_ops.h:133
MechanismType type

References Botan::copy_mem(), and type.

Referenced by send().

◆ 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 72 of file tls_handshake_io.cpp.

73 {
74 if(m_queue.size() >= 4)
75 {
76 const size_t length = 4 + make_uint32(0, m_queue[1], m_queue[2], m_queue[3]);
77
78 if(m_queue.size() >= length)
79 {
80 Handshake_Type type = static_cast<Handshake_Type>(m_queue[0]);
81
82 if(type == HANDSHAKE_NONE)
83 throw Decoding_Error("Invalid handshake message type");
84
85 std::vector<uint8_t> contents(m_queue.begin() + 4,
86 m_queue.begin() + length);
87
88 m_queue.erase(m_queue.begin(), m_queue.begin() + length);
89
90 return std::make_pair(type, contents);
91 }
92 }
93
94 return std::make_pair(HANDSHAKE_NONE, std::vector<uint8_t>());
95 }
@ HANDSHAKE_NONE
Definition: tls_magic.h:63
constexpr uint32_t make_uint32(uint8_t i0, uint8_t i1, uint8_t i2, uint8_t i3)
Definition: loadstor.h:67

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

◆ 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 122 of file tls_handshake_io.cpp.

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

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().

◆ send_under_epoch()

std::vector< uint8_t > Botan::TLS::Stream_Handshake_IO::send_under_epoch ( const Handshake_Message msg,
uint16_t  epoch 
)
overridevirtual

Implements Botan::TLS::Handshake_IO.

Definition at line 117 of file tls_handshake_io.cpp.

118 {
119 throw Invalid_State("Not possible to send under arbitrary epoch with stream based TLS");
120 }

◆ timeout_check()

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

Implements Botan::TLS::Handshake_IO.

Definition at line 76 of file tls_handshake_io.h.

76{ return false; }

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