1#include <xrpld/rpc/Role.h>
3#include <xrpl/beast/net/IPAddress.h>
4#include <xrpl/beast/net/IPEndpoint.h>
5#include <xrpl/beast/utility/instrumentation.h>
6#include <xrpl/json/json_value.h>
7#include <xrpl/resource/Consumer.h>
8#include <xrpl/resource/ResourceManager.h>
9#include <xrpl/server/Handoff.h>
10#include <xrpl/server/Port.h>
12#include <boost/asio/ip/impl/network_v4.ipp>
13#include <boost/asio/ip/impl/network_v6.ipp>
14#include <boost/asio/ip/network_v4.hpp>
15#include <boost/asio/ip/network_v6.hpp>
16#include <boost/beast/http/field.hpp>
32 "xrpl::passwordUnrequiredOrSentCorrect : non-empty admin nets");
35 return !passwordRequired ||
36 ((params[
"admin_password"].
isString() &&
59 auto ipNet = boost::asio::ip::make_network_v4(addrString);
60 for (
auto const& net : nets4)
62 if (ipNet.is_subnet_of(net) || ipNet == net)
69 auto ipNet = boost::asio::ip::make_network_v6(addrString);
70 for (
auto const& net : nets6)
72 if (ipNet.is_subnet_of(net) || ipNet == net)
122 Role const& required,
156 if (firstNonSpace == std::string_view::npos)
163 ret = ret.
substr(firstNonSpace);
169 if (
unsigned char const c = ret.
back(); c ==
' ' || c ==
'\r' || c ==
'\n')
172 if (lastNonSpace == std::string_view::npos)
179 ret = ret.
substr(0, lastNonSpace + 1);
190 if (ret.
front() ==
'"')
206 if (ret.
front() ==
'[')
214 return std::isxdigit(c) || c ==
':' || c ==
'.' || c ==
' ';
219 if (closeBracket == ret.
end() || (*closeBracket) !=
']')
234 ret, [](
unsigned char c) {
return std::isxdigit(c) || c ==
' '; });
238 if (colon == ret.
end() || (*colon) ==
':')
244 if (
std::size_t const colon = ret.
find(
':'); colon != std::string_view::npos)
245 ret = ret.
substr(0, colon);
254 if (
auto it = request.find(boost::beast::http::field::forwarded); it != request.end())
256 auto asciiToLower = [](
char c) ->
char {
257 return ((
static_cast<unsigned>(c) - 65U) < 26) ? c +
'a' -
'A' : c;
263 auto const atFieldBoundary = [begin = it->value().begin()](
auto p) {
264 return p == begin || p[-1] ==
';' || p[-1] ==
',' || p[-1] ==
' ' || p[-1] ==
'\t';
266 auto found = it->value().
begin();
274 [&asciiToLower](
char c1,
char c2) { return asciiToLower(c1) == asciiToLower(c2); });
276 if (found == it->value().end())
279 if (atFieldBoundary(found))
288 auto const end = it->value().end();
292 if (pos != std::string_view::npos)
302 if (
auto it = request.find(
"X-Forwarded-For"); it != request.end())
306 if (found == boost::string_view::npos)
307 found = it->value().length();
A version-independent IP address and port combination.
Address const & address() const
Returns the address portion of this endpoint.
std::string asString() const
Returns the unquoted string value.
Tracks load and resource consumption.
virtual Consumer newUnlimitedEndpoint(beast::IP::Endpoint const &address)=0
Create a new unlimited endpoint keyed by forwarded IP.
virtual Consumer newInboundEndpoint(beast::IP::Endpoint const &address)=0
Create a new endpoint keyed by inbound IP address or the forwarded IP if proxied.
T find_first_not_of(T... args)
T find_first_of(T... args)
T find_last_not_of(T... args)
boost::asio::ip::address Address
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Role requestRole(Role const &required, Port const &port, json::Value const ¶ms, beast::IP::Endpoint const &remoteIp, std::string_view user)
Return the allowed privilege role.
Resource::Consumer requestInboundEndpoint(Resource::Manager &manager, beast::IP::Endpoint const &remoteAddress, Role const &role, std::string_view user, std::string_view forwardedFor)
std::string_view forwardedFor(http_request_type const &request)
Role
Indicates the level of administrative permission to grant.
bool ipAllowed(beast::IP::Address const &remoteIp, std::vector< boost::asio::ip::network_v4 > const &nets4, std::vector< boost::asio::ip::network_v6 > const &nets6)
True if remoteIp is in any of adminIp.
bool isAdmin(Port const &port, json::Value const ¶ms, beast::IP::Address const &remoteIp)
static std::string_view extractIpAddrFromField(std::string_view field)
boost::beast::http::request< boost::beast::http::dynamic_body > http_request_type
bool isUnlimited(Role const &role)
ADMIN and IDENTIFIED roles shall have unlimited resources.
bool passwordUnrequiredOrSentCorrect(Port const &port, json::Value const ¶ms)
T remove_prefix(T... args)
T remove_suffix(T... args)
Configuration information for a Server listening port.
std::vector< boost::asio::ip::network_v6 > adminNetsV6
std::vector< boost::asio::ip::network_v4 > secureGatewayNetsV4
std::vector< boost::asio::ip::network_v4 > adminNetsV4
std::vector< boost::asio::ip::network_v6 > secureGatewayNetsV6
std::string adminPassword