Coverage Report

Created: 2022-05-14 06:06

/src/botan/src/lib/tls/tls_alert.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
* Alert Message
3
* (C) 2004-2006,2011 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7
8
#include <botan/tls_alert.h>
9
#include <botan/tls_exceptn.h>
10
11
namespace Botan::TLS {
12
13
Alert::Alert(const secure_vector<uint8_t>& buf)
14
22.6k
   {
15
22.6k
   if(buf.size() != 2)
16
62
      throw Decoding_Error("Bad size (" + std::to_string(buf.size()) +
17
62
                           ") for TLS alert message");
18
19
22.6k
   if(buf[0] == 1)      m_fatal = false;
20
1.55k
   else if(buf[0] == 2) m_fatal = true;
21
30
   else
22
30
      throw TLS_Exception(Alert::ILLEGAL_PARAMETER, "Bad code for TLS alert level");
23
24
22.5k
   const uint8_t dc = buf[1];
25
26
22.5k
   m_type_code = static_cast<Type>(dc);
27
22.5k
   }
28
29
std::vector<uint8_t> Alert::serialize() const
30
3.87k
   {
31
3.87k
   return std::vector<uint8_t>({
32
3.87k
      static_cast<uint8_t>(is_fatal() ? 2 : 1),
33
3.87k
      static_cast<uint8_t>(type())
34
3.87k
      });
35
3.87k
   }
36
37
std::string Alert::type_string() const
38
0
   {
39
0
   switch(type())
40
0
      {
41
0
      case CLOSE_NOTIFY:
42
0
         return "close_notify";
43
0
      case UNEXPECTED_MESSAGE:
44
0
         return "unexpected_message";
45
0
      case BAD_RECORD_MAC:
46
0
         return "bad_record_mac";
47
0
      case DECRYPTION_FAILED:
48
0
         return "decryption_failed";
49
0
      case RECORD_OVERFLOW:
50
0
         return "record_overflow";
51
0
      case DECOMPRESSION_FAILURE:
52
0
         return "decompression_failure";
53
0
      case HANDSHAKE_FAILURE:
54
0
         return "handshake_failure";
55
0
      case NO_CERTIFICATE:
56
0
         return "no_certificate";
57
0
      case BAD_CERTIFICATE:
58
0
         return "bad_certificate";
59
0
      case UNSUPPORTED_CERTIFICATE:
60
0
         return "unsupported_certificate";
61
0
      case CERTIFICATE_REVOKED:
62
0
         return "certificate_revoked";
63
0
      case CERTIFICATE_EXPIRED:
64
0
         return "certificate_expired";
65
0
      case CERTIFICATE_UNKNOWN:
66
0
         return "certificate_unknown";
67
0
      case ILLEGAL_PARAMETER:
68
0
         return "illegal_parameter";
69
0
      case UNKNOWN_CA:
70
0
         return "unknown_ca";
71
0
      case ACCESS_DENIED:
72
0
         return "access_denied";
73
0
      case DECODE_ERROR:
74
0
         return "decode_error";
75
0
      case DECRYPT_ERROR:
76
0
         return "decrypt_error";
77
0
      case EXPORT_RESTRICTION:
78
0
         return "export_restriction";
79
0
      case PROTOCOL_VERSION:
80
0
         return "protocol_version";
81
0
      case INSUFFICIENT_SECURITY:
82
0
         return "insufficient_security";
83
0
      case INTERNAL_ERROR:
84
0
         return "internal_error";
85
0
      case INAPPROPRIATE_FALLBACK:
86
0
         return "inappropriate_fallback";
87
0
      case USER_CANCELED:
88
0
         return "user_canceled";
89
0
      case NO_RENEGOTIATION:
90
0
         return "no_renegotiation";
91
0
      case MISSING_EXTENSION:
92
0
         return "missing_extension";
93
0
      case UNSUPPORTED_EXTENSION:
94
0
         return "unsupported_extension";
95
0
      case CERTIFICATE_UNOBTAINABLE:
96
0
         return "certificate_unobtainable";
97
0
      case UNRECOGNIZED_NAME:
98
0
         return "unrecognized_name";
99
0
      case BAD_CERTIFICATE_STATUS_RESPONSE:
100
0
         return "bad_certificate_status_response";
101
0
      case BAD_CERTIFICATE_HASH_VALUE:
102
0
         return "bad_certificate_hash_value";
103
0
      case UNKNOWN_PSK_IDENTITY:
104
0
         return "unknown_psk_identity";
105
0
      case CERTIFICATE_REQUIRED:
106
0
         return "certificate_required";
107
0
      case NO_APPLICATION_PROTOCOL:
108
0
         return "no_application_protocol";
109
110
0
      case NULL_ALERT:
111
0
         return "none";
112
0
      }
113
114
   /*
115
   * This is effectively the default case for the switch above, but we
116
   * leave it out so that when an alert type is added to the enum the
117
   * compiler can warn us that it is not included in the switch
118
   * statement.
119
   */
120
0
   return "unrecognized_alert_" + std::to_string(type());
121
0
   }
122
123
}