Botan 3.0.0-alpha0
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/internal/tls_handshake_hash.h>
13#include <botan/internal/tls_handshake_io.h>
14#include <botan/internal/tls_handshake_transitions.h>
15#include <botan/internal/tls_session_key.h>
16#include <botan/tls_ciphersuite.h>
17#include <botan/tls_exceptn.h>
18#include <botan/tls_handshake_msg.h>
19#include <botan/tls_callbacks.h>
20#include <botan/pk_keys.h>
21#include <botan/pubkey.h>
22#include <functional>
23#include <optional>
24
25namespace Botan {
26
27class KDF;
28
29namespace TLS {
30
31class Callbacks;
32class Policy;
33class Signature_Scheme;
34
35class Hello_Verify_Request;
36class Client_Hello_12;
37class Server_Hello_12;
38class Certificate_12;
39class Certificate_Status;
40class Server_Key_Exchange;
41class Certificate_Request_12;
42class Server_Hello_Done;
43class Client_Key_Exchange;
44class Certificate_Verify_12;
45class New_Session_Ticket_12;
46class Finished_12;
47
48/**
49* SSL/TLS Handshake State
50*
51* This is a data holder object for all state aggregated during the handshake,
52* both on client and server side and across protocol versions.
53* It does not implement any logic and offers no guarantees regarding state
54* consistency and legal TLS state transitions.
55*
56* TODO: currently it implements some logic for TLS 1.2, which should be removed
57* TODO: investigate moving the handshake_io to the channel
58*/
60 {
61 public:
62 Handshake_State(std::unique_ptr<Handshake_IO> io, Callbacks& callbacks);
64
67
68 Handshake_IO& handshake_io() { return *m_handshake_io; }
69
70 /**
71 * Return true iff we have received a particular message already
72 * @param msg_type the message type
73 */
74 bool received_handshake_msg(Handshake_Type msg_type) const;
75
76 /**
77 * Confirm that we were expecting this message type
78 * @param msg_type the message type
79 */
81
82 /**
83 * Record that we are expecting a particular message type next
84 * @param msg_type the message type
85 */
86 void set_expected_next(Handshake_Type msg_type);
87
88 std::pair<Handshake_Type, std::vector<uint8_t>>
90
91 std::vector<uint8_t> session_ticket() const;
92
93 std::pair<std::string, Signature_Format>
95 Signature_Scheme scheme,
96 const std::vector<Signature_Scheme>& offered_schemes,
97 bool for_client_auth,
98 const Policy& policy) const;
99
100 std::pair<std::string, Signature_Format>
102 Signature_Scheme& scheme,
103 bool for_client_auth,
104 const Policy& policy) const;
105
106 std::unique_ptr<KDF> protocol_specific_prf() const;
107
108 Protocol_Version version() const { return m_version; }
109
111
112 void hello_verify_request(const Hello_Verify_Request& hello_verify);
113
114 // TODO: take unique_ptr instead of raw pointers for all of these, as
115 // we're taking the ownership
123
126
129
132
134
136 { return m_client_hello.get(); }
137
139 { return m_server_hello.get(); }
140
142 { return m_server_certs.get(); }
143
145 { return m_server_kex.get(); }
146
148 { return m_cert_req.get(); }
149
151 { return m_server_hello_done.get(); }
152
154 { return m_client_certs.get(); }
155
157 { return m_client_kex.get(); }
158
160 { return m_client_verify.get(); }
161
163 { return m_server_verify.get(); }
164
166 { return m_server_cert_status.get(); }
167
169 { return m_new_session_ticket.get(); }
170
172 { return m_server_finished.get(); }
173
175 { return m_client_finished.get(); }
176
177 const Ciphersuite& ciphersuite() const;
178
179 const Session_Keys& session_keys() const { return m_session_keys; }
180
181 Callbacks& callbacks() const { return m_callbacks; }
182
184
185 void compute_session_keys(const secure_vector<uint8_t>& resume_master_secret);
186
187 Handshake_Hash& hash() { return m_handshake_hash; }
188
189 const Handshake_Hash& hash() const { return m_handshake_hash; }
190
191 void note_message(const Handshake_Message& msg);
192 private:
193
194 Callbacks& m_callbacks;
195
196 std::unique_ptr<Handshake_IO> m_handshake_io;
197
198 Handshake_Transitions m_transitions;
199 Protocol_Version m_version;
200 std::optional<Ciphersuite> m_ciphersuite;
201 Session_Keys m_session_keys;
202 Handshake_Hash m_handshake_hash;
203
204 std::unique_ptr<Client_Hello_12> m_client_hello;
205 std::unique_ptr<Server_Hello_12> m_server_hello;
206
207 std::unique_ptr<Certificate_12> m_server_certs;
208 std::unique_ptr<Certificate_Status> m_server_cert_status;
209 std::unique_ptr<Server_Key_Exchange> m_server_kex;
210 std::unique_ptr<Certificate_Request_12> m_cert_req;
211 std::unique_ptr<Server_Hello_Done> m_server_hello_done;
212 std::unique_ptr<Certificate_12> m_client_certs;
213 std::unique_ptr<Client_Key_Exchange> m_client_kex;
214 std::unique_ptr<Certificate_Verify_12> m_client_verify;
215 std::unique_ptr<Certificate_Verify_12> m_server_verify;
216 std::unique_ptr<New_Session_Ticket_12> m_new_session_ticket;
217 std::unique_ptr<Finished_12> m_server_finished;
218 std::unique_ptr<Finished_12> m_client_finished;
219 };
220
221}
222
223}
224
225#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
std::pair< Handshake_Type, std::vector< uint8_t > > get_next_handshake_msg()
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
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
Handshake_State & operator=(const Handshake_State &)=delete
std::vector< uint8_t > session_ticket() const
const Session_Keys & session_keys() const
const Client_Hello_12 * client_hello() const
Handshake_State(const Handshake_State &)=delete
const Client_Key_Exchange * client_kex() const
const Handshake_Hash & hash() const
void confirm_transition_to(Handshake_Type msg_type)
void set_version(const Protocol_Version &version)
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
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
Definition: alg_id.cpp:13
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:65