Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove default constructor from SecretKey class #4607

Merged
merged 54 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
4580b25
fix #4569: clang warning about deprecated sprintf usage.
ckeshava Jun 12, 2023
dcc6a05
fix #2942: Remove default constructor from SecretKey, Account class
ckeshava Jul 1, 2023
e87fa0c
Prevent default construction of public keys in ValidatorList class da…
ckeshava Jul 6, 2023
76fa8e7
Refactor ValidatorList::verify() function to return masterPublicKey
ckeshava Jul 7, 2023
36fdb4c
- Update the access control of PublicKey class's default constructor …
ckeshava Jul 17, 2023
73e8ccc
Split ValidatorList::publisherList variable into two variables. local…
ckeshava Jul 24, 2023
d086635
git clang format
ckeshava Jul 24, 2023
61c3c09
Remove unused code from PublicKey test file. This code was intended t…
ckeshava Jul 24, 2023
0e6df2a
rewire the internal representation of PublicKey::emptyPubKey
ckeshava Jul 24, 2023
ad4e0b1
PublicKey::size_ data member is declared as "static". Since all the c…
ckeshava Jul 25, 2023
35d4db2
Delete the default constructor of Public Key class
ckeshava Jul 25, 2023
b57e67e
- address Scott Schurr's comments: group all of the Public and Secret…
ckeshava Aug 2, 2023
295dc4d
address PR comments: remove getter functions for ValidatorKeys::Keys.…
ckeshava Aug 4, 2023
2af13a7
address Scott Schurr's comments
ckeshava Aug 15, 2023
3bd7066
address Ed's comments
ckeshava Aug 23, 2023
29e7046
Merge remote-tracking branch 'upstream/develop' into ppp
ckeshava Aug 24, 2023
6a6dbbb
address second partial review comments by Ed
ckeshava Aug 25, 2023
998d959
address comments from Ed about the usage of const& and asserts in the…
ckeshava Sep 5, 2023
afa6425
clang format changes
ckeshava Sep 5, 2023
7df60ff
Merge branch 'develop' into ppp
ckeshava Sep 5, 2023
c0934a4
include checks for the seatedness of RPCHelpers::keyPairForSignature …
ckeshava Sep 6, 2023
618d040
Merge branch 'ppp' of https://github.com/ckeshava/rippled into ppp
ckeshava Sep 6, 2023
b195d0f
refactor positive KeyGeneration tests to avoid Undefined Behavior
ckeshava Sep 12, 2023
f69b0d0
clang format
ckeshava Sep 12, 2023
92fa86d
Merge branch 'develop' into ppp
ckeshava Sep 12, 2023
ec3f3db
revert the clang-format changes to the external secp256k1 files
ckeshava Oct 10, 2023
72507e1
Merge remote-tracking branch 'upstream/develop' into ppp
ckeshava Oct 10, 2023
a2803f4
fix the unit tests associated with XChainBridge
ckeshava Oct 10, 2023
44627dc
Merge branch 'develop' into ppp
ckeshava Oct 20, 2023
236c4ef
fix failing Linux Debug builds: do not call with ValidatorList::load(…
ckeshava Oct 20, 2023
440d662
eliminate the usage of PublicKey::emptyPubKey and associated methods.…
ckeshava Oct 25, 2023
8554535
address review comments. remove old code
ckeshava Oct 25, 2023
0b0c52f
addressing Ed's comments
ckeshava Oct 30, 2023
a4a6028
[FOLD] Refactor SigningForParams
ximinez Aug 25, 2023
200c258
Merge branch 'develop' into ppp
ckeshava Oct 30, 2023
077681f
address minor PR review comments
ckeshava Oct 30, 2023
e57163e
Merge branch 'ppp' of https://github.com/ckeshava/rippled into ppp
ckeshava Oct 30, 2023
e26d1a3
Merge branch 'develop' into ppp
ckeshava Dec 6, 2023
5668d86
fix the errors from merging develop. remove reference to old code (pr…
ckeshava Dec 7, 2023
a10c802
Merge branch 'develop' into ppp
ckeshava Dec 7, 2023
37efe06
addressing PR comments from Ed
ckeshava Dec 9, 2023
1e5cc56
Merge branch 'ppp' of https://github.com/ckeshava/rippled into ppp
ckeshava Dec 9, 2023
d2c2857
Merge branch 'develop' into ppp
ckeshava Dec 20, 2023
2252b46
Merge branch 'develop' into ppp
ckeshava Jan 5, 2024
eb24be8
resolve the compilation issues by removing references to SubmitSync i…
ckeshava Jan 5, 2024
007a28f
Merge branch 'develop' into ppp
ckeshava Jan 5, 2024
1a86148
Merge branch 'develop' into ppp
ckeshava Jan 16, 2024
4fd004d
address PR comments from Scott Schurr
ckeshava Feb 2, 2024
8aada82
Merge branch 'develop' into ppp
ckeshava Feb 2, 2024
08b0cf1
addressed PR comments from Ed
ckeshava Feb 22, 2024
1bdba3d
Merge branch 'develop' into ppp
ckeshava Feb 22, 2024
39d533f
rephrase a comment as per Scott Schurr's suggestions
ckeshava Feb 28, 2024
38fdb48
Merge branch 'develop' into ppp
ckeshava Feb 28, 2024
3cbd95a
Merge branch 'develop' into ppp
ximinez Mar 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/ripple/app/consensus/RCLConsensus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ RCLConsensus::Adaptor::Adaptor(
JLOG(j_.info()) << "Validator identity: "
<< toBase58(
TokenType::NodePublic,
*validatorKeys_.masterPublicKey);
*validatorKeys_.getMasterPublicKey());
scottschurr marked this conversation as resolved.
Show resolved Hide resolved

if (validatorKeys_.masterPublicKey != validatorKeys_.publicKey)
if (validatorKeys_.getMasterPublicKey() != validatorKeys_.getPublicKey())
{
JLOG(j_.debug())
<< "Validator ephemeral signing key: "
<< toBase58(TokenType::NodePublic, *validatorKeys_.publicKey)
<< toBase58(TokenType::NodePublic, *validatorKeys_.getPublicKey())
<< " (seq: " << std::to_string(validatorKeys_.sequence) << ")";
}
}
Expand Down Expand Up @@ -211,11 +211,11 @@ RCLConsensus::Adaptor::propose(RCLCxPeerPos::Proposal const& proposal)
prop.set_proposeseq(proposal.proposeSeq());
prop.set_closetime(proposal.closeTime().time_since_epoch().count());
prop.set_nodepubkey(
validatorKeys_.publicKey->data(), validatorKeys_.publicKey->size());
validatorKeys_.getPublicKey()->data(), validatorKeys_.getPublicKey()->size());

auto sig = signDigest(
*validatorKeys_.publicKey,
*validatorKeys_.secretKey,
*validatorKeys_.getPublicKey(),
*validatorKeys_.getSecretKey(),
proposal.signingHash());

prop.set_signature(sig.data(), sig.size());
Expand All @@ -225,7 +225,7 @@ RCLConsensus::Adaptor::propose(RCLCxPeerPos::Proposal const& proposal)
proposal.prevLedger(),
proposal.proposeSeq(),
proposal.closeTime(),
*validatorKeys_.publicKey,
*validatorKeys_.getPublicKey(),
sig);

app_.getHashRouter().addSuppression(suppression);
Expand Down Expand Up @@ -801,8 +801,8 @@ RCLConsensus::Adaptor::validate(

auto v = std::make_shared<STValidation>(
lastValidationTime_,
*validatorKeys_.publicKey,
*validatorKeys_.secretKey,
*validatorKeys_.getPublicKey(),
*validatorKeys_.getSecretKey(),
validatorKeys_.nodeID,
[&](STValidation& v) {
v.setFieldH256(sfLedgerHash, ledger.id());
Expand Down Expand Up @@ -960,8 +960,8 @@ RCLConsensus::Adaptor::preStartRound(
{
// We have a key, we do not want out of sync validations after a restart
// and are not amendment blocked.
validating_ = validatorKeys_.publicKey &&
validatorKeys_.publicKey->size() != 0 &&
validating_ = validatorKeys_.getPublicKey() &&
validatorKeys_.getPublicKey() != PublicKey::emptyPubKey &&
prevLgr.seq() >= app_.getMaxDisallowedLedger() &&
!app_.getOPs().isBlocked();

Expand Down Expand Up @@ -1034,7 +1034,7 @@ RCLConsensus::Adaptor::laggards(
bool
RCLConsensus::Adaptor::validator() const
{
return validatorKeys_.publicKey.has_value();
return validatorKeys_.getPublicKey().has_value();
}

void
Expand Down
13 changes: 8 additions & 5 deletions src/ripple/app/main/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,9 +593,12 @@ class ApplicationImp : public Application, public BasicApp
PublicKey const&
getValidationPublicKey() const override
{
if (!validatorKeys_.publicKey)
if (!validatorKeys_.getPublicKey())
return PublicKey::emptyPubKey;
return *validatorKeys_.publicKey;

// do not use the getter function from ValidatorKeys class because
// const& is returned from this function
scottschurr marked this conversation as resolved.
Show resolved Hide resolved
return validatorKeys_.keys->publicKey;
}

NetworkOPs&
Expand Down Expand Up @@ -1198,7 +1201,7 @@ ApplicationImp::setup(boost::program_options::variables_map const& cmdline)
return false;
}

if (validatorKeys_.publicKey)
if (validatorKeys_.getPublicKey().has_value())
setMaxDisallowedLedger();

// Configure the amendments the server supports
Expand Down Expand Up @@ -1326,8 +1329,8 @@ ApplicationImp::setup(boost::program_options::variables_map const& cmdline)
// ValidatorKeys object.

PublicKey localSigningKey = PublicKey::emptyPubKey;
if (validatorKeys_.publicKey)
localSigningKey = *validatorKeys_.publicKey;
if (validatorKeys_.getPublicKey())
localSigningKey = *validatorKeys_.getPublicKey();

// Setup trusted validators
if (!validators_->load(
Expand Down
54 changes: 51 additions & 3 deletions src/ripple/app/misc/ValidatorKeys.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,30 @@ class Config;
class ValidatorKeys
{
public:
std::optional<PublicKey> masterPublicKey;
std::optional<PublicKey> publicKey;
std::optional<SecretKey> secretKey;
// Group all keys in a struct. Either all keys are valid or none are.
struct Keys
{
PublicKey masterPublicKey;
PublicKey publicKey;
SecretKey secretKey;

Keys() = delete;
Keys(
SecretKey const& secret_,
PublicKey const& public_,
PublicKey const& masterPublic_
scottschurr marked this conversation as resolved.
Show resolved Hide resolved
)
: masterPublicKey(masterPublic_)
, publicKey(public_)
, secretKey(secret_)
{ }
};

// Note: The existence of keys cannot be used as a proxy for checking the
// validity of a configuration. It is possible to have a valid
// configuration while not setting the keys, as per the constructor of
// the ValidatorKeys class.
std::optional<Keys> keys;
NodeID nodeID;
std::string manifest;
std::uint32_t sequence = 0;
Expand All @@ -52,6 +73,33 @@ class ValidatorKeys
return configInvalid_;
}

// Note: prefer the use of getter functions. If a const& is required for
// the publicKey, then the data member is accessed directly. An example
// is used in ApplicationImp::getValidationPublicKey()
std::optional<PublicKey const> getPublicKey() const
{
if (keys)
return keys->publicKey;

return {};
}

std::optional<PublicKey const> getMasterPublicKey() const
{
if (keys)
return keys->masterPublicKey;

return {};
}

std::optional<SecretKey const> getSecretKey() const
{
if (keys)
return keys->secretKey;

return {};
}

private:
bool configInvalid_ = false; //< Set to true if config was invalid
};
Expand Down
13 changes: 6 additions & 7 deletions src/ripple/app/misc/impl/ValidatorKeys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ ValidatorKeys::ValidatorKeys(Config const& config, beast::Journal j)
}
else
{
secretKey = token->validationSecret;
publicKey = pk;
masterPublicKey = m->masterKey;
keys.emplace(token->validationSecret, pk, m->masterKey);
scottschurr marked this conversation as resolved.
Show resolved Hide resolved
ximinez marked this conversation as resolved.
Show resolved Hide resolved
nodeID = calcNodeID(m->masterKey);
sequence = m->sequence;
manifest = std::move(token->manifest);
Expand All @@ -83,10 +81,11 @@ ValidatorKeys::ValidatorKeys(Config const& config, beast::Journal j)
}
else
{
secretKey = generateSecretKey(KeyType::secp256k1, *seed);
publicKey = derivePublicKey(KeyType::secp256k1, *secretKey);
masterPublicKey = *publicKey;
nodeID = calcNodeID(*publicKey);
SecretKey sk = generateSecretKey(KeyType::secp256k1, *seed);
PublicKey pk = derivePublicKey(KeyType::secp256k1, sk);
keys.emplace(sk,
scottschurr marked this conversation as resolved.
Show resolved Hide resolved
derivePublicKey(KeyType::secp256k1, sk), pk);
scottschurr marked this conversation as resolved.
Show resolved Hide resolved
ximinez marked this conversation as resolved.
Show resolved Hide resolved
nodeID = calcNodeID(pk);
sequence = 0;
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/test/app/ValidatorKeys_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class ValidatorKeys_test : public beast::unit_test::suite
// No config -> no key but valid
Config c;
ValidatorKeys k{c, journal};
BEAST_EXPECT(!k.publicKey);
BEAST_EXPECT(!k.getPublicKey());
BEAST_EXPECT(k.manifest.empty());
BEAST_EXPECT(!k.configInvalid());
}
Expand All @@ -117,8 +117,8 @@ class ValidatorKeys_test : public beast::unit_test::suite
c.section(SECTION_VALIDATION_SEED).append(seed);

ValidatorKeys k{c, journal};
BEAST_EXPECT(k.publicKey == seedPublicKey);
BEAST_EXPECT(k.secretKey == seedSecretKey);
BEAST_EXPECT(k.getPublicKey() == seedPublicKey);
BEAST_EXPECT(k.getSecretKey() == seedSecretKey);
BEAST_EXPECT(k.nodeID == seedNodeID);
BEAST_EXPECT(k.manifest.empty());
BEAST_EXPECT(!k.configInvalid());
Expand All @@ -131,7 +131,7 @@ class ValidatorKeys_test : public beast::unit_test::suite

ValidatorKeys k{c, journal};
BEAST_EXPECT(k.configInvalid());
BEAST_EXPECT(!k.publicKey);
BEAST_EXPECT(!k.getPublicKey());
BEAST_EXPECT(k.manifest.empty());
}

Expand All @@ -141,8 +141,8 @@ class ValidatorKeys_test : public beast::unit_test::suite
c.section(SECTION_VALIDATOR_TOKEN).append(tokenBlob);
ValidatorKeys k{c, journal};

BEAST_EXPECT(k.publicKey == tokenPublicKey);
BEAST_EXPECT(k.secretKey == tokenSecretKey);
BEAST_EXPECT(k.getPublicKey() == tokenPublicKey);
BEAST_EXPECT(k.getSecretKey() == tokenSecretKey);
BEAST_EXPECT(k.nodeID == tokenNodeID);
BEAST_EXPECT(k.manifest == tokenManifest);
BEAST_EXPECT(!k.configInvalid());
Expand All @@ -153,7 +153,7 @@ class ValidatorKeys_test : public beast::unit_test::suite
c.section(SECTION_VALIDATOR_TOKEN).append("badtoken");
ValidatorKeys k{c, journal};
BEAST_EXPECT(k.configInvalid());
BEAST_EXPECT(!k.publicKey);
BEAST_EXPECT(!k.getPublicKey());
BEAST_EXPECT(k.manifest.empty());
}

Expand All @@ -165,7 +165,7 @@ class ValidatorKeys_test : public beast::unit_test::suite
ValidatorKeys k{c, journal};

BEAST_EXPECT(k.configInvalid());
BEAST_EXPECT(!k.publicKey);
BEAST_EXPECT(!k.getPublicKey());
BEAST_EXPECT(k.manifest.empty());
}

Expand All @@ -176,7 +176,7 @@ class ValidatorKeys_test : public beast::unit_test::suite
ValidatorKeys k{c, journal};

BEAST_EXPECT(k.configInvalid());
BEAST_EXPECT(!k.publicKey);
BEAST_EXPECT(!k.getPublicKey());
BEAST_EXPECT(k.manifest.empty());
}
}
Expand Down