xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
xrpld
app
misc
detail
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
17
namespace
xrpl
{
18
ValidatorKeys::ValidatorKeys
(
Config
const
& config,
beast::Journal
j)
19
{
20
if
(config.
exists
(
Sections::kValidatorToken
) && config.
exists
(
Sections::kValidationSeed
))
21
{
22
configInvalid_
=
true
;
23
JLOG(j.
fatal
()) <<
"Cannot specify both ["
<<
Sections::kValidationSeed
<<
"] and ["
24
<<
Sections::kValidatorToken
<<
"]"
;
25
return
;
26
}
27
28
if
(config.
exists
(
Sections::kValidatorToken
))
29
{
30
// token is non-const so it can be moved from
31
if
(
auto
token =
loadValidatorToken
(config.
section
(
Sections::kValidatorToken
).
lines
()))
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 =
59
parseBase58<Seed>
(config.
section
(
Sections::kValidationSeed
).
lines
().
front
());
60
if
(!seed)
61
{
62
configInvalid_
=
true
;
63
JLOG(j.
fatal
()) <<
"Invalid seed specified in ["
<<
Sections::kValidationSeed
<<
"]"
;
64
}
65
else
66
{
67
SecretKey
const
sk =
generateSecretKey
(
KeyType::Secp256k1
, *seed);
68
PublicKey
const
pk =
derivePublicKey
(
KeyType::Secp256k1
, sk);
69
keys
.emplace(pk, pk, sk);
70
nodeID
=
calcNodeID
(pk);
71
sequence
= 0;
72
}
73
}
74
}
75
}
// namespace xrpl
beast::Journal
A generic endpoint for log messages.
Definition
Journal.h:44
beast::Journal::fatal
Stream fatal() const
Definition
Journal.h:368
xrpl::BasicConfig::exists
bool exists(std::string const &name) const
Returns true if a section with the given name exists.
Definition
BasicConfig.cpp:115
xrpl::BasicConfig::section
Section & section(std::string const &name)
Returns the section with the given name.
Definition
BasicConfig.cpp:121
xrpl::Config
Definition
src/xrpld/core/Config.h:89
xrpl::PublicKey
A public key.
Definition
PublicKey.h:53
xrpl::SecretKey
A secret key.
Definition
SecretKey.h:24
xrpl::Section::lines
std::vector< std::string > const & lines() const
Returns all the lines in the section.
Definition
BasicConfig.h:58
xrpl::ValidatorKeys::configInvalid_
bool configInvalid_
Definition
ValidatorKeys.h:56
xrpl::ValidatorKeys::sequence
std::uint32_t sequence
Definition
ValidatorKeys.h:44
xrpl::ValidatorKeys::manifest
std::string manifest
Definition
ValidatorKeys.h:43
xrpl::ValidatorKeys::ValidatorKeys
ValidatorKeys()=delete
xrpl::ValidatorKeys::nodeID
NodeID nodeID
Definition
ValidatorKeys.h:42
xrpl::ValidatorKeys::keys
std::optional< Keys > keys
Definition
ValidatorKeys.h:41
std::vector::front
T front(T... args)
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::KeyType::Secp256k1
@ Secp256k1
Definition
KeyType.h:9
xrpl::base64Decode
std::string base64Decode(std::string_view data)
Definition
libxrpl/basics/base64.cpp:199
xrpl::derivePublicKey
PublicKey derivePublicKey(KeyType type, SecretKey const &sk)
Derive the public key from a secret key.
Definition
SecretKey.cpp:306
xrpl::parseBase58
std::optional< AccountID > parseBase58(std::string const &s)
Parse AccountID from checked, base58 string.
Definition
AccountID.cpp:105
xrpl::generateSecretKey
SecretKey generateSecretKey(KeyType type, Seed const &seed)
Generate a new secret key deterministically.
Definition
SecretKey.cpp:284
xrpl::deserializeManifest
std::optional< Manifest > deserializeManifest(Slice s, beast::Journal journal)
Constructs Manifest from serialized string.
Definition
libxrpl/server/Manifest.cpp:59
xrpl::calcNodeID
NodeID calcNodeID(PublicKey const &)
Calculate the 160-bit node ID from a node public key.
Definition
PublicKey.cpp:296
xrpl::loadValidatorToken
std::optional< ValidatorToken > loadValidatorToken(std::vector< std::string > const &blob, beast::Journal journal=beast::Journal(beast::Journal::getNullSink()))
Definition
libxrpl/server/Manifest.cpp:265
xrpl::Sections::kValidationSeed
static constexpr auto kValidationSeed
Definition
Constants.h:67
xrpl::Sections::kValidatorToken
static constexpr auto kValidatorToken
Definition
Constants.h:73
utility
Generated by
1.17.0