mirror of
https://github.com/badaix/snapcast.git
synced 2025-04-29 18:27:12 +02:00
Setup SSL context
This commit is contained in:
parent
6190041e86
commit
f7bd5e733f
4 changed files with 27 additions and 1 deletions
|
@ -172,6 +172,8 @@ endif()
|
||||||
|
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
|
|
||||||
|
find_package(OpenSSL REQUIRED)
|
||||||
|
|
||||||
include(CMakePushCheckState)
|
include(CMakePushCheckState)
|
||||||
include(CheckIncludeFileCXX)
|
include(CheckIncludeFileCXX)
|
||||||
include_directories(${INCLUDE_DIRS})
|
include_directories(${INCLUDE_DIRS})
|
||||||
|
|
|
@ -116,6 +116,8 @@ else()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# list(APPEND SERVER_LIBRARIES Boost::boost)
|
# list(APPEND SERVER_LIBRARIES Boost::boost)
|
||||||
|
list(APPEND SERVER_LIBRARIES OpenSSL::Crypto OpenSSL::SSL)
|
||||||
|
|
||||||
|
|
||||||
include_directories(${SERVER_INCLUDE})
|
include_directories(${SERVER_INCLUDE})
|
||||||
if(ANDROID)
|
if(ANDROID)
|
||||||
|
|
|
@ -39,8 +39,14 @@ static constexpr auto LOG_TAG = "ControlServer";
|
||||||
|
|
||||||
ControlServer::ControlServer(boost::asio::io_context& io_context, const ServerSettings::Tcp& tcp_settings, const ServerSettings::Http& http_settings,
|
ControlServer::ControlServer(boost::asio::io_context& io_context, const ServerSettings::Tcp& tcp_settings, const ServerSettings::Http& http_settings,
|
||||||
ControlMessageReceiver* controlMessageReceiver)
|
ControlMessageReceiver* controlMessageReceiver)
|
||||||
: io_context_(io_context), tcp_settings_(tcp_settings), http_settings_(http_settings), controlMessageReceiver_(controlMessageReceiver)
|
: io_context_(io_context), ssl_context_(boost::asio::ssl::context::sslv23), tcp_settings_(tcp_settings), http_settings_(http_settings),
|
||||||
|
controlMessageReceiver_(controlMessageReceiver)
|
||||||
{
|
{
|
||||||
|
ssl_context_.set_options(boost::asio::ssl::context::default_workarounds | boost::asio::ssl::context::no_sslv2 | boost::asio::ssl::context::single_dh_use);
|
||||||
|
ssl_context_.set_password_callback(std::bind(&ControlServer::getPassword, this));
|
||||||
|
ssl_context_.use_certificate_chain_file("server.pem");
|
||||||
|
ssl_context_.use_private_key_file("server.pem", boost::asio::ssl::context::pem);
|
||||||
|
ssl_context_.use_tmp_dh_file("dh4096.pem");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,6 +56,12 @@ ControlServer::~ControlServer()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::string ControlServer::getPassword() const
|
||||||
|
{
|
||||||
|
return "test";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ControlServer::cleanup()
|
void ControlServer::cleanup()
|
||||||
{
|
{
|
||||||
auto new_end = std::remove_if(sessions_.begin(), sessions_.end(), [](const std::weak_ptr<ControlSession>& session) { return session.expired(); });
|
auto new_end = std::remove_if(sessions_.begin(), sessions_.end(), [](const std::weak_ptr<ControlSession>& session) { return session.expired(); });
|
||||||
|
@ -114,7 +126,13 @@ void ControlServer::startAccept()
|
||||||
auto accept_handler_http = [this](error_code ec, tcp::socket socket)
|
auto accept_handler_http = [this](error_code ec, tcp::socket socket)
|
||||||
{
|
{
|
||||||
if (!ec)
|
if (!ec)
|
||||||
|
{
|
||||||
handleAccept<ControlSessionHttp>(std::move(socket), http_settings_);
|
handleAccept<ControlSessionHttp>(std::move(socket), http_settings_);
|
||||||
|
// auto session = make_shared<ControlSessionHttp<boost::asio::ssl::stream<tcp::socket>>>(
|
||||||
|
// this, boost::asio::ssl::stream<tcp::socket>(std::move(socket), ssl_context_), http_settings_);
|
||||||
|
// onNewSession(std::move(session));
|
||||||
|
// startAccept();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
LOG(ERROR, LOG_TAG) << "Error while accepting socket connection: " << ec.message() << "\n";
|
LOG(ERROR, LOG_TAG) << "Error while accepting socket connection: " << ec.message() << "\n";
|
||||||
};
|
};
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
// 3rd party headers
|
// 3rd party headers
|
||||||
#include <boost/asio/io_context.hpp>
|
#include <boost/asio/io_context.hpp>
|
||||||
#include <boost/asio/ip/tcp.hpp>
|
#include <boost/asio/ip/tcp.hpp>
|
||||||
|
#include <boost/asio/ssl.hpp>
|
||||||
|
|
||||||
// standard headers
|
// standard headers
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
@ -64,6 +65,8 @@ private:
|
||||||
void onNewSession(std::shared_ptr<ControlSession> session) override;
|
void onNewSession(std::shared_ptr<ControlSession> session) override;
|
||||||
void onNewSession(std::shared_ptr<StreamSession> session) override;
|
void onNewSession(std::shared_ptr<StreamSession> session) override;
|
||||||
|
|
||||||
|
std::string getPassword() const;
|
||||||
|
|
||||||
mutable std::recursive_mutex session_mutex_;
|
mutable std::recursive_mutex session_mutex_;
|
||||||
std::vector<std::weak_ptr<ControlSession>> sessions_;
|
std::vector<std::weak_ptr<ControlSession>> sessions_;
|
||||||
|
|
||||||
|
@ -71,6 +74,7 @@ private:
|
||||||
std::vector<acceptor_ptr> acceptor_http_;
|
std::vector<acceptor_ptr> acceptor_http_;
|
||||||
|
|
||||||
boost::asio::io_context& io_context_;
|
boost::asio::io_context& io_context_;
|
||||||
|
boost::asio::ssl::context ssl_context_;
|
||||||
ServerSettings::Tcp tcp_settings_;
|
ServerSettings::Tcp tcp_settings_;
|
||||||
ServerSettings::Http http_settings_;
|
ServerSettings::Http http_settings_;
|
||||||
ControlMessageReceiver* controlMessageReceiver_;
|
ControlMessageReceiver* controlMessageReceiver_;
|
||||||
|
|
Loading…
Add table
Reference in a new issue