Botan 3.0.0-alpha0
Crypto and TLS for C&
Public Member Functions | List of all members
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 24 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 186 of file tls_handshake_transitions.cpp.

187 {
188 return (bitmask_for_handshake_type(HANDSHAKE_CCS) & m_hand_expecting_mask) != 0;
189 }
@ HANDSHAKE_CCS
Definition: tls_magic.h:87

References Botan::TLS::HANDSHAKE_CCS.

Referenced by Botan::TLS::Handshake_State::get_next_handshake_msg().

◆ 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 139 of file tls_handshake_transitions.cpp.

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

References Botan::TLS::handshake_type_to_string().

Referenced by Botan::TLS::Handshake_State::confirm_transition_to().

◆ 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 132 of file tls_handshake_transitions.cpp.

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

Referenced by Botan::TLS::Handshake_State::received_handshake_msg().

◆ 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 178 of file tls_handshake_transitions.cpp.

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

References set_expected_next(), and type.

◆ 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 173 of file tls_handshake_transitions.cpp.

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

Referenced by set_expected_next(), and Botan::TLS::Handshake_State::set_expected_next().


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