Botan 3.12.0
Crypto and TLS for C&
tls_handshake_state.h
Go to the documentation of this file.
1/*
2* TLS Handshake State
3* (C) 2004-2006,2011,2012 Jack Lloyd
4* 2017 Harry Reimann, Rohde & Schwarz Cybersecurity
5*
6* Botan is released under the Simplified BSD License (see license.txt)
7*/
8
9#ifndef BOTAN_TLS_HANDSHAKE_STATE_H_
10#define BOTAN_TLS_HANDSHAKE_STATE_H_
11
12#include <botan/tls_ciphersuite.h>
13#include <botan/tls_exceptn.h>
14#include <botan/tls_extensions.h>
15#include <botan/tls_handshake_msg.h>
16#include <botan/tls_session.h>
17#include <botan/x509cert.h>
18#include <botan/internal/tls_handshake_hash.h>
19#include <botan/internal/tls_handshake_io.h>
20#include <botan/internal/tls_handshake_transitions.h>
21#include <botan/internal/tls_session_key.h>
22#include <optional>
23#include <vector>
24
25namespace Botan {
26
27enum class Signature_Format : uint8_t;
28class Public_Key;
29class KDF;
30
31namespace TLS {
32
33class Callbacks;
34class Policy;
36
38class Client_Hello_12;
39class Server_Hello_12;
40class Certificate_12;
48class Finished_12;
49
50/**
51* SSL/TLS Handshake State
52*
53* This is a data holder object for all state aggregated during the handshake,
54* both on client and server side and across protocol versions.
55* It does not implement any logic and offers no guarantees regarding state
56* consistency and legal TLS state transitions.
57*
58* TODO: currently it implements some logic for TLS 1.2, which should be removed
59* TODO: investigate moving the handshake_io to the channel
60*/
62 public:
63 Handshake_State(std::unique_ptr<Handshake_IO> io, Callbacks& callbacks);
65
66 Handshake_State(const Handshake_State& other) = delete;
68 Handshake_State& operator=(const Handshake_State& other) = delete;
70
71 Handshake_IO& handshake_io() { return *m_handshake_io; }
72
73 std::unique_ptr<Handshake_IO> take_handshake_io() { return std::move(m_handshake_io); }
74
75 /**
76 * Return true iff we have received a particular message already
77 * @param msg_type the message type
78 */
79 bool received_handshake_msg(Handshake_Type msg_type) const;
80
81 /**
82 * Confirm that we were expecting this message type
83 * @param msg_type the message type
84 */
86
87 /**
88 * Record that we are expecting a particular message type next
89 * @param msg_type the message type
90 */
91 void set_expected_next(Handshake_Type msg_type);
92
93 std::pair<Handshake_Type, std::vector<uint8_t>> get_next_handshake_msg(size_t max_handshake_msg_size);
94
96
97 std::pair<std::string, Signature_Format> parse_sig_format(const Public_Key& key,
98 Signature_Scheme scheme,
99 const std::vector<Signature_Scheme>& offered_schemes,
100 bool for_client_auth,
101 const Policy& policy) const;
102
103 std::pair<std::string, Signature_Format> choose_sig_format(const Private_Key& key,
104 Signature_Scheme& scheme,
105 bool for_client_auth,
106 const Policy& policy) const;
107
108 std::unique_ptr<KDF> protocol_specific_prf() const;
109
110 Protocol_Version version() const { return m_version; }
111
113
114 void hello_verify_request(const Hello_Verify_Request& hello_verify);
115
116 void client_hello(std::unique_ptr<Client_Hello_12> client_hello);
117 void server_hello(std::unique_ptr<Server_Hello_12> server_hello);
118 void server_cert_status(std::unique_ptr<Certificate_Status> server_cert_status);
119 void server_kex(std::unique_ptr<Server_Key_Exchange> server_kex);
120 void cert_req(std::unique_ptr<Certificate_Request_12> cert_req);
121 void server_hello_done(std::unique_ptr<Server_Hello_Done> server_hello_done);
122 void client_kex(std::unique_ptr<Client_Key_Exchange> client_kex);
123
124 void client_certs(std::unique_ptr<Certificate_12> client_certs);
125 void server_certs(std::unique_ptr<Certificate_12> server_certs);
126
127 void client_verify(std::unique_ptr<Certificate_Verify_12> client_verify);
128 void server_verify(std::unique_ptr<Certificate_Verify_12> server_verify);
129
130 void server_finished(std::unique_ptr<Finished_12> server_finished);
131 void client_finished(std::unique_ptr<Finished_12> client_finished);
132
133 void new_session_ticket(std::unique_ptr<New_Session_Ticket_12> new_session_ticket);
134
135 const Client_Hello_12* client_hello() const { return m_client_hello.get(); }
136
137 const Server_Hello_12* server_hello() const { return m_server_hello.get(); }
138
139 const Certificate_12* server_certs() const { return m_server_certs.get(); }
140
141 const Server_Key_Exchange* server_kex() const { return m_server_kex.get(); }
142
143 const Certificate_Request_12* cert_req() const { return m_cert_req.get(); }
144
145 const Server_Hello_Done* server_hello_done() const { return m_server_hello_done.get(); }
146
147 const Certificate_12* client_certs() const { return m_client_certs.get(); }
148
149 const Client_Key_Exchange* client_kex() const { return m_client_kex.get(); }
150
151 const Certificate_Verify_12* client_verify() const { return m_client_verify.get(); }
152
153 const Certificate_Verify_12* server_verify() const { return m_server_verify.get(); }
154
155 const Certificate_Status* server_cert_status() const { return m_server_cert_status.get(); }
156
157 const New_Session_Ticket_12* new_session_ticket() const { return m_new_session_ticket.get(); }
158
159 const Finished_12* server_finished() const { return m_server_finished.get(); }
160
161 const Finished_12* client_finished() const { return m_client_finished.get(); }
162
163 virtual std::vector<X509_Certificate> peer_cert_chain() const = 0;
164
165 const Ciphersuite& ciphersuite() const;
166
167 std::optional<std::string> psk_identity() const;
168
169 const Session_Keys& session_keys() const { return m_session_keys; }
170
171 Callbacks& callbacks() const { return m_callbacks; }
172
174
175 void compute_session_keys(const secure_vector<uint8_t>& resume_master_secret);
176
177 Handshake_Hash& hash() { return m_handshake_hash; }
178
179 const Handshake_Hash& hash() const { return m_handshake_hash; }
180
181 void note_message(const Handshake_Message& msg);
182
183 private:
184 Callbacks& m_callbacks;
185
186 std::unique_ptr<Handshake_IO> m_handshake_io;
187
188 Handshake_Transitions m_transitions;
189 Protocol_Version m_version;
190 std::optional<Ciphersuite> m_ciphersuite;
191 Session_Keys m_session_keys;
192 Handshake_Hash m_handshake_hash;
193
194 std::unique_ptr<Client_Hello_12> m_client_hello;
195 std::unique_ptr<Server_Hello_12> m_server_hello;
196
197 std::unique_ptr<Certificate_12> m_server_certs;
198 std::unique_ptr<Certificate_Status> m_server_cert_status;
199 std::unique_ptr<Server_Key_Exchange> m_server_kex;
200 std::unique_ptr<Certificate_Request_12> m_cert_req;
201 std::unique_ptr<Server_Hello_Done> m_server_hello_done;
202 std::unique_ptr<Certificate_12> m_client_certs;
203 std::unique_ptr<Client_Key_Exchange> m_client_kex;
204 std::unique_ptr<Certificate_Verify_12> m_client_verify;
205 std::unique_ptr<Certificate_Verify_12> m_server_verify;
206 std::unique_ptr<New_Session_Ticket_12> m_new_session_ticket;
207 std::unique_ptr<Finished_12> m_server_finished;
208 std::unique_ptr<Finished_12> m_client_finished;
209};
210
211} // namespace TLS
212
213} // namespace Botan
214
215#endif
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
Handshake_State & operator=(const Handshake_State &other)=delete
const Server_Hello_Done * server_hello_done() const
void hello_verify_request(const Hello_Verify_Request &hello_verify)
void set_expected_next(Handshake_Type msg_type)
void note_message(const Handshake_Message &msg)
const Server_Key_Exchange * server_kex() const
std::pair< Handshake_Type, std::vector< uint8_t > > get_next_handshake_msg(size_t max_handshake_msg_size)
const Certificate_Status * server_cert_status() const
const Certificate_Verify_12 * server_verify() const
Handshake_State(std::unique_ptr< Handshake_IO > io, Callbacks &callbacks)
const Certificate_Verify_12 * client_verify() const
const Finished_12 * server_finished() const
const Session_Keys & session_keys() const
const Client_Hello_12 * client_hello() const
const Client_Key_Exchange * client_kex() const
const Handshake_Hash & hash() const
Handshake_State(const Handshake_State &other)=delete
void confirm_transition_to(Handshake_Type msg_type)
std::unique_ptr< Handshake_IO > take_handshake_io()
void set_version(const Protocol_Version &version)
std::optional< std::string > psk_identity() const
const Certificate_12 * server_certs() const
const Certificate_12 * client_certs() const
const Finished_12 * client_finished() const
const Certificate_Request_12 * cert_req() const
const Ciphersuite & ciphersuite() const
Handshake_State(Handshake_State &&other)=delete
Session_Ticket session_ticket() const
Handshake_State & operator=(Handshake_State &&other)=delete
virtual std::vector< X509_Certificate > peer_cert_chain() const =0
const Server_Hello_12 * server_hello() const
bool received_handshake_msg(Handshake_Type msg_type) const
std::unique_ptr< KDF > protocol_specific_prf() const
const New_Session_Ticket_12 * new_session_ticket() const
std::pair< std::string, Signature_Format > choose_sig_format(const Private_Key &key, Signature_Scheme &scheme, bool for_client_auth, const Policy &policy) const
Protocol_Version version() const
Strong< std::vector< uint8_t >, struct Session_Ticket_ > Session_Ticket
holds a TLS 1.2 session ticket for stateless resumption
Signature_Format
Definition pk_keys.h:32
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:68