Browse Source

LibTLS: Move TLS extensions to a separate 'extensions' struct

This has no behavioural effect.
AnotherTest 4 năm trước cách đây
mục cha
commit
d6d6750dd8

+ 2 - 2
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) {

+ 3 - 3
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) {

+ 2 - 2
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 :(");

+ 5 - 2
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<Certificate> parse_asn1(ReadonlyBytes, bool client_cert = false) const;