Botan 3.14.1
Crypto and TLS for C&
Botan::TLS::Handshake_State Class Referenceabstract

#include <tls_handshake_state.h>

Public Member Functions

Callbacks & callbacks () const
const Certificate_Request_12 & cert_req () const
void cert_req (std::unique_ptr< Certificate_Request_12 > cert_req)
std::pair< std::string, Signature_Format > choose_sig_format (const Private_Key &key, Signature_Scheme &scheme, bool for_client_auth, const Policy &policy) const
const Ciphersuite & ciphersuite () const
const Certificate_12 & client_certs () const
void client_certs (std::unique_ptr< Certificate_12 > client_certs)
const Finished_12 & client_finished () const
void client_finished (std::unique_ptr< Finished_12 > client_finished)
const Client_Hello_12 & client_hello () const
void client_hello (std::unique_ptr< Client_Hello_12 > client_hello)
const Client_Key_Exchange & client_kex () const
void client_kex (std::unique_ptr< Client_Key_Exchange > client_kex)
const Certificate_Verify_12 & client_verify () const
void client_verify (std::unique_ptr< Certificate_Verify_12 > client_verify)
void compute_session_keys ()
void compute_session_keys (const secure_vector< uint8_t > &resume_master_secret)
void confirm_transition_to (Handshake_Type msg_type)
std::pair< Handshake_Type, std::vector< uint8_t > > get_next_handshake_msg (size_t max_handshake_msg_size)
Handshake_IO & handshake_io ()
 Handshake_State (const Handshake_State &other)=delete
 Handshake_State (Handshake_State &&other)=delete
 Handshake_State (std::unique_ptr< Handshake_IO > io, Callbacks &callbacks)
bool has_cert_req () const
bool has_client_certs () const
bool has_client_finished () const
bool has_client_hello () const
bool has_client_kex () const
bool has_client_verify () const
bool has_new_session_ticket () const
bool has_server_cert_status () const
bool has_server_certs () const
bool has_server_finished () const
bool has_server_hello () const
bool has_server_hello_done () const
bool has_server_kex () const
bool has_server_verify () const
Handshake_Hash & hash ()
const Handshake_Hash & hash () const
void hello_verify_request (const Hello_Verify_Request &hello_verify)
const Certificate_Request_12 * maybe_cert_req () const
const Certificate_12 * maybe_client_certs () const
const Finished_12 * maybe_client_finished () const
const Client_Hello_12 * maybe_client_hello () const
const Client_Key_Exchange * maybe_client_kex () const
const Certificate_Verify_12 * maybe_client_verify () const
const New_Session_Ticket_12 * maybe_new_session_ticket () const
const Certificate_Status * maybe_server_cert_status () const
const Certificate_12 * maybe_server_certs () const
const Finished_12 * maybe_server_finished () const
const Server_Hello_12 * maybe_server_hello () const
const Server_Hello_Done * maybe_server_hello_done () const
const Server_Key_Exchange * maybe_server_kex () const
const Certificate_Verify_12 * maybe_server_verify () const
const New_Session_Ticket_12 & new_session_ticket () const
void new_session_ticket (std::unique_ptr< New_Session_Ticket_12 > new_session_ticket)
void note_message (const Handshake_Message &msg)
Handshake_State & operator= (const Handshake_State &other)=delete
Handshake_State & operator= (Handshake_State &&other)=delete
std::pair< std::string, Signature_Format > parse_sig_format (const Public_Key &key, Signature_Scheme scheme, const std::vector< Signature_Scheme > &offered_schemes, bool for_client_auth, const Policy &policy) const
virtual std::vector< X509_Certificate > peer_cert_chain () const =0
std::unique_ptr< KDF > protocol_specific_prf () const
std::optional< std::string > psk_identity () const
bool received_handshake_msg (Handshake_Type msg_type) const
const Certificate_Status & server_cert_status () const
void server_cert_status (std::unique_ptr< Certificate_Status > server_cert_status)
const Certificate_12 & server_certs () const
void server_certs (std::unique_ptr< Certificate_12 > server_certs)
const Finished_12 & server_finished () const
void server_finished (std::unique_ptr< Finished_12 > server_finished)
const Server_Hello_12 & server_hello () const
void server_hello (std::unique_ptr< Server_Hello_12 > server_hello)
const Server_Hello_Done & server_hello_done () const
void server_hello_done (std::unique_ptr< Server_Hello_Done > server_hello_done)
const Server_Key_Exchange & server_kex () const
void server_kex (std::unique_ptr< Server_Key_Exchange > server_kex)
const Certificate_Verify_12 & server_verify () const
void server_verify (std::unique_ptr< Certificate_Verify_12 > server_verify)
const Session_Keys & session_keys () const
Session_Ticket session_ticket () const
void set_expected_next (Handshake_Type msg_type)
void set_version (const Protocol_Version &version)
std::unique_ptr< Handshake_IO > take_handshake_io ()
Protocol_Version version () const
virtual ~Handshake_State ()

Detailed Description

SSL/TLS Handshake State

This is a data holder object for all state aggregated during the handshake, both on client and server side and across protocol versions. It does not implement any logic and offers no guarantees regarding state consistency and legal TLS state transitions.

TODO: currently it implements some logic for TLS 1.2, which should be removed TODO: investigate moving the handshake_io to the channel

Definition at line 62 of file tls_handshake_state.h.

Constructor & Destructor Documentation

◆ Handshake_State() [1/3]

Botan::TLS::Handshake_State::Handshake_State ( std::unique_ptr< Handshake_IO > io,
Callbacks & callbacks )

Definition at line 31 of file tls_handshake_state.cpp.

31 :
32 m_callbacks(cb), m_handshake_io(std::move(io)), m_version(m_handshake_io->initial_record_version()) {}

Referenced by Handshake_State(), Handshake_State(), operator=(), and operator=().

◆ ~Handshake_State()

Botan::TLS::Handshake_State::~Handshake_State ( )
virtualdefault

◆ Handshake_State() [2/3]

Botan::TLS::Handshake_State::Handshake_State ( const Handshake_State & other)
delete

References Handshake_State().

◆ Handshake_State() [3/3]

Botan::TLS::Handshake_State::Handshake_State ( Handshake_State && other)
delete

References Handshake_State().

Member Function Documentation

◆ callbacks()

◆ cert_req() [1/2]

const Certificate_Request_12 & Botan::TLS::Handshake_State::cert_req ( ) const
inline

Definition at line 180 of file tls_handshake_state.h.

180{ return require(m_cert_req); }

Referenced by choose_sig_format(), and parse_sig_format().

◆ cert_req() [2/2]

void Botan::TLS::Handshake_State::cert_req ( std::unique_ptr< Certificate_Request_12 > cert_req)

Definition at line 84 of file tls_handshake_state.cpp.

84 {
86 m_cert_req = std::move(cert_req);
87 note_message(*m_cert_req);
88}
#define BOTAN_ASSERT_NONNULL(ptr)
Definition assert.h:121
void note_message(const Handshake_Message &msg)
void cert_req(std::unique_ptr< Certificate_Request_12 > cert_req)

References BOTAN_ASSERT_NONNULL, cert_req(), and note_message().

Referenced by cert_req().

◆ choose_sig_format()

std::pair< std::string, Signature_Format > Botan::TLS::Handshake_State::choose_sig_format ( const Private_Key & key,
Signature_Scheme & scheme,
bool for_client_auth,
const Policy & policy ) const

Definition at line 195 of file tls_handshake_state.cpp.

198 {
199 const std::string sig_algo = key.algo_name();
200
201 const std::vector<Signature_Scheme> allowed = policy.allowed_signature_schemes();
202
203 std::vector<Signature_Scheme> requested =
204 (for_client_auth) ? cert_req().signature_schemes() : client_hello().signature_schemes();
205
206 for(const Signature_Scheme scheme : allowed) {
207 if(!scheme.is_available() || !scheme.is_compatible_with(version())) {
208 continue;
209 }
210
211 if(scheme.algorithm_name() == sig_algo) {
212 if(std::find(requested.begin(), requested.end(), scheme) != requested.end()) {
213 chosen_scheme = scheme;
214 break;
215 }
216 }
217 }
218
219 if(!chosen_scheme.is_set()) {
220 throw TLS_Exception(Alert::HandshakeFailure,
221 "Could not agree on a signature scheme with peer for " + sig_algo + " key");
222 }
223
224 const std::string hash = chosen_scheme.hash_function_name();
225
226 if(!policy.allowed_signature_hash(hash)) {
227 throw TLS_Exception(Alert::HandshakeFailure, "Policy refuses to accept signing with any hash supported by peer");
228 }
229
230 if(!chosen_scheme.format().has_value()) {
231 throw Invalid_Argument(sig_algo + " is invalid/unknown for TLS signatures");
232 }
233
234 return std::make_pair(chosen_scheme.padding_string(), chosen_scheme.format().value());
235}
const std::vector< Signature_Scheme > & signature_schemes() const
std::vector< Signature_Scheme > signature_schemes() const
const Client_Hello_12 & client_hello() const
const Certificate_Request_12 & cert_req() const
Protocol_Version version() const

References Botan::Asymmetric_Key::algo_name(), Botan::TLS::Policy::allowed_signature_hash(), Botan::TLS::Policy::allowed_signature_schemes(), cert_req(), client_hello(), Botan::TLS::Signature_Scheme::format(), hash(), Botan::TLS::Signature_Scheme::hash_function_name(), Botan::TLS::Signature_Scheme::is_set(), Botan::TLS::Signature_Scheme::padding_string(), Botan::TLS::Certificate_Request_12::signature_schemes(), Botan::TLS::Client_Hello::signature_schemes(), and version().

Referenced by Botan::TLS::Certificate_Verify_12::Certificate_Verify_12(), and Botan::TLS::Server_Key_Exchange::Server_Key_Exchange().

◆ ciphersuite()

const Ciphersuite & Botan::TLS::Handshake_State::ciphersuite ( ) const

Definition at line 138 of file tls_handshake_state.cpp.

138 {
139 if(!m_ciphersuite.has_value()) {
140 throw Invalid_State("Cipher suite is not set");
141 }
142 return m_ciphersuite.value();
143}

Referenced by Botan::TLS::Client_Key_Exchange::Client_Key_Exchange(), Botan::TLS::Client_Key_Exchange::Client_Key_Exchange(), protocol_specific_prf(), Botan::TLS::Server_Key_Exchange::Server_Key_Exchange(), and Botan::TLS::Session_Keys::Session_Keys().

◆ client_certs() [1/2]

const Certificate_12 & Botan::TLS::Handshake_State::client_certs ( ) const
inline

Definition at line 184 of file tls_handshake_state.h.

184{ return require(m_client_certs); }

◆ client_certs() [2/2]

void Botan::TLS::Handshake_State::client_certs ( std::unique_ptr< Certificate_12 > client_certs)

Definition at line 96 of file tls_handshake_state.cpp.

96 {
98 m_client_certs = std::move(client_certs);
99 note_message(*m_client_certs);
100}
void client_certs(std::unique_ptr< Certificate_12 > client_certs)

References BOTAN_ASSERT_NONNULL, client_certs(), and note_message().

Referenced by client_certs().

◆ client_finished() [1/2]

const Finished_12 & Botan::TLS::Handshake_State::client_finished ( ) const
inline

Definition at line 198 of file tls_handshake_state.h.

198{ return require(m_client_finished); }

◆ client_finished() [2/2]

void Botan::TLS::Handshake_State::client_finished ( std::unique_ptr< Finished_12 > client_finished)

Definition at line 132 of file tls_handshake_state.cpp.

132 {
134 m_client_finished = std::move(client_finished);
135 note_message(*m_client_finished);
136}
void client_finished(std::unique_ptr< Finished_12 > client_finished)

References BOTAN_ASSERT_NONNULL, client_finished(), and note_message().

Referenced by client_finished().

◆ client_hello() [1/2]

const Client_Hello_12 & Botan::TLS::Handshake_State::client_hello ( ) const
inline

Definition at line 172 of file tls_handshake_state.h.

172{ return require(m_client_hello); }

Referenced by choose_sig_format(), and session_ticket().

◆ client_hello() [2/2]

void Botan::TLS::Handshake_State::client_hello ( std::unique_ptr< Client_Hello_12 > client_hello)

Definition at line 48 of file tls_handshake_state.cpp.

48 {
49 // Legacy behavior (exception to the rule): Allow client_hello to be nullptr to reset state.
50 if(client_hello == nullptr) {
51 m_client_hello.reset();
52 hash().reset();
53 } else {
54 m_client_hello = std::move(client_hello);
55 note_message(*m_client_hello);
56 }
57}
void client_hello(std::unique_ptr< Client_Hello_12 > client_hello)

References client_hello(), hash(), note_message(), and Botan::TLS::Handshake_Hash::reset().

Referenced by client_hello(), Botan::TLS::Client_Key_Exchange::Client_Key_Exchange(), Botan::TLS::Client_Key_Exchange::Client_Key_Exchange(), Botan::TLS::Server_Key_Exchange::Server_Key_Exchange(), Botan::TLS::Session_Keys::Session_Keys(), Botan::TLS::Certificate_Verify_12::verify(), and Botan::TLS::Server_Key_Exchange::verify().

◆ client_kex() [1/2]

const Client_Key_Exchange & Botan::TLS::Handshake_State::client_kex ( ) const
inline

Definition at line 186 of file tls_handshake_state.h.

186{ return require(m_client_kex); }

Referenced by compute_session_keys().

◆ client_kex() [2/2]

void Botan::TLS::Handshake_State::client_kex ( std::unique_ptr< Client_Key_Exchange > client_kex)

Definition at line 102 of file tls_handshake_state.cpp.

102 {
104 m_client_kex = std::move(client_kex);
105 note_message(*m_client_kex);
106}
void client_kex(std::unique_ptr< Client_Key_Exchange > client_kex)

References BOTAN_ASSERT_NONNULL, client_kex(), and note_message().

Referenced by client_kex().

◆ client_verify() [1/2]

const Certificate_Verify_12 & Botan::TLS::Handshake_State::client_verify ( ) const
inline

Definition at line 188 of file tls_handshake_state.h.

188{ return require(m_client_verify); }

◆ client_verify() [2/2]

void Botan::TLS::Handshake_State::client_verify ( std::unique_ptr< Certificate_Verify_12 > client_verify)

Definition at line 108 of file tls_handshake_state.cpp.

108 {
110 m_client_verify = std::move(client_verify);
111 note_message(*m_client_verify);
112}
void client_verify(std::unique_ptr< Certificate_Verify_12 > client_verify)

References BOTAN_ASSERT_NONNULL, client_verify(), and note_message().

Referenced by client_verify().

◆ compute_session_keys() [1/2]

void Botan::TLS::Handshake_State::compute_session_keys ( )

Definition at line 156 of file tls_handshake_state.cpp.

156 {
157 m_session_keys = Session_Keys(this, client_kex().pre_master_secret(), false);
158}
const Client_Key_Exchange & client_kex() const

References client_kex().

◆ compute_session_keys() [2/2]

void Botan::TLS::Handshake_State::compute_session_keys ( const secure_vector< uint8_t > & resume_master_secret)

Definition at line 160 of file tls_handshake_state.cpp.

160 {
161 m_session_keys = Session_Keys(this, resume_master_secret, true);
162}

◆ confirm_transition_to()

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

Confirm that we were expecting this message type

Parameters
msg_typethe message type

Definition at line 164 of file tls_handshake_state.cpp.

164 {
165 m_transitions.confirm_transition_to(handshake_msg);
166}

◆ get_next_handshake_msg()

std::pair< Handshake_Type, std::vector< uint8_t > > Botan::TLS::Handshake_State::get_next_handshake_msg ( size_t max_handshake_msg_size)

Definition at line 176 of file tls_handshake_state.cpp.

176 {
177 return m_handshake_io->get_next_record(m_transitions.change_cipher_spec_expected(), max_handshake_msg_size);
178}

◆ handshake_io()

Handshake_IO & Botan::TLS::Handshake_State::handshake_io ( )
inline

Definition at line 72 of file tls_handshake_state.h.

72{ return *m_handshake_io; }

Referenced by hello_verify_request().

◆ has_cert_req()

bool Botan::TLS::Handshake_State::has_cert_req ( ) const
inline

Definition at line 147 of file tls_handshake_state.h.

147{ return m_cert_req != nullptr; }

Referenced by parse_sig_format().

◆ has_client_certs()

bool Botan::TLS::Handshake_State::has_client_certs ( ) const
inline

Definition at line 151 of file tls_handshake_state.h.

151{ return m_client_certs != nullptr; }

◆ has_client_finished()

bool Botan::TLS::Handshake_State::has_client_finished ( ) const
inline

Definition at line 165 of file tls_handshake_state.h.

165{ return m_client_finished != nullptr; }

◆ has_client_hello()

bool Botan::TLS::Handshake_State::has_client_hello ( ) const
inline

Definition at line 139 of file tls_handshake_state.h.

139{ return m_client_hello != nullptr; }

◆ has_client_kex()

bool Botan::TLS::Handshake_State::has_client_kex ( ) const
inline

Definition at line 153 of file tls_handshake_state.h.

153{ return m_client_kex != nullptr; }

◆ has_client_verify()

bool Botan::TLS::Handshake_State::has_client_verify ( ) const
inline

Definition at line 155 of file tls_handshake_state.h.

155{ return m_client_verify != nullptr; }

◆ has_new_session_ticket()

bool Botan::TLS::Handshake_State::has_new_session_ticket ( ) const
inline

Definition at line 161 of file tls_handshake_state.h.

161{ return m_new_session_ticket != nullptr; }

◆ has_server_cert_status()

bool Botan::TLS::Handshake_State::has_server_cert_status ( ) const
inline

Definition at line 159 of file tls_handshake_state.h.

159{ return m_server_cert_status != nullptr; }

◆ has_server_certs()

bool Botan::TLS::Handshake_State::has_server_certs ( ) const
inline

Definition at line 143 of file tls_handshake_state.h.

143{ return m_server_certs != nullptr; }

◆ has_server_finished()

bool Botan::TLS::Handshake_State::has_server_finished ( ) const
inline

Definition at line 163 of file tls_handshake_state.h.

163{ return m_server_finished != nullptr; }

◆ has_server_hello()

bool Botan::TLS::Handshake_State::has_server_hello ( ) const
inline

Definition at line 141 of file tls_handshake_state.h.

141{ return m_server_hello != nullptr; }

◆ has_server_hello_done()

bool Botan::TLS::Handshake_State::has_server_hello_done ( ) const
inline

Definition at line 149 of file tls_handshake_state.h.

149{ return m_server_hello_done != nullptr; }

◆ has_server_kex()

bool Botan::TLS::Handshake_State::has_server_kex ( ) const
inline

Definition at line 145 of file tls_handshake_state.h.

145{ return m_server_kex != nullptr; }

Referenced by Botan::TLS::Client_Key_Exchange::Client_Key_Exchange().

◆ has_server_verify()

bool Botan::TLS::Handshake_State::has_server_verify ( ) const
inline

Definition at line 157 of file tls_handshake_state.h.

157{ return m_server_verify != nullptr; }

◆ hash() [1/2]

◆ hash() [2/2]

const Handshake_Hash & Botan::TLS::Handshake_State::hash ( ) const
inline

Definition at line 247 of file tls_handshake_state.h.

247{ return m_handshake_hash; }

◆ hello_verify_request()

void Botan::TLS::Handshake_State::hello_verify_request ( const Hello_Verify_Request & hello_verify)

Definition at line 38 of file tls_handshake_state.cpp.

38 {
39 note_message(hello_verify);
40
41 BOTAN_ASSERT_NONNULL(m_client_hello);
42 m_client_hello->update_hello_cookie(hello_verify);
43 hash().reset();
44 hash().update(handshake_io().send(*m_client_hello));
45 note_message(*m_client_hello);
46}
void update(const uint8_t in[], size_t length)

References BOTAN_ASSERT_NONNULL, handshake_io(), hash(), note_message(), Botan::TLS::Handshake_Hash::reset(), and Botan::TLS::Handshake_Hash::update().

◆ maybe_cert_req()

const Certificate_Request_12 * Botan::TLS::Handshake_State::maybe_cert_req ( ) const
inline

Definition at line 211 of file tls_handshake_state.h.

211{ return m_cert_req.get(); }

◆ maybe_client_certs()

const Certificate_12 * Botan::TLS::Handshake_State::maybe_client_certs ( ) const
inline

Definition at line 215 of file tls_handshake_state.h.

215{ return m_client_certs.get(); }

◆ maybe_client_finished()

const Finished_12 * Botan::TLS::Handshake_State::maybe_client_finished ( ) const
inline

Definition at line 229 of file tls_handshake_state.h.

229{ return m_client_finished.get(); }

◆ maybe_client_hello()

const Client_Hello_12 * Botan::TLS::Handshake_State::maybe_client_hello ( ) const
inline

Definition at line 203 of file tls_handshake_state.h.

203{ return m_client_hello.get(); }

◆ maybe_client_kex()

const Client_Key_Exchange * Botan::TLS::Handshake_State::maybe_client_kex ( ) const
inline

Definition at line 217 of file tls_handshake_state.h.

217{ return m_client_kex.get(); }

◆ maybe_client_verify()

const Certificate_Verify_12 * Botan::TLS::Handshake_State::maybe_client_verify ( ) const
inline

Definition at line 219 of file tls_handshake_state.h.

219{ return m_client_verify.get(); }

◆ maybe_new_session_ticket()

const New_Session_Ticket_12 * Botan::TLS::Handshake_State::maybe_new_session_ticket ( ) const
inline

Definition at line 225 of file tls_handshake_state.h.

225{ return m_new_session_ticket.get(); }

Referenced by session_ticket().

◆ maybe_server_cert_status()

const Certificate_Status * Botan::TLS::Handshake_State::maybe_server_cert_status ( ) const
inline

Definition at line 223 of file tls_handshake_state.h.

223{ return m_server_cert_status.get(); }

◆ maybe_server_certs()

const Certificate_12 * Botan::TLS::Handshake_State::maybe_server_certs ( ) const
inline

Definition at line 207 of file tls_handshake_state.h.

207{ return m_server_certs.get(); }

◆ maybe_server_finished()

const Finished_12 * Botan::TLS::Handshake_State::maybe_server_finished ( ) const
inline

Definition at line 227 of file tls_handshake_state.h.

227{ return m_server_finished.get(); }

◆ maybe_server_hello()

const Server_Hello_12 * Botan::TLS::Handshake_State::maybe_server_hello ( ) const
inline

Definition at line 205 of file tls_handshake_state.h.

205{ return m_server_hello.get(); }

◆ maybe_server_hello_done()

const Server_Hello_Done * Botan::TLS::Handshake_State::maybe_server_hello_done ( ) const
inline

Definition at line 213 of file tls_handshake_state.h.

213{ return m_server_hello_done.get(); }

◆ maybe_server_kex()

const Server_Key_Exchange * Botan::TLS::Handshake_State::maybe_server_kex ( ) const
inline

Definition at line 209 of file tls_handshake_state.h.

209{ return m_server_kex.get(); }

◆ maybe_server_verify()

const Certificate_Verify_12 * Botan::TLS::Handshake_State::maybe_server_verify ( ) const
inline

Definition at line 221 of file tls_handshake_state.h.

221{ return m_server_verify.get(); }

◆ new_session_ticket() [1/2]

const New_Session_Ticket_12 & Botan::TLS::Handshake_State::new_session_ticket ( ) const
inline

Definition at line 194 of file tls_handshake_state.h.

194{ return require(m_new_session_ticket); }

◆ new_session_ticket() [2/2]

void Botan::TLS::Handshake_State::new_session_ticket ( std::unique_ptr< New_Session_Ticket_12 > new_session_ticket)

Definition at line 120 of file tls_handshake_state.cpp.

120 {
122 m_new_session_ticket = std::move(new_session_ticket);
123 note_message(*m_new_session_ticket);
124}
void new_session_ticket(std::unique_ptr< New_Session_Ticket_12 > new_session_ticket)

References BOTAN_ASSERT_NONNULL, new_session_ticket(), and note_message().

Referenced by new_session_ticket().

◆ note_message()

void Botan::TLS::Handshake_State::note_message ( const Handshake_Message & msg)

◆ operator=() [1/2]

Handshake_State & Botan::TLS::Handshake_State::operator= ( const Handshake_State & other)
delete

References Handshake_State().

◆ operator=() [2/2]

Handshake_State & Botan::TLS::Handshake_State::operator= ( Handshake_State && other)
delete

References Handshake_State().

◆ parse_sig_format()

std::pair< std::string, Signature_Format > Botan::TLS::Handshake_State::parse_sig_format ( const Public_Key & key,
Signature_Scheme scheme,
const std::vector< Signature_Scheme > & offered_schemes,
bool for_client_auth,
const Policy & policy ) const

Definition at line 251 of file tls_handshake_state.cpp.

256 {
257 const std::string key_type = key.algo_name();
258
259 if(!policy.allowed_signature_method(key_type)) {
260 throw TLS_Exception(Alert::HandshakeFailure, "Rejecting " + key_type + " signature");
261 }
262
263 if(!scheme.is_available()) {
264 throw TLS_Exception(Alert::IllegalParameter, "Peer sent unknown signature scheme");
265 }
266
267 if(key_type != scheme.algorithm_name()) {
268 throw Decoding_Error("Counterparty sent inconsistent key and sig types");
269 }
270
271 if(for_client_auth && !has_cert_req()) {
272 throw TLS_Exception(Alert::HandshakeFailure, "No CertificateVerify message received");
273 }
274
275 /*
276 Confirm the signature type we just received against the
277 supported_algos list that we sent; it better be there.
278 */
279
280 const std::vector<Signature_Scheme> supported_algos =
281 for_client_auth ? cert_req().signature_schemes() : offered_schemes;
282
283 if(!scheme.is_compatible_with(Protocol_Version::TLS_V12)) {
284 throw TLS_Exception(Alert::IllegalParameter, "Peer sent unacceptable signature scheme");
285 }
286
287 if(!supported_algos_include(supported_algos, scheme)) {
288 throw TLS_Exception(Alert::IllegalParameter,
289 "TLS signature extension did not allow for " + scheme.to_string() + " signature");
290 }
291
292 // The offered schemes might have been modified by the application
293 if(!value_exists(policy.acceptable_signature_schemes(), scheme)) {
294 throw TLS_Exception(Alert::IllegalParameter, "Peer sent " + scheme.to_string() + " signature rejected by policy");
295 }
296
297 if(!scheme.format().has_value()) {
298 throw Invalid_Argument(key_type + " is invalid/unknown for TLS signatures");
299 }
300
301 return std::make_pair(scheme.padding_string(), scheme.format().value());
302}
bool value_exists(const std::vector< T > &vec, const V &val)
Definition stl_util.h:44

References Botan::TLS::Policy::acceptable_signature_schemes(), Botan::Asymmetric_Key::algo_name(), Botan::TLS::Signature_Scheme::algorithm_name(), Botan::TLS::Policy::allowed_signature_method(), cert_req(), Botan::TLS::Signature_Scheme::format(), has_cert_req(), Botan::TLS::Signature_Scheme::is_available(), Botan::TLS::Signature_Scheme::is_compatible_with(), Botan::TLS::Signature_Scheme::padding_string(), Botan::TLS::Certificate_Request_12::signature_schemes(), Botan::TLS::Signature_Scheme::to_string(), and Botan::value_exists().

Referenced by Botan::TLS::Certificate_Verify_12::verify(), and Botan::TLS::Server_Key_Exchange::verify().

◆ peer_cert_chain()

virtual std::vector< X509_Certificate > Botan::TLS::Handshake_State::peer_cert_chain ( ) const
pure virtual

◆ protocol_specific_prf()

std::unique_ptr< KDF > Botan::TLS::Handshake_State::protocol_specific_prf ( ) const

Definition at line 191 of file tls_handshake_state.cpp.

191 {
192 return m_callbacks.tls12_protocol_specific_kdf(ciphersuite().prf_algo());
193}
const Ciphersuite & ciphersuite() const

References ciphersuite().

Referenced by Botan::TLS::Session_Keys::Session_Keys().

◆ psk_identity()

std::optional< std::string > Botan::TLS::Handshake_State::psk_identity ( ) const

Definition at line 145 of file tls_handshake_state.cpp.

145 {
146 if(!m_client_kex) {
147 return std::nullopt;
148 }
149 return m_client_kex->psk_identity();
150}

◆ received_handshake_msg()

bool Botan::TLS::Handshake_State::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 172 of file tls_handshake_state.cpp.

172 {
173 return m_transitions.received_handshake_msg(handshake_msg);
174}

◆ server_cert_status() [1/2]

const Certificate_Status & Botan::TLS::Handshake_State::server_cert_status ( ) const
inline

Definition at line 192 of file tls_handshake_state.h.

192{ return require(m_server_cert_status); }

◆ server_cert_status() [2/2]

void Botan::TLS::Handshake_State::server_cert_status ( std::unique_ptr< Certificate_Status > server_cert_status)

Definition at line 72 of file tls_handshake_state.cpp.

72 {
74 m_server_cert_status = std::move(server_cert_status);
75 note_message(*m_server_cert_status);
76}
void server_cert_status(std::unique_ptr< Certificate_Status > server_cert_status)

References BOTAN_ASSERT_NONNULL, note_message(), and server_cert_status().

Referenced by server_cert_status().

◆ server_certs() [1/2]

const Certificate_12 & Botan::TLS::Handshake_State::server_certs ( ) const
inline

Definition at line 176 of file tls_handshake_state.h.

176{ return require(m_server_certs); }

◆ server_certs() [2/2]

void Botan::TLS::Handshake_State::server_certs ( std::unique_ptr< Certificate_12 > server_certs)

Definition at line 66 of file tls_handshake_state.cpp.

66 {
68 m_server_certs = std::move(server_certs);
69 note_message(*m_server_certs);
70}
void server_certs(std::unique_ptr< Certificate_12 > server_certs)

References BOTAN_ASSERT_NONNULL, note_message(), and server_certs().

Referenced by Botan::TLS::Client_Key_Exchange::Client_Key_Exchange(), and server_certs().

◆ server_finished() [1/2]

const Finished_12 & Botan::TLS::Handshake_State::server_finished ( ) const
inline

Definition at line 196 of file tls_handshake_state.h.

196{ return require(m_server_finished); }

◆ server_finished() [2/2]

void Botan::TLS::Handshake_State::server_finished ( std::unique_ptr< Finished_12 > server_finished)

Definition at line 126 of file tls_handshake_state.cpp.

126 {
128 m_server_finished = std::move(server_finished);
129 note_message(*m_server_finished);
130}
void server_finished(std::unique_ptr< Finished_12 > server_finished)

References BOTAN_ASSERT_NONNULL, note_message(), and server_finished().

Referenced by server_finished().

◆ server_hello() [1/2]

const Server_Hello_12 & Botan::TLS::Handshake_State::server_hello ( ) const
inline

Definition at line 174 of file tls_handshake_state.h.

174{ return require(m_server_hello); }

◆ server_hello() [2/2]

void Botan::TLS::Handshake_State::server_hello ( std::unique_ptr< Server_Hello_12 > server_hello)

Definition at line 59 of file tls_handshake_state.cpp.

59 {
61 m_server_hello = std::move(server_hello);
62 m_ciphersuite = Ciphersuite::by_id(m_server_hello->ciphersuite());
63 note_message(*m_server_hello);
64}
static std::optional< Ciphersuite > by_id(uint16_t suite)
void server_hello(std::unique_ptr< Server_Hello_12 > server_hello)

References BOTAN_ASSERT_NONNULL, Botan::TLS::Ciphersuite::by_id(), note_message(), and server_hello().

Referenced by Botan::TLS::Client_Key_Exchange::Client_Key_Exchange(), server_hello(), Botan::TLS::Server_Key_Exchange::Server_Key_Exchange(), Botan::TLS::Session_Keys::Session_Keys(), and Botan::TLS::Server_Key_Exchange::verify().

◆ server_hello_done() [1/2]

const Server_Hello_Done & Botan::TLS::Handshake_State::server_hello_done ( ) const
inline

Definition at line 182 of file tls_handshake_state.h.

182{ return require(m_server_hello_done); }

◆ server_hello_done() [2/2]

void Botan::TLS::Handshake_State::server_hello_done ( std::unique_ptr< Server_Hello_Done > server_hello_done)

Definition at line 90 of file tls_handshake_state.cpp.

90 {
92 m_server_hello_done = std::move(server_hello_done);
93 note_message(*m_server_hello_done);
94}
void server_hello_done(std::unique_ptr< Server_Hello_Done > server_hello_done)

References BOTAN_ASSERT_NONNULL, note_message(), and server_hello_done().

Referenced by server_hello_done().

◆ server_kex() [1/2]

const Server_Key_Exchange & Botan::TLS::Handshake_State::server_kex ( ) const
inline

Definition at line 178 of file tls_handshake_state.h.

178{ return require(m_server_kex); }

◆ server_kex() [2/2]

void Botan::TLS::Handshake_State::server_kex ( std::unique_ptr< Server_Key_Exchange > server_kex)

Definition at line 78 of file tls_handshake_state.cpp.

78 {
80 m_server_kex = std::move(server_kex);
81 note_message(*m_server_kex);
82}
void server_kex(std::unique_ptr< Server_Key_Exchange > server_kex)

References BOTAN_ASSERT_NONNULL, note_message(), and server_kex().

Referenced by Botan::TLS::Client_Key_Exchange::Client_Key_Exchange(), Botan::TLS::Client_Key_Exchange::Client_Key_Exchange(), and server_kex().

◆ server_verify() [1/2]

const Certificate_Verify_12 & Botan::TLS::Handshake_State::server_verify ( ) const
inline

Definition at line 190 of file tls_handshake_state.h.

190{ return require(m_server_verify); }

◆ server_verify() [2/2]

void Botan::TLS::Handshake_State::server_verify ( std::unique_ptr< Certificate_Verify_12 > server_verify)

Definition at line 114 of file tls_handshake_state.cpp.

114 {
116 m_server_verify = std::move(server_verify);
117 note_message(*m_server_verify);
118}
void server_verify(std::unique_ptr< Certificate_Verify_12 > server_verify)

References BOTAN_ASSERT_NONNULL, note_message(), and server_verify().

Referenced by server_verify().

◆ session_keys()

const Session_Keys & Botan::TLS::Handshake_State::session_keys ( ) const
inline

Definition at line 237 of file tls_handshake_state.h.

237{ return m_session_keys; }

◆ session_ticket()

Session_Ticket Botan::TLS::Handshake_State::session_ticket ( ) const

Definition at line 180 of file tls_handshake_state.cpp.

180 {
181 if(const auto* nst = maybe_new_session_ticket()) {
182 const auto& ticket = nst->ticket();
183 if(!ticket.empty()) {
184 return ticket;
185 }
186 }
187
188 return client_hello().session_ticket();
189}
Session_Ticket session_ticket() const
const New_Session_Ticket_12 * maybe_new_session_ticket() const

References client_hello(), maybe_new_session_ticket(), and Botan::TLS::Client_Hello_12::session_ticket().

◆ set_expected_next()

void Botan::TLS::Handshake_State::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 168 of file tls_handshake_state.cpp.

168 {
169 m_transitions.set_expected_next(handshake_msg);
170}

◆ set_version()

void Botan::TLS::Handshake_State::set_version ( const Protocol_Version & version)

Definition at line 152 of file tls_handshake_state.cpp.

152 {
153 m_version = version;
154}

References version().

◆ take_handshake_io()

std::unique_ptr< Handshake_IO > Botan::TLS::Handshake_State::take_handshake_io ( )
inline

Definition at line 74 of file tls_handshake_state.h.

74{ return std::move(m_handshake_io); }

◆ version()

Protocol_Version Botan::TLS::Handshake_State::version ( ) const
inline

Definition at line 111 of file tls_handshake_state.h.

111{ return m_version; }

Referenced by choose_sig_format(), and set_version().


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