From 611a235a52d065d16540f04ed4b662a6ca649570 Mon Sep 17 00:00:00 2001 From: stelar7 Date: Thu, 13 Apr 2023 23:56:52 +0200 Subject: [PATCH] LibTLS: Rename AlertLevel Critial to FATAL This matches the wording used in the TLS RFC --- Userland/Libraries/LibTLS/Extensions.h | 8 ++++++++ Userland/Libraries/LibTLS/HandshakeClient.cpp | 2 +- Userland/Libraries/LibTLS/Record.cpp | 8 ++++---- Userland/Libraries/LibTLS/Socket.cpp | 4 ++-- Userland/Libraries/LibTLS/TLSv12.h | 5 ----- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Userland/Libraries/LibTLS/Extensions.h b/Userland/Libraries/LibTLS/Extensions.h index 68d1a13990..d73e1e98f6 100644 --- a/Userland/Libraries/LibTLS/Extensions.h +++ b/Userland/Libraries/LibTLS/Extensions.h @@ -54,6 +54,14 @@ enum class ProtocolVersion : u16 { __ENUM_PROTOCOL_VERSIONS }; +#define __ENUM_ALERT_LEVELS \ + _ENUM_KEY_VALUE(WARNING, 1) \ + _ENUM_KEY_VALUE(FATAL, 2) + +enum class AlertLevel : u8 { + __ENUM_ALERT_LEVELS +}; + #undef _ENUM_KEY #undef _ENUM_KEY_VALUE diff --git a/Userland/Libraries/LibTLS/HandshakeClient.cpp b/Userland/Libraries/LibTLS/HandshakeClient.cpp index b0eb1fb1a8..3e60705de3 100644 --- a/Userland/Libraries/LibTLS/HandshakeClient.cpp +++ b/Userland/Libraries/LibTLS/HandshakeClient.cpp @@ -365,7 +365,7 @@ ByteBuffer TLSv12::build_client_key_exchange() bool chain_verified = m_context.verify_chain(m_context.extensions.SNI); if (!chain_verified) { dbgln("certificate verification failed :("); - alert(AlertLevel::Critical, AlertDescription::BadCertificate); + alert(AlertLevel::FATAL, AlertDescription::BadCertificate); return {}; } diff --git a/Userland/Libraries/LibTLS/Record.cpp b/Userland/Libraries/LibTLS/Record.cpp index 21407c8a00..29fb54a8d3 100644 --- a/Userland/Libraries/LibTLS/Record.cpp +++ b/Userland/Libraries/LibTLS/Record.cpp @@ -17,7 +17,7 @@ namespace TLS { ByteBuffer TLSv12::build_alert(bool critical, u8 code) { PacketBuilder builder(ContentType::ALERT, (u16)m_context.options.version); - builder.append((u8)(critical ? AlertLevel::Critical : AlertLevel::Warning)); + builder.append((u8)(critical ? AlertLevel::FATAL : AlertLevel::WARNING)); builder.append(code); if (critical) @@ -31,7 +31,7 @@ ByteBuffer TLSv12::build_alert(bool critical, u8 code) void TLSv12::alert(AlertLevel level, AlertDescription code) { - auto the_alert = build_alert(level == AlertLevel::Critical, (u8)code); + auto the_alert = build_alert(level == AlertLevel::FATAL, (u8)code); write_packet(the_alert); MUST(flush()); } @@ -531,7 +531,7 @@ ssize_t TLSv12::handle_message(ReadonlyBytes buffer) auto code = plain[1]; dbgln_if(TLS_DEBUG, "Alert received with level {}, code {}", level, code); - if (level == (u8)AlertLevel::Critical) { + if (level == (u8)AlertLevel::FATAL) { dbgln("We were alerted of a critical error: {} ({})", code, alert_name((AlertDescription)code)); m_context.critical_error = code; try_disambiguate_error(); @@ -540,7 +540,7 @@ ssize_t TLSv12::handle_message(ReadonlyBytes buffer) if (code == (u8)AlertDescription::CloseNotify) { res += 2; - alert(AlertLevel::Critical, AlertDescription::CloseNotify); + alert(AlertLevel::FATAL, AlertDescription::CloseNotify); if (!m_context.cipher_spec_set) { // AWS CloudFront hits this. dbgln("Server sent a close notify and we haven't agreed on a cipher suite. Treating it as a handshake failure."); diff --git a/Userland/Libraries/LibTLS/Socket.cpp b/Userland/Libraries/LibTLS/Socket.cpp index 06caaf52b9..43f231efd0 100644 --- a/Userland/Libraries/LibTLS/Socket.cpp +++ b/Userland/Libraries/LibTLS/Socket.cpp @@ -135,7 +135,7 @@ void TLSv12::setup_connection() if (timeout_diff < m_max_wait_time_for_handshake_in_seconds + 1) { // The server did not respond fast enough, // time the connection out. - alert(AlertLevel::Critical, AlertDescription::UserCanceled); + alert(AlertLevel::FATAL, AlertDescription::UserCanceled); m_context.tls_buffer.clear(); m_context.error_code = Error::TimedOut; m_context.critical_error = (u8)Error::TimedOut; @@ -317,7 +317,7 @@ ErrorOr TLSv12::flush() void TLSv12::close() { - alert(AlertLevel::Critical, AlertDescription::CloseNotify); + alert(AlertLevel::FATAL, AlertDescription::CloseNotify); // bye bye. m_context.connection_status = ConnectionStatus::Disconnected; } diff --git a/Userland/Libraries/LibTLS/TLSv12.h b/Userland/Libraries/LibTLS/TLSv12.h index 3effa892ab..afb214e6f0 100644 --- a/Userland/Libraries/LibTLS/TLSv12.h +++ b/Userland/Libraries/LibTLS/TLSv12.h @@ -113,11 +113,6 @@ enum class Error : i8 { OutOfMemory = -23, }; -enum class AlertLevel : u8 { - Warning = 0x01, - Critical = 0x02 -}; - enum HandshakeType { HelloRequest = 0x00, ClientHello = 0x01,