Use secure RPC connections when configured

This commit is contained in:
Nik Bougalis
2014-09-27 19:01:36 -07:00
committed by Vinnie Falco
parent d618581060
commit bf9b8f4d1b
3 changed files with 24 additions and 15 deletions

View File

@@ -987,29 +987,31 @@ int RPCCall::fromCommandLine (const std::vector<std::string>& vCmd)
}
else
{
auto setup = setup_RPC (getConfig()["rpc"]);
Json::Value jvParams (Json::arrayValue);
jvParams.append (jvRequest);
if (!getConfig ().RPC_ADMIN_USER.empty ())
jvRequest["admin_user"] = getConfig ().RPC_ADMIN_USER;
if (!setup.admin_user.empty ())
jvRequest["admin_user"] = setup.admin_user;
if (!getConfig ().RPC_ADMIN_PASSWORD.empty ())
jvRequest["admin_password"] = getConfig ().RPC_ADMIN_PASSWORD;
if (!setup.admin_password.empty ())
jvRequest["admin_password"] = setup.admin_password;
boost::asio::io_service isService;
boost::asio::io_service isService;
fromNetwork (
isService,
getConfig ().getRpcIP (),
getConfig ().getRpcPort (),
getConfig ().RPC_USER,
getConfig ().RPC_PASSWORD,
setup.ip,
setup.port,
setup.admin_user,
setup.admin_password,
"",
jvRequest.isMember ("method") // Allow parser to rewrite method.
? jvRequest["method"].asString () : vCmd[0],
jvParams, // Parsed, execute.
false,
setup.secure != 0, // Use SSL
std::bind (RPCCallImp::callRPCHandler, &jvOutput,
std::placeholders::_1));
@@ -1083,15 +1085,16 @@ void RPCCall::fromNetwork (
// Connect to localhost
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
std::string strUserPass64 = RPCParser::EncodeBase64 (strUsername + ":" + strPassword);
auto const auth = RPCParser::EncodeBase64 (strUsername + ":" + strPassword);
std::map<std::string, std::string> mapRequestHeaders;
mapRequestHeaders["Authorization"] = std::string ("Basic ") + strUserPass64;
mapRequestHeaders["Authorization"] = std::string ("Basic ") + auth;
// Send request