Finish support for RPC user/pass auth.

This commit is contained in:
JoelKatz
2013-01-18 05:35:10 -08:00
parent fd76033e55
commit ae51e9d203
5 changed files with 23 additions and 13 deletions

View File

@@ -204,17 +204,19 @@ std::string DecodeBase64(std::string s)
return result;
}
bool HTTPAuthorized(std::map<std::string, std::string>& mapHeaders)
{ // This is currently not used
std::string strAuth = mapHeaders["authorization"];
if (strAuth.substr(0,6) != "Basic ")
return theConfig.RPC_ADMIN_USER.empty() && theConfig.RPC_ADMIN_PASSWORD.empty();
std::string strUserPass64 = strAuth.substr(6);
bool HTTPAuthorized(const std::map<std::string, std::string>& mapHeaders)
{
std::map<std::string, std::string>::const_iterator it = mapHeaders.find("authorization");
if ((it == mapHeaders.end()) || (it->second.substr(0,6) != "Basic "))
return theConfig.RPC_USER.empty() && theConfig.RPC_PASSWORD.empty();
std::string strUserPass64 = it->second.substr(6);
boost::trim(strUserPass64);
std::string strUserPass = DecodeBase64(strUserPass64);
std::string::size_type nColon = strUserPass.find(":");
if (nColon == std::string::npos)
return false;
std::string strUser = strUserPass.substr(0, nColon);
std::string strPassword = strUserPass.substr(nColon+1);
return (strUser == theConfig.RPC_USER) && (strPassword == theConfig.RPC_PASSWORD);