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 ripple {
11{
12 if (config.exists(SECTION_VALIDATOR_TOKEN) &&
13 config.exists(SECTION_VALIDATION_SEED))
14 {
15 configInvalid_ = true;
16 JLOG(j.fatal()) << "Cannot specify both [" SECTION_VALIDATION_SEED
17 "] and [" SECTION_VALIDATOR_TOKEN "]";
18 return;
19 }
20
21 if (config.exists(SECTION_VALIDATOR_TOKEN))
22 {
23 // token is non-const so it can be moved from
24 if (auto token = loadValidatorToken(
25 config.section(SECTION_VALIDATOR_TOKEN).lines()))
26 {
27 auto const pk =
28 derivePublicKey(KeyType::secp256k1, token->validationSecret);
29 auto const m = deserializeManifest(base64_decode(token->manifest));
30
31 if (!m || pk != m->signingKey)
32 {
33 configInvalid_ = true;
34 JLOG(j.fatal())
35 << "Invalid token specified in [" SECTION_VALIDATOR_TOKEN
36 "]";
37 }
38 else
39 {
40 keys.emplace(m->masterKey, pk, token->validationSecret);
41 nodeID = calcNodeID(m->masterKey);
42 sequence = m->sequence;
43 manifest = std::move(token->manifest);
44 }
45 }
46 else
47 {
48 configInvalid_ = true;
49 JLOG(j.fatal())
50 << "Invalid token specified in [" SECTION_VALIDATOR_TOKEN "]";
51 }
52 }
53 else if (config.exists(SECTION_VALIDATION_SEED))
54 {
55 auto const seed = parseBase58<Seed>(
56 config.section(SECTION_VALIDATION_SEED).lines().front());
57 if (!seed)
58 {
59 configInvalid_ = true;
60 JLOG(j.fatal())
61 << "Invalid seed specified in [" SECTION_VALIDATION_SEED "]";
62 }
63 else
64 {
67 keys.emplace(pk, pk, sk);
68 nodeID = calcNodeID(pk);
69 sequence = 0;
70 }
71 }
72}
73} // namespace ripple
A generic endpoint for log messages.
Definition Journal.h:41
Stream fatal() const
Definition Journal.h:333
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:51
std::optional< Keys > keys
std::uint32_t sequence
T front(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
std::optional< Manifest > deserializeManifest(Slice s, beast::Journal journal)
Constructs Manifest from serialized string.
Definition Manifest.cpp:35
std::string base64_decode(std::string_view data)
PublicKey derivePublicKey(KeyType type, SecretKey const &sk)
Derive the public key from a secret key.
SecretKey generateSecretKey(KeyType type, Seed const &seed)
Generate a new secret key deterministically.
NodeID calcNodeID(PublicKey const &)
Calculate the 160-bit node ID from a node public key.
std::optional< ValidatorToken > loadValidatorToken(std::vector< std::string > const &blob, beast::Journal journal)
Definition Manifest.cpp:245