Botan 3.14.1
Crypto and TLS for C&
Botan::TLS::Handshake_Transitions Class Reference

#include <tls_handshake_transitions.h>

Public Member Functions

bool change_cipher_spec_expected () const
void confirm_transition_to (Handshake_Type msg_type)
bool received_handshake_msg (Handshake_Type msg_type) const
void set_expected_next (const std::vector< Handshake_Type > &msg_types)
void set_expected_next (Handshake_Type msg_type)

Detailed Description

Manages the expectations for incoming handshake messages in both TLS 1.2 and 1.3. This does not bear any knowledge about the actual state machine but is a mere helper to implement state transition validation.

Definition at line 23 of file tls_handshake_transitions.h.

Member Function Documentation

◆ change_cipher_spec_expected()

bool Botan::TLS::Handshake_Transitions::change_cipher_spec_expected ( ) const

Check whether a Change Cipher Spec must be expected

Definition at line 185 of file tls_handshake_transitions.cpp.

185 {
186 return (bitmask_for_handshake_type(Handshake_Type::HandshakeCCS) & m_hand_expecting_mask) != 0;
187}

References Botan::TLS::HandshakeCCS.

◆ confirm_transition_to()

void Botan::TLS::Handshake_Transitions::confirm_transition_to ( Handshake_Type msg_type)

Confirm that we were expecting this message type

Parameters
msg_typethe message type

Definition at line 140 of file tls_handshake_transitions.cpp.

140 {
141 const uint32_t mask = bitmask_for_handshake_type(msg_type);
142
143 const bool ok = (m_hand_expecting_mask & mask) != 0; // overlap?
144
145 if(!ok) {
146 const uint32_t seen_so_far = m_hand_received_mask & ~mask;
147
148 std::ostringstream msg;
149
150 msg << "Unexpected state transition in handshake got a " << handshake_type_to_string(msg_type);
151
152 if(m_hand_expecting_mask == 0) {
153 msg << " not expecting messages";
154 } else {
155 msg << " expected " << handshake_mask_to_string(m_hand_expecting_mask, '|');
156 }
157
158 if(seen_so_far != 0) {
159 msg << " seen " << handshake_mask_to_string(seen_so_far, '+');
160 }
161
162 throw Unexpected_Message(msg.str());
163 }
164
165 // Record the message as received only once the transition is accepted
166 m_hand_received_mask |= mask;
167
168 /* We don't know what to expect next, so force a call to
169 set_expected_next; if it doesn't happen, the next transition
170 check will always fail which is what we want.
171 */
172 m_hand_expecting_mask = 0;
173}
const char * handshake_type_to_string(Handshake_Type type)
Definition tls_magic.cpp:15

References Botan::TLS::handshake_type_to_string().

◆ received_handshake_msg()

bool Botan::TLS::Handshake_Transitions::received_handshake_msg ( Handshake_Type msg_type) const

Return true iff we have received a particular message already

Parameters
msg_typethe message type

Definition at line 134 of file tls_handshake_transitions.cpp.

134 {
135 const uint32_t mask = bitmask_for_handshake_type(msg_type);
136
137 return (m_hand_received_mask & mask) != 0;
138}

◆ set_expected_next() [1/2]

void Botan::TLS::Handshake_Transitions::set_expected_next ( const std::vector< Handshake_Type > & msg_types)

Record that we are expecting one of the enumerated message types next. Note that receiving any of the expected messages in confirm_transition_to resets all the expectations.

Parameters
msg_typesthe message types

Definition at line 179 of file tls_handshake_transitions.cpp.

179 {
180 for(const auto type : msg_types) {
181 set_expected_next(type);
182 }
183}
void set_expected_next(Handshake_Type msg_type)

References set_expected_next().

◆ set_expected_next() [2/2]

void Botan::TLS::Handshake_Transitions::set_expected_next ( Handshake_Type msg_type)

Record that we are expecting a particular message type next

Parameters
msg_typethe message type

Definition at line 175 of file tls_handshake_transitions.cpp.

175 {
176 m_hand_expecting_mask |= bitmask_for_handshake_type(msg_type);
177}

Referenced by set_expected_next().


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