Merge branch 'rpc_refactor'

This commit is contained in:
Arthur Britto
2012-12-03 18:08:56 -08:00
3 changed files with 115 additions and 56 deletions

View File

@@ -229,6 +229,34 @@ Json::Value RPCParser::parseUnlDelete(const Json::Value& jvParams)
return jvRequest; return jvRequest;
} }
// validation_create [<pass_phrase>|<seed>|<seed_key>]
//
// 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;
}
// validation_seed [<pass_phrase>|<seed>|<seed_key>]
//
// 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 <seed> // wallet_accounts <seed>
Json::Value RPCParser::parseWalletAccounts(const Json::Value& jvParams) Json::Value RPCParser::parseWalletAccounts(const Json::Value& jvParams)
{ {
@@ -239,6 +267,29 @@ Json::Value RPCParser::parseWalletAccounts(const Json::Value& jvParams)
return jvRequest; return jvRequest;
} }
// wallet_propose [<passphrase>]
// <passphrase> is only for testing. Master seeds should only be generated randomly.
Json::Value RPCParser::parseWalletPropose(const Json::Value& jvParams)
{
Json::Value jvRequest;
if (jvParams.size())
jvRequest["passphrase"] = jvParams[0u].asString();
return jvRequest;
}
// wallet_seed [<seed>|<passphrase>|<passkey>]
Json::Value RPCParser::parseWalletSeed(const Json::Value& jvParams)
{
Json::Value jvRequest;
if (jvParams.size())
jvRequest["secret"] = jvParams[0u].asString();
return jvRequest;
}
// //
// parseCommand // parseCommand
// //
@@ -263,9 +314,6 @@ Json::Value RPCParser::parseCommand(std::string strMethod, Json::Value jvParams)
{ "account_info", &RPCParser::parseAccountInfo, 1, 2 }, { "account_info", &RPCParser::parseAccountInfo, 1, 2 },
{ "account_tx", &RPCParser::parseAccountTransactions, 2, 3 }, { "account_tx", &RPCParser::parseAccountTransactions, 2, 3 },
{ "connect", &RPCParser::parseConnect, 1, 2 }, { "connect", &RPCParser::parseConnect, 1, 2 },
// { "data_delete", &RPCParser::doDataDelete, 1, 1, true, false, optNone },
// { "data_fetch", &RPCParser::doDataFetch, 1, 1, true, false, optNone },
// { "data_store", &RPCParser::doDataStore, 2, 2, true, false, optNone },
// { "get_counts", &RPCParser::doGetCounts, 0, 1, true, false, optNone }, // { "get_counts", &RPCParser::doGetCounts, 0, 1, true, false, optNone },
{ "ledger", &RPCParser::parseLedger, 0, 2 }, { "ledger", &RPCParser::parseLedger, 0, 2 },
{ "ledger_accept", &RPCParser::parseAsIs, 0, 0 }, { "ledger_accept", &RPCParser::parseAsIs, 0, 0 },
@@ -296,14 +344,18 @@ Json::Value RPCParser::parseCommand(std::string strMethod, Json::Value jvParams)
{ "unl_reset", &RPCParser::parseAsIs, 0, 0 }, { "unl_reset", &RPCParser::parseAsIs, 0, 0 },
{ "unl_score", &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 }, { "validation_seed", &RPCParser::parseValidationSeed, 0, 1 },
{ "wallet_accounts", &RPCParser::parseWalletAccounts, 1, 1 }, { "wallet_accounts", &RPCParser::parseWalletAccounts, 1, 1 },
// { "wallet_propose", &RPCParser::doWalletPropose, 0, 1, false, false, optNone }, { "wallet_propose", &RPCParser::parseWalletPropose, 0, 1 },
// { "wallet_seed", &RPCParser::doWalletSeed, 0, 1, false, false, optNone }, { "wallet_seed", &RPCParser::parseWalletSeed, 0, 1 },
//
// XXX Unnecessary commands which should be removed.
// { "login", &RPCParser::doLogin, 2, 2, true, false, optNone }, // { "login", &RPCParser::doLogin, 2, 2, true, false, optNone },
// { "data_delete", &RPCParser::doDataDelete, 1, 1, true, false, optNone },
// { "data_fetch", &RPCParser::doDataFetch, 1, 1, true, false, optNone },
// { "data_store", &RPCParser::doDataStore, 2, 2, true, false, optNone },
// Evented methods // Evented methods
{ "subscribe", &RPCParser::parseEvented, -1, -1 }, { "subscribe", &RPCParser::parseEvented, -1, -1 },

View File

@@ -11,17 +11,21 @@ class RPCParser
protected: protected:
typedef Json::Value (RPCParser::*parseFuncPtr)(const Json::Value &jvParams); typedef Json::Value (RPCParser::*parseFuncPtr)(const Json::Value &jvParams);
Json::Value parseAsIs(const Json::Value& jvParams);
Json::Value parseAccountInfo(const Json::Value& jvParams); Json::Value parseAccountInfo(const Json::Value& jvParams);
Json::Value parseAccountTransactions(const Json::Value& jvParams); Json::Value parseAccountTransactions(const Json::Value& jvParams);
Json::Value parseAsIs(const Json::Value& jvParams);
Json::Value parseConnect(const Json::Value& jvParams); Json::Value parseConnect(const Json::Value& jvParams);
Json::Value parseEvented(const Json::Value& jvParams); Json::Value parseEvented(const Json::Value& jvParams);
Json::Value parseLedger(const Json::Value& jvParams); Json::Value parseLedger(const Json::Value& jvParams);
Json::Value parseWalletAccounts(const Json::Value& jvParams);
Json::Value parseRippleLinesGet(const Json::Value& jvParams); Json::Value parseRippleLinesGet(const Json::Value& jvParams);
Json::Value parseSubmit(const Json::Value& jvParams); Json::Value parseSubmit(const Json::Value& jvParams);
Json::Value parseUnlAdd(const Json::Value& jvParams); Json::Value parseUnlAdd(const Json::Value& jvParams);
Json::Value parseUnlDelete(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);
public: public:
Json::Value parseCommand(std::string strMethod, Json::Value jvParams); Json::Value parseCommand(std::string strMethod, Json::Value jvParams);

View File

@@ -1237,40 +1237,38 @@ Json::Value RPCHandler::doAccountTransactions(Json::Value jvRequest)
#endif #endif
} }
// validation_create [<pass_phrase>|<seed>|<seed_key>] // {
// // secret: <string>
// 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 jvParams) {
Json::Value RPCHandler::doValidationCreate(Json::Value params) { RippleAddress raSeed;
RippleAddress naSeed;
Json::Value obj(Json::objectValue); 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); return rpcError(rpcBAD_SEED);
} }
obj["validation_public_key"] = RippleAddress::createNodePublic(naSeed).humanNodePublic(); obj["validation_public_key"] = RippleAddress::createNodePublic(raSeed).humanNodePublic();
obj["validation_seed"] = naSeed.humanSeed(); obj["validation_seed"] = raSeed.humanSeed();
obj["validation_key"] = naSeed.humanSeed1751(); obj["validation_key"] = raSeed.humanSeed1751();
return obj; return obj;
} }
// validation_seed [<pass_phrase>|<seed>|<seed_key>] // {
// // secret: <string>
// 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 jvRequest) {
Json::Value RPCHandler::doValidationSeed(Json::Value params) {
Json::Value obj(Json::objectValue); Json::Value obj(Json::objectValue);
if (params.empty()) if (!jvRequest.isMember("secret"))
{ {
std::cerr << "Unset validation seed." << std::endl; std::cerr << "Unset validation seed." << std::endl;
@@ -1278,16 +1276,18 @@ Json::Value RPCHandler::doValidationSeed(Json::Value params) {
theConfig.VALIDATION_PUB.clear(); theConfig.VALIDATION_PUB.clear();
theConfig.VALIDATION_PRIV.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_PUB.clear();
theConfig.VALIDATION_PRIV.clear(); theConfig.VALIDATION_PRIV.clear();
return rpcError(rpcBAD_SEED); return rpcError(rpcBAD_SEED);
} }
else else
{ {
theConfig.VALIDATION_PUB = RippleAddress::createNodePublic(theConfig.VALIDATION_SEED); theConfig.VALIDATION_PUB = RippleAddress::createNodePublic(theConfig.VALIDATION_SEED);
theConfig.VALIDATION_PRIV = RippleAddress::createNodePrivate(theConfig.VALIDATION_SEED); theConfig.VALIDATION_PRIV = RippleAddress::createNodePrivate(theConfig.VALIDATION_SEED);
obj["validation_public_key"] = theConfig.VALIDATION_PUB.humanNodePublic(); obj["validation_public_key"] = theConfig.VALIDATION_PUB.humanNodePublic();
obj["validation_seed"] = theConfig.VALIDATION_SEED.humanSeed(); obj["validation_seed"] = theConfig.VALIDATION_SEED.humanSeed();
obj["validation_key"] = theConfig.VALIDATION_SEED.humanSeed1751(); obj["validation_key"] = theConfig.VALIDATION_SEED.humanSeed1751();
@@ -1372,20 +1372,21 @@ Json::Value RPCHandler::doLogRotate(Json::Value)
return Log::rotateLog(); return Log::rotateLog();
} }
// wallet_propose [<passphrase>] // {
// <passphrase> is only for testing. Master seeds should only be generated randomly. // passphrase: <string>
Json::Value RPCHandler::doWalletPropose(Json::Value params) // }
Json::Value RPCHandler::doWalletPropose(Json::Value jvRequest)
{ {
RippleAddress naSeed; RippleAddress naSeed;
RippleAddress naAccount; RippleAddress naAccount;
if (params.empty()) if (jvRequest.isMember("passphrase"))
{ {
naSeed.setSeedRandom(); naSeed = RippleAddress::createSeedGeneric(jvRequest["passphrase"].asString());
} }
else else
{ {
naSeed = RippleAddress::createSeedGeneric(params[0u].asString()); naSeed.setSeedRandom();
} }
RippleAddress naGenerator = RippleAddress::createGeneratorPublic(naSeed); RippleAddress naGenerator = RippleAddress::createGeneratorPublic(naSeed);
@@ -1400,39 +1401,40 @@ Json::Value RPCHandler::doWalletPropose(Json::Value params)
return obj; return obj;
} }
// wallet_seed [<seed>|<passphrase>|<passkey>] // {
Json::Value RPCHandler::doWalletSeed(Json::Value params) // secret: <string>
// }
Json::Value RPCHandler::doWalletSeed(Json::Value jvRequest)
{ {
RippleAddress naSeed; RippleAddress raSeed;
bool bSecret = jvRequest.isMember("secret");
if (params.size() if (bSecret && !raSeed.setSeedGeneric(jvRequest["secret"].asString()))
&& !naSeed.setSeedGeneric(params[0u].asString()))
{ {
return rpcError(rpcBAD_SEED); return rpcError(rpcBAD_SEED);
} }
else else
{ {
RippleAddress naAccount; RippleAddress raAccount;
if (!params.size()) if (!bSecret)
{ {
naSeed.setSeedRandom(); raSeed.setSeedRandom();
} }
RippleAddress naGenerator = RippleAddress::createGeneratorPublic(naSeed); RippleAddress raGenerator = RippleAddress::createGeneratorPublic(raSeed);
naAccount.setAccountPublic(naGenerator, 0); raAccount.setAccountPublic(raGenerator, 0);
Json::Value obj(Json::objectValue); Json::Value obj(Json::objectValue);
obj["seed"] = naSeed.humanSeed(); obj["seed"] = raSeed.humanSeed();
obj["key"] = naSeed.humanSeed1751(); obj["key"] = raSeed.humanSeed1751();
return obj; return obj;
} }
} }
// TODO: for now this simply checks if this is the admin account // TODO: for now this simply checks if this is the admin account
// TODO: need to prevent them hammering this over and over // TODO: need to prevent them hammering this over and over
// TODO: maybe a better way is only allow admin from local host // TODO: maybe a better way is only allow admin from local host
@@ -2182,9 +2184,6 @@ Json::Value RPCHandler::doCommand(Json::Value& jvParams, int iRole)
{ "account_info", &RPCHandler::doAccountInfo, -1, -1, false, false, optCurrent }, { "account_info", &RPCHandler::doAccountInfo, -1, -1, false, false, optCurrent },
{ "account_tx", &RPCHandler::doAccountTransactions, -1, -1, false, false, optNetwork }, { "account_tx", &RPCHandler::doAccountTransactions, -1, -1, false, false, optNetwork },
{ "connect", &RPCHandler::doConnect, 1, 2, true, false, optNone }, { "connect", &RPCHandler::doConnect, 1, 2, true, false, optNone },
{ "data_delete", &RPCHandler::doDataDelete, 1, 1, true, false, optNone },
{ "data_fetch", &RPCHandler::doDataFetch, 1, 1, true, false, optNone },
{ "data_store", &RPCHandler::doDataStore, 2, 2, true, false, optNone },
{ "get_counts", &RPCHandler::doGetCounts, 0, 1, true, false, optNone }, { "get_counts", &RPCHandler::doGetCounts, 0, 1, true, false, optNone },
{ "ledger", &RPCHandler::doLedger, -1, -1, false, false, optNetwork }, { "ledger", &RPCHandler::doLedger, -1, -1, false, false, optNetwork },
{ "ledger_accept", &RPCHandler::doLedgerAccept, -1, -1, true, false, optCurrent }, { "ledger_accept", &RPCHandler::doLedgerAccept, -1, -1, true, false, optCurrent },
@@ -2215,14 +2214,18 @@ Json::Value RPCHandler::doCommand(Json::Value& jvParams, int iRole)
{ "unl_reset", &RPCHandler::doUnlReset, -1, -1, true, false, optNone }, { "unl_reset", &RPCHandler::doUnlReset, -1, -1, true, false, optNone },
{ "unl_score", &RPCHandler::doUnlScore, -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 }, { "validation_seed", &RPCHandler::doValidationSeed, -1, -1, false, false, optNone },
{ "wallet_accounts", &RPCHandler::doWalletAccounts, -1, -1, false, false, optCurrent }, { "wallet_accounts", &RPCHandler::doWalletAccounts, -1, -1, false, false, optCurrent },
{ "wallet_propose", &RPCHandler::doWalletPropose, 0, 1, false, false, optNone }, { "wallet_propose", &RPCHandler::doWalletPropose, -1, -1, false, false, optNone },
{ "wallet_seed", &RPCHandler::doWalletSeed, 0, 1, false, false, optNone }, { "wallet_seed", &RPCHandler::doWalletSeed, -1, -1, false, false, optNone },
// XXX Unnecessary commands which should be removed.
{ "login", &RPCHandler::doLogin, 2, 2, true, false, optNone }, { "login", &RPCHandler::doLogin, 2, 2, true, false, optNone },
{ "data_delete", &RPCHandler::doDataDelete, 1, 1, true, false, optNone },
{ "data_fetch", &RPCHandler::doDataFetch, 1, 1, true, false, optNone },
{ "data_store", &RPCHandler::doDataStore, 2, 2, true, false, optNone },
// Evented methods // Evented methods
{ "subscribe", &RPCHandler::doSubscribe, -1, -1, false, true, optNone }, { "subscribe", &RPCHandler::doSubscribe, -1, -1, false, true, optNone },