Botan 3.14.1
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
15#if defined(BOTAN_HAS_TLS_DOWNGRADE_SUPPORT)
16 #include <botan/tls_messages_13.h>
17#endif
18
19namespace Botan {
20
22
23namespace TLS {
24
26 public:
27 class Settings final {
28 public:
29 explicit Settings(const Protocol_Version version, std::string_view hostname = "") :
30 m_new_session_version(version), m_hostname(hostname) {}
31
32 Protocol_Version protocol_version() const { return m_new_session_version; }
33
34 const std::string& hostname() const { return m_hostname; }
35
36 private:
37 const Protocol_Version m_new_session_version;
38 const std::string m_hostname;
39 };
40
41 public:
43 Handshake_Hash& hash,
44 const Policy& policy,
45 Callbacks& cb,
47 std::vector<uint8_t> reneg_info,
48 const Settings& client_settings,
49 std::vector<std::string> next_protocols);
50
52 Handshake_Hash& hash,
53 const Policy& policy,
54 Callbacks& cb,
56 std::vector<uint8_t> reneg_info,
57 const Session_with_Handle& session_and_handle,
58 std::vector<std::string> next_protocols);
59
60 explicit Client_Hello_12(std::span<const uint8_t> buf);
61
62#if defined(BOTAN_HAS_TLS_DOWNGRADE_SUPPORT)
63 /**
64 * This creates a TLS 1.2 Client Hello object from a TLS 1.3 Client Hello
65 * object. This is used for downgrades from TLS 1.3 to TLS 1.2.
66 */
68#endif
69
70 private:
71 explicit Client_Hello_12(std::unique_ptr<Client_Hello_Internal> data);
72
73 public:
76
77 bool prefers_compressed_ec_points() const;
78
79 bool secure_renegotiation() const;
80
81 std::vector<uint8_t> renegotiation_info() const;
82
83 bool supports_session_ticket() const;
84
85 Session_Ticket session_ticket() const;
86
87 std::optional<Session_Handle> session_handle() const;
88
89 bool supports_extended_master_secret() const;
90
91 bool supports_cert_status_message() const;
92
93 bool supports_encrypt_then_mac() const;
94
95 void update_hello_cookie(const Hello_Verify_Request& hello_verify);
96
97 private:
98 void add_tls12_supported_groups_extensions(const Policy& policy);
99};
100
102 public:
103 class Settings final {
104 public:
105 Settings(Session_ID new_session_id,
106 Protocol_Version new_session_version,
107 uint16_t ciphersuite,
109 m_new_session_id(std::move(new_session_id)),
110 m_new_session_version(new_session_version),
111 m_ciphersuite(ciphersuite),
112 m_offer_session_ticket(offer_session_ticket) {}
113
114 const Session_ID& session_id() const { return m_new_session_id; }
115
116 Protocol_Version protocol_version() const { return m_new_session_version; }
117
118 uint16_t ciphersuite() const { return m_ciphersuite; }
119
120 bool offer_session_ticket() const { return m_offer_session_ticket; }
121
122 private:
123 const Session_ID m_new_session_id;
124 Protocol_Version m_new_session_version;
125 uint16_t m_ciphersuite;
126 bool m_offer_session_ticket;
127 };
128
130 Handshake_Hash& hash,
131 const Policy& policy,
132 Callbacks& cb,
134 std::vector<uint8_t> secure_reneg_info,
135 const Client_Hello_12& client_hello,
136 const Settings& settings,
137 std::string_view next_protocol,
138 TLS_Flavor flavor);
139
141 Handshake_Hash& hash,
142 const Policy& policy,
143 Callbacks& cb,
145 std::vector<uint8_t> secure_reneg_info,
146 const Client_Hello_12& client_hello,
147 const Session& resumed_session,
148 bool offer_session_ticket,
149 std::string_view next_protocol,
150 TLS_Flavor flavor);
151
152 explicit Server_Hello_12(std::span<const uint8_t> buf);
153
154 private:
155 explicit Server_Hello_12(std::unique_ptr<Server_Hello_Internal> data);
156
157 public:
162
163 bool secure_renegotiation() const;
164
165 std::vector<uint8_t> renegotiation_info() const;
166
167 std::string next_protocol() const;
168
169 bool supports_extended_master_secret() const;
170
171 bool supports_encrypt_then_mac() const;
172
173 bool supports_certificate_status_message() const;
174
175 bool supports_session_ticket() const;
176
177 uint16_t srtp_profile() const;
178 bool prefers_compressed_ec_points() const;
179};
180
181/**
182* Client Key Exchange Message
183*/
185 public:
187
188 const secure_vector<uint8_t>& pre_master_secret() const { return m_pre_master; }
189
190 /**
191 * @returns the agreed upon PSK identity or std::nullopt if not applicable
192 */
193 const std::optional<std::string>& psk_identity() const { return m_psk_identity; }
194
196 Handshake_State& state,
197 const Policy& policy,
198 Credentials_Manager& creds,
199 const Public_Key* server_public_key,
200 std::string_view hostname,
202
203 Client_Key_Exchange(std::span<const uint8_t> buf,
204 const Handshake_State& state,
205 const Private_Key* server_rsa_kex_key,
206 Credentials_Manager& creds,
207 const Policy& policy,
209
210 private:
211 std::vector<uint8_t> serialize() const override { return m_key_material; }
212
213 std::vector<uint8_t> m_key_material;
214 secure_vector<uint8_t> m_pre_master;
215 std::optional<std::string> m_psk_identity;
216};
217
218/**
219* Certificate Message of TLS 1.2
220*/
221class BOTAN_UNSTABLE_API Certificate_12 final : public Handshake_Message /* NOLINT(*-special-member-functions) */ {
222 public:
224
225 const std::vector<X509_Certificate>& cert_chain() const { return m_certs; }
226
227 size_t count() const;
228
229 bool empty() const { return m_certs.empty(); }
230
231 Certificate_12(Handshake_IO& io, Handshake_Hash& hash, std::vector<X509_Certificate> certs);
232
233 Certificate_12(std::span<const uint8_t> buf, const Policy& policy);
234
235 ~Certificate_12() override;
236
237 std::vector<uint8_t> serialize() const override;
238
239 private:
240 std::vector<X509_Certificate> m_certs;
241};
242
243/**
244* Certificate Request Message (TLS 1.2)
245*/
247 public:
248 Handshake_Type type() const override;
249
250 const std::vector<std::string>& acceptable_cert_types() const;
251
252 const std::vector<X509_DN>& acceptable_CAs() const;
253
254 const std::vector<Signature_Scheme>& signature_schemes() const;
255
257 Handshake_Hash& hash,
258 const Policy& policy,
259 std::vector<X509_DN> allowed_cas);
260
261 explicit Certificate_Request_12(std::span<const uint8_t> buf);
262
264
269
270 std::vector<uint8_t> serialize() const override;
271
272 private:
273 std::vector<X509_DN> m_names;
274 std::vector<std::string> m_cert_key_types;
275 std::vector<Signature_Scheme> m_schemes;
276};
277
278/**
279* Certificate Verify Message
280*/
282 public:
284
286 Handshake_State& state,
287 const Policy& policy,
289 const Private_Key* key);
290
291 /**
292 * Check the signature on a certificate verify message
293 * @param cert the purported certificate
294 * @param state the handshake state
295 * @param policy the TLS policy
296 */
297 bool verify(const X509_Certificate& cert, const Handshake_State& state, const Policy& policy) const;
298};
299
300/**
301* Certificate Status (RFC 6066)
302*/
304 public:
305 /*
306 * Create a Certificate_Status message using an already DER encoded OCSP response.
307 */
308 Certificate_Status_12(Handshake_IO& io, Handshake_Hash& hash, std::vector<uint8_t> raw_response_bytes);
309};
310
312 public:
313 using Finished::Finished;
315
316 bool verify(const Handshake_State& state, Connection_Side side) const;
317};
318
319/**
320* Hello Request Message
321*/
323 public:
325
326 explicit Hello_Request(Handshake_IO& io);
327 explicit Hello_Request(std::span<const uint8_t> buf);
328
329 private:
330 std::vector<uint8_t> serialize() const override;
331};
332
333/**
334* Server Key Exchange Message
335*/
337 public:
339
340 const std::vector<uint8_t>& params() const { return m_params; }
341
342 bool verify(const Public_Key& server_key, const Handshake_State& state, const Policy& policy) const;
343
344 // Only valid for certain kex types
345 const PK_Key_Agreement_Key& server_kex_key() const;
346
347 /**
348 * @returns the agreed upon KEX group or std::nullopt if the KEX type does
349 * not depend on a group
350 */
351 const std::optional<Group_Params>& shared_group() const { return m_shared_group; }
352
354 Handshake_State& state,
355 const Policy& policy,
356 Credentials_Manager& creds,
358 const Private_Key* signing_key = nullptr);
359
360 Server_Key_Exchange(std::span<const uint8_t> buf,
361 Kex_Algo kex_alg,
362 Auth_Method sig_alg,
363 Protocol_Version version);
364
366
371
372 private:
373 std::vector<uint8_t> serialize() const override;
374
375 std::unique_ptr<PK_Key_Agreement_Key> m_kex_key;
376 std::optional<Group_Params> m_shared_group;
377
378 std::vector<uint8_t> m_params;
379
380 std::vector<uint8_t> m_signature;
381 Signature_Scheme m_scheme;
382};
383
384/**
385* Server Hello Done Message
386*/
388 public:
390
391 explicit Server_Hello_Done(Handshake_IO& io, Handshake_Hash& hash);
392 explicit Server_Hello_Done(std::span<const uint8_t> buf);
393
394 private:
395 std::vector<uint8_t> serialize() const override;
396};
397
398/**
399* New Session Ticket Message
400*/
402 public:
404
405 uint32_t ticket_lifetime_hint() const { return m_ticket_lifetime_hint; }
406
407 const Session_Ticket& ticket() const { return m_ticket; }
408
410 Handshake_Hash& hash,
411 Session_Ticket ticket,
412 uint32_t lifetime_in_seconds);
413
415
416 explicit New_Session_Ticket_12(std::span<const uint8_t> buf);
417
418 std::vector<uint8_t> serialize() const override;
419
420 private:
421 uint32_t m_ticket_lifetime_hint = 0;
422 Session_Ticket m_ticket;
423};
424
425/**
426* Change Cipher Spec
427*/
429 public:
431
432 std::vector<uint8_t> serialize() const override { return std::vector<uint8_t>(1, 1); }
433};
434
435} // namespace TLS
436} // namespace Botan
437
438#endif
#define BOTAN_UNSTABLE_API
Definition api.h:34
Handshake_Type type() const override
const std::vector< X509_Certificate > & cert_chain() const
std::vector< uint8_t > serialize() const override
Certificate_12(Handshake_IO &io, Handshake_Hash &hash, std::vector< X509_Certificate > certs)
Certificate_Request_12(const Certificate_Request_12 &)=delete
Certificate_Request_12(Handshake_IO &io, Handshake_Hash &hash, const Policy &policy, std::vector< X509_DN > allowed_cas)
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 & 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(std::span< const uint8_t > buf, Connection_Side from)
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(std::span< const uint8_t > buf)
Certificate_Verify(std::span< const 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(std::span< const uint8_t > buf)
Client_Hello_12(Handshake_IO &io, Handshake_Hash &hash, const Policy &policy, Callbacks &cb, RandomNumberGenerator &rng, std::vector< uint8_t > reneg_info, const Settings &client_settings, 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)
bool verify(const Handshake_State &state, Connection_Side side) const
Finished_12(Handshake_IO &io, Handshake_State &state, Connection_Side side)
Finished(std::vector< uint8_t > buf)
Finished(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(std::span< const uint8_t > buf)
Server_Hello_12(Handshake_IO &io, Handshake_Hash &hash, const Policy &policy, Callbacks &cb, RandomNumberGenerator &rng, std::vector< uint8_t > secure_reneg_info, const Client_Hello_12 &client_hello, const Settings &settings, std::string_view next_protocol, TLS_Flavor flavor)
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:128