Botan 3.14.1
Crypto and TLS for C&
tls_alert.h
Go to the documentation of this file.
1/*
2* Alert Message
3* (C) 2004-2006,2011,2012 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#ifndef BOTAN_TLS_ALERT_H_
9#define BOTAN_TLS_ALERT_H_
10
11#include <botan/secmem.h>
12#include <string>
13
14namespace Botan::TLS {
15
16/**
17* Type codes for TLS alerts
18*
19* The enumeration value matches the wire encoding
20*/
21enum class AlertType : uint16_t {
25 DecryptionFailed = 21, // Not specified in TLS 1.3 (RFC 9846)
27 DecompressionFailure = 30, // Not specified in TLS 1.3 (RFC 9846)
29 NoCertificate = 41, // SSLv3 only
40 ExportRestriction = 60, // Not specified in TLS 1.3 (RFC 9846)
46 NoRenegotiation = 100, // Not specified in TLS 1.3 (RFC 9846)
49 CertificateUnobtainable = 111, // Not specified in TLS 1.3 (RFC 9846)
52 BadCertificateHashValue = 114, // Not specified in TLS 1.3 (RFC 9846)
57
58 // pseudo alert values
59 None = 256,
60
61 // Compat enum variants, will be removed in a future major release
62 // TODO(Botan4): remove these
66};
67
68/**
69* SSL/TLS Alert Message
70*/
71class BOTAN_PUBLIC_API(2, 0) Alert final {
72 public:
73 typedef AlertType Type;
74 using enum AlertType;
75
76 /**
77 * @return true iff this alert is non-empty and has a type that can be encoded
78 */
79 bool is_valid() const {
80 // Values greater than 255 are used for pseudo alert types that
81 // cannot actually be sent on the wire
82 return static_cast<uint16_t>(m_type_code) <= 255;
83 }
84
85 /**
86 * Return true if this alert is fatal. A fatal alert causes the connection
87 * to be immediately disconnected. Otherwise, the alert is a warning and
88 * the connection remains valid.
89 *
90 * Note:
91 * RFC 8446 6.
92 * In TLS 1.3, the severity is implicit in the type of alert being sent,
93 * and the "level" field can safely be ignored.
94 * Everything is considered fatal except for UserCanceled and CloseNotify (RFC 8446 6.1)
95 *
96 * @return if this alert is fatal or not
97 */
98 bool is_fatal() const { return m_fatal; }
99
100 /**
101 * Returns the type of the alert as an enum
102 *
103 * @return type of alert
104 */
105 Type type() const { return m_type_code; }
106
107 /**
108 * Returns the type of the alert as a string
109 *
110 * @return type of alert
111 */
112 std::string type_string() const;
113
114 /**
115 * Serialize an alert
116 */
117 std::vector<uint8_t> serialize() const;
118
119 /**
120 * Deserialize an Alert message
121 * @param buf the serialized alert
122 */
123 explicit Alert(const secure_vector<uint8_t>& buf);
124
125 /**
126 * Create a new Alert
127 * @param type_code the type of alert
128 * @param fatal specifies if this is a fatal alert
129 */
130 Alert(Type type_code, bool fatal = false) : // NOLINT(*-explicit-conversions,*-explicit-constructor)
131 m_fatal(fatal), m_type_code(type_code) {}
132
133 Alert() : m_fatal(false), m_type_code(AlertType::None) {}
134
135 private:
136 bool m_fatal;
137 Type m_type_code;
138};
139
140} // namespace Botan::TLS
141
142#endif
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:21
#define BOTAN_DEPRECATED(msg)
Definition api.h:73
bool is_valid() const
Definition tls_alert.h:79
AlertType Type
Definition tls_alert.h:73
Alert(Type type_code, bool fatal=false)
Definition tls_alert.h:130
Alert(const secure_vector< uint8_t > &buf)
Definition tls_alert.cpp:14
bool is_fatal() const
Definition tls_alert.h:98
Type type() const
Definition tls_alert.h:105
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:128