Botan 3.11.0
Crypto and TLS for C&
tls_messages_internal.h
Go to the documentation of this file.
1/*
2* TLS Client/Server Hello Internal Data Containers
3* (C) 2004-2026 Jack Lloyd
4* 2021 Elektrobit Automotive GmbH
5* 2022 René Meusel, Hannes Rantzsch - neXenio GmbH
6* 2026 René Meusel - Rohde & Schwarz Cybersecurity GmbH
7*
8* Botan is released under the Simplified BSD License (see license.txt)
9*/
10
11#ifndef BOTAN_TLS_MESSAGES_INTERNAL_H_
12#define BOTAN_TLS_MESSAGES_INTERNAL_H_
13
14#include <botan/tls_extensions.h>
15#include <botan/tls_session.h>
16#include <botan/tls_version.h>
17#include <vector>
18
19namespace Botan {
21
22namespace TLS {
23class Callbacks;
24class Policy;
25} // namespace TLS
26
27} // namespace Botan
28
29namespace Botan::TLS {
30
31/**
32 * Generate a (client) hello random value.
33 *
34 * Depending on the policy, the RNG output may be hashed and if TLS 1.2 is
35 * offered, the random value may contain a timestamp.
36 */
37std::vector<uint8_t> make_hello_random(RandomNumberGenerator& rng, Callbacks& cb, const Policy& policy);
38
39/**
40 * Generate a server hello random value for the given protocol version.
41 *
42 * Depending on the protocol version, the random value is generated differently.
43 * For instance, TLS 1.2 requested a timestamp in the random value. Also, when
44 * downgrading to TLS 1.2 from a peer that could also negotiate TLS 1.3, the
45 * random value must be slightly modified to signal the downgrade.
46 */
47std::vector<uint8_t> make_server_hello_random(RandomNumberGenerator& rng,
48 Protocol_Version offered_version,
49 Callbacks& cb,
50 const Policy& policy);
51
52/**
53 * Version-agnostic internal client hello data container that allows
54 * parsing Client_Hello messages without prior knowledge of the contained
55 * protocol version.
56 */
58 public:
60
61 explicit Client_Hello_Internal(const std::vector<uint8_t>& buf);
62
63 /**
64 * This distinguishes between a TLS 1.3 compliant Client Hello (containing
65 * the "supported_version" extension) and legacy Client Hello messages.
66 *
67 * @return TLS 1.3 if the Client Hello contains "supported_versions", or
68 * the content of the "legacy_version" version field if it
69 * indicates (D)TLS 1.2 or older, or
70 * (D)TLS 1.2 if the "legacy_version" was some other odd value.
71 */
72 Protocol_Version version() const;
73
75
76 const Session_ID& session_id() const { return m_session_id; }
77
78 const std::vector<uint8_t>& random() const { return m_random; }
79
80 const std::vector<uint16_t>& ciphersuites() const { return m_suites; }
81
82 const std::vector<uint8_t>& comp_methods() const { return m_comp_methods; }
83
84 const std::vector<uint8_t>& hello_cookie() const { return m_hello_cookie; }
85
86 const std::vector<uint8_t>& hello_cookie_input_bits() const { return m_cookie_input_bits; }
87
88 const Extensions& extensions() const { return m_extensions; }
89
91
92 public:
93 Protocol_Version m_legacy_version; // NOLINT(*-non-private-member-variable*)
94 Session_ID m_session_id; // NOLINT(*-non-private-member-variable*)
95 std::vector<uint8_t> m_random; // NOLINT(*-non-private-member-variable*)
96 std::vector<uint16_t> m_suites; // NOLINT(*-non-private-member-variable*)
97 std::vector<uint8_t> m_comp_methods; // NOLINT(*-non-private-member-variable*)
98 Extensions m_extensions; // NOLINT(*-non-private-member-variable*)
99
100 // These fields are only for DTLS:
101 std::vector<uint8_t> m_hello_cookie; // NOLINT(*-non-private-member-variable*)
102 std::vector<uint8_t> m_cookie_input_bits; // NOLINT(*-non-private-member-variable*)
103};
104
105/**
106* Version-agnostic internal server hello data container that allows
107* parsing Server_Hello messages without prior knowledge of the contained
108* protocol version.
109*/
111 public:
112 /**
113 * Deserialize a Server Hello message
114 */
115 explicit Server_Hello_Internal(const std::vector<uint8_t>& buf);
116
118 Session_ID sid,
119 std::vector<uint8_t> r,
120 const uint16_t cs,
121 const uint8_t cm,
122 bool is_hrr = false) :
123 m_legacy_version(lv),
124 m_session_id(std::move(sid)),
125 m_random(std::move(r)),
126 m_is_hello_retry_request(is_hrr),
127 m_ciphersuite(cs),
128 m_comp_method(cm) {}
129
131
132 Protocol_Version legacy_version() const { return m_legacy_version; }
133
134 const Session_ID& session_id() const { return m_session_id; }
135
136 const std::vector<uint8_t>& random() const { return m_random; }
137
138 uint16_t ciphersuite() const { return m_ciphersuite; }
139
140 uint8_t comp_method() const { return m_comp_method; }
141
142 bool is_hello_retry_request() const { return m_is_hello_retry_request; }
143
144 const Extensions& extensions() const { return m_extensions; }
145
146 Extensions& extensions() { return m_extensions; }
147
148 private:
149 Protocol_Version m_legacy_version;
150 Session_ID m_session_id;
151 std::vector<uint8_t> m_random;
152 bool m_is_hello_retry_request;
153 uint16_t m_ciphersuite;
154 uint8_t m_comp_method;
155
156 Extensions m_extensions;
157};
158
159} // namespace Botan::TLS
160
161#endif
const Session_ID & session_id() const
const Extensions & extensions() const
const std::vector< uint8_t > & comp_methods() const
const std::vector< uint8_t > & hello_cookie() const
const std::vector< uint8_t > & hello_cookie_input_bits() const
const std::vector< uint8_t > & random() const
Protocol_Version legacy_version() const
const std::vector< uint16_t > & ciphersuites() const
Server_Hello_Internal(Protocol_Version lv, Session_ID sid, std::vector< uint8_t > r, const uint16_t cs, const uint8_t cm, bool is_hrr=false)
Server_Hello_Internal(const std::vector< uint8_t > &buf)
const Extensions & extensions() const
const std::vector< uint8_t > & random() const
const Session_ID & session_id() const
std::vector< uint8_t > make_hello_random(RandomNumberGenerator &rng, Callbacks &cb, const Policy &policy)
Strong< std::vector< uint8_t >, struct Session_ID_ > Session_ID
holds a TLS 1.2 session ID for stateful resumption
std::vector< uint8_t > make_server_hello_random(RandomNumberGenerator &rng, Protocol_Version offered_version, Callbacks &cb, const Policy &policy)