Botan 3.11.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 <string>
22#include <vector>
23
24namespace Botan {
25
26class Public_Key;
29class X509_DN;
31
32class OctetString;
34
35namespace OCSP {
36class Response;
37}
38
39namespace TLS {
40
41enum class Extension_Code : uint16_t;
42
43class Session_Manager;
44class Extensions;
45class Handshake_IO;
46class Handshake_State;
48class Callbacks;
49class Cipher_State;
51class Session;
52class Policy;
53
54/**
55* DTLS Hello Verify Request
56*/
58 public:
59 std::vector<uint8_t> serialize() const override;
60
62
63 const std::vector<uint8_t>& cookie() const { return m_cookie; }
64
65 explicit Hello_Verify_Request(const std::vector<uint8_t>& buf);
66
67 Hello_Verify_Request(const std::vector<uint8_t>& client_hello_bits,
68 std::string_view client_identity,
69 const SymmetricKey& secret_key);
70
71 private:
72 std::vector<uint8_t> m_cookie;
73};
74
75class Client_Hello_Internal;
76
77/**
78* Client Hello Message
79*/
81 public:
82 Client_Hello(const Client_Hello&) = delete;
85 Client_Hello& operator=(Client_Hello&&) noexcept;
86
87 ~Client_Hello() override;
88
89 Handshake_Type type() const override;
90
91 /**
92 * Return the version indicated in the ClientHello.
93 * This may differ from the version indicated in the supported_versions extension.
94 *
95 * See RFC 8446 4.1.2:
96 * TLS 1.3, the client indicates its version preferences in the
97 * "supported_versions" extension (Section 4.2.1) and the
98 * legacy_version field MUST be set to 0x0303, which is the version
99 * number for TLS 1.2.
100 */
102
103 const std::vector<uint8_t>& random() const;
104
105 const Session_ID& session_id() const;
106
107 const std::vector<uint16_t>& ciphersuites() const;
108
109 bool offered_suite(uint16_t ciphersuite) const;
110
111 std::vector<Signature_Scheme> signature_schemes() const;
113
114 std::vector<Group_Params> supported_ecc_curves() const;
115
116 // This returns any groups in the FFDHE range
117 std::vector<Group_Params> supported_dh_groups() const;
118
119 std::vector<Protocol_Version> supported_versions() const;
120
121 std::string sni_hostname() const;
122
123 bool supports_alpn() const;
124
125 bool sent_signature_algorithms() const;
126
127 std::vector<std::string> next_protocols() const;
128
129 std::vector<uint16_t> srtp_profiles() const;
130
131 std::vector<uint8_t> serialize() const override;
132
133 const std::vector<uint8_t>& cookie() const;
134
135 std::vector<uint8_t> cookie_input_data() const;
136
137 std::set<Extension_Code> extension_types() const;
138
139 const Extensions& extensions() const;
140
141 protected:
142 Client_Hello();
143 explicit Client_Hello(std::unique_ptr<Client_Hello_Internal> data);
144
145 const std::vector<uint8_t>& compression_methods() const;
146
147 protected:
148 std::unique_ptr<Client_Hello_Internal> m_data; // NOLINT(*non-private-member-variable*)
149};
150
151/**
152 * Basic implementation of Client_Hello from TLS 1.2. The full implementation
153 * is in Client_Hello_12 in the tls12 module. This is meant to be used by the
154 * TLS 1.3 implementation to parse, validate and understand a downgrade request.
155 */
157 public:
158 explicit Client_Hello_12_Shim(const std::vector<uint8_t>& buf);
159
160 protected:
162
163 friend class Client_Hello_13; // to allow construction by Client_Hello_13::parse()
164 explicit Client_Hello_12_Shim(std::unique_ptr<Client_Hello_Internal> data);
165};
166
168
169/**
170* Server Hello Message
171*/
173 public:
174 Server_Hello(const Server_Hello&) = delete;
177 Server_Hello& operator=(Server_Hello&&) noexcept;
178
179 ~Server_Hello() override;
180
181 std::vector<uint8_t> serialize() const override;
182
183 Handshake_Type type() const override;
184
185 // methods available in both subclasses' interface
186 uint16_t ciphersuite() const;
187 const Extensions& extensions() const;
188 const Session_ID& session_id() const;
189
191
192 protected:
193 explicit Server_Hello(std::unique_ptr<Server_Hello_Internal> data);
194
195 // methods used internally and potentially exposed by one of the subclasses
196 std::set<Extension_Code> extension_types() const;
197 const std::vector<uint8_t>& random() const;
198 uint8_t compression_method() const;
200
201 protected:
202 std::unique_ptr<Server_Hello_Internal> m_data; // NOLINT(*non-private-member-variable*)
203};
204
205/**
206 * Basic implementation of Server_Hello from TLS 1.2. The full implementation
207 * is in Server_Hello_12 in the tls12 module. This is meant to be used by the
208 * TLS 1.3 implementation to parse, validate and understand a downgrade request.
209 */
211 public:
212 explicit Server_Hello_12_Shim(const std::vector<uint8_t>& buf);
213
214 protected:
215 friend class Server_Hello_13; // to allow construction by Server_Hello_13::parse()
216 explicit Server_Hello_12_Shim(std::unique_ptr<Server_Hello_Internal> data);
217
218 public:
219 /**
220 * @returns the selected version as indicated in the legacy_version field
221 */
223
224 /**
225 * Return desired downgrade version indicated by hello random, if any.
226 */
227 std::optional<Protocol_Version> random_signals_downgrade() const;
228};
229
230/**
231* Certificate Status (RFC 6066)
232*/
234 public:
236
237 //std::shared_ptr<const OCSP::Response> response() const { return m_response; }
238
239 const std::vector<uint8_t>& response() const { return m_response; }
240
241 explicit Certificate_Status(const std::vector<uint8_t>& buf, Connection_Side from);
242
243 explicit Certificate_Status(std::vector<uint8_t> raw_response_bytes);
244
245 std::vector<uint8_t> serialize() const final;
246
247 private:
248 std::vector<uint8_t> m_response;
249};
250
252 public:
254
256
257 explicit Certificate_Verify(const std::vector<uint8_t>& buf);
259
260 std::vector<uint8_t> serialize() const override;
261
262 protected:
263 std::vector<uint8_t> m_signature; // NOLINT(*non-private-member-variable*)
264 Signature_Scheme m_scheme; // NOLINT(*non-private-member-variable*)
265};
266
267/**
268* Finished Message
269*/
271 public:
272 explicit Finished(const std::vector<uint8_t>& buf) : m_verification_data(buf) {}
273
274 Handshake_Type type() const override { return Handshake_Type::Finished; }
275
276 std::vector<uint8_t> verify_data() const { return m_verification_data; }
277
278 std::vector<uint8_t> serialize() const override { return m_verification_data; }
279
280 protected:
282 std::vector<uint8_t> m_verification_data; // NOLINT(*non-private-member-variable*)
283};
284
285} // namespace TLS
286
287} // namespace Botan
288
289#endif
#define BOTAN_UNSTABLE_API
Definition api.h:34
const std::vector< uint8_t > & response() const
Handshake_Type type() const final
Certificate_Status(const std::vector< uint8_t > &buf, Connection_Side from)
Handshake_Type type() const override
Certificate_Verify(const std::vector< uint8_t > &buf)
std::vector< uint8_t > serialize() const override
Signature_Scheme signature_scheme() const
std::vector< uint8_t > m_signature
Client_Hello_12_Shim(const std::vector< 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
Finished(const std::vector< uint8_t > &buf)
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
Handshake_Type type() const override
Hello_Verify_Request(const std::vector< uint8_t > &buf)
const std::vector< uint8_t > & cookie() const
std::vector< uint8_t > serialize() const override
Server_Hello_12_Shim(const std::vector< 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
OctetString SymmetricKey
Definition symkey.h:140