Botan 3.11.0
Crypto and TLS for C&
tls_messages_12.h
Go to the documentation of this file.
1/*
2* TLS Messages
3* (C) 2004-2011,2015 Jack Lloyd
4* 2016 Matthias Gierlings
5*
6* Botan is released under the Simplified BSD License (see license.txt)
7*/
8
9#ifndef BOTAN_TLS_MESSAGES_12_H_
10#define BOTAN_TLS_MESSAGES_12_H_
11
12#include <botan/secmem.h>
13#include <botan/tls_messages.h>
14
15namespace Botan {
16
18
19namespace TLS {
20
22 public:
23 class Settings final {
24 public:
25 explicit Settings(const Protocol_Version version, std::string_view hostname = "") :
26 m_new_session_version(version), m_hostname(hostname) {}
27
28 Protocol_Version protocol_version() const { return m_new_session_version; }
29
30 const std::string& hostname() const { return m_hostname; }
31
32 private:
33 const Protocol_Version m_new_session_version;
34 const std::string m_hostname;
35 };
36
37 public:
39 Handshake_Hash& hash,
40 const Policy& policy,
41 Callbacks& cb,
43 const std::vector<uint8_t>& reneg_info,
44 const Settings& client_settings,
45 const std::vector<std::string>& next_protocols);
46
48 Handshake_Hash& hash,
49 const Policy& policy,
50 Callbacks& cb,
52 const std::vector<uint8_t>& reneg_info,
53 const Session_with_Handle& session_and_handle,
54 const std::vector<std::string>& next_protocols);
55
56 explicit Client_Hello_12(const std::vector<uint8_t>& buf);
57
58 private:
59 explicit Client_Hello_12(std::unique_ptr<Client_Hello_Internal> data);
60
61 public:
64
65 bool prefers_compressed_ec_points() const;
66
67 bool secure_renegotiation() const;
68
69 std::vector<uint8_t> renegotiation_info() const;
70
71 bool supports_session_ticket() const;
72
73 Session_Ticket session_ticket() const;
74
75 std::optional<Session_Handle> session_handle() const;
76
77 bool supports_extended_master_secret() const;
78
79 bool supports_cert_status_message() const;
80
81 bool supports_encrypt_then_mac() const;
82
83 void update_hello_cookie(const Hello_Verify_Request& hello_verify);
84
85 private:
86 void add_tls12_supported_groups_extensions(const Policy& policy);
87};
88
90 public:
91 class Settings final {
92 public:
93 Settings(Session_ID new_session_id,
94 Protocol_Version new_session_version,
95 uint16_t ciphersuite,
97 m_new_session_id(std::move(new_session_id)),
98 m_new_session_version(new_session_version),
99 m_ciphersuite(ciphersuite),
100 m_offer_session_ticket(offer_session_ticket) {}
101
102 const Session_ID& session_id() const { return m_new_session_id; }
103
104 Protocol_Version protocol_version() const { return m_new_session_version; }
105
106 uint16_t ciphersuite() const { return m_ciphersuite; }
107
108 bool offer_session_ticket() const { return m_offer_session_ticket; }
109
110 private:
111 const Session_ID m_new_session_id;
112 Protocol_Version m_new_session_version;
113 uint16_t m_ciphersuite;
114 bool m_offer_session_ticket;
115 };
116
118 Handshake_Hash& hash,
119 const Policy& policy,
120 Callbacks& cb,
122 const std::vector<uint8_t>& secure_reneg_info,
123 const Client_Hello_12& client_hello,
124 const Settings& settings,
125 std::string_view next_protocol);
126
128 Handshake_Hash& hash,
129 const Policy& policy,
130 Callbacks& cb,
132 const std::vector<uint8_t>& secure_reneg_info,
133 const Client_Hello_12& client_hello,
134 const Session& resumed_session,
135 bool offer_session_ticket,
136 std::string_view next_protocol);
137
138 explicit Server_Hello_12(const std::vector<uint8_t>& buf);
139
140 private:
141 explicit Server_Hello_12(std::unique_ptr<Server_Hello_Internal> data);
142
143 public:
148
149 bool secure_renegotiation() const;
150
151 std::vector<uint8_t> renegotiation_info() const;
152
153 std::string next_protocol() const;
154
155 bool supports_extended_master_secret() const;
156
157 bool supports_encrypt_then_mac() const;
158
159 bool supports_certificate_status_message() const;
160
161 bool supports_session_ticket() const;
162
163 uint16_t srtp_profile() const;
164 bool prefers_compressed_ec_points() const;
165};
166
167/**
168* Client Key Exchange Message
169*/
171 public:
173
174 const secure_vector<uint8_t>& pre_master_secret() const { return m_pre_master; }
175
176 /**
177 * @returns the agreed upon PSK identity or std::nullopt if not applicable
178 */
179 const std::optional<std::string>& psk_identity() const { return m_psk_identity; }
180
182 Handshake_State& state,
183 const Policy& policy,
184 Credentials_Manager& creds,
185 const Public_Key* server_public_key,
186 std::string_view hostname,
188
189 Client_Key_Exchange(const std::vector<uint8_t>& buf,
190 const Handshake_State& state,
191 const Private_Key* server_rsa_kex_key,
192 Credentials_Manager& creds,
193 const Policy& policy,
195
196 private:
197 std::vector<uint8_t> serialize() const override { return m_key_material; }
198
199 std::vector<uint8_t> m_key_material;
200 secure_vector<uint8_t> m_pre_master;
201 std::optional<std::string> m_psk_identity;
202};
203
204/**
205* Certificate Message of TLS 1.2
206*/
207class BOTAN_UNSTABLE_API Certificate_12 final : public Handshake_Message /* NOLINT(*-special-member-functions) */ {
208 public:
210
211 const std::vector<X509_Certificate>& cert_chain() const { return m_certs; }
212
213 size_t count() const;
214
215 bool empty() const { return m_certs.empty(); }
216
217 Certificate_12(Handshake_IO& io, Handshake_Hash& hash, const std::vector<X509_Certificate>& certs);
218
219 Certificate_12(const std::vector<uint8_t>& buf, const Policy& policy);
220
221 ~Certificate_12() override;
222
223 std::vector<uint8_t> serialize() const override;
224
225 private:
226 std::vector<X509_Certificate> m_certs;
227};
228
229/**
230* Certificate Request Message (TLS 1.2)
231*/
233 public:
234 Handshake_Type type() const override;
235
236 const std::vector<std::string>& acceptable_cert_types() const;
237
238 const std::vector<X509_DN>& acceptable_CAs() const;
239
240 const std::vector<Signature_Scheme>& signature_schemes() const;
241
243 Handshake_Hash& hash,
244 const Policy& policy,
245 const std::vector<X509_DN>& allowed_cas);
246
247 explicit Certificate_Request_12(const std::vector<uint8_t>& buf);
248
250
255
256 std::vector<uint8_t> serialize() const override;
257
258 private:
259 std::vector<X509_DN> m_names;
260 std::vector<std::string> m_cert_key_types;
261 std::vector<Signature_Scheme> m_schemes;
262};
263
264/**
265* Certificate Verify Message
266*/
268 public:
270
272 Handshake_State& state,
273 const Policy& policy,
275 const Private_Key* key);
276
277 /**
278 * Check the signature on a certificate verify message
279 * @param cert the purported certificate
280 * @param state the handshake state
281 * @param policy the TLS policy
282 */
283 bool verify(const X509_Certificate& cert, const Handshake_State& state, const Policy& policy) const;
284};
285
286/**
287* Certificate Status (RFC 6066)
288*/
290 public:
291 /*
292 * Create a Certificate_Status message using an already DER encoded OCSP response.
293 */
294 Certificate_Status_12(Handshake_IO& io, Handshake_Hash& hash, std::vector<uint8_t> raw_response_bytes);
295};
296
298 public:
299 using Finished::Finished;
301
302 bool verify(const Handshake_State& state, Connection_Side side) const;
303};
304
305/**
306* Hello Request Message
307*/
309 public:
311
312 explicit Hello_Request(Handshake_IO& io);
313 explicit Hello_Request(const std::vector<uint8_t>& buf);
314
315 private:
316 std::vector<uint8_t> serialize() const override;
317};
318
319/**
320* Server Key Exchange Message
321*/
323 public:
325
326 const std::vector<uint8_t>& params() const { return m_params; }
327
328 bool verify(const Public_Key& server_key, const Handshake_State& state, const Policy& policy) const;
329
330 // Only valid for certain kex types
331 const PK_Key_Agreement_Key& server_kex_key() const;
332
333 /**
334 * @returns the agreed upon KEX group or std::nullopt if the KEX type does
335 * not depend on a group
336 */
337 const std::optional<Group_Params>& shared_group() const { return m_shared_group; }
338
340 Handshake_State& state,
341 const Policy& policy,
342 Credentials_Manager& creds,
344 const Private_Key* signing_key = nullptr);
345
346 Server_Key_Exchange(const std::vector<uint8_t>& buf,
347 Kex_Algo kex_alg,
348 Auth_Method sig_alg,
349 Protocol_Version version);
350
352
357
358 private:
359 std::vector<uint8_t> serialize() const override;
360
361 std::unique_ptr<PK_Key_Agreement_Key> m_kex_key;
362 std::optional<Group_Params> m_shared_group;
363
364 std::vector<uint8_t> m_params;
365
366 std::vector<uint8_t> m_signature;
367 Signature_Scheme m_scheme;
368};
369
370/**
371* Server Hello Done Message
372*/
374 public:
376
377 explicit Server_Hello_Done(Handshake_IO& io, Handshake_Hash& hash);
378 explicit Server_Hello_Done(const std::vector<uint8_t>& buf);
379
380 private:
381 std::vector<uint8_t> serialize() const override;
382};
383
384/**
385* New Session Ticket Message
386*/
388 public:
390
391 uint32_t ticket_lifetime_hint() const { return m_ticket_lifetime_hint; }
392
393 const Session_Ticket& ticket() const { return m_ticket; }
394
396 Handshake_Hash& hash,
397 Session_Ticket ticket,
398 uint32_t lifetime_in_seconds);
399
401
402 explicit New_Session_Ticket_12(const std::vector<uint8_t>& buf);
403
404 std::vector<uint8_t> serialize() const override;
405
406 private:
407 uint32_t m_ticket_lifetime_hint = 0;
408 Session_Ticket m_ticket;
409};
410
411/**
412* Change Cipher Spec
413*/
415 public:
417
418 std::vector<uint8_t> serialize() const override { return std::vector<uint8_t>(1, 1); }
419};
420
421} // namespace TLS
422} // namespace Botan
423
424#endif
#define BOTAN_UNSTABLE_API
Definition api.h:34
Handshake_Type type() const override
const std::vector< X509_Certificate > & cert_chain() const
Certificate_12(Handshake_IO &io, Handshake_Hash &hash, const std::vector< X509_Certificate > &certs)
std::vector< uint8_t > serialize() const override
Certificate_Request_12(const Certificate_Request_12 &)=delete
const std::vector< std::string > & acceptable_cert_types() const
Certificate_Request_12 & operator=(const Certificate_Request_12 &other)=delete
const std::vector< Signature_Scheme > & signature_schemes() const
std::vector< uint8_t > serialize() const override
const std::vector< X509_DN > & acceptable_CAs() const
Certificate_Request_12(Handshake_IO &io, Handshake_Hash &hash, const Policy &policy, const std::vector< X509_DN > &allowed_cas)
Certificate_Request_12 & operator=(Certificate_Request_12 &&other)=delete
Certificate_Request_12(Certificate_Request_12 &&)=delete
Handshake_Type type() const override
Certificate_Status_12(Handshake_IO &io, Handshake_Hash &hash, std::vector< uint8_t > raw_response_bytes)
Certificate_Status(const std::vector< uint8_t > &buf, Connection_Side from)
Certificate_Verify(const std::vector< uint8_t > &buf)
bool verify(const X509_Certificate &cert, const Handshake_State &state, const Policy &policy) const
Certificate_Verify_12(Handshake_IO &io, Handshake_State &state, const Policy &policy, RandomNumberGenerator &rng, const Private_Key *key)
Certificate_Verify(const std::vector< uint8_t > &buf)
std::vector< uint8_t > serialize() const override
Handshake_Type type() const override
const std::string & hostname() const
Settings(const Protocol_Version version, std::string_view hostname="")
Protocol_Version protocol_version() const
Client_Hello_12_Shim(const std::vector< uint8_t > &buf)
Client_Hello_12(Handshake_IO &io, Handshake_Hash &hash, const Policy &policy, Callbacks &cb, RandomNumberGenerator &rng, const std::vector< uint8_t > &reneg_info, const Settings &client_settings, const std::vector< std::string > &next_protocols)
const std::vector< uint8_t > & random() const
const std::vector< uint8_t > & compression_methods() const
Handshake_Type type() const override
const std::optional< std::string > & psk_identity() const
const secure_vector< uint8_t > & pre_master_secret() const
Client_Key_Exchange(Handshake_IO &io, Handshake_State &state, const Policy &policy, Credentials_Manager &creds, const Public_Key *server_public_key, std::string_view hostname, RandomNumberGenerator &rng)
Finished(const std::vector< uint8_t > &buf)
bool verify(const Handshake_State &state, Connection_Side side) const
Finished_12(Handshake_IO &io, Handshake_State &state, Connection_Side side)
Finished(const std::vector< uint8_t > &buf)
Handshake_Type type() const override
New_Session_Ticket_12(Handshake_IO &io, Handshake_Hash &hash, Session_Ticket ticket, uint32_t lifetime_in_seconds)
Handshake_Type type() const override
const Session_Ticket & ticket() const
Protocol_Version protocol_version() const
Settings(Session_ID new_session_id, Protocol_Version new_session_version, uint16_t ciphersuite, bool offer_session_ticket)
const Session_ID & session_id() const
Server_Hello_12_Shim(const std::vector< uint8_t > &buf)
Server_Hello_12(Handshake_IO &io, Handshake_Hash &hash, const Policy &policy, Callbacks &cb, RandomNumberGenerator &rng, const std::vector< uint8_t > &secure_reneg_info, const Client_Hello_12 &client_hello, const Settings &settings, std::string_view next_protocol)
Handshake_Type type() const override
Server_Hello_Done(Handshake_IO &io, Handshake_Hash &hash)
std::set< Extension_Code > extension_types() const
const std::vector< uint8_t > & random() const
Protocol_Version legacy_version() const
Handshake_Type type() const override
Server_Key_Exchange & operator=(Server_Key_Exchange &&other)=delete
const std::vector< uint8_t > & params() const
const std::optional< Group_Params > & shared_group() const
Server_Key_Exchange(Handshake_IO &io, Handshake_State &state, const Policy &policy, Credentials_Manager &creds, RandomNumberGenerator &rng, const Private_Key *signing_key=nullptr)
Server_Key_Exchange(const Server_Key_Exchange &other)=delete
Server_Key_Exchange(Server_Key_Exchange &&other)=delete
Server_Key_Exchange & operator=(const Server_Key_Exchange &other)=delete
Strong< std::vector< uint8_t >, struct Session_ID_ > Session_ID
holds a TLS 1.2 session ID for stateful resumption
Strong< std::vector< uint8_t >, struct Session_Ticket_ > Session_Ticket
holds a TLS 1.2 session ticket for stateless resumption
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:68