Coverage Report

Created: 2021-05-04 09:02

/src/botan/build/include/botan/tls_alert.h
Line
Count
Source (jump to first uncovered line)
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
         CERTIFICATE_REQUIRED            = 116, // RFC 8446
60
61
         NO_APPLICATION_PROTOCOL         = 120, // RFC 7301
62
63
         // pseudo alert values
64
         NULL_ALERT                      = 256
65
      };
66
67
      /**
68
      * @return true iff this alert is non-empty
69
      */
70
7.35k
      bool is_valid() const { return (m_type_code != NULL_ALERT); }
71
72
      /**
73
      * @return if this alert is a fatal one or not
74
      */
75
113k
      bool is_fatal() const { return m_fatal; }
76
77
      /**
78
      * @return type of alert
79
      */
80
168k
      Type type() const { return m_type_code; }
81
82
      /**
83
      * @return type of alert
84
      */
85
      std::string type_string() const;
86
87
      /**
88
      * Serialize an alert
89
      */
90
      std::vector<uint8_t> serialize() const;
91
92
      /**
93
      * Deserialize an Alert message
94
      * @param buf the serialized alert
95
      */
96
      explicit Alert(const secure_vector<uint8_t>& buf);
97
98
      /**
99
      * Create a new Alert
100
      * @param type_code the type of alert
101
      * @param fatal specifies if this is a fatal alert
102
      */
103
      Alert(Type type_code, bool fatal = false) :
104
7.35k
         m_fatal(fatal), m_type_code(type_code) {}
105
106
0
      Alert() : m_fatal(false), m_type_code(NULL_ALERT) {}
107
   private:
108
      bool m_fatal;
109
      Type m_type_code;
110
   };
111
112
}
113
114
}
115
116
#endif