mirror of https://gitee.com/bigwinds/arangodb
refactoring
This commit is contained in:
parent
886739a679
commit
603747b024
|
@ -1,5 +1,5 @@
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief ssl general server
|
/// @brief general ssl server
|
||||||
///
|
///
|
||||||
/// @file
|
/// @file
|
||||||
///
|
///
|
||||||
|
@ -25,8 +25,8 @@
|
||||||
/// @author Copyright 2010-2012, triAGENS GmbH, Cologne, Germany
|
/// @author Copyright 2010-2012, triAGENS GmbH, Cologne, Germany
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef TRIAGENS_HTTP_SERVER_SSL_GENERAL_SERVER_H
|
#ifndef TRIAGENS_GENERAL_SERVER_GENERAL_SSL_SERVER_H
|
||||||
#define TRIAGENS_HTTP_SERVER_SSL_GENERAL_SERVER_H 1
|
#define TRIAGENS_GENERAL_SERVER_GENERAL_SSL_SERVER_H 1
|
||||||
|
|
||||||
#include "GeneralServer/GeneralServer.h"
|
#include "GeneralServer/GeneralServer.h"
|
||||||
|
|
||||||
|
@ -34,14 +34,15 @@
|
||||||
|
|
||||||
#include "Basics/ssl-helper.h"
|
#include "Basics/ssl-helper.h"
|
||||||
#include "Logger/Logger.h"
|
#include "Logger/Logger.h"
|
||||||
|
#include "HttpServer/SslAsyncCommTask.h"
|
||||||
#include "Scheduler/Scheduler.h"
|
#include "Scheduler/Scheduler.h"
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// --SECTION-- class SslGeneralServer
|
// --SECTION-- class GeneralSslServer
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @addtogroup HttpServer
|
/// @addtogroup GeneralServer
|
||||||
/// @{
|
/// @{
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@ -49,11 +50,11 @@ namespace triagens {
|
||||||
namespace rest {
|
namespace rest {
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief http server
|
/// @brief ssl general server
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
template<typename S, typename HF, typename CT>
|
template<typename S, typename HF, typename CT>
|
||||||
class SslGeneralServer : virtual public GeneralServer<S, HF, CT> {
|
class GeneralSslServer : virtual public GeneralServer<S, HF, CT> {
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @}
|
/// @}
|
||||||
|
@ -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:
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief constructs a new http server
|
/// @brief constructs a new general ssl server
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
SslGeneralServer (Scheduler* scheduler,
|
GeneralSslServer (Scheduler* scheduler,
|
||||||
Dispatcher* dispatcher,
|
Dispatcher* dispatcher,
|
||||||
HttpHandlerFactory* handlerFactory,
|
HF* handlerFactory,
|
||||||
SSL_CTX* ctx)
|
SSL_CTX* ctx)
|
||||||
: GeneralServer<S, HF, CT>(scheduler),
|
: GeneralServer<S, HF, CT>(scheduler),
|
||||||
ctx(ctx),
|
ctx(ctx),
|
||||||
|
@ -210,7 +211,7 @@ namespace triagens {
|
||||||
/// @brief destructor
|
/// @brief destructor
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
virtual ~SslGeneralServer () {
|
virtual ~GeneralSslServer () {
|
||||||
SSL_CTX_free(ctx);
|
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
|
// with the above bio
|
||||||
SSL_set_bio(ssl, sbio, sbio);
|
SSL_set_bio(ssl, sbio, sbio);
|
||||||
|
|
||||||
// create a https task
|
// create an ssl task
|
||||||
SocketTask* task = new SslAsyncCommTask<S, CT>(dynamic_cast<S*>(this), socket, info, sbio);
|
SocketTask* task = new SslAsyncCommTask<S, CT>(dynamic_cast<S*>(this), socket, info, sbio);
|
||||||
|
|
||||||
// add the task, otherwise it will not be shut down properly
|
// add the task, otherwise it will not be shut down properly
|
||||||
|
@ -323,7 +324,7 @@ namespace triagens {
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @addtogroup HttpServer
|
/// @addtogroup GeneralServer
|
||||||
/// @{
|
/// @{
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#ifndef TRIAGENS_HTTP_SERVER_HTTPS_SERVER_H
|
#ifndef TRIAGENS_HTTP_SERVER_HTTPS_SERVER_H
|
||||||
#define TRIAGENS_HTTP_SERVER_HTTPS_SERVER_H 1
|
#define TRIAGENS_HTTP_SERVER_HTTPS_SERVER_H 1
|
||||||
|
|
||||||
|
#include "GeneralServer/GeneralSslServer.h"
|
||||||
#include "HttpServer/GeneralHttpServer.h"
|
#include "HttpServer/GeneralHttpServer.h"
|
||||||
|
|
||||||
#include <openssl/ssl.h>
|
#include <openssl/ssl.h>
|
||||||
|
@ -38,7 +39,6 @@
|
||||||
#include "HttpServer/HttpCommTask.h"
|
#include "HttpServer/HttpCommTask.h"
|
||||||
#include "HttpServer/HttpHandler.h"
|
#include "HttpServer/HttpHandler.h"
|
||||||
#include "HttpServer/SslAsyncCommTask.h"
|
#include "HttpServer/SslAsyncCommTask.h"
|
||||||
#include "HttpServer/SslGeneralServer.h"
|
|
||||||
#include "Scheduler/Scheduler.h"
|
#include "Scheduler/Scheduler.h"
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
@ -57,7 +57,7 @@ namespace triagens {
|
||||||
/// @brief http server
|
/// @brief http server
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
class HttpsServer : public SslGeneralServer<HttpsServer, HttpHandlerFactory, HttpCommTask<HttpsServer> >,
|
class HttpsServer : public GeneralSslServer<HttpsServer, HttpHandlerFactory, HttpCommTask<HttpsServer> >,
|
||||||
public GeneralHttpServer<HttpsServer, HttpCommTask<HttpsServer> > {
|
public GeneralHttpServer<HttpsServer, HttpCommTask<HttpsServer> > {
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -206,12 +206,8 @@ namespace triagens {
|
||||||
HttpHandlerFactory* handlerFactory,
|
HttpHandlerFactory* handlerFactory,
|
||||||
SSL_CTX* ctx)
|
SSL_CTX* ctx)
|
||||||
: GeneralServer<HttpsServer, HttpHandlerFactory, HttpCommTask<HttpsServer> >(scheduler),
|
: GeneralServer<HttpsServer, HttpHandlerFactory, HttpCommTask<HttpsServer> >(scheduler),
|
||||||
SslGeneralServer<HttpsServer, HttpHandlerFactory, HttpCommTask<HttpsServer> >(scheduler, dispatcher, handlerFactory, ctx),
|
GeneralSslServer<HttpsServer, HttpHandlerFactory, HttpCommTask<HttpsServer> >(scheduler, dispatcher, handlerFactory, ctx),
|
||||||
GeneralHttpServer<HttpsServer, HttpCommTask< HttpsServer> >(scheduler, dispatcher, handlerFactory) {
|
GeneralHttpServer<HttpsServer, HttpCommTask< HttpsServer> >(scheduler, dispatcher, handlerFactory) {
|
||||||
// : GeneralHttpServer<HttpsServer, HttpCommTask< HttpsServer> >(scheduler, dispatcher, handlerFactory),
|
|
||||||
// ctx(ctx),
|
|
||||||
// verificationMode(SSL_VERIFY_NONE),
|
|
||||||
// verificationCallback(0) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -219,7 +215,6 @@ namespace triagens {
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
~HttpsServer () {
|
~HttpsServer () {
|
||||||
// SSL_CTX_free(ctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -230,49 +225,6 @@ namespace triagens {
|
||||||
// --SECTION-- public methods
|
// --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
|
/// @addtogroup HttpServer
|
||||||
/// @{
|
/// @{
|
||||||
|
@ -283,82 +235,15 @@ namespace triagens {
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// {@inheritDoc}
|
/// {@inheritDoc}
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void handleConnected (socket_t socket, ConnectionInfo& info) {
|
void handleConnected (socket_t socket, ConnectionInfo& info) {
|
||||||
LOGGER_DEBUG << "trying to establish secure connection";
|
GeneralSslServer::handleConnected(socket, info);
|
||||||
|
|
||||||
// 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<HttpsServer, HttpCommTask<HttpsServer> >(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<GeneralCommTask<HttpsServer, HttpHandlerFactory>*>(task));
|
|
||||||
GENERAL_SERVER_UNLOCK(&this->_commTasksLock);
|
|
||||||
|
|
||||||
// and register it
|
|
||||||
_scheduler->registerTask(task);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @}
|
/// @}
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
// --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 *);
|
|
||||||
*/
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue