WebFramework v3.0.12
Web framework for C++.
Loading...
Searching...
No Matches
BaseWebServer.cpp
1#include "BaseWebServer.h"
2
3#include "Utility/Singletons/HTTPSSingleton.h"
4#include "Exceptions/SSLException.h"
5
6using namespace std;
7
8namespace framework
9{
10 BaseWebServer::BaseWebServer() :
11 context(nullptr)
12 {
13 utility::HTTPSSingleton& httpsSettings = utility::HTTPSSingleton::get();
14
15 if (useHTTPS = httpsSettings.getUseHTTPS(); useHTTPS)
16 {
17 context = SSL_CTX_new(TLS_server_method());
18
19 if (!context)
20 {
21 throw web::exceptions::SSLException(__LINE__, __FILE__);
22 }
23
24 if (int errorCode = SSL_CTX_use_certificate_file(context, httpsSettings.getPathToCertificate().string().data(), SSL_FILETYPE_PEM); errorCode != 1)
25 {
26 throw web::exceptions::SSLException(__LINE__, __FILE__, errorCode);
27 }
28
29 if (int errorCode = SSL_CTX_use_PrivateKey_file(context, httpsSettings.getPathToKey().string().data(), SSL_FILETYPE_PEM); errorCode != 1)
30 {
31 throw web::exceptions::SSLException(__LINE__, __FILE__, errorCode);
32 }
33 }
34 }
35
36 BaseWebServer::~BaseWebServer()
37 {
38 if (useHTTPS)
39 {
40 SSL_CTX_free(context);
41 }
42 }
43}