]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Add support to IOHook for retrieving the hostname sent via SNI.
authorPeter Powell <petpow@saberuk.com>
Sun, 29 Oct 2017 11:15:47 +0000 (11:15 +0000)
committerPeter Powell <petpow@saberuk.com>
Sun, 29 Oct 2017 11:15:47 +0000 (11:15 +0000)
include/modules/ssl.h
src/modules/extra/m_ssl_gnutls.cpp
src/modules/extra/m_ssl_openssl.cpp
src/modules/m_sslinfo.cpp

index 9cc504128daae20a0daee6b4ea0c2880d8ccaa67..d3372c5094f79b2b2563dd9fe0654c0d909bc1d9 100644 (file)
@@ -204,6 +204,13 @@ class SSLIOHook : public IOHook
         * @param out String where the ciphersuite string will be appended to
         */
        virtual void GetCiphersuite(std::string& out) const = 0;
+
+
+       /** Retrieves the name of the SSL connection which is sent via SNI.
+        * @param out String that the server name will be appended to.
+        * returns True if the server name was retrieved; otherwise, false.
+        */
+       virtual bool GetServerName(std::string& out) const = 0;
 };
 
 /** Helper functions for obtaining SSL client certificates and key fingerprints
index 08b4be08f375cfcb15fbbb720de071045f539eb3..50c847ee4f7e87c4df3208d0b20379c56a5649f4 100644 (file)
@@ -1182,6 +1182,25 @@ info_done_dealloc:
                out.append(UnknownIfNULL(gnutls_mac_get_name(gnutls_mac_get(sess))));
        }
 
+       bool GetServerName(std::string& out) const CXX11_OVERRIDE
+       {
+               std::vector<char> nameBuffer;
+               size_t nameLength = 0;
+               unsigned int nameType = GNUTLS_NAME_DNS;
+
+               // First, determine the size of the hostname.
+               if (gnutls_server_name_get(sess, &nameBuffer[0], &nameLength, &nameType, 0) != GNUTLS_E_SHORT_MEMORY_BUFFER)
+                       return false;
+
+               // Then retrieve the hostname.
+               nameBuffer.resize(nameLength);
+               if (gnutls_server_name_get(sess, &nameBuffer[0], &nameLength, &nameType, 0) != GNUTLS_E_SUCCESS)
+                       return false;
+
+               out.append(&nameBuffer[0]);
+               return true;
+       }
+
        GnuTLS::Profile* GetProfile() { return profile; }
        bool IsHandshakeDone() const { return (status == ISSL_HANDSHAKEN); }
 };
index 4c246d6f5a2d6569ce8d38a8e3e74b7dbdb56e7f..45a728106c0a08dad30d6a2ab5d0f15d05b8d913 100644 (file)
@@ -779,6 +779,16 @@ class OpenSSLIOHook : public SSLIOHook
                out.append(SSL_get_cipher(sess));
        }
 
+       bool GetServerName(std::string& out) const CXX11_OVERRIDE
+       {
+               const char* name = SSL_get_servername(sess, TLSEXT_NAMETYPE_host_name);
+               if (!name)
+                       return false;
+
+               out.append(name);
+               return true;
+       }
+
        bool IsHandshakeDone() const { return (status == ISSL_OPEN); }
 };
 
index 9682e92cfce2c43ccd5f26d904baf85b3016cb08..5a5b40319b192ee3301cce9e9e89543d7a8c9346 100644 (file)
@@ -220,7 +220,10 @@ class ModuleSSLInfo : public Module, public Whois::EventListener
                ssl_cert* const cert = ssliohook->GetCertificate();
 
                {
-                       std::string text = "*** You are connected using SSL cipher '";
+                       std::string text = "*** You are connected to ";
+                       if (!ssliohook->GetServerName(text))
+                               text.append(ServerInstance->Config->ServerName);
+                       text.append(" using SSL cipher '");
                        ssliohook->GetCiphersuite(text);
                        text.push_back('\'');
                        if ((cert) && (!cert->GetFingerprint().empty()))