rippled
Loading...
Searching...
No Matches
ValidatorKeys.cpp
1#include <xrpld/app/misc/Manifest.h>
2#include <xrpld/app/misc/ValidatorKeys.h>
3#include <xrpld/core/Config.h>
4#include <xrpld/core/ConfigSections.h>
5
6#include <xrpl/basics/Log.h>
7#include <xrpl/basics/base64.h>
8
9namespace xrpl {
11{
12 if (config.exists(SECTION_VALIDATOR_TOKEN) && config.exists(SECTION_VALIDATION_SEED))
13 {
14 configInvalid_ = true;
15 JLOG(j.fatal()) << "Cannot specify both [" SECTION_VALIDATION_SEED "] and [" SECTION_VALIDATOR_TOKEN "]";
16 return;
17 }
18
19 if (config.exists(SECTION_VALIDATOR_TOKEN))
20 {
21 // token is non-const so it can be moved from
22 if (auto token = loadValidatorToken(config.section(SECTION_VALIDATOR_TOKEN).lines()))
23 {
24 auto const pk = derivePublicKey(KeyType::secp256k1, token->validationSecret);
25 auto const m = deserializeManifest(base64_decode(token->manifest));
26
27 if (!m || pk != m->signingKey)
28 {
29 configInvalid_ = true;
30 JLOG(j.fatal()) << "Invalid token specified in [" SECTION_VALIDATOR_TOKEN "]";
31 }
32 else
33 {
34 keys.emplace(m->masterKey, pk, token->validationSecret);
35 nodeID = calcNodeID(m->masterKey);
36 sequence = m->sequence;
37 manifest = std::move(token->manifest);
38 }
39 }
40 else
41 {
42 configInvalid_ = true;
43 JLOG(j.fatal()) << "Invalid token specified in [" SECTION_VALIDATOR_TOKEN "]";
44 }
45 }
46 else if (config.exists(SECTION_VALIDATION_SEED))
47 {
48 auto const seed = parseBase58<Seed>(config.section(SECTION_VALIDATION_SEED).lines().front());
49 if (!seed)
50 {
51 configInvalid_ = true;
52 JLOG(j.fatal()) << "Invalid seed specified in [" SECTION_VALIDATION_SEED "]";
53 }
54 else
55 {
58 keys.emplace(pk, pk, sk);
59 nodeID = calcNodeID(pk);
60 sequence = 0;
61 }
62 }
63}
64} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:41
Stream fatal() const
Definition Journal.h:325
bool exists(std::string const &name) const
Returns true if a section with the given name exists.
Section & section(std::string const &name)
Returns the section with the given name.
A public key.
Definition PublicKey.h:43
A secret key.
Definition SecretKey.h:19
std::vector< std::string > const & lines() const
Returns all the lines in the section.
Definition BasicConfig.h:50
std::uint32_t sequence
std::optional< Keys > keys
T front(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
PublicKey derivePublicKey(KeyType type, SecretKey const &sk)
Derive the public key from a secret key.
std::string base64_decode(std::string_view data)
SecretKey generateSecretKey(KeyType type, Seed const &seed)
Generate a new secret key deterministically.
std::optional< Manifest > deserializeManifest(Slice s, beast::Journal journal)
Constructs Manifest from serialized string.
Definition Manifest.cpp:35
std::optional< ValidatorToken > loadValidatorToken(std::vector< std::string > const &blob, beast::Journal journal)
Definition Manifest.cpp:230
NodeID calcNodeID(PublicKey const &)
Calculate the 160-bit node ID from a node public key.