Botan 3.3.0
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 175 of file tls_handshake_transitions.cpp.

175 {
176 return (bitmask_for_handshake_type(Handshake_Type::HandshakeCCS) & m_hand_expecting_mask) != 0;
177}

References Botan::TLS::HandshakeCCS.

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

131 {
132 const uint32_t mask = bitmask_for_handshake_type(msg_type);
133
134 m_hand_received_mask |= mask;
135
136 const bool ok = (m_hand_expecting_mask & mask) != 0; // overlap?
137
138 if(!ok) {
139 const uint32_t seen_so_far = m_hand_received_mask & ~mask;
140
141 std::ostringstream msg;
142
143 msg << "Unexpected state transition in handshake got a " << handshake_type_to_string(msg_type);
144
145 if(m_hand_expecting_mask == 0) {
146 msg << " not expecting messages";
147 } else {
148 msg << " expected " << handshake_mask_to_string(m_hand_expecting_mask, '|');
149 }
150
151 if(seen_so_far != 0) {
152 msg << " seen " << handshake_mask_to_string(seen_so_far, '+');
153 }
154
155 throw Unexpected_Message(msg.str());
156 }
157
158 /* We don't know what to expect next, so force a call to
159 set_expected_next; if it doesn't happen, the next transition
160 check will always fail which is what we want.
161 */
162 m_hand_expecting_mask = 0;
163}
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 125 of file tls_handshake_transitions.cpp.

125 {
126 const uint32_t mask = bitmask_for_handshake_type(msg_type);
127
128 return (m_hand_received_mask & mask) != 0;
129}

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

169 {
170 for(const auto type : msg_types) {
171 set_expected_next(type);
172 }
173}
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 165 of file tls_handshake_transitions.cpp.

165 {
166 m_hand_expecting_mask |= bitmask_for_handshake_type(msg_type);
167}

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


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