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