This function checks username and password against -rpcauth entries from config file.
| 86 | //This function checks username and password against -rpcauth |
| 87 | //entries from config file. |
| 88 | static bool multiUserAuthorized(std::string strUserPass) |
| 89 | { |
| 90 | if (strUserPass.find(':') == std::string::npos) { |
| 91 | return false; |
| 92 | } |
| 93 | std::string strUser = strUserPass.substr(0, strUserPass.find(':')); |
| 94 | std::string strPass = strUserPass.substr(strUserPass.find(':') + 1); |
| 95 | |
| 96 | for (const std::string& strRPCAuth : gArgs.GetArgs("-rpcauth")) { |
| 97 | //Search for multi-user login/pass "rpcauth" from config |
| 98 | std::vector<std::string> vFields; |
| 99 | boost::split(vFields, strRPCAuth, boost::is_any_of(":$")); |
| 100 | if (vFields.size() != 3) { |
| 101 | //Incorrect formatting in config file |
| 102 | continue; |
| 103 | } |
| 104 | |
| 105 | std::string strName = vFields[0]; |
| 106 | if (!TimingResistantEqual(strName, strUser)) { |
| 107 | continue; |
| 108 | } |
| 109 | |
| 110 | std::string strSalt = vFields[1]; |
| 111 | std::string strHash = vFields[2]; |
| 112 | |
| 113 | static const unsigned int KEY_SIZE = 32; |
| 114 | unsigned char out[KEY_SIZE]; |
| 115 | |
| 116 | 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); |
| 117 | std::vector<unsigned char> hexvec(out, out+KEY_SIZE); |
| 118 | std::string strHashFromPass = HexStr(hexvec); |
| 119 | |
| 120 | if (TimingResistantEqual(strHashFromPass, strHash)) { |
| 121 | return true; |
| 122 | } |
| 123 | } |
| 124 | return false; |
| 125 | } |
| 126 | |
| 127 | static bool RPCAuthorized(const std::string& strAuth, std::string& strAuthUsernameOut) |
| 128 | { |
no test coverage detected