From 9435dbee1895860a85076e1cf7bfdfbdc8532793 Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Mon, 3 Dec 2012 17:57:18 -0800 Subject: [PATCH] Refactor RPC validation_create. --- src/cpp/ripple/CallRPC.cpp | 16 +++++++++++++++- src/cpp/ripple/CallRPC.h | 1 + src/cpp/ripple/RPCHandler.cpp | 27 +++++++++++++-------------- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/cpp/ripple/CallRPC.cpp b/src/cpp/ripple/CallRPC.cpp index 22c2129aa..2b3ffbf7d 100644 --- a/src/cpp/ripple/CallRPC.cpp +++ b/src/cpp/ripple/CallRPC.cpp @@ -229,6 +229,20 @@ Json::Value RPCParser::parseUnlDelete(const Json::Value& jvParams) return jvRequest; } +// validation_create [||] +// +// NOTE: It is poor security to specify secret information on the command line. This information might be saved in the command +// shell history file (e.g. .bash_history) and it may be leaked via the process status command (i.e. ps). +Json::Value RPCParser::parseValidationCreate(const Json::Value& jvParams) +{ + Json::Value jvRequest; + + if (jvParams.size()) + jvRequest["secret"] = jvParams[0u].asString(); + + return jvRequest; +} + // wallet_accounts Json::Value RPCParser::parseWalletAccounts(const Json::Value& jvParams) { @@ -319,7 +333,7 @@ Json::Value RPCParser::parseCommand(std::string strMethod, Json::Value jvParams) { "unl_reset", &RPCParser::parseAsIs, 0, 0 }, { "unl_score", &RPCParser::parseAsIs, 0, 0 }, -// { "validation_create", &RPCParser::doValidationCreate, 0, 1, false, false, optNone }, + { "validation_create", &RPCParser::parseValidationCreate, 0, 1 }, // { "validation_seed", &RPCParser::doValidationSeed, 0, 1, false, false, optNone }, { "wallet_accounts", &RPCParser::parseWalletAccounts, 1, 1 }, diff --git a/src/cpp/ripple/CallRPC.h b/src/cpp/ripple/CallRPC.h index 37431d547..5741fb53e 100644 --- a/src/cpp/ripple/CallRPC.h +++ b/src/cpp/ripple/CallRPC.h @@ -21,6 +21,7 @@ protected: Json::Value parseSubmit(const Json::Value& jvParams); Json::Value parseUnlAdd(const Json::Value& jvParams); Json::Value parseUnlDelete(const Json::Value& jvParams); + Json::Value parseValidationCreate(const Json::Value& jvParams); Json::Value parseWalletAccounts(const Json::Value& jvParams); Json::Value parseWalletPropose(const Json::Value& jvParams); Json::Value parseWalletSeed(const Json::Value& jvParams); diff --git a/src/cpp/ripple/RPCHandler.cpp b/src/cpp/ripple/RPCHandler.cpp index f9794c980..3e04a9b67 100644 --- a/src/cpp/ripple/RPCHandler.cpp +++ b/src/cpp/ripple/RPCHandler.cpp @@ -1237,28 +1237,27 @@ Json::Value RPCHandler::doAccountTransactions(Json::Value jvRequest) #endif } -// validation_create [||] -// -// NOTE: It is poor security to specify secret information on the command line. This information might be saved in the command -// shell history file (e.g. .bash_history) and it may be leaked via the process status command (i.e. ps). -Json::Value RPCHandler::doValidationCreate(Json::Value params) { - RippleAddress naSeed; +// { +// secret: +// } +Json::Value RPCHandler::doValidationCreate(Json::Value jvParams) { + RippleAddress raSeed; Json::Value obj(Json::objectValue); - if (params.empty()) + if (!jvParams.isMember("secret")) { - std::cerr << "Creating random validation seed." << std::endl; + cLog(lsDEBUG) << "Creating random validation seed."; - naSeed.setSeedRandom(); // Get a random seed. + raSeed.setSeedRandom(); // Get a random seed. } - else if (!naSeed.setSeedGeneric(params[0u].asString())) + else if (!raSeed.setSeedGeneric(jvParams["secret"].asString())) { return rpcError(rpcBAD_SEED); } - obj["validation_public_key"] = RippleAddress::createNodePublic(naSeed).humanNodePublic(); - obj["validation_seed"] = naSeed.humanSeed(); - obj["validation_key"] = naSeed.humanSeed1751(); + obj["validation_public_key"] = RippleAddress::createNodePublic(raSeed).humanNodePublic(); + obj["validation_seed"] = raSeed.humanSeed(); + obj["validation_key"] = raSeed.humanSeed1751(); return obj; } @@ -2217,7 +2216,7 @@ Json::Value RPCHandler::doCommand(Json::Value& jvParams, int iRole) { "unl_reset", &RPCHandler::doUnlReset, -1, -1, true, false, optNone }, { "unl_score", &RPCHandler::doUnlScore, -1, -1, true, false, optNone }, - { "validation_create", &RPCHandler::doValidationCreate, 0, 1, false, false, optNone }, + { "validation_create", &RPCHandler::doValidationCreate, -1, -1, false, false, optNone }, { "validation_seed", &RPCHandler::doValidationSeed, 0, 1, false, false, optNone }, { "wallet_accounts", &RPCHandler::doWalletAccounts, -1, -1, false, false, optCurrent },