59 lines
1.5 KiB
C++
59 lines
1.5 KiB
C++
#ifndef GEMINISERVER_NETWORK_HPP
|
|
#define GEMINISERVER_NETWORK_HPP
|
|
|
|
#include <boost/asio/io_context.hpp>
|
|
#include <boost/asio/ssl.hpp>
|
|
#include <boost/asio/ip/tcp.hpp>
|
|
#include "information.hpp"
|
|
|
|
namespace gemini {
|
|
namespace asio = boost::asio;
|
|
namespace ssl = asio::ssl;
|
|
|
|
using asio::ip::tcp;
|
|
using ssl_socket = ssl::stream<tcp::socket>;
|
|
|
|
/**
|
|
* \brief This class is used for all the network things for the server.
|
|
*/
|
|
class Network {
|
|
private:
|
|
asio::io_context &io_context;
|
|
ssl::context ctx;
|
|
ssl_socket socket;
|
|
tcp::endpoint endpoint;
|
|
tcp::acceptor acceptor;
|
|
|
|
static ssl::context helper_context(const Information &infos) {
|
|
const auto options = ssl::context::no_tlsv1_2 |
|
|
ssl::context::no_tlsv1 |
|
|
ssl::context::no_sslv2 |
|
|
ssl::context::no_sslv3 |
|
|
ssl::context::no_tlsv1_1;
|
|
ssl::context ctx(ssl::context::tlsv13_server);
|
|
ctx.set_options(options);
|
|
ctx.set_default_verify_paths();
|
|
ctx.use_certificate_chain_file(infos.ssl_pem_path);
|
|
ctx.use_private_key_file(infos.ssl_pem_path, ssl::context::pem);
|
|
return ctx;
|
|
}
|
|
|
|
public:
|
|
const Information &information;
|
|
static constexpr std::uint32_t port{ 1965 };
|
|
|
|
Network() = delete;
|
|
|
|
Network(asio::io_context &ioContext, const Information &information) :
|
|
io_context(ioContext),
|
|
ctx(helper_context(information)),
|
|
socket(io_context, ctx),
|
|
endpoint(tcp::v4(), port),
|
|
acceptor(io_context, endpoint),
|
|
information(information) {}
|
|
};
|
|
}
|
|
|
|
|
|
#endif //GEMINISERVER_NETWORK_HPP
|