From ecf8c6976394195e0de7b9be99157028b52604a5 Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Mon, 3 Dec 2012 18:00:59 -0800 Subject: [PATCH] Refactor RPC validation_seed. --- src/cpp/ripple/CallRPC.cpp | 16 +++++++++++++++- src/cpp/ripple/CallRPC.h | 1 + src/cpp/ripple/RPCHandler.cpp | 17 +++++++++-------- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/cpp/ripple/CallRPC.cpp b/src/cpp/ripple/CallRPC.cpp index 2b3ffbf7da..1f0287775b 100644 --- a/src/cpp/ripple/CallRPC.cpp +++ b/src/cpp/ripple/CallRPC.cpp @@ -243,6 +243,20 @@ Json::Value RPCParser::parseValidationCreate(const Json::Value& jvParams) return jvRequest; } +// validation_seed [||] +// +// 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::parseValidationSeed(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) { @@ -334,7 +348,7 @@ Json::Value RPCParser::parseCommand(std::string strMethod, Json::Value jvParams) { "unl_score", &RPCParser::parseAsIs, 0, 0 }, { "validation_create", &RPCParser::parseValidationCreate, 0, 1 }, -// { "validation_seed", &RPCParser::doValidationSeed, 0, 1, false, false, optNone }, + { "validation_seed", &RPCParser::parseValidationSeed, 0, 1 }, { "wallet_accounts", &RPCParser::parseWalletAccounts, 1, 1 }, { "wallet_propose", &RPCParser::parseWalletPropose, 0, 1 }, diff --git a/src/cpp/ripple/CallRPC.h b/src/cpp/ripple/CallRPC.h index 5741fb53e0..5dfe1b3743 100644 --- a/src/cpp/ripple/CallRPC.h +++ b/src/cpp/ripple/CallRPC.h @@ -22,6 +22,7 @@ protected: Json::Value parseUnlAdd(const Json::Value& jvParams); Json::Value parseUnlDelete(const Json::Value& jvParams); Json::Value parseValidationCreate(const Json::Value& jvParams); + Json::Value parseValidationSeed(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 3e04a9b679..0d577202c1 100644 --- a/src/cpp/ripple/RPCHandler.cpp +++ b/src/cpp/ripple/RPCHandler.cpp @@ -1262,14 +1262,13 @@ Json::Value RPCHandler::doValidationCreate(Json::Value jvParams) { return obj; } -// validation_seed [||] -// -// 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::doValidationSeed(Json::Value params) { +// { +// secret: +// } +Json::Value RPCHandler::doValidationSeed(Json::Value jvRequest) { Json::Value obj(Json::objectValue); - if (params.empty()) + if (!jvRequest.isMember("secret")) { std::cerr << "Unset validation seed." << std::endl; @@ -1277,16 +1276,18 @@ Json::Value RPCHandler::doValidationSeed(Json::Value params) { theConfig.VALIDATION_PUB.clear(); theConfig.VALIDATION_PRIV.clear(); } - else if (!theConfig.VALIDATION_SEED.setSeedGeneric(params[0u].asString())) + else if (!theConfig.VALIDATION_SEED.setSeedGeneric(jvRequest["secret"].asString())) { theConfig.VALIDATION_PUB.clear(); theConfig.VALIDATION_PRIV.clear(); + return rpcError(rpcBAD_SEED); } else { theConfig.VALIDATION_PUB = RippleAddress::createNodePublic(theConfig.VALIDATION_SEED); theConfig.VALIDATION_PRIV = RippleAddress::createNodePrivate(theConfig.VALIDATION_SEED); + obj["validation_public_key"] = theConfig.VALIDATION_PUB.humanNodePublic(); obj["validation_seed"] = theConfig.VALIDATION_SEED.humanSeed(); obj["validation_key"] = theConfig.VALIDATION_SEED.humanSeed1751(); @@ -2217,7 +2218,7 @@ Json::Value RPCHandler::doCommand(Json::Value& jvParams, int iRole) { "unl_score", &RPCHandler::doUnlScore, -1, -1, true, false, optNone }, { "validation_create", &RPCHandler::doValidationCreate, -1, -1, false, false, optNone }, - { "validation_seed", &RPCHandler::doValidationSeed, 0, 1, false, false, optNone }, + { "validation_seed", &RPCHandler::doValidationSeed, -1, -1, false, false, optNone }, { "wallet_accounts", &RPCHandler::doWalletAccounts, -1, -1, false, false, optCurrent }, { "wallet_propose", &RPCHandler::doWalletPropose, -1, -1, false, false, optNone },