Botan
3.6.1
Crypto and TLS for C&
src
lib
tls
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
10
#include <botan/tls_exceptn.h>
11
12
namespace
Botan::TLS
{
13
14
Alert::Alert
(
const
secure_vector<uint8_t>
& buf) {
15
if
(buf.size() != 2) {
16
throw
Decoding_Error
(
"Bad size ("
+ std::to_string(buf.size()) +
") for TLS alert message"
);
17
}
18
19
if
(buf[0] == 1) {
20
m_fatal =
false
;
21
}
else
if
(buf[0] == 2) {
22
m_fatal =
true
;
23
}
else
{
24
throw
TLS_Exception
(Alert::IllegalParameter,
"Bad code for TLS alert level"
);
25
}
26
27
const
uint8_t dc = buf[1];
28
29
m_type_code =
static_cast<
Type
>
(dc);
30
}
31
32
std::vector<uint8_t>
Alert::serialize
()
const
{
33
return
std::vector<uint8_t>({
static_cast<
uint8_t
>
(
is_fatal
() ? 2 : 1),
static_cast<
uint8_t
>
(
type
())});
34
}
35
36
namespace
{
37
38
const
char
* alert_type_to_string(
AlertType
type) {
39
switch
(type) {
40
case
AlertType::CloseNotify
:
41
return
"close_notify"
;
42
case
AlertType::UnexpectedMessage
:
43
return
"unexpected_message"
;
44
case
AlertType::BadRecordMac
:
45
return
"bad_record_mac"
;
46
case
AlertType::DecryptionFailed
:
47
return
"decryption_failed"
;
48
case
AlertType::RecordOverflow
:
49
return
"record_overflow"
;
50
case
AlertType::DecompressionFailure
:
51
return
"decompression_failure"
;
52
case
AlertType::HandshakeFailure
:
53
return
"handshake_failure"
;
54
case
AlertType::NoCertificate
:
55
return
"no_certificate"
;
56
case
AlertType::BadCertificate
:
57
return
"bad_certificate"
;
58
case
AlertType::UnsupportedCertificate
:
59
return
"unsupported_certificate"
;
60
case
AlertType::CertificateRevoked
:
61
return
"certificate_revoked"
;
62
case
AlertType::CertificateExpired
:
63
return
"certificate_expired"
;
64
case
AlertType::CertificateUnknown
:
65
return
"certificate_unknown"
;
66
case
AlertType::IllegalParameter
:
67
return
"illegal_parameter"
;
68
case
AlertType::UnknownCA
:
69
return
"unknown_ca"
;
70
case
AlertType::AccessDenied
:
71
return
"access_denied"
;
72
case
AlertType::DecodeError
:
73
return
"decode_error"
;
74
case
AlertType::DecryptError
:
75
return
"decrypt_error"
;
76
case
AlertType::ExportRestriction
:
77
return
"export_restriction"
;
78
case
AlertType::ProtocolVersion
:
79
return
"protocol_version"
;
80
case
AlertType::InsufficientSecurity
:
81
return
"insufficient_security"
;
82
case
AlertType::InternalError
:
83
return
"internal_error"
;
84
case
AlertType::InappropriateFallback
:
85
return
"inappropriate_fallback"
;
86
case
AlertType::UserCanceled
:
87
return
"user_canceled"
;
88
case
AlertType::NoRenegotiation
:
89
return
"no_renegotiation"
;
90
case
AlertType::MissingExtension
:
91
return
"missing_extension"
;
92
case
AlertType::UnsupportedExtension
:
93
return
"unsupported_extension"
;
94
case
AlertType::CertificateUnobtainable
:
95
return
"certificate_unobtainable"
;
96
case
AlertType::UnrecognizedName
:
97
return
"unrecognized_name"
;
98
case
AlertType::BadCertificateStatusResponse
:
99
return
"bad_certificate_status_response"
;
100
case
AlertType::BadCertificateHashValue
:
101
return
"bad_certificate_hash_value"
;
102
case
AlertType::UnknownPSKIdentity
:
103
return
"unknown_psk_identity"
;
104
case
AlertType::CertificateRequired
:
105
return
"certificate_required"
;
106
case
AlertType::NoApplicationProtocol
:
107
return
"no_application_protocol"
;
108
109
case
AlertType::None
:
110
return
"none"
;
111
}
112
113
return
nullptr
;
114
}
115
116
}
// namespace
117
118
std::string
Alert::type_string
()
const
{
119
if
(
const
char
* known_alert = alert_type_to_string(
type
())) {
120
return
std::string(known_alert);
121
}
122
123
return
"unrecognized_alert_"
+ std::to_string(
static_cast<
size_t
>
(
type
()));
124
}
125
126
}
// namespace Botan::TLS
Botan::Decoding_Error
Definition
exceptn.h:191
Botan::TLS::Alert::Alert
Alert()
Definition
tls_alert.h:126
Botan::TLS::Alert::serialize
std::vector< uint8_t > serialize() const
Definition
tls_alert.cpp:32
Botan::TLS::Alert::type_string
std::string type_string() const
Definition
tls_alert.cpp:118
Botan::TLS::Alert::is_fatal
bool is_fatal() const
Definition
tls_alert.h:92
Botan::TLS::Alert::type
Type type() const
Definition
tls_alert.h:99
Botan::TLS::TLS_Exception
Definition
tls_exceptn.h:19
Botan::TLS
Definition
asio_context.cpp:17
Botan::TLS::AlertType
AlertType
Definition
tls_alert.h:21
Botan::TLS::AlertType::UnrecognizedName
@ UnrecognizedName
Botan::TLS::AlertType::InappropriateFallback
@ InappropriateFallback
Botan::TLS::AlertType::BadCertificateHashValue
@ BadCertificateHashValue
Botan::TLS::AlertType::BadRecordMac
@ BadRecordMac
Botan::TLS::AlertType::UnknownCA
@ UnknownCA
Botan::TLS::AlertType::DecompressionFailure
@ DecompressionFailure
Botan::TLS::AlertType::DecodeError
@ DecodeError
Botan::TLS::AlertType::CertificateExpired
@ CertificateExpired
Botan::TLS::AlertType::NoCertificate
@ NoCertificate
Botan::TLS::AlertType::NoRenegotiation
@ NoRenegotiation
Botan::TLS::AlertType::None
@ None
Botan::TLS::AlertType::UnsupportedExtension
@ UnsupportedExtension
Botan::TLS::AlertType::CertificateRevoked
@ CertificateRevoked
Botan::TLS::AlertType::InternalError
@ InternalError
Botan::TLS::AlertType::CertificateUnknown
@ CertificateUnknown
Botan::TLS::AlertType::NoApplicationProtocol
@ NoApplicationProtocol
Botan::TLS::AlertType::ExportRestriction
@ ExportRestriction
Botan::TLS::AlertType::UnsupportedCertificate
@ UnsupportedCertificate
Botan::TLS::AlertType::BadCertificateStatusResponse
@ BadCertificateStatusResponse
Botan::TLS::AlertType::ProtocolVersion
@ ProtocolVersion
Botan::TLS::AlertType::IllegalParameter
@ IllegalParameter
Botan::TLS::AlertType::UnexpectedMessage
@ UnexpectedMessage
Botan::TLS::AlertType::CloseNotify
@ CloseNotify
Botan::TLS::AlertType::DecryptError
@ DecryptError
Botan::TLS::AlertType::AccessDenied
@ AccessDenied
Botan::TLS::AlertType::RecordOverflow
@ RecordOverflow
Botan::TLS::AlertType::DecryptionFailed
@ DecryptionFailed
Botan::TLS::AlertType::UserCanceled
@ UserCanceled
Botan::TLS::AlertType::CertificateRequired
@ CertificateRequired
Botan::TLS::AlertType::HandshakeFailure
@ HandshakeFailure
Botan::TLS::AlertType::UnknownPSKIdentity
@ UnknownPSKIdentity
Botan::TLS::AlertType::InsufficientSecurity
@ InsufficientSecurity
Botan::TLS::AlertType::BadCertificate
@ BadCertificate
Botan::TLS::AlertType::MissingExtension
@ MissingExtension
Botan::TLS::AlertType::CertificateUnobtainable
@ CertificateUnobtainable
Botan::secure_vector
std::vector< T, secure_allocator< T > > secure_vector
Definition
secmem.h:61
Generated by
1.12.0