Skip to content

Commit 0b9a05a

Browse files
committed
Merge branch 'rpcpassword' of https://github.com/gmaxwell/bitcoin
2 parents 30999ec + b04f301 commit 0b9a05a

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/bitcoinrpc.cpp

+16-7
Original file line numberDiff line numberDiff line change
@@ -2368,18 +2368,25 @@ void ThreadRPCServer2(void* parg)
23682368
printf("ThreadRPCServer started\n");
23692369

23702370
strRPCUserColonPass = mapArgs["-rpcuser"] + ":" + mapArgs["-rpcpassword"];
2371-
if (strRPCUserColonPass == ":")
2371+
if (mapArgs["-rpcpassword"] == "")
23722372
{
2373+
unsigned char rand_pwd[32];
2374+
RAND_bytes(rand_pwd, 32);
23732375
string strWhatAmI = "To use bitcoind";
23742376
if (mapArgs.count("-server"))
23752377
strWhatAmI = strprintf(_("To use the %s option"), "\"-server\"");
23762378
else if (mapArgs.count("-daemon"))
23772379
strWhatAmI = strprintf(_("To use the %s option"), "\"-daemon\"");
23782380
PrintConsole(
2379-
_("Error: %s, you must set rpcpassword=<password>\nin the configuration file: %s\n"
2381+
_("Error: %s, you must set a rpcpassword in the configuration file:\n %s\n"
2382+
"It is recommended you use the following random password:\n"
2383+
"rpcuser=bitcoinrpc\n"
2384+
"rpcpassword=%s\n"
2385+
"(you do not need to remember this password)\n"
23802386
"If the file does not exist, create it with owner-readable-only file permissions.\n"),
23812387
strWhatAmI.c_str(),
2382-
GetConfigFile().c_str());
2388+
GetConfigFile().c_str(),
2389+
EncodeBase58(&rand_pwd[0],&rand_pwd[0]+32).c_str());
23832390
#ifndef QT_GUI
23842391
CreateThread(Shutdown, NULL);
23852392
#endif
@@ -2468,12 +2475,14 @@ void ThreadRPCServer2(void* parg)
24682475
}
24692476
if (!HTTPAuthorized(mapHeaders))
24702477
{
2471-
// Deter brute-forcing short passwords
2472-
if (mapArgs["-rpcpassword"].size() < 15)
2473-
Sleep(50);
2478+
printf("ThreadRPCServer incorrect password attempt from %s\n",peer.address().to_string().c_str());
2479+
/* Deter brute-forcing short passwords.
2480+
If this results in a DOS the user really
2481+
shouldn't have their RPC port exposed.*/
2482+
if (mapArgs["-rpcpassword"].size() < 20)
2483+
Sleep(250);
24742484

24752485
stream << HTTPReply(401, "") << std::flush;
2476-
printf("ThreadRPCServer incorrect password attempt\n");
24772486
continue;
24782487
}
24792488

0 commit comments

Comments
 (0)