Remote protocol now over SSL
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include <boost/asio/placeholders.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
#include "Server.hpp"
|
||||
@@ -13,9 +14,18 @@ Server::Server(boost::asio::io_service& ioService, const endpoint_type& bindEndp
|
||||
_ioService(ioService),
|
||||
_acceptor(_ioService, bindEndpoint, true /*SO_REUSEADDR*/),
|
||||
_connectionManager(),
|
||||
_socket(_ioService),
|
||||
_context(boost::asio::ssl::context::tlsv1_server),
|
||||
_requestHandler(dbPath)
|
||||
{
|
||||
_context.set_options( boost::asio::ssl::context::default_workarounds // TODO check this thing
|
||||
| boost::asio::ssl::context::single_dh_use
|
||||
| boost::asio::ssl::context::no_sslv2
|
||||
| boost::asio::ssl::context::no_sslv3
|
||||
);
|
||||
// context_.set_password_callback(boost::bind(&server::get_password, this));
|
||||
_context.use_certificate_chain_file("cert.pem"); // TODO parametrize
|
||||
_context.use_private_key_file("privkey.pem", boost::asio::ssl::context::pem); // TODO parametrize
|
||||
_context.use_tmp_dh_file("dh2048.pem"); // TODO parametrize
|
||||
}
|
||||
|
||||
void
|
||||
@@ -30,12 +40,16 @@ Server::run()
|
||||
void
|
||||
Server::asyncAccept()
|
||||
{
|
||||
_acceptor.async_accept(_socket, boost::bind(&Server::handleAccept, this, boost::asio::placeholders::error));
|
||||
std::shared_ptr<Connection> newConnection = std::make_shared<Connection>(_ioService, _context, _connectionManager, _requestHandler);
|
||||
|
||||
_acceptor.async_accept(newConnection->getSocket(),
|
||||
boost::bind(&Server::handleAccept, this, newConnection, boost::asio::placeholders::error));
|
||||
}
|
||||
|
||||
void
|
||||
Server::handleAccept(boost::system::error_code ec)
|
||||
Server::handleAccept(std::shared_ptr<Connection> newConnection, boost::system::error_code ec)
|
||||
{
|
||||
std::cout << "Server::handleAccept..." << std::endl;
|
||||
// Check whether the server was stopped before this
|
||||
// completion handler had a chance to run.
|
||||
if (!_acceptor.is_open())
|
||||
@@ -45,8 +59,10 @@ Server::handleAccept(boost::system::error_code ec)
|
||||
|
||||
if (!ec)
|
||||
{
|
||||
_connectionManager.start(std::make_shared<Connection>(std::move(_socket), _connectionManager, _requestHandler));
|
||||
_connectionManager.start(newConnection);
|
||||
|
||||
// Accept another connection
|
||||
// TODO: add some limit?
|
||||
asyncAccept();
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user