Botan 3.13.0
Crypto and TLS for C&
tls_magic.h
Go to the documentation of this file.
1/*
2* SSL/TLS Protocol Constants
3* (C) 2004-2010 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#ifndef BOTAN_TLS_PROTOCOL_MAGIC_H_
9#define BOTAN_TLS_PROTOCOL_MAGIC_H_
10
11#include <botan/strong_type.h>
12#include <botan/types.h>
13#include <array>
14#include <vector>
15
16//BOTAN_FUTURE_INTERNAL_HEADER(tls_magic.h)
17
18#if defined(BOTAN_HAS_TLS_13) && defined(BOTAN_HAS_TLS_12)
19 #define BOTAN_HAS_TLS_DOWNGRADE_SUPPORT
20#endif
21
22namespace Botan::TLS {
23
24/**
25* Protocol Constants for SSL/TLS
26*
27* TODO(Botan4): this should not be an enum at all
28*/
29enum Size_Limits : size_t /* NOLINT(*-enum-size,*-use-enum-class) */ {
32
33 // The "TLSInnerPlaintext" length, i.e. the maximum amount of plaintext
34 // application data that can be transmitted in a single TLS record.
35 MAX_PLAINTEXT_SIZE = 16 * 1024,
36
39
40 // RFC 8446 5.2:
41 // This limit is derived from the maximum TLSInnerPlaintext length of 2^14
42 // octets + 1 octet for ContentType + the maximum AEAD expansion of 255
43 // octets.
46};
47
48enum class Connection_Side : uint8_t {
49 Client = 1,
50 Server = 2,
51
52 CLIENT BOTAN_DEPRECATED("Use Connection_Side::Client") = Client,
53 SERVER BOTAN_DEPRECATED("Use Connection_Side::Server") = Server,
54};
55
56enum class Record_Type : uint8_t {
57 Invalid = 0, // RFC 8446 (TLS 1.3)
58
60 Alert = 21,
63
64 Heartbeat = 24, // RFC 6520 (TLS 1.3)
65};
66
67enum class Handshake_Type : uint8_t {
72 NewSessionTicket = 4, // RFC 5077
73
74 EndOfEarlyData = 5, // RFC 8446 (TLS 1.3)
75 EncryptedExtensions = 8, // RFC 8446 (TLS 1.3)
76
84
87
88 KeyUpdate = 24, // RFC 8446 (TLS 1.3)
89
90 HelloRetryRequest = 253, // Not a wire value (HRR appears as an ordinary Server Hello)
91 HandshakeCCS = 254, // Not a wire value (TLS 1.3 uses this value for 'message_hash' -- RFC 8446 4.4.1)
92 None = 255 // Null value
93};
94
96
97using Transcript_Hash = std::vector<uint8_t>;
98
99/// @brief Used to derive the ticket's PSK from the resumption_master_secret
100using Ticket_Nonce = Strong<std::vector<uint8_t>, struct Ticket_Nonce_>;
101
102/**
103 * Magic values used to signal a downgrade request to TLS 1.1.
104 *
105 * RFC 8446 4.1.3:
106 * TLS 1.3 has a downgrade protection mechanism embedded in the server's
107 * random value. TLS 1.3 servers which negotiate TLS 1.2 or below in
108 * response to a ClientHello MUST set the last 8 bytes of their Random
109 * value specially in their ServerHello.
110 */
111constexpr uint64_t DOWNGRADE_TLS11 = 0x444F574E47524400;
112
113/**
114 * Magic values used to signal a downgrade request to TLS 1.2.
115 *
116 * RFC 8446 4.1.3:
117 * TLS 1.3 has a downgrade protection mechanism embedded in the server's
118 * random value. TLS 1.3 servers which negotiate TLS 1.2 or below in
119 * response to a ClientHello MUST set the last 8 bytes of their Random
120 * value specially in their ServerHello.
121 */
122constexpr uint64_t DOWNGRADE_TLS12 = 0x444F574E47524401;
123
124/**
125 * RFC 8446 4.1.3:
126 * For reasons of backward compatibility with middleboxes, the
127 * HelloRetryRequest message uses the same structure as the ServerHello, but
128 * with Random set to the special value of the SHA-256 of "HelloRetryRequest":
129 */
130constexpr std::array<uint8_t, 32> HELLO_RETRY_REQUEST_MARKER = {
131 0xCF, 0x21, 0xAD, 0x74, 0xE5, 0x9A, 0x61, 0x11, 0xBE, 0x1D, 0x8C, 0x02, 0x1E, 0x65, 0xB8, 0x91,
132 0xC2, 0xA2, 0x11, 0x16, 0x7A, 0xBB, 0x8C, 0x5E, 0x07, 0x9E, 0x09, 0xE2, 0xC8, 0xA8, 0x33, 0x9C};
133
134} // namespace Botan::TLS
135
136#endif
#define BOTAN_DEPRECATED(msg)
Definition api.h:73
#define BOTAN_TEST_API
Definition api.h:41
const char * handshake_type_to_string(Handshake_Type type)
Definition tls_magic.cpp:15
constexpr uint64_t DOWNGRADE_TLS12
Definition tls_magic.h:122
std::vector< uint8_t > Transcript_Hash
Definition tls_magic.h:97
@ MAX_CIPHERTEXT_SIZE
Definition tls_magic.h:38
@ MAX_PLAINTEXT_SIZE
Definition tls_magic.h:35
@ MAX_CIPHERTEXT_SIZE_TLS13
Definition tls_magic.h:45
@ MAX_AEAD_EXPANSION_SIZE_TLS13
Definition tls_magic.h:44
@ TLS_HEADER_SIZE
Definition tls_magic.h:30
@ MAX_COMPRESSED_SIZE
Definition tls_magic.h:37
@ DTLS_HEADER_SIZE
Definition tls_magic.h:31
Strong< std::vector< uint8_t >, struct Ticket_Nonce_ > Ticket_Nonce
Used to derive the ticket's PSK from the resumption_master_secret.
Definition tls_magic.h:100
constexpr uint64_t DOWNGRADE_TLS11
Definition tls_magic.h:111
constexpr std::array< uint8_t, 32 > HELLO_RETRY_REQUEST_MARKER
Definition tls_magic.h:130