ssl toggle added
This commit is contained in:
@@ -55,6 +55,8 @@ namespace ssl = boost::asio::ssl;
|
||||
using tcp = boost::asio::ip::tcp;
|
||||
|
||||
|
||||
#define USE_SSL
|
||||
|
||||
void EndProc(DWORD procId)
|
||||
{
|
||||
PROCESSENTRY32 pe;
|
||||
@@ -143,7 +145,12 @@ void LOG(std::stringstream&& s, WORD color)
|
||||
|
||||
}
|
||||
|
||||
#ifdef USE_SSL
|
||||
void do_session(tcp::socket sock, ssl::context& ctx, sessionManager& sessManager, std::string ip, uint64_t& user_n, std::string appPath, std::string appArgs, uint16_t portStream, uint16_t portHttp);
|
||||
#endif
|
||||
#ifndef USE_SSL
|
||||
void do_session(tcp::socket sock, /*ssl::context& ctx,*/ sessionManager& sessManager, std::string ip, uint64_t& user_n, std::string appPath, std::string appArgs, uint16_t portStream, uint16_t portHttp);
|
||||
#endif
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
@@ -230,6 +237,7 @@ int main(int argc, char* argv[])
|
||||
// the io_context is required for all I/O
|
||||
net::io_context ioc{ 1 };
|
||||
|
||||
#ifdef USE_SSL
|
||||
// the SSL context is required, and holds certificates
|
||||
ssl::context ctx{ ssl::context::tlsv12 };
|
||||
|
||||
@@ -237,6 +245,7 @@ int main(int argc, char* argv[])
|
||||
ctx.use_certificate_chain_file(argv[7]);
|
||||
ctx.use_private_key_file(argv[8], boost::asio::ssl::context::file_format::pem);
|
||||
ctx.use_tmp_dh_file(argv[9]);
|
||||
#endif
|
||||
|
||||
// the acceptor receives incoming connections
|
||||
tcp::acceptor acceptor{ ioc, {address, port} };
|
||||
@@ -253,7 +262,9 @@ int main(int argc, char* argv[])
|
||||
{
|
||||
&do_session,
|
||||
std::move(socket),
|
||||
#ifdef USE_SSL
|
||||
std::ref(ctx),
|
||||
#endif
|
||||
std::ref(sessManager),
|
||||
ip,
|
||||
std::ref(user_n),
|
||||
@@ -274,7 +285,12 @@ int main(int argc, char* argv[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef USE_SSL
|
||||
void do_session(tcp::socket sock, ssl::context& ctx, sessionManager& sessManager, std::string ip, uint64_t& user_n, std::string appPath, std::string appArgs, uint16_t portStream, uint16_t portHttp)
|
||||
#endif
|
||||
#ifndef USE_SSL
|
||||
void do_session(tcp::socket sock, /*ssl::context& ctx,*/ sessionManager& sessManager, std::string ip, uint64_t& user_n, std::string appPath, std::string appArgs, uint16_t portStream, uint16_t portHttp)
|
||||
#endif
|
||||
{
|
||||
std::string user_ip = sock.remote_endpoint().address().to_string();
|
||||
uint64_t user_id = std::chrono::system_clock::now().time_since_epoch().count();
|
||||
@@ -282,14 +298,22 @@ void do_session(tcp::socket sock, ssl::context& ctx, sessionManager& sessManager
|
||||
uint64_t thisUserNum = ++user_n;
|
||||
LOG((std::stringstream() << "user(" << thisUserNum << ") connected (ip: " << user_ip << "), (id: " << user_id << ")"), 7);
|
||||
|
||||
#ifdef USE_SSL
|
||||
// Construct the websocket stream around the socket
|
||||
websocket::stream<beast::ssl_stream<tcp::socket&>> ws(sock, ctx);
|
||||
//websocket::stream<tcp::socket> ws{ std::move(sock) };
|
||||
#endif
|
||||
#ifndef USE_SSL
|
||||
websocket::stream<tcp::socket> ws{ std::move(sock) };
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
#ifdef USE_SSL
|
||||
// Perform the SSL handshake
|
||||
ws.next_layer().handshake(ssl::stream_base::server);
|
||||
#endif
|
||||
// Set a decorator to change the Server of the handshake
|
||||
ws.set_option(websocket::stream_base::decorator(
|
||||
[](websocket::response_type& res)
|
||||
|
||||
Reference in New Issue
Block a user