Botan 3.0.0
Crypto and TLS for C&
tls_alert.cpp
Go to the documentation of this file.
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
11namespace Botan::TLS {
12
14 {
15 if(buf.size() != 2)
16 throw Decoding_Error("Bad size (" + std::to_string(buf.size()) +
17 ") for TLS alert message");
18
19 if(buf[0] == 1) m_fatal = false;
20 else if(buf[0] == 2) m_fatal = true;
21 else
22 throw TLS_Exception(Alert::IllegalParameter, "Bad code for TLS alert level");
23
24 const uint8_t dc = buf[1];
25
26 m_type_code = static_cast<Type>(dc);
27 }
28
29std::vector<uint8_t> Alert::serialize() const
30 {
31 return std::vector<uint8_t>({
32 static_cast<uint8_t>(is_fatal() ? 2 : 1),
33 static_cast<uint8_t>(type())
34 });
35 }
36
37namespace {
38
39const char* alert_type_to_string(AlertType type)
40 {
41 switch(type)
42 {
44 return "close_notify";
46 return "unexpected_message";
48 return "bad_record_mac";
50 return "decryption_failed";
52 return "record_overflow";
54 return "decompression_failure";
56 return "handshake_failure";
58 return "no_certificate";
60 return "bad_certificate";
62 return "unsupported_certificate";
64 return "certificate_revoked";
66 return "certificate_expired";
68 return "certificate_unknown";
70 return "illegal_parameter";
72 return "unknown_ca";
74 return "access_denied";
76 return "decode_error";
78 return "decrypt_error";
80 return "export_restriction";
82 return "protocol_version";
84 return "insufficient_security";
86 return "internal_error";
88 return "inappropriate_fallback";
90 return "user_canceled";
92 return "no_renegotiation";
94 return "missing_extension";
96 return "unsupported_extension";
98 return "certificate_unobtainable";
100 return "unrecognized_name";
102 return "bad_certificate_status_response";
104 return "bad_certificate_hash_value";
106 return "unknown_psk_identity";
108 return "certificate_required";
110 return "no_application_protocol";
111
112 case AlertType::None:
113 return "none";
114 }
115
116 return nullptr;
117 }
118
119}
120
121std::string Alert::type_string() const
122 {
123 if(const char* known_alert = alert_type_to_string(type()))
124 return std::string(known_alert);
125
126 return "unrecognized_alert_" + std::to_string(static_cast<size_t>(type()));
127 }
128
129}
std::vector< uint8_t > serialize() const
Definition: tls_alert.cpp:29
std::string type_string() const
Definition: tls_alert.cpp:121
bool is_fatal() const
Definition: tls_alert.h:91
Type type() const
Definition: tls_alert.h:96
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:64