Botan 3.13.0
Crypto and TLS for C&
tls_messages.h
Go to the documentation of this file.
1/*
2* TLS Messages
3* (C) 2004-2011,2015 Jack Lloyd
4* 2016 Matthias Gierlings
5* 2021 Elektrobit Automotive GmbH
6* 2022 René Meusel, Hannes Rantzsch - neXenio GmbH
7*
8* Botan is released under the Simplified BSD License (see license.txt)
9*/
10
11#ifndef BOTAN_TLS_MESSAGES_H_
12#define BOTAN_TLS_MESSAGES_H_
13
14#include <botan/tls_algos.h>
15#include <botan/tls_handshake_msg.h>
16#include <botan/tls_session_id.h>
17#include <botan/tls_signature_scheme.h>
18#include <botan/tls_version.h>
19#include <memory>
20#include <set>
21#include <span>
22#include <string>
23#include <vector>
24
25namespace Botan {
26
27class Public_Key;
30class X509_DN;
32
33namespace OCSP {
34class Response;
35}
36
37namespace TLS {
38
39enum class Extension_Code : uint16_t;
40
41class Session_Manager;
42class Extensions;
43class Handshake_IO;
44class Handshake_State;
46class Callbacks;
47class Cipher_State;
49class Session;
50class Policy;
51
52/**
53* DTLS Hello Verify Request
54*/
56 public:
57 std::vector<uint8_t> serialize() const override;
58
60
61 const std::vector<uint8_t>& cookie() const { return m_cookie; }
62
63 explicit Hello_Verify_Request(std::span<const uint8_t> buf);
64
65 Hello_Verify_Request(std::span<const uint8_t> client_hello_bits,
66 std::string_view client_identity,
67 std::span<const uint8_t> cookie_secret);
68
69 private:
70 std::vector<uint8_t> m_cookie;
71};
72
73class Client_Hello_Internal;
74
75/**
76* Client Hello Message
77*/
79 public:
80 Client_Hello(const Client_Hello&) = delete;
83 Client_Hello& operator=(Client_Hello&&) noexcept;
84
85 ~Client_Hello() override;
86
87 Handshake_Type type() const override;
88
89 /**
90 * Return the version indicated in the ClientHello.
91 * This may differ from the version indicated in the supported_versions extension.
92 *
93 * See RFC 8446 4.1.2:
94 * TLS 1.3, the client indicates its version preferences in the
95 * "supported_versions" extension (Section 4.2.1) and the
96 * legacy_version field MUST be set to 0x0303, which is the version
97 * number for TLS 1.2.
98 */
100
101 const std::vector<uint8_t>& random() const;
102
103 const Session_ID& session_id() const;
104
105 const std::vector<uint16_t>& ciphersuites() const;
106
107 bool offered_suite(uint16_t ciphersuite) const;
108
109 std::vector<Signature_Scheme> signature_schemes() const;
111
112 std::vector<Group_Params> supported_ecc_curves() const;
113
114 // This returns any groups in the FFDHE range
115 std::vector<Group_Params> supported_dh_groups() const;
116
117 std::vector<Protocol_Version> supported_versions() const;
118
119 std::string sni_hostname() const;
120
121 bool supports_alpn() const;
122
123 bool sent_signature_algorithms() const;
124
125 std::vector<std::string> next_protocols() const;
126
127 std::vector<uint16_t> srtp_profiles() const;
128
129 std::vector<uint8_t> serialize() const override;
130
131 const std::vector<uint8_t>& cookie() const;
132
133 std::vector<uint8_t> cookie_input_data() const;
134
135 std::set<Extension_Code> extension_types() const;
136
137 const Extensions& extensions() const;
138
139 protected:
140 Client_Hello();
141 explicit Client_Hello(std::unique_ptr<Client_Hello_Internal> data);
142
143 const std::vector<uint8_t>& compression_methods() const;
144
145 protected:
146 std::unique_ptr<Client_Hello_Internal> m_data; // NOLINT(*non-private-member-variable*)
147};
148
149/**
150 * Basic implementation of Client_Hello from TLS 1.2. The full implementation
151 * is in Client_Hello_12 in the tls12 module. This is meant to be used by the
152 * TLS 1.3 implementation to parse, validate and understand a downgrade request.
153 */
155 public:
156 explicit Client_Hello_12_Shim(std::span<const uint8_t> buf);
157
158 protected:
160
161 friend class Client_Hello_13; // to allow construction by Client_Hello_13::parse()
162 explicit Client_Hello_12_Shim(std::unique_ptr<Client_Hello_Internal> data);
163};
164
166
167/**
168* Server Hello Message
169*/
171 public:
172 Server_Hello(const Server_Hello&) = delete;
175 Server_Hello& operator=(Server_Hello&&) noexcept;
176
177 ~Server_Hello() override;
178
179 std::vector<uint8_t> serialize() const override;
180
181 Handshake_Type type() const override;
182
183 // methods available in both subclasses' interface
184 uint16_t ciphersuite() const;
185 const Extensions& extensions() const;
186 const Session_ID& session_id() const;
187
189
190 protected:
191 explicit Server_Hello(std::unique_ptr<Server_Hello_Internal> data);
192
193 // methods used internally and potentially exposed by one of the subclasses
194 std::set<Extension_Code> extension_types() const;
195 const std::vector<uint8_t>& random() const;
196 uint8_t compression_method() const;
198
199 protected:
200 std::unique_ptr<Server_Hello_Internal> m_data; // NOLINT(*non-private-member-variable*)
201};
202
203/**
204 * Basic implementation of Server_Hello from TLS 1.2. The full implementation
205 * is in Server_Hello_12 in the tls12 module. This is meant to be used by the
206 * TLS 1.3 implementation to parse, validate and understand a downgrade request.
207 */
209 public:
210 explicit Server_Hello_12_Shim(std::span<const uint8_t> buf);
211
212 protected:
213 friend class Server_Hello_13; // to allow construction by Server_Hello_13::parse()
214 explicit Server_Hello_12_Shim(std::unique_ptr<Server_Hello_Internal> data);
215
216 public:
217 /**
218 * @returns the selected version as indicated in the legacy_version field
219 */
221
222 /**
223 * Return desired downgrade version indicated by hello random, if any.
224 */
225 std::optional<Protocol_Version> random_signals_downgrade() const;
226};
227
228/**
229* Certificate Status (RFC 6066)
230*/
232 public:
234
235 //std::shared_ptr<const OCSP::Response> response() const { return m_response; }
236
237 const std::vector<uint8_t>& response() const { return m_response; }
238
239 explicit Certificate_Status(std::span<const uint8_t> buf, Connection_Side from);
240
241 explicit Certificate_Status(std::vector<uint8_t> raw_response_bytes);
242
243 std::vector<uint8_t> serialize() const final;
244
245 private:
246 std::vector<uint8_t> m_response;
247};
248
250 public:
252
254
255 explicit Certificate_Verify(std::span<const uint8_t> buf);
257
258 std::vector<uint8_t> serialize() const override;
259
260 protected:
261 std::vector<uint8_t> m_signature; // NOLINT(*non-private-member-variable*)
262 Signature_Scheme m_scheme; // NOLINT(*non-private-member-variable*)
263};
264
265/**
266* Finished Message
267*/
269 public:
270 explicit Finished(std::vector<uint8_t> buf) : m_verification_data(std::move(buf)) {}
271
272 Handshake_Type type() const override { return Handshake_Type::Finished; }
273
274 std::vector<uint8_t> verify_data() const { return m_verification_data; }
275
276 std::vector<uint8_t> serialize() const override { return m_verification_data; }
277
278 protected:
280 std::vector<uint8_t> m_verification_data; // NOLINT(*non-private-member-variable*)
281};
282
283} // namespace TLS
284
285} // namespace Botan
286
287#endif
#define BOTAN_UNSTABLE_API
Definition api.h:34
const std::vector< uint8_t > & response() const
Handshake_Type type() const final
Certificate_Status(std::span< const uint8_t > buf, Connection_Side from)
Handshake_Type type() const override
std::vector< uint8_t > serialize() const override
Signature_Scheme signature_scheme() const
Certificate_Verify(std::span< const uint8_t > buf)
std::vector< uint8_t > m_signature
Client_Hello_12_Shim(std::span< const uint8_t > buf)
Client_Hello(const Client_Hello &)=delete
const std::vector< uint8_t > & cookie() const
std::string sni_hostname() const
std::vector< uint8_t > serialize() const override
const std::vector< uint8_t > & random() const
std::vector< Signature_Scheme > signature_schemes() const
const Extensions & extensions() const
Client_Hello(Client_Hello &&) noexcept
bool offered_suite(uint16_t ciphersuite) const
std::unique_ptr< Client_Hello_Internal > m_data
std::vector< Group_Params > supported_ecc_curves() const
std::vector< Signature_Scheme > certificate_signature_schemes() const
const std::vector< uint16_t > & ciphersuites() const
std::vector< uint8_t > cookie_input_data() const
std::set< Extension_Code > extension_types() const
std::vector< Group_Params > supported_dh_groups() const
std::vector< std::string > next_protocols() const
const Session_ID & session_id() const
Protocol_Version legacy_version() const
const std::vector< uint8_t > & compression_methods() const
Client_Hello & operator=(const Client_Hello &)=delete
std::vector< uint16_t > srtp_profiles() const
Handshake_Type type() const override
std::vector< Protocol_Version > supported_versions() const
Client_Hello(const Client_Hello &)=delete
Handshake_Message()=default
std::vector< uint8_t > serialize() const override
std::vector< uint8_t > verify_data() const
std::vector< uint8_t > m_verification_data
Handshake_Type type() const override
Finished(std::vector< uint8_t > buf)
Hello_Verify_Request(std::span< const uint8_t > buf)
Handshake_Type type() const override
const std::vector< uint8_t > & cookie() const
std::vector< uint8_t > serialize() const override
Server_Hello_12_Shim(std::span< const uint8_t > buf)
Protocol_Version selected_version() const final
std::optional< Protocol_Version > random_signals_downgrade() const
Server_Hello(const Server_Hello &)=delete
std::vector< uint8_t > serialize() const override
std::set< Extension_Code > extension_types() const
Handshake_Type type() const override
const Session_ID & session_id() const
const std::vector< uint8_t > & random() const
Server_Hello(Server_Hello &&) noexcept
std::unique_ptr< Server_Hello_Internal > m_data
const Extensions & extensions() const
Server_Hello & operator=(const Server_Hello &)=delete
virtual Protocol_Version selected_version() const =0
Protocol_Version legacy_version() const
Strong< std::vector< uint8_t >, struct Session_ID_ > Session_ID
holds a TLS 1.2 session ID for stateful resumption