rippled
rpc/handlers/Manifest.cpp
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2019 Dev Null Productions
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #include <ripple/app/main/Application.h>
21 #include <ripple/basics/base64.h>
22 #include <ripple/json/json_value.h>
23 #include <ripple/net/RPCErr.h>
24 #include <ripple/protocol/ErrorCodes.h>
25 #include <ripple/protocol/jss.h>
26 #include <ripple/rpc/Context.h>
27 
28 namespace ripple {
31 {
32  if (context.app.config().reporting())
34 
35  auto& params = context.params;
36 
37  if (!params.isMember(jss::public_key))
38  return RPC::missing_field_error(jss::public_key);
39 
40  auto const requested = params[jss::public_key].asString();
41 
42  Json::Value ret;
43  ret[jss::requested] = requested;
44 
45  auto const pk = parseBase58<PublicKey>(TokenType::NodePublic, requested);
46  if (!pk)
47  {
49  return ret;
50  }
51 
52  // first attempt to use params as ephemeral key,
53  // if this lookup succeeds master key will be returned,
54  // else pk will just be returned and we will assume that
55  // is master key anyways
56  auto const mk = context.app.validatorManifests().getMasterKey(*pk);
57 
58  auto const ek = context.app.validatorManifests().getSigningKey(mk);
59 
60  // if ephemeral key not found, we don't have specified manifest
61  if (ek == mk)
62  return ret;
63 
64  if (auto const manifest = context.app.validatorManifests().getManifest(mk))
65  ret[jss::manifest] = base64_encode(*manifest);
66  Json::Value details;
67 
68  details[jss::master_key] = toBase58(TokenType::NodePublic, mk);
69  details[jss::ephemeral_key] = toBase58(TokenType::NodePublic, ek);
70 
71  if (auto const seq = context.app.validatorManifests().getSequence(mk))
72  details[jss::seq] = *seq;
73 
74  if (auto const domain = context.app.validatorManifests().getDomain(mk))
75  details[jss::domain] = *domain;
76 
77  ret[jss::details] = details;
78  return ret;
79 }
80 } // namespace ripple
ripple::RPC::JsonContext
Definition: Context.h:53
ripple::ManifestCache::getMasterKey
PublicKey getMasterKey(PublicKey const &pk) const
Returns ephemeral signing key's master public key.
Definition: app/misc/impl/Manifest.cpp:303
ripple::rpcINVALID_PARAMS
@ rpcINVALID_PARAMS
Definition: ErrorCodes.h:84
ripple::rpcError
Json::Value rpcError(int iError)
Definition: RPCErr.cpp:29
ripple::HashPrefix::manifest
@ manifest
Manifest.
ripple::base64_encode
std::string base64_encode(std::uint8_t const *data, std::size_t len)
Definition: base64.cpp:236
ripple::toBase58
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition: AccountID.cpp:104
ripple::doManifest
Json::Value doManifest(RPC::JsonContext &)
Definition: rpc/handlers/Manifest.cpp:30
ripple::rpcREPORTING_UNSUPPORTED
@ rpcREPORTING_UNSUPPORTED
Definition: ErrorCodes.h:141
ripple::RPC::missing_field_error
Json::Value missing_field_error(std::string const &name)
Definition: ErrorCodes.h:262
ripple::Config::reporting
bool reporting() const
Definition: Config.h:337
ripple::Application::config
virtual Config & config()=0
ripple::RPC::Context::app
Application & app
Definition: Context.h:42
ripple::ManifestCache::getSigningKey
PublicKey getSigningKey(PublicKey const &pk) const
Returns master key's current signing key.
Definition: app/misc/impl/Manifest.cpp:291
ripple::ManifestCache::getSequence
std::optional< std::uint32_t > getSequence(PublicKey const &pk) const
Returns master key's current manifest sequence.
Definition: app/misc/impl/Manifest.cpp:315
ripple::ManifestCache::getManifest
std::optional< std::string > getManifest(PublicKey const &pk) const
Returns mainfest corresponding to a given public key.
Definition: app/misc/impl/Manifest.cpp:339
ripple::ManifestCache::getDomain
std::optional< std::string > getDomain(PublicKey const &pk) const
Returns domain claimed by a given public key.
Definition: app/misc/impl/Manifest.cpp:327
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::Application::validatorManifests
virtual ManifestCache & validatorManifests()=0
ripple::TokenType::NodePublic
@ NodePublic
ripple::RPC::JsonContext::params
Json::Value params
Definition: Context.h:64
ripple::RPC::inject_error
void inject_error(error_code_i code, JsonValue &json)
Add or update the json update to reflect the error code.
Definition: ErrorCodes.h:212
Json::Value
Represents a JSON value.
Definition: json_value.h:145