mirror of
https://github.com/XRPLF/clio.git
synced 2025-12-01 17:15:52 +00:00
rebases Listener
This commit is contained in:
@@ -2,11 +2,13 @@
|
||||
#include <ripple/protocol/STLedgerEntry.h>
|
||||
#include <boost/asio/strand.hpp>
|
||||
#include <boost/beast/http.hpp>
|
||||
#include <boost/beast/ssl.hpp>
|
||||
#include <boost/json.hpp>
|
||||
#include <boost/json/src.hpp>
|
||||
#include <boost/log/trivial.hpp>
|
||||
#include <etl/ETLSource.h>
|
||||
#include <etl/ReportingETL.h>
|
||||
#include <server/Ssl.h>
|
||||
|
||||
// Create ETL source without grpc endpoint
|
||||
// Fetch ledger and load initial ledger will fail for this source
|
||||
@@ -19,9 +21,6 @@ ETLSource::ETLSource(
|
||||
std::shared_ptr<NetworkValidatedLedgers> networkValidatedLedgers,
|
||||
ETLLoadBalancer& balancer)
|
||||
: ioc_(ioContext)
|
||||
, ws_(std::make_unique<
|
||||
boost::beast::websocket::stream<boost::beast::tcp_stream>>(
|
||||
boost::asio::make_strand(ioc_)))
|
||||
, resolver_(boost::asio::make_strand(ioc_))
|
||||
, timer_(ioc_)
|
||||
, networkValidatedLedgers_(networkValidatedLedgers)
|
||||
@@ -29,6 +28,28 @@ ETLSource::ETLSource(
|
||||
, subscriptions_(subscriptions)
|
||||
, balancer_(balancer)
|
||||
{
|
||||
std::optional<boost::asio::ssl::context> sslCtx;
|
||||
if (config.contains("ssl_cert_file") &&
|
||||
config.contains("ssl_key_file"))
|
||||
{
|
||||
sslCtx = parse_certs(
|
||||
config.at("ssl_cert_file").as_string().c_str(),
|
||||
config.at("ssl_key_file").as_string().c_str());
|
||||
}
|
||||
|
||||
if (sslCtx)
|
||||
{
|
||||
ws_ = nullptr;
|
||||
// std::make_unique<boost::beast::websocket::stream<
|
||||
// boost::beast::ssl_stream<boost::beast::tcp_stream>>>(
|
||||
// boost::asio::make_strand(ioc_), *sslCtx);
|
||||
}
|
||||
else
|
||||
{
|
||||
ws_ = std::make_unique<boost::beast::websocket::stream<
|
||||
boost::beast::tcp_stream>>(boost::asio::make_strand(ioc_));
|
||||
}
|
||||
|
||||
if (config.contains("ip"))
|
||||
{
|
||||
auto ipJs = config.at("ip").as_string();
|
||||
|
||||
@@ -4,11 +4,12 @@
|
||||
#include <boost/asio/dispatch.hpp>
|
||||
#include <boost/beast/core.hpp>
|
||||
#include <boost/beast/websocket.hpp>
|
||||
#include <webserver/HttpSession.h>
|
||||
#include <webserver/PlainWsSession.h>
|
||||
#include <webserver/SslHttpSession.h>
|
||||
#include <webserver/SslWsSession.h>
|
||||
#include <webserver/SubscriptionManager.h>
|
||||
#include <server/HttpSession.h>
|
||||
#include <server/PlainWsSession.h>
|
||||
#include <server/Ssl.h>
|
||||
#include <server/SslHttpSession.h>
|
||||
#include <server/SslWsSession.h>
|
||||
#include <server/SubscriptionManager.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
@@ -253,42 +254,8 @@ private:
|
||||
};
|
||||
|
||||
namespace Server {
|
||||
std::optional<ssl::context>
|
||||
parse_certs(const char* certFilename, const char* keyFilename)
|
||||
{
|
||||
std::ifstream readCert(certFilename, std::ios::in | std::ios::binary);
|
||||
if (!readCert)
|
||||
return {};
|
||||
|
||||
std::stringstream contents;
|
||||
contents << readCert.rdbuf();
|
||||
readCert.close();
|
||||
std::string cert = contents.str();
|
||||
|
||||
std::ifstream readKey(keyFilename, std::ios::in | std::ios::binary);
|
||||
if (!readKey)
|
||||
return {};
|
||||
|
||||
contents.str("");
|
||||
contents << readKey.rdbuf();
|
||||
readKey.close();
|
||||
std::string key = contents.str();
|
||||
|
||||
ssl::context ctx{ssl::context::tlsv12};
|
||||
|
||||
ctx.set_options(
|
||||
boost::asio::ssl::context::default_workarounds |
|
||||
boost::asio::ssl::context::no_sslv2);
|
||||
|
||||
ctx.use_certificate_chain(boost::asio::buffer(cert.data(), cert.size()));
|
||||
|
||||
ctx.use_private_key(
|
||||
boost::asio::buffer(key.data(), key.size()),
|
||||
boost::asio::ssl::context::file_format::pem);
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
using WebsocketServer = Listener<WsUpgrader, SslWsUpgrader>;
|
||||
using HttpServer = Listener<HttpSession, SslHttpSession>;
|
||||
|
||||
static std::shared_ptr<HttpServer>
|
||||
|
||||
66
src/webserver/Ssl.h
Normal file
66
src/webserver/Ssl.h
Normal file
@@ -0,0 +1,66 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of rippled: https://github.com/ripple/rippled
|
||||
Copyright (c) 2021 Ripple Labs Inc.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#ifndef REPORTING_SSL_H
|
||||
#define REPORTING_SSL_H
|
||||
|
||||
#include <boost/asio/ssl.hpp>
|
||||
|
||||
#include <fstream>
|
||||
#include <optional>
|
||||
|
||||
namespace ssl = boost::asio::ssl;
|
||||
|
||||
static std::optional<ssl::context>
|
||||
parse_certs(const char* certFilename, const char* keyFilename)
|
||||
{
|
||||
std::ifstream readCert(certFilename, std::ios::in | std::ios::binary);
|
||||
if (!readCert)
|
||||
return {};
|
||||
|
||||
std::stringstream contents;
|
||||
contents << readCert.rdbuf();
|
||||
readCert.close();
|
||||
std::string cert = contents.str();
|
||||
|
||||
std::ifstream readKey(keyFilename, std::ios::in | std::ios::binary);
|
||||
if (!readKey)
|
||||
return {};
|
||||
|
||||
contents.str("");
|
||||
contents << readKey.rdbuf();
|
||||
readKey.close();
|
||||
std::string key = contents.str();
|
||||
|
||||
ssl::context ctx{ssl::context::tlsv12};
|
||||
|
||||
ctx.set_options(
|
||||
boost::asio::ssl::context::default_workarounds |
|
||||
boost::asio::ssl::context::no_sslv2);
|
||||
|
||||
ctx.use_certificate_chain(boost::asio::buffer(cert.data(), cert.size()));
|
||||
|
||||
ctx.use_private_key(
|
||||
boost::asio::buffer(key.data(), key.size()),
|
||||
boost::asio::ssl::context::file_format::pem);
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
# endif // REPORTING_SSL_H
|
||||
Reference in New Issue
Block a user