Botan 3.6.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 {
22 CloseNotify = 0,
24 BadRecordMac = 20,
26 RecordOverflow = 22,
29 NoCertificate = 41, // SSLv3 only
30 BadCertificate = 42,
36 UnknownCA = 48,
37 AccessDenied = 49,
38 DecodeError = 50,
39 DecryptError = 51,
41 ProtocolVersion = 70,
43 InternalError = 80,
45 UserCanceled = 90,
46 NoRenegotiation = 100,
47 MissingExtension = 109, // RFC 8446
50 UnrecognizedName = 112,
54 CertificateRequired = 116, // RFC 8446
55 NoApplicationProtocol = 120, // RFC 7301
56
57 // pseudo alert values
58 None = 256,
59
60 // Compat enum variants, will be removed in a future major release
61 CLOSE_NOTIFY BOTAN_DEPRECATED("Use CloseNotify") = CloseNotify,
63 PROTOCOL_VERSION BOTAN_DEPRECATED("Use ProtocolVersion") = ProtocolVersion,
64};
65
66/**
67* SSL/TLS Alert Message
68*/
70 public:
71 typedef AlertType Type;
72 using enum AlertType;
73
74 /**
75 * @return true iff this alert is non-empty
76 */
77 bool is_valid() const { return (m_type_code != AlertType::None); }
78
79 /**
80 * Return true if this alert is fatal. A fatal alert causes the connection
81 * to be immediately disconnected. Otherwise, the alert is a warning and
82 * the connection remains valid.
83 *
84 * Note:
85 * RFC 8446 6.
86 * In TLS 1.3, the severity is implicit in the type of alert being sent,
87 * and the "level" field can safely be ignored.
88 * Everything is considered fatal except for UserCanceled and CloseNotify (RFC 8446 6.1)
89 *
90 * @return if this alert is fatal or not
91 */
92 bool is_fatal() const { return m_fatal; }
93
94 /**
95 * Returns the type of the alert as an enum
96 *
97 * @return type of alert
98 */
99 Type type() const { return m_type_code; }
100
101 /**
102 * Returns the type of the alert as a string
103 *
104 * @return type of alert
105 */
106 std::string type_string() const;
107
108 /**
109 * Serialize an alert
110 */
111 std::vector<uint8_t> serialize() const;
112
113 /**
114 * Deserialize an Alert message
115 * @param buf the serialized alert
116 */
117 explicit Alert(const secure_vector<uint8_t>& buf);
118
119 /**
120 * Create a new Alert
121 * @param type_code the type of alert
122 * @param fatal specifies if this is a fatal alert
123 */
124 Alert(Type type_code, bool fatal = false) : m_fatal(fatal), m_type_code(type_code) {}
125
126 Alert() : m_fatal(false), m_type_code(AlertType::None) {}
127
128 private:
129 bool m_fatal;
130 Type m_type_code;
131};
132
133} // namespace Botan::TLS
134
135#endif
bool is_valid() const
Definition tls_alert.h:77
Alert(Type type_code, bool fatal=false)
Definition tls_alert.h:124
AlertType Type
Definition tls_alert.h:71
bool is_fatal() const
Definition tls_alert.h:92
Type type() const
Definition tls_alert.h:99
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)
Definition compiler.h:31
#define BOTAN_DEPRECATED(msg)
Definition compiler.h:125
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61