From d6d6750dd81be115c24f38f395c82e3c84d66aaa Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Sun, 7 Feb 2021 07:19:34 +0330 Subject: [PATCH] LibTLS: Move TLS extensions to a separate 'extensions' struct This has no behavioural effect. --- Userland/Libraries/LibTLS/ClientHandshake.cpp | 4 ++-- Userland/Libraries/LibTLS/Handshake.cpp | 6 +++--- Userland/Libraries/LibTLS/TLSv12.cpp | 4 ++-- Userland/Libraries/LibTLS/TLSv12.h | 7 +++++-- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Userland/Libraries/LibTLS/ClientHandshake.cpp b/Userland/Libraries/LibTLS/ClientHandshake.cpp index 5ee2c447f4..60635d56f8 100644 --- a/Userland/Libraries/LibTLS/ClientHandshake.cpp +++ b/Userland/Libraries/LibTLS/ClientHandshake.cpp @@ -163,8 +163,8 @@ ssize_t TLSv12::handle_hello(ReadonlyBytes buffer, WritePacketStage& write_packe } if (sni_host_length) { - m_context.SNI = String { (const char*)buffer.offset_pointer(res + 5), sni_host_length }; - dbgln("server name indicator: {}", m_context.SNI); + m_context.extensions.SNI = String { (const char*)buffer.offset_pointer(res + 5), sni_host_length }; + dbgln("server name indicator: {}", m_context.extensions.SNI); } } else if (extension_type == HandshakeExtension::ApplicationLayerProtocolNegotiation && m_context.alpn.size()) { if (buffer.size() - res > 2) { diff --git a/Userland/Libraries/LibTLS/Handshake.cpp b/Userland/Libraries/LibTLS/Handshake.cpp index f3eccd714e..623c38e963 100644 --- a/Userland/Libraries/LibTLS/Handshake.cpp +++ b/Userland/Libraries/LibTLS/Handshake.cpp @@ -86,8 +86,8 @@ ByteBuffer TLSv12::build_hello() // set SNI if we have one auto sni_length = 0; - if (!m_context.SNI.is_null()) - sni_length = m_context.SNI.length(); + if (!m_context.extensions.SNI.is_null()) + sni_length = m_context.extensions.SNI.length(); if (sni_length) extension_length += sni_length + 9; @@ -105,7 +105,7 @@ ByteBuffer TLSv12::build_hello() builder.append((u8)0); // SNI host length + value builder.append((u16)sni_length); - builder.append((const u8*)m_context.SNI.characters(), sni_length); + builder.append((const u8*)m_context.extensions.SNI.characters(), sni_length); } if (alpn_length) { diff --git a/Userland/Libraries/LibTLS/TLSv12.cpp b/Userland/Libraries/LibTLS/TLSv12.cpp index 6b61234b30..7f0abb2e39 100644 --- a/Userland/Libraries/LibTLS/TLSv12.cpp +++ b/Userland/Libraries/LibTLS/TLSv12.cpp @@ -667,13 +667,13 @@ void TLSv12::try_disambiguate_error() const switch ((AlertDescription)m_context.critical_error) { case AlertDescription::HandshakeFailure: if (!m_context.cipher_spec_set) { - dbgln("- No cipher suite in common with {}", m_context.SNI); + dbgln("- No cipher suite in common with {}", m_context.extensions.SNI); } else { dbgln("- Unknown internal issue"); } break; case AlertDescription::InsufficientSecurity: - dbgln("- No cipher suite in common with {} (the server is oh so secure)", m_context.SNI); + dbgln("- No cipher suite in common with {} (the server is oh so secure)", m_context.extensions.SNI); break; case AlertDescription::ProtocolVersion: dbgln("- The server refused to negotiate with TLS 1.2 :("); diff --git a/Userland/Libraries/LibTLS/TLSv12.h b/Userland/Libraries/LibTLS/TLSv12.h index 52ee2862cd..6633cedf87 100644 --- a/Userland/Libraries/LibTLS/TLSv12.h +++ b/Userland/Libraries/LibTLS/TLSv12.h @@ -242,7 +242,10 @@ struct Context { bool is_child { false }; - String SNI; // I hate your existence + struct { + // Server Name Indicator + String SNI; // I hate your existence + } extensions; u8 request_client_certificate { 0 }; @@ -278,7 +281,7 @@ public: dbgln("invalid state for set_sni"); return; } - m_context.SNI = sni; + m_context.extensions.SNI = sni; } Optional parse_asn1(ReadonlyBytes, bool client_cert = false) const;