| 82 | } |
| 83 | |
| 84 | static bool RPCAuthorized(const std::string& strAuth, std::string& strAuthUsernameOut) |
| 85 | { |
| 86 | if (!strAuth.starts_with("Basic ")) |
| 87 | return false; |
| 88 | std::string_view strUserPass64 = TrimStringView(std::string_view{strAuth}.substr(6)); |
| 89 | auto userpass_data = DecodeBase64(strUserPass64); |
| 90 | std::string strUserPass; |
| 91 | if (!userpass_data) return false; |
| 92 | strUserPass.assign(userpass_data->begin(), userpass_data->end()); |
| 93 | |
| 94 | size_t colon_pos = strUserPass.find(':'); |
| 95 | if (colon_pos == std::string::npos) { |
| 96 | return false; // Invalid basic auth. |
| 97 | } |
| 98 | std::string user = strUserPass.substr(0, colon_pos); |
| 99 | std::string pass = strUserPass.substr(colon_pos + 1); |
| 100 | strAuthUsernameOut = user; |
| 101 | return CheckUserAuthorized(user, pass); |
| 102 | } |
| 103 | |
| 104 | UniValue ExecuteHTTPRPC(const UniValue& valRequest, JSONRPCRequest& jreq, HTTPStatusCode& status) |
| 105 | { |
no test coverage detected