xrpld
Loading...
Searching...
No Matches
ValidatorKeys.cpp
1#include <xrpld/app/misc/ValidatorKeys.h>
2
3#include <xrpld/core/Config.h>
4
5#include <xrpl/basics/Log.h>
6#include <xrpl/basics/base64.h>
7#include <xrpl/beast/utility/Journal.h>
8#include <xrpl/config/Constants.h>
9#include <xrpl/protocol/KeyType.h>
10#include <xrpl/protocol/PublicKey.h>
11#include <xrpl/protocol/SecretKey.h>
12#include <xrpl/protocol/Seed.h>
13#include <xrpl/server/Manifest.h>
14
15#include <utility>
16
17namespace xrpl {
19{
21 {
22 configInvalid_ = true;
23 JLOG(j.fatal()) << "Cannot specify both [" << Sections::kValidationSeed << "] and ["
25 return;
26 }
27
29 {
30 // token is non-const so it can be moved from
32 {
33 auto const pk = derivePublicKey(KeyType::Secp256k1, token->validationSecret);
34 auto const m = deserializeManifest(base64Decode(token->manifest));
35
36 if (!m || pk != m->signingKey)
37 {
38 configInvalid_ = true;
39 JLOG(j.fatal()) << "Invalid token specified in [" << Sections::kValidatorToken
40 << "]";
41 }
42 else
43 {
44 keys.emplace(m->masterKey, pk, token->validationSecret);
45 nodeID = calcNodeID(m->masterKey);
46 sequence = m->sequence;
47 manifest = std::move(token->manifest);
48 }
49 }
50 else
51 {
52 configInvalid_ = true;
53 JLOG(j.fatal()) << "Invalid token specified in [" << Sections::kValidatorToken << "]";
54 }
55 }
56 else if (config.exists(Sections::kValidationSeed))
57 {
58 auto const seed =
60 if (!seed)
61 {
62 configInvalid_ = true;
63 JLOG(j.fatal()) << "Invalid seed specified in [" << Sections::kValidationSeed << "]";
64 }
65 else
66 {
69 keys.emplace(pk, pk, sk);
70 nodeID = calcNodeID(pk);
71 sequence = 0;
72 }
73 }
74}
75} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:38
Stream fatal() const
Definition Journal.h:321
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
std::string base64Decode(std::string_view data)
PublicKey derivePublicKey(KeyType type, SecretKey const &sk)
Derive the public key from a secret key.
std::optional< AccountID > parseBase58(std::string const &s)
Parse AccountID from checked, base58 string.
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()))
static constexpr auto kValidationSeed
Definition Constants.h:66
static constexpr auto kValidatorToken
Definition Constants.h:72