Botan
3.14.1
Crypto and TLS for C&
src
lib
tls
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
22
namespace
Botan::TLS
{
23
24
/**
25
* Protocol Constants for SSL/TLS
26
*
27
* TODO(Botan4): this should not be an enum at all
28
*/
29
enum
Size_Limits
:
size_t
/* NOLINT(*-enum-size,*-use-enum-class) */
{
30
TLS_HEADER_SIZE
= 5,
31
DTLS_HEADER_SIZE
=
TLS_HEADER_SIZE
+ 8,
32
33
TLS_HANDSHAKE_HEADER_LENGTH
= 4,
34
35
// The "TLSInnerPlaintext" length, i.e. the maximum amount of plaintext
36
// application data that can be transmitted in a single TLS record.
37
MAX_PLAINTEXT_SIZE
= 16 * 1024,
38
39
MAX_COMPRESSED_SIZE
=
MAX_PLAINTEXT_SIZE
+ 1024,
40
MAX_CIPHERTEXT_SIZE
=
MAX_COMPRESSED_SIZE
+ 1024,
41
42
// RFC 8446 5.2:
43
// This limit is derived from the maximum TLSInnerPlaintext length of 2^14
44
// octets + 1 octet for ContentType + the maximum AEAD expansion of 255
45
// octets.
46
MAX_AEAD_EXPANSION_SIZE_TLS13
= 255,
47
MAX_CIPHERTEXT_SIZE_TLS13
=
MAX_PLAINTEXT_SIZE
+
MAX_AEAD_EXPANSION_SIZE_TLS13
+ 1
48
};
49
50
enum class
Connection_Side
: uint8_t {
51
Client
= 1,
52
Server
= 2,
53
54
CLIENT
BOTAN_DEPRECATED
(
"Use Connection_Side::Client"
) =
Client
,
55
SERVER
BOTAN_DEPRECATED
(
"Use Connection_Side::Server"
) =
Server
,
56
};
57
58
enum class
Record_Type
: uint8_t {
59
Invalid
= 0,
// RFC 8446 (TLS 1.3)
60
61
ChangeCipherSpec
= 20,
62
Alert
= 21,
63
Handshake
= 22,
64
ApplicationData
= 23,
65
66
Heartbeat
= 24,
// RFC 6520
67
};
68
69
enum class
TLS_Flavor
:
bool
{
70
TLS
,
71
DTLS
,
72
};
73
74
enum class
Handshake_Type
: uint8_t {
75
HelloRequest
= 0,
76
ClientHello
= 1,
77
ServerHello
= 2,
78
HelloVerifyRequest
= 3,
79
NewSessionTicket
= 4,
// RFC 5077
80
81
EndOfEarlyData
= 5,
// RFC 8446 (TLS 1.3)
82
EncryptedExtensions
= 8,
// RFC 8446 (TLS 1.3)
83
84
Certificate
= 11,
85
ServerKeyExchange
= 12,
86
CertificateRequest
= 13,
87
ServerHelloDone
= 14,
88
CertificateVerify
= 15,
89
ClientKeyExchange
= 16,
90
Finished
= 20,
91
92
CertificateUrl
= 21,
93
CertificateStatus
= 22,
94
95
KeyUpdate
= 24,
// RFC 8446 (TLS 1.3)
96
97
HandshakeCCS
= 252,
// Not a wire value
98
HelloRetryRequest
= 253,
// Not a wire value (HRR appears as an ordinary Server Hello)
99
MessageHash
= 254,
// Not a wire value (RFC 9846 4.1)
100
None
= 255
// Null value
101
};
102
103
BOTAN_TEST_API
const
char
*
handshake_type_to_string
(
Handshake_Type
t);
104
105
using
Transcript_Hash
= std::vector<uint8_t>;
106
107
/// @brief Used to derive the ticket's PSK from the resumption_master_secret
108
using
Ticket_Nonce
=
Strong<std::vector<uint8_t>
,
struct
Ticket_Nonce_>;
109
110
/**
111
* Magic values used to signal a downgrade request to TLS 1.1.
112
*
113
* RFC 8446 4.1.3:
114
* TLS 1.3 has a downgrade protection mechanism embedded in the server's
115
* random value. TLS 1.3 servers which negotiate TLS 1.2 or below in
116
* response to a ClientHello MUST set the last 8 bytes of their Random
117
* value specially in their ServerHello.
118
*/
119
constexpr
uint64_t
DOWNGRADE_TLS11
= 0x444F574E47524400;
120
121
/**
122
* Magic values used to signal a downgrade request to TLS 1.2.
123
*
124
* RFC 8446 4.1.3:
125
* TLS 1.3 has a downgrade protection mechanism embedded in the server's
126
* random value. TLS 1.3 servers which negotiate TLS 1.2 or below in
127
* response to a ClientHello MUST set the last 8 bytes of their Random
128
* value specially in their ServerHello.
129
*/
130
constexpr
uint64_t
DOWNGRADE_TLS12
= 0x444F574E47524401;
131
132
/**
133
* RFC 8446 4.1.3:
134
* For reasons of backward compatibility with middleboxes, the
135
* HelloRetryRequest message uses the same structure as the ServerHello, but
136
* with Random set to the special value of the SHA-256 of "HelloRetryRequest":
137
*/
138
constexpr
std::array<uint8_t, 32>
HELLO_RETRY_REQUEST_MARKER
= {
139
0xCF, 0x21, 0xAD, 0x74, 0xE5, 0x9A, 0x61, 0x11, 0xBE, 0x1D, 0x8C, 0x02, 0x1E, 0x65, 0xB8, 0x91,
140
0xC2, 0xA2, 0x11, 0x16, 0x7A, 0xBB, 0x8C, 0x5E, 0x07, 0x9E, 0x09, 0xE2, 0xC8, 0xA8, 0x33, 0x9C};
141
142
}
// namespace Botan::TLS
143
144
#endif
BOTAN_DEPRECATED
#define BOTAN_DEPRECATED(msg)
Definition
api.h:73
BOTAN_TEST_API
#define BOTAN_TEST_API
Definition
api.h:41
Botan::Strong
Definition
strong_type.h:270
Botan::TLS::Alert
Definition
tls_alert.h:71
Botan::TLS::Client
Definition
tls_client.h:33
Botan::TLS::Finished
Definition
tls_messages.h:270
Botan::TLS::Server
Definition
tls_server.h:30
Botan::TLS
Definition
asio_context.cpp:17
Botan::TLS::handshake_type_to_string
const char * handshake_type_to_string(Handshake_Type type)
Definition
tls_magic.cpp:15
Botan::TLS::DOWNGRADE_TLS12
constexpr uint64_t DOWNGRADE_TLS12
Definition
tls_magic.h:130
Botan::TLS::Transcript_Hash
std::vector< uint8_t > Transcript_Hash
Definition
tls_magic.h:105
Botan::TLS::TLS_Flavor
TLS_Flavor
Definition
tls_magic.h:69
Botan::TLS::TLS_Flavor::DTLS
@ DTLS
Definition
tls_magic.h:71
Botan::TLS::Record_Type
Record_Type
Definition
tls_magic.h:58
Botan::TLS::Record_Type::ApplicationData
@ ApplicationData
Definition
tls_magic.h:64
Botan::TLS::Record_Type::Invalid
@ Invalid
Definition
tls_magic.h:59
Botan::TLS::Record_Type::ChangeCipherSpec
@ ChangeCipherSpec
Definition
tls_magic.h:61
Botan::TLS::Record_Type::Handshake
@ Handshake
Definition
tls_magic.h:63
Botan::TLS::Record_Type::Heartbeat
@ Heartbeat
Definition
tls_magic.h:66
Botan::TLS::Size_Limits
Size_Limits
Definition
tls_magic.h:29
Botan::TLS::MAX_CIPHERTEXT_SIZE
@ MAX_CIPHERTEXT_SIZE
Definition
tls_magic.h:40
Botan::TLS::MAX_PLAINTEXT_SIZE
@ MAX_PLAINTEXT_SIZE
Definition
tls_magic.h:37
Botan::TLS::MAX_CIPHERTEXT_SIZE_TLS13
@ MAX_CIPHERTEXT_SIZE_TLS13
Definition
tls_magic.h:47
Botan::TLS::MAX_AEAD_EXPANSION_SIZE_TLS13
@ MAX_AEAD_EXPANSION_SIZE_TLS13
Definition
tls_magic.h:46
Botan::TLS::TLS_HEADER_SIZE
@ TLS_HEADER_SIZE
Definition
tls_magic.h:30
Botan::TLS::TLS_HANDSHAKE_HEADER_LENGTH
@ TLS_HANDSHAKE_HEADER_LENGTH
Definition
tls_magic.h:33
Botan::TLS::MAX_COMPRESSED_SIZE
@ MAX_COMPRESSED_SIZE
Definition
tls_magic.h:39
Botan::TLS::DTLS_HEADER_SIZE
@ DTLS_HEADER_SIZE
Definition
tls_magic.h:31
Botan::TLS::Ticket_Nonce
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:108
Botan::TLS::AlertType::None
@ None
Definition
tls_alert.h:59
Botan::TLS::Connection_Side
Connection_Side
Definition
tls_magic.h:50
Botan::TLS::Connection_Side::SERVER
@ SERVER
Definition
tls_magic.h:55
Botan::TLS::Connection_Side::CLIENT
@ CLIENT
Definition
tls_magic.h:54
Botan::TLS::Handshake_Type
Handshake_Type
Definition
tls_magic.h:74
Botan::TLS::Handshake_Type::HelloRequest
@ HelloRequest
Definition
tls_magic.h:75
Botan::TLS::Handshake_Type::HelloRetryRequest
@ HelloRetryRequest
Definition
tls_magic.h:98
Botan::TLS::Handshake_Type::CertificateUrl
@ CertificateUrl
Definition
tls_magic.h:92
Botan::TLS::Handshake_Type::ClientHello
@ ClientHello
Definition
tls_magic.h:76
Botan::TLS::Handshake_Type::ServerHelloDone
@ ServerHelloDone
Definition
tls_magic.h:87
Botan::TLS::Handshake_Type::CertificateStatus
@ CertificateStatus
Definition
tls_magic.h:93
Botan::TLS::Handshake_Type::HandshakeCCS
@ HandshakeCCS
Definition
tls_magic.h:97
Botan::TLS::Handshake_Type::MessageHash
@ MessageHash
Definition
tls_magic.h:99
Botan::TLS::Handshake_Type::CertificateVerify
@ CertificateVerify
Definition
tls_magic.h:88
Botan::TLS::Handshake_Type::KeyUpdate
@ KeyUpdate
Definition
tls_magic.h:95
Botan::TLS::Handshake_Type::ClientKeyExchange
@ ClientKeyExchange
Definition
tls_magic.h:89
Botan::TLS::Handshake_Type::EndOfEarlyData
@ EndOfEarlyData
Definition
tls_magic.h:81
Botan::TLS::Handshake_Type::HelloVerifyRequest
@ HelloVerifyRequest
Definition
tls_magic.h:78
Botan::TLS::Handshake_Type::CertificateRequest
@ CertificateRequest
Definition
tls_magic.h:86
Botan::TLS::Handshake_Type::NewSessionTicket
@ NewSessionTicket
Definition
tls_magic.h:79
Botan::TLS::Handshake_Type::ServerHello
@ ServerHello
Definition
tls_magic.h:77
Botan::TLS::Handshake_Type::Certificate
@ Certificate
Definition
tls_magic.h:84
Botan::TLS::Handshake_Type::ServerKeyExchange
@ ServerKeyExchange
Definition
tls_magic.h:85
Botan::TLS::Handshake_Type::EncryptedExtensions
@ EncryptedExtensions
Definition
tls_magic.h:82
Botan::TLS::DOWNGRADE_TLS11
constexpr uint64_t DOWNGRADE_TLS11
Definition
tls_magic.h:119
Botan::TLS::HELLO_RETRY_REQUEST_MARKER
constexpr std::array< uint8_t, 32 > HELLO_RETRY_REQUEST_MARKER
Definition
tls_magic.h:138
Generated by
1.16.1