1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
// --------------------------------------------------------------------------
//
// File
// Name: ServerTLS.h
// Purpose: Implementation of a server using TLS streams
// Created: 2003/08/06
//
// --------------------------------------------------------------------------
#ifndef SERVERTLS__H
#define SERVERTLS__H
#include "BoxPortsAndFiles.h"
#include "ServerStream.h"
#include "SocketStreamTLS.h"
#include "SSLLib.h"
#include "TLSContext.h"
// --------------------------------------------------------------------------
//
// Class
// Name: ServerTLS
// Purpose: Implementation of a server using TLS streams
// Created: 2003/08/06
//
// --------------------------------------------------------------------------
template<int Port, int ListenBacklog = 128, bool ForkToHandleRequests = true>
class ServerTLS : public ServerStream<SocketStreamTLS, Port, ListenBacklog, ForkToHandleRequests>
{
public:
ServerTLS()
{
// Safe to call this here, as the Daemon class makes sure there is only one instance every of a Daemon.
SSLLib::Initialise();
}
~ServerTLS()
{
}
private:
ServerTLS(const ServerTLS &)
{
}
public:
virtual void Run2(bool &rChildExit)
{
// First, set up the SSL context.
// Get parameters from the configuration
// this-> in next line required to build under some gcc versions
const Configuration &conf(this->GetConfiguration());
const Configuration &serverconf(conf.GetSubConfiguration("Server"));
std::string certFile(serverconf.GetKeyValue("CertificateFile"));
std::string keyFile(serverconf.GetKeyValue("PrivateKeyFile"));
std::string caFile(serverconf.GetKeyValue("TrustedCAsFile"));
int ssl_security_level(serverconf.GetKeyValueInt("SSLSecurityLevel",
BOX_DEFAULT_SSL_SECURITY_LEVEL));
mContext.Initialise(true /* as server */, certFile.c_str(),
keyFile.c_str(), caFile.c_str(), ssl_security_level);
// Then do normal stream server stuff
ServerStream<SocketStreamTLS, Port, ListenBacklog,
ForkToHandleRequests>::Run2(rChildExit);
}
virtual void HandleConnection(std::auto_ptr<SocketStreamTLS> apStream)
{
apStream->Handshake(mContext, true /* is server */);
// this-> in next line required to build under some gcc versions
this->Connection(apStream);
}
private:
TLSContext mContext;
};
#define SERVERTLS_VERIFY_SERVER_KEYS(DEFAULT_ADDRESSES) \
ConfigurationVerifyKey("CertificateFile", ConfigTest_Exists), \
ConfigurationVerifyKey("PrivateKeyFile", ConfigTest_Exists), \
ConfigurationVerifyKey("TrustedCAsFile", ConfigTest_Exists), \
ConfigurationVerifyKey("SSLSecurityLevel", ConfigTest_IsInt, \
BOX_DEFAULT_SSL_SECURITY_LEVEL), \
SERVERSTREAM_VERIFY_SERVER_KEYS(DEFAULT_ADDRESSES)
#endif // SERVERTLS__H
|