MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / multiUserAuthorized

Function multiUserAuthorized

src/httprpc.cpp:88–125  ·  view source on GitHub ↗

This function checks username and password against -rpcauth entries from config file.

Source from the content-addressed store, hash-verified

86//This function checks username and password against -rpcauth
87//entries from config file.
88static 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
127static bool RPCAuthorized(const std::string& strAuth, std::string& strAuthUsernameOut)
128{

Callers 1

RPCAuthorizedFunction · 0.85

Calls 8

TimingResistantEqualFunction · 0.85
CHMAC_SHA256Class · 0.85
HexStrFunction · 0.85
GetArgsMethod · 0.80
findMethod · 0.45
sizeMethod · 0.45
FinalizeMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected