MCPcopy Create free account
hub / github.com/LUX-Core/lux / GenerateAuthCookie

Function GenerateAuthCookie

src/rpcprotocol.cpp:80–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78}
79
80bool GenerateAuthCookie(std::string *cookie_out)
81{
82 unsigned char rand_pwd[32];
83 GetRandBytes(rand_pwd, 32);
84 std::string cookie = COOKIEAUTH_USER + ":" + EncodeBase64(&rand_pwd[0],32);
85
86 /** the umask determines what permissions are used to create this file -
87 * these are set to 077 in init.cpp unless overridden with -sysperms.
88 */
89 std::ofstream file;
90 boost::filesystem::path filepath = GetAuthCookieFile();
91 file.open(filepath.string().c_str());
92 if (!file.is_open()) {
93 LogPrintf("Unable to open cookie authentication file %s for writing\n", filepath.string());
94 return false;
95 }
96 file << cookie;
97 file.close();
98 LogPrintf("Generated RPC authentication cookie %s\n", filepath.string());
99
100 if (cookie_out)
101 *cookie_out = cookie;
102 return true;
103}
104
105bool GetAuthCookie(std::string *cookie_out)
106{

Callers 1

InitRPCAuthenticationFunction · 0.85

Calls 5

GetRandBytesFunction · 0.85
EncodeBase64Function · 0.85
GetAuthCookieFileFunction · 0.85
openMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected