Botan 3.13.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
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
140 Handshake_Hash& hash,
141 const Policy& policy,
142 Callbacks& cb,
144 std::vector<uint8_t> secure_reneg_info,
145 const Client_Hello_12& client_hello,
146 const Session& resumed_session,
147 bool offer_session_ticket,
148 std::string_view next_protocol);
149
150 explicit Server_Hello_12(std::span<const uint8_t> buf);
151
152 private:
153 explicit Server_Hello_12(std::unique_ptr<Server_Hello_Internal> data);
154
155 public:
160
161 bool secure_renegotiation() const;
162
163 std::vector<uint8_t> renegotiation_info() const;
164
165 std::string next_protocol() const;
166
167 bool supports_extended_master_secret() const;
168
169 bool supports_encrypt_then_mac() const;
170
171 bool supports_certificate_status_message() const;
172
173 bool supports_session_ticket() const;
174
175 uint16_t srtp_profile() const;
176 bool prefers_compressed_ec_points() const;
177};
178
179/**
180* Client Key Exchange Message
181*/
183 public:
185
186 const secure_vector<uint8_t>& pre_master_secret() const { return m_pre_master; }
187
188 /**
189 * @returns the agreed upon PSK identity or std::nullopt if not applicable
190 */
191 const std::optional<std::string>& psk_identity() const { return m_psk_identity; }
192
194 Handshake_State& state,
195 const Policy& policy,
196 Credentials_Manager& creds,
197 const Public_Key* server_public_key,
198 std::string_view hostname,
200
201 Client_Key_Exchange(std::span<const uint8_t> buf,
202 const Handshake_State& state,
203 const Private_Key* server_rsa_kex_key,
204 Credentials_Manager& creds,
205 const Policy& policy,
207
208 private:
209 std::vector<uint8_t> serialize() const override { return m_key_material; }
210
211 std::vector<uint8_t> m_key_material;
212 secure_vector<uint8_t> m_pre_master;
213 std::optional<std::string> m_psk_identity;
214};
215
216/**
217* Certificate Message of TLS 1.2
218*/
219class BOTAN_UNSTABLE_API Certificate_12 final : public Handshake_Message /* NOLINT(*-special-member-functions) */ {
220 public:
222
223 const std::vector<X509_Certificate>& cert_chain() const { return m_certs; }
224
225 size_t count() const;
226
227 bool empty() const { return m_certs.empty(); }
228
229 Certificate_12(Handshake_IO& io, Handshake_Hash& hash, std::vector<X509_Certificate> certs);
230
231 Certificate_12(std::span<const uint8_t> buf, const Policy& policy);
232
233 ~Certificate_12() override;
234
235 std::vector<uint8_t> serialize() const override;
236
237 private:
238 std::vector<X509_Certificate> m_certs;
239};
240
241/**
242* Certificate Request Message (TLS 1.2)
243*/
245 public:
246 Handshake_Type type() const override;
247
248 const std::vector<std::string>& acceptable_cert_types() const;
249
250 const std::vector<X509_DN>& acceptable_CAs() const;
251
252 const std::vector<Signature_Scheme>& signature_schemes() const;
253
255 Handshake_Hash& hash,
256 const Policy& policy,
257 std::vector<X509_DN> allowed_cas);
258
259 explicit Certificate_Request_12(std::span<const uint8_t> buf);
260
262
267
268 std::vector<uint8_t> serialize() const override;
269
270 private:
271 std::vector<X509_DN> m_names;
272 std::vector<std::string> m_cert_key_types;
273 std::vector<Signature_Scheme> m_schemes;
274};
275
276/**
277* Certificate Verify Message
278*/
280 public:
282
284 Handshake_State& state,
285 const Policy& policy,
287 const Private_Key* key);
288
289 /**
290 * Check the signature on a certificate verify message
291 * @param cert the purported certificate
292 * @param state the handshake state
293 * @param policy the TLS policy
294 */
295 bool verify(const X509_Certificate& cert, const Handshake_State& state, const Policy& policy) const;
296};
297
298/**
299* Certificate Status (RFC 6066)
300*/
302 public:
303 /*
304 * Create a Certificate_Status message using an already DER encoded OCSP response.
305 */
306 Certificate_Status_12(Handshake_IO& io, Handshake_Hash& hash, std::vector<uint8_t> raw_response_bytes);
307};
308
310 public:
311 using Finished::Finished;
313
314 bool verify(const Handshake_State& state, Connection_Side side) const;
315};
316
317/**
318* Hello Request Message
319*/
321 public:
323
324 explicit Hello_Request(Handshake_IO& io);
325 explicit Hello_Request(std::span<const uint8_t> buf);
326
327 private:
328 std::vector<uint8_t> serialize() const override;
329};
330
331/**
332* Server Key Exchange Message
333*/
335 public:
337
338 const std::vector<uint8_t>& params() const { return m_params; }
339
340 bool verify(const Public_Key& server_key, const Handshake_State& state, const Policy& policy) const;
341
342 // Only valid for certain kex types
343 const PK_Key_Agreement_Key& server_kex_key() const;
344
345 /**
346 * @returns the agreed upon KEX group or std::nullopt if the KEX type does
347 * not depend on a group
348 */
349 const std::optional<Group_Params>& shared_group() const { return m_shared_group; }
350
352 Handshake_State& state,
353 const Policy& policy,
354 Credentials_Manager& creds,
356 const Private_Key* signing_key = nullptr);
357
358 Server_Key_Exchange(std::span<const uint8_t> buf,
359 Kex_Algo kex_alg,
360 Auth_Method sig_alg,
361 Protocol_Version version);
362
364
369
370 private:
371 std::vector<uint8_t> serialize() const override;
372
373 std::unique_ptr<PK_Key_Agreement_Key> m_kex_key;
374 std::optional<Group_Params> m_shared_group;
375
376 std::vector<uint8_t> m_params;
377
378 std::vector<uint8_t> m_signature;
379 Signature_Scheme m_scheme;
380};
381
382/**
383* Server Hello Done Message
384*/
386 public:
388
389 explicit Server_Hello_Done(Handshake_IO& io, Handshake_Hash& hash);
390 explicit Server_Hello_Done(std::span<const uint8_t> buf);
391
392 private:
393 std::vector<uint8_t> serialize() const override;
394};
395
396/**
397* New Session Ticket Message
398*/
400 public:
402
403 uint32_t ticket_lifetime_hint() const { return m_ticket_lifetime_hint; }
404
405 const Session_Ticket& ticket() const { return m_ticket; }
406
408 Handshake_Hash& hash,
409 Session_Ticket ticket,
410 uint32_t lifetime_in_seconds);
411
413
414 explicit New_Session_Ticket_12(std::span<const uint8_t> buf);
415
416 std::vector<uint8_t> serialize() const override;
417
418 private:
419 uint32_t m_ticket_lifetime_hint = 0;
420 Session_Ticket m_ticket;
421};
422
423/**
424* Change Cipher Spec
425*/
427 public:
429
430 std::vector<uint8_t> serialize() const override { return std::vector<uint8_t>(1, 1); }
431};
432
433} // namespace TLS
434} // namespace Botan
435
436#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)
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