20#include <xrpld/app/ledger/LedgerMaster.h> 
   21#include <xrpld/app/main/Application.h> 
   22#include <xrpld/overlay/detail/Handshake.h> 
   24#include <xrpl/basics/base64.h> 
   25#include <xrpl/beast/core/LexicalCast.h> 
   26#include <xrpl/beast/rfc2616.h> 
   27#include <xrpl/protocol/digest.h> 
   29#include <boost/regex.hpp> 
   40    boost::beast::http::fields 
const& headers,
 
   43    auto const header = headers.find(
"X-Protocol-Ctl");
 
   44    if (header == headers.end())
 
   47    boost::regex rx(feature + 
"=([^;\\s]+)");
 
   49    if (boost::regex_search(allFeatures, 
match, rx))
 
 
   56    boost::beast::http::fields 
const& headers,
 
 
   68    boost::beast::http::fields 
const& headers,
 
 
   77    bool ledgerReplayEnabled,
 
   78    bool txReduceRelayEnabled,
 
   79    bool vpReduceRelayEnabled)
 
   84    if (ledgerReplayEnabled)
 
   86    if (txReduceRelayEnabled)
 
   88    if (vpReduceRelayEnabled)
 
 
   97    bool ledgerReplayEnabled,
 
   98    bool txReduceRelayEnabled,
 
   99    bool vpReduceRelayEnabled)
 
 
  130    constexpr std::size_t sslMinimumFinishedLength = 12;
 
  132    unsigned char buf[1024];
 
  133    size_t len = 
get(ssl, buf, 
sizeof(buf));
 
  135    if (len < sslMinimumFinishedLength)
 
  141    SHA512(buf, len, cookie.
data());
 
 
  148    auto const cookie1 = 
hashLastMessage(ssl.native_handle(), SSL_get_finished);
 
  151        JLOG(journal.
error()) << 
"Cookie generation: local setup not complete";
 
  159        JLOG(journal.
error()) << 
"Cookie generation: peer setup not complete";
 
  163    auto const result = (*cookie1 ^ *cookie2);
 
  167    if (result == beast::zero)
 
  169        JLOG(journal.
error())
 
  170            << 
"Cookie generation: identical finished messages";
 
 
  179    boost::beast::http::fields& h,
 
  205        h.insert(
"Session-Signature", 
base64_encode(sig.data(), sig.size()));
 
  214        h.insert(
"Remote-IP", remote_ip.to_string());
 
  216    if (!public_ip.is_unspecified())
 
  217        h.insert(
"Local-IP", public_ip.to_string());
 
  221        h.insert(
"Closed-Ledger", 
strHex(cl->info().hash));
 
  222        h.insert(
"Previous-Ledger", 
strHex(cl->info().parentHash));
 
 
  228    boost::beast::http::fields 
const& headers,
 
  235    if (
auto const iter = headers.find(
"Server-Domain"); iter != headers.end())
 
  241    if (
auto const iter = headers.find(
"Network-ID"); iter != headers.end())
 
  248        if (networkID && nid != *networkID)
 
  252    if (
auto const iter = headers.find(
"Network-Time"); iter != headers.end())
 
  255            TimeKeeper::duration::rep val;
 
  268        auto const tolerance = 20s;
 
  276                return duration_cast<std::chrono::seconds>(a - b);
 
  277            return -duration_cast<std::chrono::seconds>(b - a);
 
  280        auto const offset = calculateOffset(netTime, ourTime);
 
  282        if (
abs(offset) > tolerance)
 
  287        if (
auto const iter = headers.find(
"Public-Key"); iter != headers.end())
 
  311        auto const iter = headers.find(
"Session-Signature");
 
  313        if (iter == headers.end())
 
  325    if (
auto const iter = headers.find(
"Local-IP"); iter != headers.end())
 
  327        boost::system::error_code ec;
 
  328        auto const local_ip =
 
  336                "Incorrect Local-IP: " + remote.to_string() + 
" instead of " +
 
  337                local_ip.to_string());
 
  340    if (
auto const iter = headers.find(
"Remote-IP"); iter != headers.end())
 
  342        boost::system::error_code ec;
 
  343        auto const remote_ip =
 
  354            if (remote_ip != public_ip)
 
  356                    "Incorrect Remote-IP: " + public_ip.to_string() +
 
  357                    " instead of " + remote_ip.to_string());
 
 
  368    bool ledgerReplayEnabled,
 
  369    bool txReduceRelayEnabled,
 
  373    m.method(boost::beast::http::verb::get);
 
  378    m.insert(
"Connection", 
"Upgrade");
 
  379    m.insert(
"Connect-As", 
"Peer");
 
  380    m.insert(
"Crawl", crawlPublic ? 
"public" : 
"private");
 
  386            txReduceRelayEnabled,
 
  387            vpReduceRelayEnabled));
 
 
  403    resp.result(boost::beast::http::status::switching_protocols);
 
  404    resp.version(req.version());
 
  405    resp.insert(
"Connection", 
"Upgrade");
 
  407    resp.insert(
"Connect-As", 
"Peer");
 
  409    resp.insert(
"Crawl", crawlPublic ? 
"public" : 
"private");
 
  419    buildHandshake(resp, sharedValue, networkID, public_ip, remote_ip, app);
 
 
A generic endpoint for log messages.
 
typename Clock::time_point time_point
 
typename Clock::duration duration
 
virtual Config & config()=0
 
virtual TimeKeeper & timeKeeper()=0
 
virtual LedgerMaster & getLedgerMaster()=0
 
virtual std::uint64_t instanceID() const =0
Returns a 64-bit instance identifier, generated at startup.
 
virtual std::pair< PublicKey, SecretKey > const & nodeIdentity()=0
 
bool VP_REDUCE_RELAY_BASE_SQUELCH_ENABLE
 
bool TX_REDUCE_RELAY_ENABLE
 
std::string SERVER_DOMAIN
 
std::shared_ptr< Ledger const > getClosedLedger()
 
An immutable linear range of bytes.
 
time_point now() const override
Returns the current time, using the server's clock.
 
Integers of any length that is a multiple of 32-bits.
 
bool is_public(Address const &addr)
Returns true if the address is a public routable address.
 
bool is_unspecified(Address const &addr)
Returns true if the address is unspecified.
 
boost::asio::ip::address Address
 
bool token_in_list(boost::string_ref const &value, boost::string_ref const &token)
Returns true if the specified token exists in the list.
 
bool lexicalCastChecked(Out &out, In in)
Intelligently convert from one type to another.
 
std::string const & getFullVersionString()
Full server version string.
 
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
 
boost::beast::ssl_stream< socket_type > stream_type
 
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
 
std::string makeFeaturesResponseHeader(http_request_type const &headers, bool comprEnabled, bool ledgerReplayEnabled, bool txReduceRelayEnabled, bool vpReduceRelayEnabled)
Make response header X-Protocol-Ctl value with supported features.
 
bool verifyDigest(PublicKey const &publicKey, uint256 const &digest, Slice const &sig, bool mustBeFullyCanonical=true) noexcept
Verify a secp256k1 signature on the digest of a message.
 
static constexpr char DELIM_FEATURE[]
 
boost::beast::http::response< boost::beast::http::dynamic_body > http_response_type
 
void buildHandshake(boost::beast::http::fields &h, ripple::uint256 const &sharedValue, std::optional< std::uint32_t > networkID, beast::IP::Address public_ip, beast::IP::Address remote_ip, Application &app)
Insert fields headers necessary for upgrading the link to the peer protocol.
 
static constexpr char FEATURE_COMPR[]
 
std::string makeFeaturesRequestHeader(bool comprEnabled, bool ledgerReplayEnabled, bool txReduceRelayEnabled, bool vpReduceRelayEnabled)
Make request header X-Protocol-Ctl value with supported features.
 
std::string base64_decode(std::string_view data)
 
http_response_type makeResponse(bool crawlPublic, http_request_type const &req, beast::IP::Address public_ip, beast::IP::Address remote_ip, uint256 const &sharedValue, std::optional< std::uint32_t > networkID, ProtocolVersion protocol, Application &app)
Make http response.
 
static constexpr char FEATURE_LEDGER_REPLAY[]
 
bool isFeatureValue(boost::beast::http::fields const &headers, std::string const &feature, std::string const &value)
Check if a feature's value is equal to the specified value.
 
std::optional< uint256 > makeSharedValue(stream_type &ssl, beast::Journal journal)
Computes a shared value based on the SSL connection state.
 
std::string const & supportedProtocolVersions()
The list of all the protocol versions we support.
 
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
 
std::string strHex(FwdIt begin, FwdIt end)
 
static std::optional< base_uint< 512 > > hashLastMessage(SSL const *ssl, size_t(*get)(const SSL *, void *, size_t))
Hashes the latest finished message from an SSL stream.
 
std::enable_if_t< std::is_same< T, char >::value||std::is_same< T, unsigned char >::value, Slice > makeSlice(std::array< T, N > const &a)
 
std::string base64_encode(std::uint8_t const *data, std::size_t len)
 
Buffer signDigest(PublicKey const &pk, SecretKey const &sk, uint256 const &digest)
Generate a signature for a message digest.
 
boost::beast::http::request< boost::beast::http::dynamic_body > http_request_type
 
bool featureEnabled(boost::beast::http::fields const &headers, std::string const &feature)
Check if a feature is enabled.
 
std::optional< std::string > getFeatureValue(boost::beast::http::fields const &headers, std::string const &feature)
Get feature's header value.
 
static constexpr char FEATURE_TXRR[]
 
std::string to_string(base_uint< Bits, Tag > const &a)
 
T get(Section const §ion, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.
 
auto makeRequest(bool crawlPublic, bool comprEnabled, bool ledgerReplayEnabled, bool txReduceRelayEnabled, bool vpReduceRelayEnabled) -> request_type
Make outbound http request.
 
boost::beast::http::request< boost::beast::http::empty_body > request_type
 
PublicKey verifyHandshake(boost::beast::http::fields const &headers, ripple::uint256 const &sharedValue, std::optional< std::uint32_t > networkID, beast::IP::Address public_ip, beast::IP::Address remote, Application &app)
Validate header fields necessary for upgrading the link to the peer protocol.
 
bool isProperlyFormedTomlDomain(std::string_view domain)
Determines if the given string looks like a TOML-file hosting domain.
 
sha512_half_hasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.
 
static constexpr char FEATURE_VPRR[]
 
constexpr Number abs(Number x) noexcept