Botan 3.3.0
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 if this alert is fatal or not
81 *
82 * Note:
83 * RFC 8446 6.
84 * In TLS 1.3, the severity is implicit in the type of alert being sent,
85 * and the "level" field can safely be ignored.
86 * Everything is considered fatal except for UserCanceled and CloseNotify (RFC 8446 6.1)
87 */
88 bool is_fatal() const { return m_fatal; }
89
90 /**
91 * @return type of alert
92 */
93 Type type() const { return m_type_code; }
94
95 /**
96 * @return type of alert
97 */
98 std::string type_string() const;
99
100 /**
101 * Serialize an alert
102 */
103 std::vector<uint8_t> serialize() const;
104
105 /**
106 * Deserialize an Alert message
107 * @param buf the serialized alert
108 */
109 explicit Alert(const secure_vector<uint8_t>& buf);
110
111 /**
112 * Create a new Alert
113 * @param type_code the type of alert
114 * @param fatal specifies if this is a fatal alert
115 */
116 Alert(Type type_code, bool fatal = false) : m_fatal(fatal), m_type_code(type_code) {}
117
118 Alert() : m_fatal(false), m_type_code(AlertType::None) {}
119
120 private:
121 bool m_fatal;
122 Type m_type_code;
123};
124
125} // namespace Botan::TLS
126
127#endif
bool is_valid() const
Definition tls_alert.h:77
AlertType Type
Definition tls_alert.h:71
Alert(Type type_code, bool fatal=false)
Definition tls_alert.h:116
bool is_fatal() const
Definition tls_alert.h:88
Type type() const
Definition tls_alert.h:93
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