mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Use secure RPC connections when configured
This commit is contained in:
committed by
Vinnie Falco
parent
d618581060
commit
bf9b8f4d1b
@@ -75,7 +75,13 @@ public:
|
|||||||
//if (! is_unspecified (ep))
|
//if (! is_unspecified (ep))
|
||||||
{
|
{
|
||||||
HTTP::Port port;
|
HTTP::Port port;
|
||||||
port.security = HTTP::Port::Security::allow_ssl;
|
|
||||||
|
if (setup_.secure == 0)
|
||||||
|
port.security = HTTP::Port::Security::no_ssl;
|
||||||
|
else if (setup_.secure == 1)
|
||||||
|
port.security = HTTP::Port::Security::allow_ssl;
|
||||||
|
else
|
||||||
|
port.security = HTTP::Port::Security::require_ssl;
|
||||||
port.addr = ep.at_port(0);
|
port.addr = ep.at_port(0);
|
||||||
if (setup_.port != 0)
|
if (setup_.port != 0)
|
||||||
port.port = setup_.port;
|
port.port = setup_.port;
|
||||||
|
|||||||
@@ -497,7 +497,7 @@ struct Setup
|
|||||||
int port = 5001;
|
int port = 5001;
|
||||||
std::string user;
|
std::string user;
|
||||||
std::string password;
|
std::string password;
|
||||||
bool secure = false;
|
int secure = 0;
|
||||||
std::string ssl_cert;
|
std::string ssl_cert;
|
||||||
std::string ssl_chain;
|
std::string ssl_chain;
|
||||||
std::string ssl_key;
|
std::string ssl_key;
|
||||||
|
|||||||
@@ -987,29 +987,31 @@ int RPCCall::fromCommandLine (const std::vector<std::string>& vCmd)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
auto setup = setup_RPC (getConfig()["rpc"]);
|
||||||
|
|
||||||
Json::Value jvParams (Json::arrayValue);
|
Json::Value jvParams (Json::arrayValue);
|
||||||
|
|
||||||
jvParams.append (jvRequest);
|
jvParams.append (jvRequest);
|
||||||
|
|
||||||
if (!getConfig ().RPC_ADMIN_USER.empty ())
|
if (!setup.admin_user.empty ())
|
||||||
jvRequest["admin_user"] = getConfig ().RPC_ADMIN_USER;
|
jvRequest["admin_user"] = setup.admin_user;
|
||||||
|
|
||||||
if (!getConfig ().RPC_ADMIN_PASSWORD.empty ())
|
if (!setup.admin_password.empty ())
|
||||||
jvRequest["admin_password"] = getConfig ().RPC_ADMIN_PASSWORD;
|
jvRequest["admin_password"] = setup.admin_password;
|
||||||
|
|
||||||
boost::asio::io_service isService;
|
boost::asio::io_service isService;
|
||||||
|
|
||||||
fromNetwork (
|
fromNetwork (
|
||||||
isService,
|
isService,
|
||||||
getConfig ().getRpcIP (),
|
setup.ip,
|
||||||
getConfig ().getRpcPort (),
|
setup.port,
|
||||||
getConfig ().RPC_USER,
|
setup.admin_user,
|
||||||
getConfig ().RPC_PASSWORD,
|
setup.admin_password,
|
||||||
"",
|
"",
|
||||||
jvRequest.isMember ("method") // Allow parser to rewrite method.
|
jvRequest.isMember ("method") // Allow parser to rewrite method.
|
||||||
? jvRequest["method"].asString () : vCmd[0],
|
? jvRequest["method"].asString () : vCmd[0],
|
||||||
jvParams, // Parsed, execute.
|
jvParams, // Parsed, execute.
|
||||||
false,
|
setup.secure != 0, // Use SSL
|
||||||
std::bind (RPCCallImp::callRPCHandler, &jvOutput,
|
std::bind (RPCCallImp::callRPCHandler, &jvOutput,
|
||||||
std::placeholders::_1));
|
std::placeholders::_1));
|
||||||
|
|
||||||
@@ -1083,15 +1085,16 @@ void RPCCall::fromNetwork (
|
|||||||
// Connect to localhost
|
// Connect to localhost
|
||||||
if (!getConfig ().QUIET)
|
if (!getConfig ().QUIET)
|
||||||
{
|
{
|
||||||
std::cerr << "Connecting to: " << strIp << ":" << iPort << std::endl;
|
std::cerr << (bSSL ? "Securely connecting to " : "Connecting to ") <<
|
||||||
|
strIp << ":" << iPort << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// HTTP basic authentication
|
// HTTP basic authentication
|
||||||
std::string strUserPass64 = RPCParser::EncodeBase64 (strUsername + ":" + strPassword);
|
auto const auth = RPCParser::EncodeBase64 (strUsername + ":" + strPassword);
|
||||||
|
|
||||||
std::map<std::string, std::string> mapRequestHeaders;
|
std::map<std::string, std::string> mapRequestHeaders;
|
||||||
|
|
||||||
mapRequestHeaders["Authorization"] = std::string ("Basic ") + strUserPass64;
|
mapRequestHeaders["Authorization"] = std::string ("Basic ") + auth;
|
||||||
|
|
||||||
// Send request
|
// Send request
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user