]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Warning: Loads of craq logging in here atm. /connect with openssl is broken, gnutls...
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Fri, 6 Jul 2007 17:31:44 +0000 (17:31 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Fri, 6 Jul 2007 17:31:44 +0000 (17:31 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@7428 e03df62e-2008-0410-955e-edbf42e46eb7

src/inspsocket.cpp
src/modules/extra/m_ssl_gnutls.cpp
src/modules/extra/m_ssl_openssl.cpp

index f76543562152235cade8d2cce675ca4e2d3e49f6..c2b80a225d7d2d73dd6726bc7e867330417ad573 100644 (file)
@@ -578,8 +578,10 @@ bool InspSocket::Poll()
 #else
                        this->SetState(I_CONNECTED);
 #endif
+                       Instance->Log(DEBUG,"Inspsocket I_CONNECTING state");
                        if (Instance->Config->GetIOHook(this))
                        {
+                               Instance->Log(DEBUG,"Hook for raw connect");
                                try
                                {
                                        Instance->Config->GetIOHook(this)->OnRawSocketConnect(this->fd);
index a6fd64fa76687fe55d4fce9f1ede4d8349958e8e..5b119791588c140170b3c3822a5c63bf00b37f3f 100644 (file)
@@ -506,6 +506,7 @@ class ModuleSSLGnuTLS : public Module
 
                if (!session->sess)
                {
+                       ServerInstance->Log(DEBUG,"No session");
                        CloseSession(session);
                        return 1;
                }
@@ -514,9 +515,10 @@ class ModuleSSLGnuTLS : public Module
                sendbuffer = session->outbuf.c_str();
                count = session->outbuf.size();
 
-               if(session->status == ISSL_HANDSHAKING_WRITE)
+               if (session->status == ISSL_HANDSHAKING_WRITE)
                {
                        // The handshake isn't finished, try to finish it.
+                       ServerInstance->Log(DEBUG,"Finishing handshake");
                        Handshake(session);
                        errno = EAGAIN;
                        return -1;
@@ -524,11 +526,13 @@ class ModuleSSLGnuTLS : public Module
 
                int ret = 0;
 
-               if(session->status == ISSL_HANDSHAKEN)
+               if (session->status == ISSL_HANDSHAKEN)
                {
+                       ServerInstance->Log(DEBUG,"Send record");
                        ret = gnutls_record_send(session->sess, sendbuffer, count);
+                       ServerInstance->Log(DEBUG,"Return: %d", ret);
 
-                       if(ret == 0)
+                       if (ret == 0)
                        {
                                CloseSession(session);
                        }
@@ -536,16 +540,19 @@ class ModuleSSLGnuTLS : public Module
                        {
                                if(ret != GNUTLS_E_AGAIN && ret != GNUTLS_E_INTERRUPTED)
                                {
+                                       ServerInstance->Log(DEBUG,"Not egain or interrupt, close session");
                                        CloseSession(session);
                                }
                                else
                                {
+                                       ServerInstance->Log(DEBUG,"Again please");
                                        errno = EAGAIN;
                                        return -1;
                                }
                        }
                        else
                        {
+                               ServerInstance->Log(DEBUG,"Trim buffer");
                                session->outbuf = session->outbuf.substr(ret);
                        }
                }
index 1d323e3b8be5d2282f6e52f623de8b60aa187e07..3db495c8bd266943a47490339d6c4099ffb0e05b 100644 (file)
@@ -420,6 +420,7 @@ class ModuleSSLOpenSSL : public Module
 
        virtual void OnRawSocketConnect(int fd)
        {
+               ServerInstance->Log(DEBUG,"OnRawSocketConnect connecting");
                issl_session* session = &sessions[fd];
 
                session->fd = fd;
@@ -439,6 +440,7 @@ class ModuleSSLOpenSSL : public Module
                }
 
                Handshake(session);
+               ServerInstance->Log(DEBUG,"Exiting OnRawSocketConnect");
        }
 
        virtual void OnRawSocketClose(int fd)
@@ -460,8 +462,11 @@ class ModuleSSLOpenSSL : public Module
        {
                issl_session* session = &sessions[fd];
 
+               ServerInstance->Log(DEBUG,"OnRawSocketRead");
+
                if (!session->sess)
                {
+                       ServerInstance->Log(DEBUG,"OnRawSocketRead has no session");
                        readresult = 0;
                        CloseSession(session);
                        return 1;
@@ -471,9 +476,11 @@ class ModuleSSLOpenSSL : public Module
                {
                        if (session->rstat == ISSL_READ || session->wstat == ISSL_READ)
                        {
+                               ServerInstance->Log(DEBUG,"Resume handshake in read");
                                // The handshake isn't finished and it wants to read, try to finish it.
                                if (!Handshake(session))
                                {
+                                       ServerInstance->Log(DEBUG,"Cant resume handshake in read");
                                        // Couldn't resume handshake.
                                        return -1;
                                }
@@ -538,6 +545,7 @@ class ModuleSSLOpenSSL : public Module
 
                if (!session->sess)
                {
+                       ServerInstance->Log(DEBUG,"Close session missing sess");
                        CloseSession(session);
                        return -1;
                }
@@ -548,16 +556,25 @@ class ModuleSSLOpenSSL : public Module
                {
                        // The handshake isn't finished, try to finish it.
                        if (session->rstat == ISSL_WRITE || session->wstat == ISSL_WRITE)
+                       {
+                               ServerInstance->Log(DEBUG,"Handshake resume");
                                Handshake(session);
+                       }
                }
 
                if (session->status == ISSL_OPEN)
                {
                        if (session->rstat == ISSL_WRITE)
+                       {
+                               ServerInstance->Log(DEBUG,"DoRead");
                                DoRead(session);
+                       }
 
                        if (session->wstat == ISSL_WRITE)
+                       {
+                               ServerInstance->Log(DEBUG,"DoWrite");
                                return DoWrite(session);
+                       }
                }
 
                return 1;
@@ -572,6 +589,7 @@ class ModuleSSLOpenSSL : public Module
 
                if (ret == 0)
                {
+                       ServerInstance->Log(DEBUG,"Oops, got 0 from SSL_write");
                        CloseSession(session);
                        return 0;
                }
@@ -591,6 +609,7 @@ class ModuleSSLOpenSSL : public Module
                        }
                        else
                        {
+                               ServerInstance->Log(DEBUG,"Close due to returned -1 in SSL_Write");
                                CloseSession(session);
                                return 0;
                        }
@@ -606,12 +625,15 @@ class ModuleSSLOpenSSL : public Module
        {
                // Is this right? Not sure if the unencrypted data is garaunteed to be the same length.
                // Read into the inbuffer, offset from the beginning by the amount of data we have that insp hasn't taken yet.
+               
+               ServerInstance->Log(DEBUG,"DoRead");
 
                int ret = SSL_read(session->sess, session->inbuf + session->inbufoffset, inbufsize - session->inbufoffset);
 
                if (ret == 0)
                {
                        // Client closed connection.
+                       ServerInstance->Log(DEBUG,"Oops, got 0 from SSL_read");
                        CloseSession(session);
                        return 0;
                }
@@ -622,15 +644,18 @@ class ModuleSSLOpenSSL : public Module
                        if (err == SSL_ERROR_WANT_READ)
                        {
                                session->rstat = ISSL_READ;
+                               ServerInstance->Log(DEBUG,"Setting want_read");
                                return -1;
                        }
                        else if (err == SSL_ERROR_WANT_WRITE)
                        {
                                session->rstat = ISSL_WRITE;
+                               ServerInstance->Log(DEBUG,"Setting want_write");
                                return -1;
                        }
                        else
                        {
+                               ServerInstance->Log(DEBUG,"Closed due to returned -1 in SSL_Read");
                                CloseSession(session);
                                return 0;
                        }
@@ -691,10 +716,14 @@ class ModuleSSLOpenSSL : public Module
 
        bool Handshake(issl_session* session)
        {
+               ServerInstance->Log(DEBUG,"Handshake");
                int ret;
 
                if (session->outbound)
+               {
+                       ServerInstance->Log(DEBUG,"SSL_connect");
                        ret = SSL_connect(session->sess);
+               }
                else
                        ret = SSL_accept(session->sess);
 
@@ -704,17 +733,22 @@ class ModuleSSLOpenSSL : public Module
 
                        if (err == SSL_ERROR_WANT_READ)
                        {
+                               ServerInstance->Log(DEBUG,"Want read, handshaking");
                                session->rstat = ISSL_READ;
                                session->status = ISSL_HANDSHAKING;
+                               return true;
                        }
                        else if (err == SSL_ERROR_WANT_WRITE)
                        {
+                               ServerInstance->Log(DEBUG,"Want write, handshaking");
                                session->wstat = ISSL_WRITE;
                                session->status = ISSL_HANDSHAKING;
                                MakePollWrite(session);
+                               return true;
                        }
                        else
                        {
+                               ServerInstance->Log(DEBUG,"Handshake failed");
                                CloseSession(session);
                        }
 
@@ -739,6 +773,9 @@ class ModuleSSLOpenSSL : public Module
                }
                else if (ret == 0)
                {
+                       int ssl_err = SSL_get_error(session->sess, ret);
+                       char buf[1024];
+                       ServerInstance->Log(DEBUG,"Handshake fail 2: %d: %s", ssl_err, ERR_error_string(ssl_err,buf));
                        CloseSession(session);
                        return true;
                }
@@ -771,6 +808,9 @@ class ModuleSSLOpenSSL : public Module
        void MakePollWrite(issl_session* session)
        {
                OnRawSocketWrite(session->fd, NULL, 0);
+               //EventHandler* eh = ServerInstance->FindDescriptor(session->fd);
+               //if (eh)
+               //      ServerInstance->SE->WantWrite(eh);
        }
 
        void CloseSession(issl_session* session)