mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Use SecretKey, PublicKey
This commit is contained in:
committed by
Nik Bougalis
parent
6fccd07479
commit
163e8eb8fc
@@ -36,8 +36,8 @@ make_Manifest (std::string s)
|
||||
STObject st (sfGeneric);
|
||||
SerialIter sit (s.data (), s.size ());
|
||||
st.set (sit);
|
||||
auto const opt_pk = get<AnyPublicKey>(st, sfPublicKey);
|
||||
auto const opt_spk = get<AnyPublicKey>(st, sfSigningPubKey);
|
||||
auto const opt_pk = get<PublicKey>(st, sfPublicKey);
|
||||
auto const opt_spk = get<PublicKey>(st, sfSigningPubKey);
|
||||
auto const opt_seq = get (st, sfSequence);
|
||||
auto const opt_sig = get (st, sfSignature);
|
||||
if (!opt_pk || !opt_spk || !opt_seq || !opt_sig)
|
||||
@@ -57,11 +57,11 @@ Stream&
|
||||
logMftAct (
|
||||
Stream& s,
|
||||
std::string const& action,
|
||||
AnyPublicKey const& pk,
|
||||
PublicKey const& pk,
|
||||
std::uint32_t seq)
|
||||
{
|
||||
s << "Manifest: " << action <<
|
||||
";Pk: " << toString (pk) <<
|
||||
";Pk: " << toBase58 (TokenType::TOKEN_NODE_PUBLIC, pk) <<
|
||||
";Seq: " << seq << ";";
|
||||
return s;
|
||||
}
|
||||
@@ -70,20 +70,20 @@ template<class Stream>
|
||||
Stream& logMftAct (
|
||||
Stream& s,
|
||||
std::string const& action,
|
||||
AnyPublicKey const& pk,
|
||||
PublicKey const& pk,
|
||||
std::uint32_t seq,
|
||||
std::uint32_t oldSeq)
|
||||
{
|
||||
s << "Manifest: " << action <<
|
||||
";Pk: " << toString (pk) <<
|
||||
";Pk: " << toBase58 (TokenType::TOKEN_NODE_PUBLIC, pk) <<
|
||||
";Seq: " << seq <<
|
||||
";OldSeq: " << oldSeq << ";";
|
||||
return s;
|
||||
}
|
||||
|
||||
Manifest::Manifest (std::string s,
|
||||
AnyPublicKey pk,
|
||||
AnyPublicKey spk,
|
||||
PublicKey pk,
|
||||
PublicKey spk,
|
||||
std::uint32_t seq)
|
||||
: serialized (std::move (s))
|
||||
, masterKey (std::move (pk))
|
||||
@@ -97,7 +97,7 @@ bool Manifest::verify () const
|
||||
STObject st (sfGeneric);
|
||||
SerialIter sit (serialized.data (), serialized.size ());
|
||||
st.set (sit);
|
||||
return ripple::verify (st, HashPrefix::manifest, masterKey);
|
||||
return ripple::verify (st, HashPrefix::manifest, masterKey, true);
|
||||
}
|
||||
|
||||
uint256 Manifest::hash () const
|
||||
@@ -146,11 +146,11 @@ ManifestCache::configValidatorKey(
|
||||
throw std::runtime_error ("Expected Ed25519 key (0xED)");
|
||||
}
|
||||
|
||||
auto const masterKey = AnyPublicKey (key.data() + 1, key.size() - 1);
|
||||
auto const masterKey = PublicKey (Slice(key.data() + 1, key.size() - 1));
|
||||
std::string comment = std::move(words[1]);
|
||||
|
||||
if (journal.debug) journal.debug
|
||||
<< masterKey << " " << comment;
|
||||
<< toBase58(TokenType::TOKEN_NODE_PUBLIC, masterKey) << " " << comment;
|
||||
|
||||
addTrustedKey (masterKey, std::move(comment));
|
||||
}
|
||||
@@ -172,7 +172,7 @@ ManifestCache::configManifest(Manifest m, beast::Journal const& journal)
|
||||
}
|
||||
|
||||
void
|
||||
ManifestCache::addTrustedKey (AnyPublicKey const& pk, std::string comment)
|
||||
ManifestCache::addTrustedKey (PublicKey const& pk, std::string comment)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock (mutex_);
|
||||
|
||||
@@ -188,7 +188,7 @@ ManifestCache::addTrustedKey (AnyPublicKey const& pk, std::string comment)
|
||||
}
|
||||
|
||||
ManifestDisposition
|
||||
ManifestCache::canApply (AnyPublicKey const& pk, std::uint32_t seq,
|
||||
ManifestCache::canApply (PublicKey const& pk, std::uint32_t seq,
|
||||
beast::Journal const& journal) const
|
||||
{
|
||||
auto const iter = map_.find(pk);
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#include <ripple/basics/BasicConfig.h>
|
||||
#include <ripple/basics/UnorderedContainers.h>
|
||||
#include <ripple/protocol/AnyPublicKey.h>
|
||||
#include <ripple/protocol/PublicKey.h>
|
||||
#include <ripple/protocol/STExchange.h>
|
||||
#include <beast/utility/Journal.h>
|
||||
#include <boost/optional.hpp>
|
||||
@@ -85,11 +85,11 @@ namespace ripple {
|
||||
struct Manifest
|
||||
{
|
||||
std::string serialized;
|
||||
AnyPublicKey masterKey;
|
||||
AnyPublicKey signingKey;
|
||||
PublicKey masterKey;
|
||||
PublicKey signingKey;
|
||||
std::uint32_t sequence;
|
||||
|
||||
Manifest(std::string s, AnyPublicKey pk, AnyPublicKey spk, std::uint32_t seq);
|
||||
Manifest(std::string s, PublicKey pk, PublicKey spk, std::uint32_t seq);
|
||||
|
||||
#ifdef _MSC_VER
|
||||
Manifest(Manifest&& other)
|
||||
@@ -166,7 +166,7 @@ private:
|
||||
#endif
|
||||
MappedType(std::string comment,
|
||||
std::string serialized,
|
||||
AnyPublicKey pk, AnyPublicKey spk, std::uint32_t seq)
|
||||
PublicKey pk, PublicKey spk, std::uint32_t seq)
|
||||
:comment (std::move(comment))
|
||||
{
|
||||
m.emplace (std::move(serialized), std::move(pk), std::move(spk),
|
||||
@@ -177,13 +177,13 @@ private:
|
||||
boost::optional<Manifest> m;
|
||||
};
|
||||
|
||||
using MapType = hash_map<AnyPublicKey, MappedType>;
|
||||
using MapType = hash_map<PublicKey, MappedType>;
|
||||
|
||||
mutable std::mutex mutex_;
|
||||
MapType map_;
|
||||
|
||||
ManifestDisposition
|
||||
canApply (AnyPublicKey const& pk, std::uint32_t seq,
|
||||
canApply (PublicKey const& pk, std::uint32_t seq,
|
||||
beast::Journal const& journal) const;
|
||||
|
||||
public:
|
||||
@@ -195,7 +195,7 @@ public:
|
||||
void configValidatorKey(std::string const& line, beast::Journal const& journal);
|
||||
void configManifest(Manifest m, beast::Journal const& journal);
|
||||
|
||||
void addTrustedKey (AnyPublicKey const& pk, std::string comment);
|
||||
void addTrustedKey (PublicKey const& pk, std::string comment);
|
||||
|
||||
ManifestDisposition
|
||||
applyManifest (Manifest m, beast::Journal const& journal);
|
||||
|
||||
@@ -1147,13 +1147,14 @@ PeerImp::onMessage (std::shared_ptr <protocol::TMProposeSet> const& m)
|
||||
if ((set.closetime() + 180) < getApp().getOPs().getCloseTimeNC())
|
||||
return;
|
||||
|
||||
auto const type = publicKeyType(
|
||||
makeSlice(set.nodepubkey()));
|
||||
|
||||
// VFALCO Magic numbers are bad
|
||||
// Roll this into a validation function
|
||||
if (
|
||||
if ((! type) ||
|
||||
(set.currenttxhash ().size () != 32) ||
|
||||
(set.nodepubkey ().size () < 28) ||
|
||||
(set.signature ().size () < 56) ||
|
||||
(set.nodepubkey ().size () > 128) ||
|
||||
(set.signature ().size () > 128)
|
||||
)
|
||||
{
|
||||
@@ -1215,7 +1216,8 @@ PeerImp::onMessage (std::shared_ptr <protocol::TMProposeSet> const& m)
|
||||
|
||||
auto proposal = std::make_shared<LedgerProposal> (
|
||||
prevLedger, set.proposeseq (), proposeHash, set.closetime (),
|
||||
signerPublic, suppression);
|
||||
signerPublic, PublicKey(makeSlice(set.nodepubkey())),
|
||||
suppression);
|
||||
|
||||
getApp().getJobQueue ().addJob (isTrusted ? jtPROPOSAL_t : jtPROPOSAL_ut,
|
||||
"recvPropose->checkPropose", std::bind(beast::weak_fn(
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <ripple/overlay/impl/Manifest.h>
|
||||
#include <ripple/core/DatabaseCon.h>
|
||||
#include <ripple/app/main/DBInit.h>
|
||||
#include <ripple/protocol/SecretKey.h>
|
||||
#include <ripple/protocol/Sign.h>
|
||||
#include <ripple/protocol/STExchange.h>
|
||||
#include <boost/filesystem.hpp>
|
||||
@@ -85,18 +86,18 @@ public:
|
||||
|
||||
Manifest
|
||||
make_Manifest
|
||||
(AnySecretKey const& sk, AnyPublicKey const& spk, int seq,
|
||||
(KeyType type, SecretKey const& sk, PublicKey const& spk, int seq,
|
||||
bool broken = false)
|
||||
{
|
||||
auto const pk = sk.publicKey();
|
||||
auto const pk = derivePublicKey(type, sk);
|
||||
|
||||
STObject st(sfGeneric);
|
||||
set(st, sfSequence, seq);
|
||||
set(st, sfPublicKey, pk);
|
||||
set(st, sfSigningPubKey, spk);
|
||||
|
||||
sign(st, HashPrefix::manifest, sk);
|
||||
expect(verify(st, HashPrefix::manifest, pk));
|
||||
sign(st, HashPrefix::manifest, type, sk);
|
||||
expect(verify(st, HashPrefix::manifest, pk, true));
|
||||
|
||||
if (broken)
|
||||
{
|
||||
@@ -191,19 +192,19 @@ public:
|
||||
|
||||
beast::Journal journal;
|
||||
|
||||
auto const sk_a = AnySecretKey::make_ed25519 ();
|
||||
auto const sk_b = AnySecretKey::make_ed25519 ();
|
||||
auto const pk_a = sk_a.publicKey ();
|
||||
auto const pk_b = sk_b.publicKey ();
|
||||
auto const kp_a = AnySecretKey::make_secp256k1_pair ();
|
||||
auto const kp_b = AnySecretKey::make_secp256k1_pair ();
|
||||
auto const sk_a = randomSecretKey();
|
||||
auto const pk_a = derivePublicKey(KeyType::ed25519, sk_a);
|
||||
auto const kp_a = randomKeyPair(KeyType::secp256k1);
|
||||
auto const s_a0 = make_Manifest (KeyType::ed25519, sk_a, kp_a.first, 0);
|
||||
auto const s_a1 = make_Manifest (KeyType::ed25519, sk_a, kp_a.first, 1);
|
||||
|
||||
auto const s_a0 = make_Manifest (sk_a, kp_a.second, 0);
|
||||
auto const s_a1 = make_Manifest (sk_a, kp_a.second, 1);
|
||||
auto const s_b0 = make_Manifest (sk_b, kp_b.second, 0);
|
||||
auto const s_b1 = make_Manifest (sk_b, kp_b.second, 1);
|
||||
auto const sk_b = randomSecretKey();
|
||||
auto const pk_b = derivePublicKey(KeyType::ed25519, sk_b);
|
||||
auto const kp_b = randomKeyPair(KeyType::secp256k1);
|
||||
auto const s_b0 = make_Manifest (KeyType::ed25519, sk_b, kp_b.first, 0);
|
||||
auto const s_b1 = make_Manifest (KeyType::ed25519, sk_b, kp_b.first, 1);
|
||||
auto const s_b2 =
|
||||
make_Manifest (sk_b, kp_b.second, 2, true); // broken
|
||||
make_Manifest (KeyType::ed25519, sk_b, kp_b.first, 2, true); // broken
|
||||
auto const fake = s_b1.serialized + '\0';
|
||||
|
||||
expect (cache.applyManifest (clone (s_a0), journal) == untrusted,
|
||||
|
||||
Reference in New Issue
Block a user