From a53da00bce41c9fb50ed4c9d33507f27803c1eb7 Mon Sep 17 00:00:00 2001 From: brain Date: Fri, 6 Jul 2007 17:31:44 +0000 Subject: Warning: Loads of craq logging in here atm. /connect with openssl is broken, gnutls seems fine git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@7428 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/inspsocket.cpp | 2 ++ src/modules/extra/m_ssl_gnutls.cpp | 13 +++++++++--- src/modules/extra/m_ssl_openssl.cpp | 40 +++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/inspsocket.cpp b/src/inspsocket.cpp index f76543562..c2b80a225 100644 --- a/src/inspsocket.cpp +++ b/src/inspsocket.cpp @@ -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); diff --git a/src/modules/extra/m_ssl_gnutls.cpp b/src/modules/extra/m_ssl_gnutls.cpp index a6fd64fa7..5b1197915 100644 --- a/src/modules/extra/m_ssl_gnutls.cpp +++ b/src/modules/extra/m_ssl_gnutls.cpp @@ -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); } } diff --git a/src/modules/extra/m_ssl_openssl.cpp b/src/modules/extra/m_ssl_openssl.cpp index 1d323e3b8..3db495c8b 100644 --- a/src/modules/extra/m_ssl_openssl.cpp +++ b/src/modules/extra/m_ssl_openssl.cpp @@ -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) -- cgit v1.2.3