Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

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:

## 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 65 of file tls_handshake_io.h.

## Member Typedef Documentation

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

Definition at line 68 of file tls_handshake_io.h.

## Constructor & Destructor Documentation

Botan::TLS::Stream_Handshake_IO::Stream_Handshake_IO | ( | writer_fn | writer | ) |
| inline explicit

Definition at line 70 of file tls_handshake_io.h.

70 : m_send_hs(writer) {}

## Member Function Documentation

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

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 }
Botan::ASN1::to_string
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:47
Botan::TLS::HANDSHAKE_CCS
Definition: tls_magic.h:55
Botan::TLS::CHANGE_CIPHER_SPEC
Definition: tls_magic.h:30
Botan::TLS::HANDSHAKE
Definition: tls_magic.h:32

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

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 }
type
MechanismType type
Definition: p11_mechanism.cpp:43
Botan::copy_mem
void copy_mem(T *out, const T *in, size_t n)
Definition: mem_ops.h:68

std::pair< Handshake_Type, std::vector< uint8_t > > 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 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 = make_uint32(0, m_queue[1], m_queue[2], m_queue[3]);
87
88 if(m_queue.size() >= length + 4)
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() + 4 + length);
94
95 m_queue.erase(m_queue.begin(), m_queue.begin() + 4 + length);
96
97 return std::make_pair(type, contents);
98 }
99 }
100
101 return std::make_pair(HANDSHAKE_NONE, std::vector<uint8_t>());
102 }
Botan::TLS::HANDSHAKE_NONE
Definition: tls_magic.h:56
type
MechanismType type
Definition: p11_mechanism.cpp:43
Botan::make_uint32
uint32_t make_uint32(uint8_t i0, uint8_t i1, uint8_t i2, uint8_t i3)
Definition: loadstor.h:73
Botan::TLS::Handshake_Type
Handshake_Type
Definition: tls_magic.h:38

Protocol_Version Botan::TLS::Stream_Handshake_IO::initial_record_version | ( |  | ) | const
| override virtual

Implements Botan::TLS::Handshake_IO.

Definition at line 56 of file tls_handshake_io.cpp.

References Botan::TLS::Protocol_Version::TLS_V10.

57 {
58 return Protocol_Version::TLS_V10;
59 }
Botan::TLS::Protocol_Version::TLS_V10
Definition: tls_version.h:25

std::vector< uint8_t > Botan::TLS::Stream_Handshake_IO::send | ( | const Handshake_Message & | msg | ) |
| override virtual

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 }
Botan::TLS::HANDSHAKE_CCS
Definition: tls_magic.h:55
Botan::TLS::CHANGE_CIPHER_SPEC
Definition: tls_magic.h:30
Botan::TLS::Stream_Handshake_IO::format
std::vector< uint8_t > format(const std::vector< uint8_t > &handshake_msg, Handshake_Type handshake_type) const override
Definition: tls_handshake_io.cpp:105
Botan::TLS::HANDSHAKE
Definition: tls_magic.h:32

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.

74 { return false; }

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

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