| 78 | } |
| 79 | |
| 80 | bool 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 | |
| 105 | bool GetAuthCookie(std::string *cookie_out) |
| 106 | { |
no test coverage detected