17 #include <boost/algorithm/string.hpp> 18 #include <boost/foreach.hpp> 33 tv.tv_sec = millis/1000;
34 tv.tv_usec = (millis%1000)*1000;
78 req->
WriteHeader(
"Content-Type",
"application/json");
86 if (strUserPass.find(
":") == std::string::npos) {
89 std::string strUser = strUserPass.substr(0, strUserPass.find(
":"));
90 std::string strPass = strUserPass.substr(strUserPass.find(
":") + 1);
94 BOOST_FOREACH(std::string strRPCAuth,
mapMultiArgs[
"-rpcauth"])
96 std::vector<std::string> vFields;
97 boost::split(vFields, strRPCAuth, boost::is_any_of(
":$"));
98 if (vFields.size() != 3) {
103 std::string strName = vFields[0];
108 std::string strSalt = vFields[1];
109 std::string strHash = vFields[2];
111 unsigned int KEY_SIZE = 32;
112 unsigned char *
out =
new unsigned char[KEY_SIZE];
114 CHMAC_SHA256(reinterpret_cast<const unsigned char*>(strSalt.c_str()), strSalt.size()).Write(reinterpret_cast<const unsigned char*>(strPass.c_str()), strPass.size()).Finalize(
out);
115 std::vector<unsigned char> hexvec(
out,
out+KEY_SIZE);
116 std::string strHashFromPass =
HexStr(hexvec);
130 if (strAuth.substr(0, 6) !=
"Basic ")
132 std::string strUserPass64 = strAuth.substr(6);
133 boost::trim(strUserPass64);
151 std::pair<bool, std::string> authHeader = req->
GetHeader(
"authorization");
152 if (!authHeader.first) {
178 std::string strReply;
181 jreq.
parse(valRequest);
189 }
else if (valRequest.
isArray())
194 req->
WriteHeader(
"Content-Type",
"application/json");
196 }
catch (
const UniValue& objError) {
199 }
catch (
const std::exception& e) {
208 if (
mapArgs[
"-rpcpassword"] ==
"")
210 LogPrintf(
"No rpcpassword set - using random cookie authentication\n");
213 _(
"Error: A fatal internal error occurred, see debug.log for details"),
218 LogPrintf(
"Config options rpcuser and rpcpassword will soon be deprecated. Locally-run instances may remove rpcuser to use cookie-based auth, or may be replaced with rpcauth. Please see share/rpcuser for rpcauth auth generation.\n");
226 LogPrint(
"rpc",
"Starting HTTP RPC server\n");
240 LogPrint(
"rpc",
"Interrupting HTTP RPC server\n");
245 LogPrint(
"rpc",
"Stopping HTTP RPC server\n");
void MilliSleep(int64_t n)
static const char * WWW_AUTH_HEADER_DATA
static std::string strRPCUserColonPass
std::string JSONRPCExecBatch(const UniValue &vReq)
static bool InitRPCAuthentication()
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
static void JSONErrorReply(HTTPRequest *req, const UniValue &objError, const UniValue &id)
HTTPRPCTimer(struct event_base *eventBase, boost::function< void(void)> &func, int64_t millis)
std::string ToString(bool fUseGetnameinfo=true) const
void trigger(struct timeval *tv)
static bool HTTPReq_JSONRPC(HTTPRequest *req, const std::string &)
boost::signals2::signal< bool(const std::string &message, const std::string &caption, unsigned int style), boost::signals2::last_value< bool > > ThreadSafeMessageBox
HTTPRPCTimerInterface(struct event_base *base)
const UniValue & find_value(const UniValue &obj, const std::string &name)
void RegisterHTTPHandler(const std::string &prefix, bool exactMatch, const HTTPRequestHandler &handler)
bool TimingResistantEqual(const T &a, const T &b)
static bool multiUserAuthorized(std::string strUserPass)
static int LogPrint(const char *category, const char *format)
vector< unsigned char > DecodeBase64(const char *p, bool *pfInvalid)
void WriteReply(int nStatus, const std::string &strReply="")
static bool RPCAuthorized(const std::string &strAuth)
CClientUIInterface uiInterface
void UnregisterHTTPHandler(const std::string &prefix, bool exactMatch)
struct event_base * EventBase()
std::pair< bool, std::string > GetHeader(const std::string &hdr)
void RPCRegisterTimerInterface(RPCTimerInterface *iface)
bool GenerateAuthCookie(std::string *cookie_out)
static HTTPRPCTimerInterface * httpRPCTimerInterface
RequestMethod GetRequestMethod()
RPCTimerBase * NewTimer(boost::function< void(void)> &func, int64_t millis)
const UniValue NullUniValue
void WriteHeader(const std::string &hdr, const std::string &value)
void parse(const UniValue &valRequest)
Standard JSON-RPC 2.0 errors.
string JSONRPCReply(const UniValue &result, const UniValue &error, const UniValue &id)
UniValue execute(const std::string &method, const UniValue ¶ms) const
bool read(const char *raw)
map< string, vector< string > > mapMultiArgs
UniValue JSONRPCError(int code, const string &message)
const UniValue & get_array() const
std::string _(const char *psz)
map< string, string > mapArgs
static struct event_base * eventBase
libevent event loop
void RPCUnregisterTimerInterface(RPCTimerInterface *iface)