Botan  2.4.0
Crypto and TLS for C++11
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 
14 namespace Botan {
15 
16 namespace TLS {
17 
18 /**
19 * SSL/TLS Alert Message
20 */
21 class BOTAN_PUBLIC_API(2,0) Alert final
22  {
23  public:
24  /**
25  * Type codes for TLS alerts
26  */
27  enum Type {
28  CLOSE_NOTIFY = 0,
29  UNEXPECTED_MESSAGE = 10,
30  BAD_RECORD_MAC = 20,
31  DECRYPTION_FAILED = 21,
32  RECORD_OVERFLOW = 22,
33  DECOMPRESSION_FAILURE = 30,
34  HANDSHAKE_FAILURE = 40,
35  NO_CERTIFICATE = 41, // SSLv3 only
36  BAD_CERTIFICATE = 42,
37  UNSUPPORTED_CERTIFICATE = 43,
38  CERTIFICATE_REVOKED = 44,
39  CERTIFICATE_EXPIRED = 45,
40  CERTIFICATE_UNKNOWN = 46,
41  ILLEGAL_PARAMETER = 47,
42  UNKNOWN_CA = 48,
43  ACCESS_DENIED = 49,
44  DECODE_ERROR = 50,
45  DECRYPT_ERROR = 51,
46  EXPORT_RESTRICTION = 60,
47  PROTOCOL_VERSION = 70,
48  INSUFFICIENT_SECURITY = 71,
49  INTERNAL_ERROR = 80,
50  INAPPROPRIATE_FALLBACK = 86,
51  USER_CANCELED = 90,
52  NO_RENEGOTIATION = 100,
53  UNSUPPORTED_EXTENSION = 110,
54  CERTIFICATE_UNOBTAINABLE = 111,
55  UNRECOGNIZED_NAME = 112,
56  BAD_CERTIFICATE_STATUS_RESPONSE = 113,
57  BAD_CERTIFICATE_HASH_VALUE = 114,
58  UNKNOWN_PSK_IDENTITY = 115,
59 
60  NO_APPLICATION_PROTOCOL = 120, // RFC 7301
61 
62  // pseudo alert values
63  NULL_ALERT = 256
64  };
65 
66  /**
67  * @return true iff this alert is non-empty
68  */
69  bool is_valid() const { return (m_type_code != NULL_ALERT); }
70 
71  /**
72  * @return if this alert is a fatal one or not
73  */
74  bool is_fatal() const { return m_fatal; }
75 
76  /**
77  * @return type of alert
78  */
79  Type type() const { return m_type_code; }
80 
81  /**
82  * @return type of alert
83  */
84  std::string type_string() const;
85 
86  /**
87  * Serialize an alert
88  */
89  std::vector<uint8_t> serialize() const;
90 
91  /**
92  * Deserialize an Alert message
93  * @param buf the serialized alert
94  */
95  explicit Alert(const secure_vector<uint8_t>& buf);
96 
97  /**
98  * Create a new Alert
99  * @param type_code the type of alert
100  * @param fatal specifies if this is a fatal alert
101  */
102  Alert(Type type_code, bool fatal = false) :
103  m_fatal(fatal), m_type_code(type_code) {}
104 
105  Alert() : m_fatal(false), m_type_code(NULL_ALERT) {}
106  private:
107  bool m_fatal;
108  Type m_type_code;
109  };
110 
111 }
112 
113 }
114 
115 #endif
Type type() const
Definition: tls_alert.h:79
bool is_fatal() const
Definition: tls_alert.h:74
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
Definition: alg_id.cpp:13
bool is_valid() const
Definition: tls_alert.h:69
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88
Alert(Type type_code, bool fatal=false)
Definition: tls_alert.h:102