]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Deduplicate code for on connect SSL ciphersuite NOTICE by moving it into m_sslinfo
authorAttila Molnar <attilamolnar@hush.com>
Thu, 28 Apr 2016 15:10:10 +0000 (17:10 +0200)
committerAttila Molnar <attilamolnar@hush.com>
Thu, 28 Apr 2016 15:10:10 +0000 (17:10 +0200)
src/modules/extra/m_ssl_gnutls.cpp
src/modules/extra/m_ssl_openssl.cpp
src/modules/m_sslinfo.cpp

index 69aedf03d5704e58bf1afdcfb2d1fa6307f68a13..a1c989163ff0fea98012ac1913e3a89ce0964695 100644 (file)
@@ -1150,20 +1150,6 @@ info_done_dealloc:
                return 1;
        }
 
-       void TellCiphersAndFingerprint(LocalUser* user)
-       {
-               if (sess)
-               {
-                       std::string text = "*** You are connected using SSL cipher '";
-                       GetCiphersuite(text);
-                       text += '\'';
-                       if (!certificate->fingerprint.empty())
-                               text += " and your SSL certificate fingerprint is " + certificate->fingerprint;
-
-                       user->WriteNotice(text);
-               }
-       }
-
        void GetCiphersuite(std::string& out) const CXX11_OVERRIDE
        {
                if (!IsHandshakeDone())
@@ -1346,13 +1332,6 @@ class ModuleSSLGnuTLS : public Module
                return Version("Provides SSL support for clients", VF_VENDOR);
        }
 
-       void OnUserConnect(LocalUser* user) CXX11_OVERRIDE
-       {
-               IOHook* hook = user->eh.GetIOHook();
-               if (hook && hook->prov->creator == this)
-                       static_cast<GnuTLSIOHook*>(hook)->TellCiphersAndFingerprint(user);
-       }
-
        ModResult OnCheckReady(LocalUser* user) CXX11_OVERRIDE
        {
                if ((user->eh.GetIOHook()) && (user->eh.GetIOHook()->prov->creator == this))
index ed66291f4c4679861f85b244222faf98bdf7b8a4..80c9d93959116a6b21e8476aff48ac3f6c4fb632 100644 (file)
@@ -720,21 +720,6 @@ class OpenSSLIOHook : public SSLIOHook
                return 1;
        }
 
-       void TellCiphersAndFingerprint(LocalUser* user)
-       {
-               if (sess)
-               {
-                       std::string text = "*** You are connected using SSL cipher '";
-                       GetCiphersuite(text);
-                       text += '\'';
-                       const std::string& fingerprint = certificate->fingerprint;
-                       if (!fingerprint.empty())
-                               text += " and your SSL certificate fingerprint is " + fingerprint;
-
-                       user->WriteNotice(text);
-               }
-       }
-
        void GetCiphersuite(std::string& out) const CXX11_OVERRIDE
        {
                if (!IsHandshakeDone())
@@ -919,13 +904,6 @@ class ModuleSSLOpenSSL : public Module
                }
        }
 
-       void OnUserConnect(LocalUser* user) CXX11_OVERRIDE
-       {
-               IOHook* hook = user->eh.GetIOHook();
-               if (hook && hook->prov->creator == this)
-                       static_cast<OpenSSLIOHook*>(hook)->TellCiphersAndFingerprint(user);
-       }
-
        void OnCleanup(int target_type, void* item) CXX11_OVERRIDE
        {
                if (target_type == TYPE_USER)
index 6a29d3bde913a731f97ee7c348a43b28d2924cd3..9682e92cfce2c43ccd5f26d904baf85b3016cb08 100644 (file)
@@ -209,8 +209,26 @@ class ModuleSSLInfo : public Module, public Whois::EventListener
 
        void OnPostConnect(User* user) CXX11_OVERRIDE
        {
-               ssl_cert *cert = cmd.CertExt.get(user);
-               if (!cert || cert->fingerprint.empty())
+               LocalUser* const localuser = IS_LOCAL(user);
+               if (!localuser)
+                       return;
+
+               const SSLIOHook* const ssliohook = SSLIOHook::IsSSL(&localuser->eh);
+               if (!ssliohook)
+                       return;
+
+               ssl_cert* const cert = ssliohook->GetCertificate();
+
+               {
+                       std::string text = "*** You are connected using SSL cipher '";
+                       ssliohook->GetCiphersuite(text);
+                       text.push_back('\'');
+                       if ((cert) && (!cert->GetFingerprint().empty()))
+                               text.append(" and your SSL certificate fingerprint is ").append(cert->GetFingerprint());
+                       user->WriteNotice(text);
+               }
+
+               if (!cert)
                        return;
                // find an auto-oper block for this user
                for (ServerConfig::OperIndex::const_iterator i = ServerInstance->Config->oper_blocks.begin(); i != ServerInstance->Config->oper_blocks.end(); ++i)