diff --git a/lib/HttpServer/SslGeneralServer.h b/lib/GeneralServer/GeneralSslServer.h similarity index 94% rename from lib/HttpServer/SslGeneralServer.h rename to lib/GeneralServer/GeneralSslServer.h index 48cd80bfaf..ba28ad94a2 100644 --- a/lib/HttpServer/SslGeneralServer.h +++ b/lib/GeneralServer/GeneralSslServer.h @@ -1,5 +1,5 @@ //////////////////////////////////////////////////////////////////////////////// -/// @brief ssl general server +/// @brief general ssl server /// /// @file /// @@ -25,8 +25,8 @@ /// @author Copyright 2010-2012, triAGENS GmbH, Cologne, Germany //////////////////////////////////////////////////////////////////////////////// -#ifndef TRIAGENS_HTTP_SERVER_SSL_GENERAL_SERVER_H -#define TRIAGENS_HTTP_SERVER_SSL_GENERAL_SERVER_H 1 +#ifndef TRIAGENS_GENERAL_SERVER_GENERAL_SSL_SERVER_H +#define TRIAGENS_GENERAL_SERVER_GENERAL_SSL_SERVER_H 1 #include "GeneralServer/GeneralServer.h" @@ -34,14 +34,15 @@ #include "Basics/ssl-helper.h" #include "Logger/Logger.h" +#include "HttpServer/SslAsyncCommTask.h" #include "Scheduler/Scheduler.h" // ----------------------------------------------------------------------------- -// --SECTION-- class SslGeneralServer +// --SECTION-- class GeneralSslServer // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// -/// @addtogroup HttpServer +/// @addtogroup GeneralServer /// @{ //////////////////////////////////////////////////////////////////////////////// @@ -49,11 +50,11 @@ namespace triagens { namespace rest { //////////////////////////////////////////////////////////////////////////////// -/// @brief http server +/// @brief ssl general server //////////////////////////////////////////////////////////////////////////////// template - class SslGeneralServer : virtual public GeneralServer { + class GeneralSslServer : virtual public GeneralServer { //////////////////////////////////////////////////////////////////////////////// /// @} @@ -64,7 +65,7 @@ namespace triagens { // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// -/// @addtogroup HttpServer +/// @addtogroup GeneralServer /// @{ //////////////////////////////////////////////////////////////////////////////// @@ -93,7 +94,7 @@ namespace triagens { // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// -/// @addtogroup HttpServer +/// @addtogroup GeneralServer /// @{ //////////////////////////////////////////////////////////////////////////////// @@ -186,19 +187,19 @@ namespace triagens { // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// -/// @addtogroup HttpServer +/// @addtogroup GeneralServer /// @{ //////////////////////////////////////////////////////////////////////////////// public: //////////////////////////////////////////////////////////////////////////////// -/// @brief constructs a new http server +/// @brief constructs a new general ssl server //////////////////////////////////////////////////////////////////////////////// - SslGeneralServer (Scheduler* scheduler, + GeneralSslServer (Scheduler* scheduler, Dispatcher* dispatcher, - HttpHandlerFactory* handlerFactory, + HF* handlerFactory, SSL_CTX* ctx) : GeneralServer(scheduler), ctx(ctx), @@ -210,7 +211,7 @@ namespace triagens { /// @brief destructor //////////////////////////////////////////////////////////////////////////////// - virtual ~SslGeneralServer () { + virtual ~GeneralSslServer () { SSL_CTX_free(ctx); } @@ -223,7 +224,7 @@ namespace triagens { // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// -/// @addtogroup HttpServer +/// @addtogroup GeneralServer /// @{ //////////////////////////////////////////////////////////////////////////////// @@ -262,7 +263,7 @@ namespace triagens { // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// -/// @addtogroup HttpServer +/// @addtogroup GeneralServer /// @{ //////////////////////////////////////////////////////////////////////////////// @@ -302,7 +303,7 @@ namespace triagens { // with the above bio SSL_set_bio(ssl, sbio, sbio); - // create a https task + // create an ssl task SocketTask* task = new SslAsyncCommTask(dynamic_cast(this), socket, info, sbio); // add the task, otherwise it will not be shut down properly @@ -323,7 +324,7 @@ namespace triagens { // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// -/// @addtogroup HttpServer +/// @addtogroup GeneralServer /// @{ //////////////////////////////////////////////////////////////////////////////// diff --git a/lib/HttpServer/HttpsServer.h b/lib/HttpServer/HttpsServer.h index 922af8a897..067c96f99b 100644 --- a/lib/HttpServer/HttpsServer.h +++ b/lib/HttpServer/HttpsServer.h @@ -28,6 +28,7 @@ #ifndef TRIAGENS_HTTP_SERVER_HTTPS_SERVER_H #define TRIAGENS_HTTP_SERVER_HTTPS_SERVER_H 1 +#include "GeneralServer/GeneralSslServer.h" #include "HttpServer/GeneralHttpServer.h" #include @@ -38,7 +39,6 @@ #include "HttpServer/HttpCommTask.h" #include "HttpServer/HttpHandler.h" #include "HttpServer/SslAsyncCommTask.h" -#include "HttpServer/SslGeneralServer.h" #include "Scheduler/Scheduler.h" // ----------------------------------------------------------------------------- @@ -57,7 +57,7 @@ namespace triagens { /// @brief http server //////////////////////////////////////////////////////////////////////////////// - class HttpsServer : public SslGeneralServer >, + class HttpsServer : public GeneralSslServer >, public GeneralHttpServer > { //////////////////////////////////////////////////////////////////////////////// @@ -206,12 +206,8 @@ namespace triagens { HttpHandlerFactory* handlerFactory, SSL_CTX* ctx) : GeneralServer >(scheduler), - SslGeneralServer >(scheduler, dispatcher, handlerFactory, ctx), + GeneralSslServer >(scheduler, dispatcher, handlerFactory, ctx), GeneralHttpServer >(scheduler, dispatcher, handlerFactory) { -// : GeneralHttpServer >(scheduler, dispatcher, handlerFactory), -// ctx(ctx), -// verificationMode(SSL_VERIFY_NONE), -// verificationCallback(0) { } //////////////////////////////////////////////////////////////////////////////// @@ -219,7 +215,6 @@ namespace triagens { //////////////////////////////////////////////////////////////////////////////// ~HttpsServer () { -// SSL_CTX_free(ctx); } //////////////////////////////////////////////////////////////////////////////// @@ -230,49 +225,6 @@ namespace triagens { // --SECTION-- public methods // ----------------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup HttpServer -/// @{ -//////////////////////////////////////////////////////////////////////////////// - - public: - - void handleConnected (socket_t socket, ConnectionInfo& info) { - SslGeneralServer::handleConnected(socket, info); - } -/* -//////////////////////////////////////////////////////////////////////////////// -/// @brief return encryption to be used -//////////////////////////////////////////////////////////////////////////////// - - virtual Endpoint::Encryption getEncryption () const { - return Endpoint::ENCRYPTION_SSL; - } - -//////////////////////////////////////////////////////////////////////////////// -/// @brief sets the verification mode -//////////////////////////////////////////////////////////////////////////////// - - void setVerificationMode (int mode) { - verificationMode = mode; - } - -//////////////////////////////////////////////////////////////////////////////// -/// @brief sets the verification callback -//////////////////////////////////////////////////////////////////////////////// - - void setVerificationCallback (int (*func)(int, X509_STORE_CTX *)) { - verificationCallback = func; - } - -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - -// ----------------------------------------------------------------------------- -// --SECTION-- GeneralServer methods -// ----------------------------------------------------------------------------- - //////////////////////////////////////////////////////////////////////////////// /// @addtogroup HttpServer /// @{ @@ -283,82 +235,15 @@ namespace triagens { //////////////////////////////////////////////////////////////////////////////// /// {@inheritDoc} //////////////////////////////////////////////////////////////////////////////// - + void handleConnected (socket_t socket, ConnectionInfo& info) { - LOGGER_DEBUG << "trying to establish secure connection"; - - // convert in a SSL BIO structure - BIO * sbio = BIO_new_socket((int) socket, BIO_NOCLOSE); - - if (sbio == 0) { - LOGGER_WARNING << "cannot build new SSL BIO: " << triagens::basics::lastSSLError(); - ::close(socket); - return; - } - - // build a new connection - SSL * ssl = SSL_new(ctx); - - info.sslContext = ssl; - - if (ssl == 0) { - BIO_free_all(sbio); - LOGGER_WARNING << "cannot build new SSL connection: " << triagens::basics::lastSSLError(); - ::close(socket); - return; - } - - // enforce verification - SSL_set_verify(ssl, verificationMode, verificationCallback); - - // with the above bio - SSL_set_bio(ssl, sbio, sbio); - - // create a https task - SocketTask* task = new SslAsyncCommTask >(this, socket, info, sbio); - - // add the task, otherwise it will not be shut down properly - GENERAL_SERVER_LOCK(&this->_commTasksLock); - this->_commTasks.insert(dynamic_cast*>(task)); - GENERAL_SERVER_UNLOCK(&this->_commTasksLock); - - // and register it - _scheduler->registerTask(task); + GeneralSslServer::handleConnected(socket, info); } //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// -// ----------------------------------------------------------------------------- -// --SECTION-- private variables -// ----------------------------------------------------------------------------- - -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup HttpServer -/// @{ -//////////////////////////////////////////////////////////////////////////////// - - private: - -//////////////////////////////////////////////////////////////////////////////// -/// @brief ssl context -//////////////////////////////////////////////////////////////////////////////// - - SSL_CTX* ctx; - -//////////////////////////////////////////////////////////////////////////////// -/// @brief verification mode -//////////////////////////////////////////////////////////////////////////////// - - int verificationMode; - -//////////////////////////////////////////////////////////////////////////////// -/// @brief verification callback -//////////////////////////////////////////////////////////////////////////////// - - int (*verificationCallback)(int, X509_STORE_CTX *); - */ }; } }