rippled
Loading...
Searching...
No Matches
ValidatorKeys.cpp
1#include <xrpld/app/misc/ValidatorKeys.h>
2#include <xrpld/core/Config.h>
3#include <xrpld/core/ConfigSections.h>
4
5#include <xrpl/basics/Log.h>
6#include <xrpl/basics/base64.h>
7#include <xrpl/server/Manifest.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
16 "] and [" SECTION_VALIDATOR_TOKEN "]";
17 return;
18 }
19
20 if (config.exists(SECTION_VALIDATOR_TOKEN))
21 {
22 // token is non-const so it can be moved from
23 if (auto token = loadValidatorToken(config.section(SECTION_VALIDATOR_TOKEN).lines()))
24 {
25 auto const pk = derivePublicKey(KeyType::secp256k1, token->validationSecret);
26 auto const m = deserializeManifest(base64_decode(token->manifest));
27
28 if (!m || pk != m->signingKey)
29 {
30 configInvalid_ = true;
31 JLOG(j.fatal()) << "Invalid token specified in [" SECTION_VALIDATOR_TOKEN "]";
32 }
33 else
34 {
35 keys.emplace(m->masterKey, pk, token->validationSecret);
36 nodeID = calcNodeID(m->masterKey);
37 sequence = m->sequence;
38 manifest = std::move(token->manifest);
39 }
40 }
41 else
42 {
43 configInvalid_ = true;
44 JLOG(j.fatal()) << "Invalid token specified in [" SECTION_VALIDATOR_TOKEN "]";
45 }
46 }
47 else if (config.exists(SECTION_VALIDATION_SEED))
48 {
49 auto const seed =
50 parseBase58<Seed>(config.section(SECTION_VALIDATION_SEED).lines().front());
51 if (!seed)
52 {
53 configInvalid_ = true;
54 JLOG(j.fatal()) << "Invalid seed specified in [" SECTION_VALIDATION_SEED "]";
55 }
56 else
57 {
60 keys.emplace(pk, pk, sk);
61 nodeID = calcNodeID(pk);
62 sequence = 0;
63 }
64 }
65}
66} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:40
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:42
A secret key.
Definition SecretKey.h:18
std::vector< std::string > const & lines() const
Returns all the lines in the section.
Definition BasicConfig.h:49
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:5
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.
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=beast::Journal(beast::Journal::getNullSink()))