X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fbitcoinrpc.cpp;h=6d96ec6425104d61c99da9aeaca892937e6bf31b;hb=ef17ac0211ddd486127e1f94756fbb3fd704a9b4;hp=863e4fe791677ab0fe3c87c5c4b6b1be9cc4f169;hpb=ff5e242cae806847be87faa1e6c46ce04916ea10;p=novacoin.git diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 863e4fe..6d96ec6 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -297,7 +297,6 @@ static const CRPCCommand vRPCCommands[] = { "submitblock", &submitblock, false, false }, { "listsinceblock", &listsinceblock, false, false }, { "dumpprivkey", &dumpprivkey, false, false }, - { "dumppem", &dumppem, true, false }, { "dumpwallet", &dumpwallet, true, false }, { "importwallet", &importwallet, false, false }, { "importprivkey", &importprivkey, false, false }, @@ -323,10 +322,6 @@ static const CRPCCommand vRPCCommands[] = { "listmalleableviews", &listmalleableviews, false, false}, { "dumpmalleablekey", &dumpmalleablekey, false, false}, { "importmalleablekey", &importmalleablekey, true, false }, - { "encryptdata", &encryptdata, false, false }, - { "decryptdata", &decryptdata, false, false }, - { "encryptmessage", &encryptmessage, false, false }, - { "decryptmessage", &decryptmessage, false, false }, { "sendalert", &sendalert, false, false}, }; @@ -475,7 +470,7 @@ int ReadHTTP(std::basic_istream& stream, map& mapHeadersRe return nStatus; } -bool HTTPAuthorized(map& mapHeaders) +bool HTTPAuthorized(ix::WebSocketHttpHeaders& mapHeaders) { string strAuth = mapHeaders["authorization"]; if (strAuth.substr(0,6) != "Basic ") @@ -610,6 +605,31 @@ static CCriticalSection cs_THREAD_RPCHANDLER; void StartRPCServer() { +strRPCUserColonPass = mapArgs["-rpcuser"] + ":" + mapArgs["-rpcpassword"]; + if (mapArgs["-rpcpassword"].empty()) + { + unsigned char rand_pwd[32]; + RAND_bytes(rand_pwd, 32); + string strWhatAmI = "To use novacoind"; + if (mapArgs.count("-server")) + strWhatAmI = strprintf(_("To use the %s option"), "\"-server\""); + else if (mapArgs.count("-daemon")) + strWhatAmI = strprintf(_("To use the %s option"), "\"-daemon\""); + uiInterface.ThreadSafeMessageBox(strprintf( + _("%s, you must set a rpcpassword in the configuration file:\n %s\n" + "It is recommended you use the following random password:\n" + "rpcuser=novacoinrpc\n" + "rpcpassword=%s\n" + "(you do not need to remember this password)\n" + "If the file does not exist, create it with owner-readable-only file permissions.\n"), + strWhatAmI.c_str(), + GetConfigFile().string().c_str(), + EncodeBase58(&rand_pwd[0],&rand_pwd[0]+32).c_str()), + _("Error"), CClientUIInterface::OK | CClientUIInterface::MODAL); + StartShutdown(); + return; + } + string host = GetArg("-rpchost", "127.0.0.1"); int port = GetArg("-rpcport", GetDefaultRPCPort()); @@ -620,8 +640,18 @@ void StartRPCServer() g_server->setOnConnectionCallback([](ix::HttpRequestPtr request, std::shared_ptr connectionState) -> ix::HttpResponsePtr { ix::WebSocketHttpHeaders headers; + headers["Server"] = string("novacoin-json-rpc/") + FormatFullVersion(); + headers["WWW-Authenticate"] = "Basic realm=\"jsonrpc\""; + + if (!HTTPAuthorized(request->headers)) + { + printf("ThreadRPCServer incorrect password attempt from %s\n", connectionState->getRemoteIp().c_str()); + connectionState->setTerminated(); + return std::make_shared(401, "Unauthorized", ix::HttpErrorCode::Ok, headers, "Not authorized"); + } if (request->method != "POST") { + connectionState->setTerminated(); return std::make_shared(400, "Bad request", ix::HttpErrorCode::Ok, headers, "Bad request"); } @@ -674,6 +704,9 @@ void StartRPCServer() return StartShutdown(); } + // Run listening thread + g_server->start(); + // We're listening now vnThreadsRunning[THREAD_RPCLISTENER]++; }