Use SecretKey, PublicKey

This commit is contained in:
Vinnie Falco
2015-07-10 19:55:39 -07:00
committed by Nik Bougalis
parent 6fccd07479
commit 163e8eb8fc
34 changed files with 202 additions and 693 deletions

View File

@@ -2711,10 +2711,6 @@
</ClCompile> </ClCompile>
<ClInclude Include="..\..\src\ripple\protocol\AccountID.h"> <ClInclude Include="..\..\src\ripple\protocol\AccountID.h">
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\ripple\protocol\AnyPublicKey.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\protocol\AnySecretKey.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\protocol\Book.h"> <ClInclude Include="..\..\src\ripple\protocol\Book.h">
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\ripple\protocol\BuildInfo.h"> <ClInclude Include="..\..\src\ripple\protocol\BuildInfo.h">
@@ -2729,14 +2725,6 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\ripple\protocol\impl\AnyPublicKey.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple\protocol\impl\AnySecretKey.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple\protocol\impl\BuildInfo.cpp"> <ClCompile Include="..\..\src\ripple\protocol\impl\BuildInfo.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>

View File

@@ -3435,12 +3435,6 @@
<ClInclude Include="..\..\src\ripple\protocol\AccountID.h"> <ClInclude Include="..\..\src\ripple\protocol\AccountID.h">
<Filter>ripple\protocol</Filter> <Filter>ripple\protocol</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\ripple\protocol\AnyPublicKey.h">
<Filter>ripple\protocol</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\protocol\AnySecretKey.h">
<Filter>ripple\protocol</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\protocol\Book.h"> <ClInclude Include="..\..\src\ripple\protocol\Book.h">
<Filter>ripple\protocol</Filter> <Filter>ripple\protocol</Filter>
</ClInclude> </ClInclude>
@@ -3459,12 +3453,6 @@
<ClCompile Include="..\..\src\ripple\protocol\impl\AccountID.cpp"> <ClCompile Include="..\..\src\ripple\protocol\impl\AccountID.cpp">
<Filter>ripple\protocol\impl</Filter> <Filter>ripple\protocol\impl</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\ripple\protocol\impl\AnyPublicKey.cpp">
<Filter>ripple\protocol\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\protocol\impl\AnySecretKey.cpp">
<Filter>ripple\protocol\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\protocol\impl\BuildInfo.cpp"> <ClCompile Include="..\..\src\ripple\protocol\impl\BuildInfo.cpp">
<Filter>ripple\protocol\impl</Filter> <Filter>ripple\protocol\impl</Filter>
</ClCompile> </ClCompile>

View File

@@ -38,6 +38,7 @@
#include <ripple/core/SociDB.h> #include <ripple/core/SociDB.h>
#include <ripple/protocol/Indexes.h> #include <ripple/protocol/Indexes.h>
#include <ripple/protocol/JsonFields.h> #include <ripple/protocol/JsonFields.h>
#include <ripple/protocol/PublicKey.h>
#include <ripple/core/Config.h> #include <ripple/core/Config.h>
#include <ripple/core/JobQueue.h> #include <ripple/core/JobQueue.h>
#include <ripple/core/LoadFeeTrack.h> #include <ripple/core/LoadFeeTrack.h>
@@ -134,8 +135,7 @@ makeGenesisAccount (AccountID const& id,
// other constructor with appropriate parameters, and // other constructor with appropriate parameters, and
// then create the master account / flush dirty. // then create the master account / flush dirty.
// //
// VFALCO Use `AnyPublicKey masterPublicKey` Ledger::Ledger (AccountID const& masterAccountID,
Ledger::Ledger (RippleAddress const& masterPublicKey,
std::uint64_t balanceInDrops) std::uint64_t balanceInDrops)
: mTotCoins (balanceInDrops) : mTotCoins (balanceInDrops)
, mCloseResolution (ledgerDefaultTimeResolution) , mCloseResolution (ledgerDefaultTimeResolution)
@@ -151,8 +151,7 @@ Ledger::Ledger (RippleAddress const& masterPublicKey,
// first ledger // first ledger
info_.seq = 1; info_.seq = 1;
auto const sle = makeGenesisAccount( auto const sle = makeGenesisAccount(
calcAccountID(masterPublicKey), masterAccountID, balanceInDrops);
balanceInDrops);
WriteLog (lsTRACE, Ledger) WriteLog (lsTRACE, Ledger)
<< "root account: " << sle->getJson(0); << "root account: " << sle->getJson(0);
rawInsert(sle); rawInsert(sle);

View File

@@ -82,10 +82,10 @@ public:
/** Construct the genesis ledger. /** Construct the genesis ledger.
@param masterPublicKey The public of the account that @param masterAccountID The public of the account that
will hold `startAmount` XRP in drops. will hold `balanceInDrops` XRP in drops.
*/ */
Ledger (RippleAddress const& masterPublicKey, Ledger (AccountID const& masterAccountID,
std::uint64_t balanceInDrops); std::uint64_t balanceInDrops);
// Used for ledgers loaded from JSON files // Used for ledgers loaded from JSON files

View File

@@ -33,6 +33,7 @@ LedgerProposal::LedgerProposal (
uint256 const& tx, uint256 const& tx,
std::uint32_t closeTime, std::uint32_t closeTime,
RippleAddress const& publicKey, RippleAddress const& publicKey,
PublicKey const& pk,
uint256 const& suppression) uint256 const& suppression)
: mPreviousLedger (pLgr) : mPreviousLedger (pLgr)
, mCurrentHash (tx) , mCurrentHash (tx)
@@ -40,6 +41,7 @@ LedgerProposal::LedgerProposal (
, mCloseTime (closeTime) , mCloseTime (closeTime)
, mProposeSeq (seq) , mProposeSeq (seq)
, mPublicKey (publicKey) , mPublicKey (publicKey)
, publicKey_ (pk)
{ {
mPeerID = mPublicKey.getNodeID (); mPeerID = mPublicKey.getNodeID ();
mTime = std::chrono::steady_clock::now (); mTime = std::chrono::steady_clock::now ();
@@ -72,12 +74,47 @@ uint256 LedgerProposal::getSigningHash () const
mCurrentHash); mCurrentHash);
} }
struct HashStream
{
static beast::endian const endian =
beast::endian::big;
std::vector<std::uint8_t> v;
std::uint8_t const*
data() const
{
return v.data();
}
std::size_t
size() const
{
return v.size();
}
void
operator()(void const* data,
std::size_t size) noexcept
{
auto const p = reinterpret_cast<
std::uint8_t const*>(data);
v.insert(v.end(), p, p + size);
}
};
bool LedgerProposal::checkSign (std::string const& signature) const bool LedgerProposal::checkSign (std::string const& signature) const
{ {
return mPublicKey.verifyNodePublic ( auto const valid = mPublicKey.verifyNodePublic(
getSigningHash (), getSigningHash(), signature, ECDSA::not_strict);
signature,
ECDSA::not_strict); HashStream h;
hash_append(h);
assert(valid == (publicKey_.verify(
Slice(h.data(), h.size()),
makeSlice(signature), false)));
return valid;
} }
bool LedgerProposal::changePosition ( bool LedgerProposal::changePosition (

View File

@@ -23,7 +23,10 @@
#include <ripple/basics/CountedObject.h> #include <ripple/basics/CountedObject.h>
#include <ripple/basics/base_uint.h> #include <ripple/basics/base_uint.h>
#include <ripple/json/json_value.h> #include <ripple/json/json_value.h>
#include <ripple/protocol/HashPrefix.h>
#include <ripple/protocol/PublicKey.h>
#include <ripple/protocol/RippleAddress.h> #include <ripple/protocol/RippleAddress.h>
#include <beast/hash/hash_append.h>
#include <chrono> #include <chrono>
#include <cstdint> #include <cstdint>
#include <string> #include <string>
@@ -53,6 +56,7 @@ public:
uint256 const& propose, uint256 const& propose,
std::uint32_t closeTime, std::uint32_t closeTime,
RippleAddress const& publicKey, RippleAddress const& publicKey,
PublicKey const& pk,
uint256 const& suppress); uint256 const& suppress);
// Our own proposal: the publicKey, if set, indicates we are a validating // Our own proposal: the publicKey, if set, indicates we are a validating
@@ -116,11 +120,24 @@ public:
Json::Value getJson () const; Json::Value getJson () const;
private: private:
template <class Hasher>
void
hash_append (Hasher& h) const
{
using beast::hash_append;
hash_append(h, HashPrefix::proposal);
hash_append(h, std::uint32_t(mProposeSeq));
hash_append(h, std::uint32_t(mCloseTime));
hash_append(h, mPreviousLedger);
hash_append(h, mCurrentHash);
}
uint256 mPreviousLedger, mCurrentHash, mSuppression; uint256 mPreviousLedger, mCurrentHash, mSuppression;
std::uint32_t mCloseTime, mProposeSeq; std::uint32_t mCloseTime, mProposeSeq;
NodeID mPeerID; NodeID mPeerID;
RippleAddress mPublicKey; RippleAddress mPublicKey;
PublicKey publicKey_;
std::chrono::steady_clock::time_point mTime; std::chrono::steady_clock::time_point mTime;
}; };

View File

@@ -59,6 +59,7 @@
#include <ripple/nodestore/Manager.h> #include <ripple/nodestore/Manager.h>
#include <ripple/overlay/make_Overlay.h> #include <ripple/overlay/make_Overlay.h>
#include <ripple/protocol/Indexes.h> #include <ripple/protocol/Indexes.h>
#include <ripple/protocol/SecretKey.h>
#include <ripple/protocol/STParsedJSON.h> #include <ripple/protocol/STParsedJSON.h>
#include <ripple/protocol/types.h> #include <ripple/protocol/types.h>
#include <ripple/server/make_ServerHandler.h> #include <ripple/server/make_ServerHandler.h>
@@ -1048,7 +1049,13 @@ void ApplicationImp::startNewLedger ()
m_journal.info << "Root account: " << toBase58(calcAccountID(rootAddress)); m_journal.info << "Root account: " << toBase58(calcAccountID(rootAddress));
{ {
Ledger::pointer firstLedger = std::make_shared<Ledger> (rootAddress, SYSTEM_CURRENCY_START); auto const masterAccountID =
calcAccountID(generateKeyPair(
KeyType::secp256k1,
generateSeed("masterpassphrase")).first);
auto firstLedger = std::make_shared<Ledger>(
masterAccountID, SYSTEM_CURRENCY_START);
assert (firstLedger->exists(keylet::account( assert (firstLedger->exists(keylet::account(
calcAccountID(rootAddress)))); calcAccountID(rootAddress))));
// TODO(david): Add any default amendments // TODO(david): Add any default amendments

View File

@@ -93,18 +93,6 @@ strJoin (Iterator first, Iterator last, std::string strSeparator)
return ossValues.str (); return ossValues.str ();
} }
static
std::string
encodeCredential (AnyPublicKey const& pk, unsigned char type)
{
Blob buffer;
buffer.reserve(1 + pk.size());
buffer.push_back (type);
auto const data = pk.data();
buffer.insert (buffer.end(), data, data + pk.size());
return Base58::encodeWithCheck (buffer);
}
template <size_t I, class String> template <size_t I, class String>
void selectBlobsIntoStrings ( void selectBlobsIntoStrings (
soci::session& s, soci::session& s,
@@ -229,7 +217,7 @@ private:
// XXX Make this faster, make this the contents vector unsigned char or raw public key. // XXX Make this faster, make this the contents vector unsigned char or raw public key.
// XXX Contents needs to based on score. // XXX Contents needs to based on score.
hash_set<std::string> mUNL; hash_set<std::string> mUNL;
hash_map<AnyPublicKey, std::string> ephemeralValidatorKeys_; hash_map<PublicKey, std::string> ephemeralValidatorKeys_;
boost::posix_time::ptime mtpScoreNext; // When to start scoring. boost::posix_time::ptime mtpScoreNext; // When to start scoring.
boost::posix_time::ptime mtpScoreStart; // Time currently started scoring. boost::posix_time::ptime mtpScoreStart; // Time currently started scoring.
@@ -260,8 +248,8 @@ public:
// Get update times and start fetching and scoring as needed. // Get update times and start fetching and scoring as needed.
void start(); void start();
void insertEphemeralKey (AnyPublicKey pk, std::string comment); void insertEphemeralKey (PublicKey pk, std::string comment);
void deleteEphemeralKey (AnyPublicKey const& pk); void deleteEphemeralKey (PublicKey const& pk);
// Add a trusted node. Called by RPC or other source. // Add a trusted node. Called by RPC or other source.
void nodeAddPublic (RippleAddress const& naNodePublic, ValidatorSource vsWhy, std::string const& strComment); void nodeAddPublic (RippleAddress const& naNodePublic, ValidatorSource vsWhy, std::string const& strComment);
@@ -487,14 +475,14 @@ void UniqueNodeListImp::start()
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
void UniqueNodeListImp::insertEphemeralKey (AnyPublicKey pk, std::string comment) void UniqueNodeListImp::insertEphemeralKey (PublicKey pk, std::string comment)
{ {
ScopedUNLLockType sl (mUNLLock); ScopedUNLLockType sl (mUNLLock);
ephemeralValidatorKeys_.insert (std::make_pair(std::move(pk), std::move(comment))); ephemeralValidatorKeys_.insert (std::make_pair(std::move(pk), std::move(comment)));
} }
void UniqueNodeListImp::deleteEphemeralKey (AnyPublicKey const& pk) void UniqueNodeListImp::deleteEphemeralKey (PublicKey const& pk)
{ {
ScopedUNLLockType sl (mUNLLock); ScopedUNLLockType sl (mUNLLock);
@@ -648,7 +636,7 @@ void UniqueNodeListImp::nodeScore()
bool UniqueNodeListImp::nodeInUNL (RippleAddress const& naNodePublic) bool UniqueNodeListImp::nodeInUNL (RippleAddress const& naNodePublic)
{ {
auto const& blob = naNodePublic.getNodePublic(); auto const& blob = naNodePublic.getNodePublic();
AnyPublicKey const pk (blob.data(), blob.size()); PublicKey const pk (Slice(blob.data(), blob.size()));
ScopedUNLLockType sl (mUNLLock); ScopedUNLLockType sl (mUNLLock);
@@ -932,7 +920,7 @@ Json::Value UniqueNodeListImp::getUnlJson()
{ {
Json::Value node (Json::objectValue); Json::Value node (Json::objectValue);
node["publicKey"] = encodeCredential (key.first, TOKEN_NODE_PUBLIC); node["publicKey"] = toBase58(TokenType::TOKEN_NODE_PUBLIC, key.first);
node["comment"] = key.second; node["comment"] = key.second;
ret.append (node); ret.append (node);

View File

@@ -21,7 +21,7 @@
#define RIPPLE_APP_PEERS_UNIQUENODELIST_H_INCLUDED #define RIPPLE_APP_PEERS_UNIQUENODELIST_H_INCLUDED
#include <ripple/overlay/ClusterNodeStatus.h> #include <ripple/overlay/ClusterNodeStatus.h>
#include <ripple/protocol/AnyPublicKey.h> #include <ripple/protocol/PublicKey.h>
#include <ripple/protocol/RippleAddress.h> #include <ripple/protocol/RippleAddress.h>
#include <beast/cxx14/memory.h> // <memory> #include <beast/cxx14/memory.h> // <memory>
#include <beast/threads/Stoppable.h> #include <beast/threads/Stoppable.h>
@@ -55,8 +55,8 @@ public:
// VFALCO TODO Roll this into the constructor so there is one less state. // VFALCO TODO Roll this into the constructor so there is one less state.
virtual void start () = 0; virtual void start () = 0;
virtual void insertEphemeralKey (AnyPublicKey pk, std::string comment) = 0; virtual void insertEphemeralKey (PublicKey pk, std::string comment) = 0;
virtual void deleteEphemeralKey (AnyPublicKey const& pk) = 0; virtual void deleteEphemeralKey (PublicKey const& pk) = 0;
// VFALCO TODO rename all these, the "node" prefix is redundant (lol) // VFALCO TODO rename all these, the "node" prefix is redundant (lol)
virtual void nodeAddPublic (RippleAddress const& naNodePublic, ValidatorSource vsWhy, std::string const& strComment) = 0; virtual void nodeAddPublic (RippleAddress const& naNodePublic, ValidatorSource vsWhy, std::string const& strComment) = 0;

View File

@@ -147,10 +147,7 @@ class View_test
testLedger() testLedger()
{ {
using namespace jtx; using namespace jtx;
Account const master("master"); auto const ledger = Env::genesis();
auto const ledger =
std::make_shared<Ledger>(
master.pk(), 1000000000);
wipe(*ledger); wipe(*ledger);
ReadView& v = *ledger; ReadView& v = *ledger;
succ(v, 0, boost::none); succ(v, 0, boost::none);
@@ -391,10 +388,7 @@ class View_test
// ApplyView on that, then another ApplyView, // ApplyView on that, then another ApplyView,
// erase the item, apply. // erase the item, apply.
{ {
Account const master("master"); auto const ledger = Env::genesis();
auto const ledger =
std::make_shared<Ledger>(
master.pk(), 1000000000);
wipe(*ledger); wipe(*ledger);
ledger->rawInsert(sle(1)); ledger->rawInsert(sle(1));
ReadView& v0 = *ledger; ReadView& v0 = *ledger;

View File

@@ -36,8 +36,8 @@ make_Manifest (std::string s)
STObject st (sfGeneric); STObject st (sfGeneric);
SerialIter sit (s.data (), s.size ()); SerialIter sit (s.data (), s.size ());
st.set (sit); st.set (sit);
auto const opt_pk = get<AnyPublicKey>(st, sfPublicKey); auto const opt_pk = get<PublicKey>(st, sfPublicKey);
auto const opt_spk = get<AnyPublicKey>(st, sfSigningPubKey); auto const opt_spk = get<PublicKey>(st, sfSigningPubKey);
auto const opt_seq = get (st, sfSequence); auto const opt_seq = get (st, sfSequence);
auto const opt_sig = get (st, sfSignature); auto const opt_sig = get (st, sfSignature);
if (!opt_pk || !opt_spk || !opt_seq || !opt_sig) if (!opt_pk || !opt_spk || !opt_seq || !opt_sig)
@@ -57,11 +57,11 @@ Stream&
logMftAct ( logMftAct (
Stream& s, Stream& s,
std::string const& action, std::string const& action,
AnyPublicKey const& pk, PublicKey const& pk,
std::uint32_t seq) std::uint32_t seq)
{ {
s << "Manifest: " << action << s << "Manifest: " << action <<
";Pk: " << toString (pk) << ";Pk: " << toBase58 (TokenType::TOKEN_NODE_PUBLIC, pk) <<
";Seq: " << seq << ";"; ";Seq: " << seq << ";";
return s; return s;
} }
@@ -70,20 +70,20 @@ template<class Stream>
Stream& logMftAct ( Stream& logMftAct (
Stream& s, Stream& s,
std::string const& action, std::string const& action,
AnyPublicKey const& pk, PublicKey const& pk,
std::uint32_t seq, std::uint32_t seq,
std::uint32_t oldSeq) std::uint32_t oldSeq)
{ {
s << "Manifest: " << action << s << "Manifest: " << action <<
";Pk: " << toString (pk) << ";Pk: " << toBase58 (TokenType::TOKEN_NODE_PUBLIC, pk) <<
";Seq: " << seq << ";Seq: " << seq <<
";OldSeq: " << oldSeq << ";"; ";OldSeq: " << oldSeq << ";";
return s; return s;
} }
Manifest::Manifest (std::string s, Manifest::Manifest (std::string s,
AnyPublicKey pk, PublicKey pk,
AnyPublicKey spk, PublicKey spk,
std::uint32_t seq) std::uint32_t seq)
: serialized (std::move (s)) : serialized (std::move (s))
, masterKey (std::move (pk)) , masterKey (std::move (pk))
@@ -97,7 +97,7 @@ bool Manifest::verify () const
STObject st (sfGeneric); STObject st (sfGeneric);
SerialIter sit (serialized.data (), serialized.size ()); SerialIter sit (serialized.data (), serialized.size ());
st.set (sit); st.set (sit);
return ripple::verify (st, HashPrefix::manifest, masterKey); return ripple::verify (st, HashPrefix::manifest, masterKey, true);
} }
uint256 Manifest::hash () const uint256 Manifest::hash () const
@@ -146,11 +146,11 @@ ManifestCache::configValidatorKey(
throw std::runtime_error ("Expected Ed25519 key (0xED)"); 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]); std::string comment = std::move(words[1]);
if (journal.debug) journal.debug if (journal.debug) journal.debug
<< masterKey << " " << comment; << toBase58(TokenType::TOKEN_NODE_PUBLIC, masterKey) << " " << comment;
addTrustedKey (masterKey, std::move(comment)); addTrustedKey (masterKey, std::move(comment));
} }
@@ -172,7 +172,7 @@ ManifestCache::configManifest(Manifest m, beast::Journal const& journal)
} }
void void
ManifestCache::addTrustedKey (AnyPublicKey const& pk, std::string comment) ManifestCache::addTrustedKey (PublicKey const& pk, std::string comment)
{ {
std::lock_guard<std::mutex> lock (mutex_); std::lock_guard<std::mutex> lock (mutex_);
@@ -188,7 +188,7 @@ ManifestCache::addTrustedKey (AnyPublicKey const& pk, std::string comment)
} }
ManifestDisposition ManifestDisposition
ManifestCache::canApply (AnyPublicKey const& pk, std::uint32_t seq, ManifestCache::canApply (PublicKey const& pk, std::uint32_t seq,
beast::Journal const& journal) const beast::Journal const& journal) const
{ {
auto const iter = map_.find(pk); auto const iter = map_.find(pk);

View File

@@ -22,7 +22,7 @@
#include <ripple/basics/BasicConfig.h> #include <ripple/basics/BasicConfig.h>
#include <ripple/basics/UnorderedContainers.h> #include <ripple/basics/UnorderedContainers.h>
#include <ripple/protocol/AnyPublicKey.h> #include <ripple/protocol/PublicKey.h>
#include <ripple/protocol/STExchange.h> #include <ripple/protocol/STExchange.h>
#include <beast/utility/Journal.h> #include <beast/utility/Journal.h>
#include <boost/optional.hpp> #include <boost/optional.hpp>
@@ -85,11 +85,11 @@ namespace ripple {
struct Manifest struct Manifest
{ {
std::string serialized; std::string serialized;
AnyPublicKey masterKey; PublicKey masterKey;
AnyPublicKey signingKey; PublicKey signingKey;
std::uint32_t sequence; 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 #ifdef _MSC_VER
Manifest(Manifest&& other) Manifest(Manifest&& other)
@@ -166,7 +166,7 @@ private:
#endif #endif
MappedType(std::string comment, MappedType(std::string comment,
std::string serialized, std::string serialized,
AnyPublicKey pk, AnyPublicKey spk, std::uint32_t seq) PublicKey pk, PublicKey spk, std::uint32_t seq)
:comment (std::move(comment)) :comment (std::move(comment))
{ {
m.emplace (std::move(serialized), std::move(pk), std::move(spk), m.emplace (std::move(serialized), std::move(pk), std::move(spk),
@@ -177,13 +177,13 @@ private:
boost::optional<Manifest> m; boost::optional<Manifest> m;
}; };
using MapType = hash_map<AnyPublicKey, MappedType>; using MapType = hash_map<PublicKey, MappedType>;
mutable std::mutex mutex_; mutable std::mutex mutex_;
MapType map_; MapType map_;
ManifestDisposition ManifestDisposition
canApply (AnyPublicKey const& pk, std::uint32_t seq, canApply (PublicKey const& pk, std::uint32_t seq,
beast::Journal const& journal) const; beast::Journal const& journal) const;
public: public:
@@ -195,7 +195,7 @@ public:
void configValidatorKey(std::string const& line, beast::Journal const& journal); void configValidatorKey(std::string const& line, beast::Journal const& journal);
void configManifest(Manifest m, 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 ManifestDisposition
applyManifest (Manifest m, beast::Journal const& journal); applyManifest (Manifest m, beast::Journal const& journal);

View File

@@ -1147,13 +1147,14 @@ PeerImp::onMessage (std::shared_ptr <protocol::TMProposeSet> const& m)
if ((set.closetime() + 180) < getApp().getOPs().getCloseTimeNC()) if ((set.closetime() + 180) < getApp().getOPs().getCloseTimeNC())
return; return;
auto const type = publicKeyType(
makeSlice(set.nodepubkey()));
// VFALCO Magic numbers are bad // VFALCO Magic numbers are bad
// Roll this into a validation function // Roll this into a validation function
if ( if ((! type) ||
(set.currenttxhash ().size () != 32) || (set.currenttxhash ().size () != 32) ||
(set.nodepubkey ().size () < 28) ||
(set.signature ().size () < 56) || (set.signature ().size () < 56) ||
(set.nodepubkey ().size () > 128) ||
(set.signature ().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> ( auto proposal = std::make_shared<LedgerProposal> (
prevLedger, set.proposeseq (), proposeHash, set.closetime (), prevLedger, set.proposeseq (), proposeHash, set.closetime (),
signerPublic, suppression); signerPublic, PublicKey(makeSlice(set.nodepubkey())),
suppression);
getApp().getJobQueue ().addJob (isTrusted ? jtPROPOSAL_t : jtPROPOSAL_ut, getApp().getJobQueue ().addJob (isTrusted ? jtPROPOSAL_t : jtPROPOSAL_ut,
"recvPropose->checkPropose", std::bind(beast::weak_fn( "recvPropose->checkPropose", std::bind(beast::weak_fn(

View File

@@ -22,6 +22,7 @@
#include <ripple/overlay/impl/Manifest.h> #include <ripple/overlay/impl/Manifest.h>
#include <ripple/core/DatabaseCon.h> #include <ripple/core/DatabaseCon.h>
#include <ripple/app/main/DBInit.h> #include <ripple/app/main/DBInit.h>
#include <ripple/protocol/SecretKey.h>
#include <ripple/protocol/Sign.h> #include <ripple/protocol/Sign.h>
#include <ripple/protocol/STExchange.h> #include <ripple/protocol/STExchange.h>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
@@ -85,18 +86,18 @@ public:
Manifest Manifest
make_Manifest make_Manifest
(AnySecretKey const& sk, AnyPublicKey const& spk, int seq, (KeyType type, SecretKey const& sk, PublicKey const& spk, int seq,
bool broken = false) bool broken = false)
{ {
auto const pk = sk.publicKey(); auto const pk = derivePublicKey(type, sk);
STObject st(sfGeneric); STObject st(sfGeneric);
set(st, sfSequence, seq); set(st, sfSequence, seq);
set(st, sfPublicKey, pk); set(st, sfPublicKey, pk);
set(st, sfSigningPubKey, spk); set(st, sfSigningPubKey, spk);
sign(st, HashPrefix::manifest, sk); sign(st, HashPrefix::manifest, type, sk);
expect(verify(st, HashPrefix::manifest, pk)); expect(verify(st, HashPrefix::manifest, pk, true));
if (broken) if (broken)
{ {
@@ -191,19 +192,19 @@ public:
beast::Journal journal; beast::Journal journal;
auto const sk_a = AnySecretKey::make_ed25519 (); auto const sk_a = randomSecretKey();
auto const sk_b = AnySecretKey::make_ed25519 (); auto const pk_a = derivePublicKey(KeyType::ed25519, sk_a);
auto const pk_a = sk_a.publicKey (); auto const kp_a = randomKeyPair(KeyType::secp256k1);
auto const pk_b = sk_b.publicKey (); auto const s_a0 = make_Manifest (KeyType::ed25519, sk_a, kp_a.first, 0);
auto const kp_a = AnySecretKey::make_secp256k1_pair (); auto const s_a1 = make_Manifest (KeyType::ed25519, sk_a, kp_a.first, 1);
auto const kp_b = AnySecretKey::make_secp256k1_pair ();
auto const s_a0 = make_Manifest (sk_a, kp_a.second, 0); auto const sk_b = randomSecretKey();
auto const s_a1 = make_Manifest (sk_a, kp_a.second, 1); auto const pk_b = derivePublicKey(KeyType::ed25519, sk_b);
auto const s_b0 = make_Manifest (sk_b, kp_b.second, 0); auto const kp_b = randomKeyPair(KeyType::secp256k1);
auto const s_b1 = make_Manifest (sk_b, kp_b.second, 1); 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 = 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'; auto const fake = s_b1.serialized + '\0';
expect (cache.applyManifest (clone (s_a0), journal) == untrusted, expect (cache.applyManifest (clone (s_a0), journal) == untrusted,

View File

@@ -22,7 +22,7 @@
#include <ripple/protocol/tokens.h> #include <ripple/protocol/tokens.h>
// VFALCO Uncomment when the header issues are resolved // VFALCO Uncomment when the header issues are resolved
//#include <ripple/protocol/AnyPublicKey.h> //#include <ripple/protocol/PublicKey.h>
#include <ripple/basics/base_uint.h> #include <ripple/basics/base_uint.h>
#include <ripple/basics/UnorderedContainers.h> #include <ripple/basics/UnorderedContainers.h>
#include <ripple/json/json_value.h> #include <ripple/json/json_value.h>
@@ -33,9 +33,6 @@
namespace ripple { namespace ripple {
// VFALCO Forward declared due to header issues
class AnyPublicKey;
namespace detail { namespace detail {
class AccountIDTag { }; class AccountIDTag { };
@@ -96,8 +93,9 @@ parseHexOrBase58 (std::string const& s);
guard bytes included in the base58 representation. guard bytes included in the base58 representation.
*/ */
AccountID // VFALCO In PublicKey.h for now
calcAccountID (AnyPublicKey const& pk); //AccountID
//calcAccountID (PublicKey const& pk);
/** A special account that's used as the "issuer" for XRP. */ /** A special account that's used as the "issuer" for XRP. */
AccountID const& AccountID const&

View File

@@ -1,188 +0,0 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_PROTOCOL_ANYPUBLICKEY_H_INCLUDED
#define RIPPLE_PROTOCOL_ANYPUBLICKEY_H_INCLUDED
#include <ripple/basics/Buffer.h>
#include <ripple/crypto/KeyType.h>
#include <ripple/protocol/HashPrefix.h>
#include <ripple/protocol/STExchange.h>
#include <ripple/protocol/STObject.h>
#include <beast/hash/hash_append.h>
#include <beast/utility/noexcept.h>
#include <boost/utility/base_from_member.hpp>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <utility>
namespace ripple {
/** Variant container for all public keys. */
class AnyPublicKeySlice
: public Slice
{
public:
#ifdef _MSC_VER
AnyPublicKeySlice (
void const* data, std::size_t size)
: Slice (data, size)
{
}
#else
using Slice::Slice;
#endif
AnyPublicKeySlice() = delete;
AnyPublicKeySlice (
AnyPublicKeySlice const&) = default;
AnyPublicKeySlice& operator= (
AnyPublicKeySlice const&) = default;
/** Returns the type of key stored. */
KeyType
type() const noexcept;
/** Verify a signature using this public key. */
bool
verify (void const* msg, std::size_t msg_size,
void const* sig, std::size_t sig_size) const;
};
template <>
struct STExchange<STBlob, AnyPublicKeySlice>
{
using value_type = AnyPublicKeySlice;
static
void
get (boost::optional<value_type>& t,
STBlob const& u)
{
t = boost::in_place(u.data(), u.size());
}
static
std::unique_ptr<STBlob>
set (SField const& f, AnyPublicKeySlice const& t)
{
return std::make_unique<STBlob>(
f, t.data(), t.size());
}
};
//------------------------------------------------------------------------------
/** Variant container for all public keys, with ownership. */
class AnyPublicKey
: private boost::base_from_member<Buffer>
, public AnyPublicKeySlice
{
private:
using buffer_type = boost::base_from_member<Buffer>;
public:
AnyPublicKey() = delete;
AnyPublicKey& operator= (AnyPublicKey const&) = delete;
AnyPublicKey (AnyPublicKey const& other)
: buffer_type(other.buffer_type::member.data(),
other.buffer_type::member.size())
, AnyPublicKeySlice (buffer_type::member.data(),
buffer_type::member.size())
{
}
#ifdef _MSC_VER
AnyPublicKey (AnyPublicKey&& other)
: buffer_type(std::move(other.buffer_type::member))
, AnyPublicKeySlice (buffer_type::member.data(),
buffer_type::member.size())
{
}
AnyPublicKey& operator= (AnyPublicKey&& other)
{
buffer_type::member =
std::move (other.buffer_type::member);
AnyPublicKeySlice::operator= (other);
return *this;
}
#else
AnyPublicKey (AnyPublicKey&&) = default;
AnyPublicKey& operator= (AnyPublicKey&&) = default;
#endif
AnyPublicKey (void const* data_, std::size_t size_)
: buffer_type (data_, size_)
, AnyPublicKeySlice (
member.data(), member.size())
{
}
/** Returns ownership of the underlying Buffer.
After calling this function, only the destructor
or the move assignment operator may be called.
*/
Buffer
releaseBuffer() noexcept
{
return std::move(buffer_type::member);
}
};
template <>
struct STExchange<STBlob, AnyPublicKey>
{
using value_type = AnyPublicKey;
static
void
get (boost::optional<value_type>& t,
STBlob const& u)
{
t = boost::in_place(u.data(), u.size());
}
static
std::unique_ptr<STBlob>
set (SField const& f, AnyPublicKey const& t)
{
return std::make_unique<STBlob>(
f, t.data(), t.size());
}
static
std::unique_ptr<STBlob>
set (SField const& f, AnyPublicKey&& t)
{
return std::make_unique<STBlob>(
f, t.releaseBuffer());
}
};
std::string
toString (AnyPublicKey const& pk);
} // ripple
#endif

View File

@@ -1,85 +0,0 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_PROTOCOL_ANYSECRETKEY_H_INCLUDED
#define RIPPLE_PROTOCOL_ANYSECRETKEY_H_INCLUDED
#include <ripple/basics/Buffer.h>
#include <ripple/protocol/AnyPublicKey.h>
#include <ripple/protocol/HashPrefix.h>
#include <boost/utility/base_from_member.hpp>
#include <cstdint>
#include <memory>
#include <utility>
namespace ripple {
/** Variant container for secret key, with ownership. */
class AnySecretKey
{
private:
Buffer p_;
KeyType type_;
public:
AnySecretKey() = delete;
AnySecretKey (AnySecretKey const&) = delete;
AnySecretKey& operator= (AnySecretKey const&) = delete;
/** Destroy the key.
The memory area is secure erased.
*/
~AnySecretKey();
AnySecretKey (AnySecretKey&& other);
AnySecretKey& operator= (AnySecretKey&& other);
AnySecretKey (KeyType type,
void const* data, std::size_t size);
/** Returns the type of secret key. */
KeyType
type() const noexcept
{
return type_;
}
/** Returns the corresponding public key. */
AnyPublicKey
publicKey() const;
/** Create a signature for the given message. */
Buffer
sign (void const* msg, std::size_t msg_len) const;
/** Securely generate a new ed25519 secret key. */
static
AnySecretKey
make_ed25519();
/** Securely generate a new secp256k1 key pair. */
static
std::pair<AnySecretKey, AnyPublicKey>
make_secp256k1_pair();
};
} // ripple
#endif

View File

@@ -20,9 +20,9 @@
#ifndef RIPPLE_PROTOCOL_SIGN_H_INCLUDED #ifndef RIPPLE_PROTOCOL_SIGN_H_INCLUDED
#define RIPPLE_PROTOCOL_SIGN_H_INCLUDED #define RIPPLE_PROTOCOL_SIGN_H_INCLUDED
#include <ripple/protocol/AnyPublicKey.h>
#include <ripple/protocol/AnySecretKey.h>
#include <ripple/protocol/HashPrefix.h> #include <ripple/protocol/HashPrefix.h>
#include <ripple/protocol/PublicKey.h>
#include <ripple/protocol/SecretKey.h>
#include <ripple/protocol/STObject.h> #include <ripple/protocol/STObject.h>
#include <utility> #include <utility>
@@ -35,7 +35,7 @@ namespace ripple {
void void
sign (STObject& st, sign (STObject& st,
HashPrefix const& prefix, HashPrefix const& prefix,
AnySecretKey const& sk); KeyType type, SecretKey const& sk);
/** Verify the signature on a STObject. /** Verify the signature on a STObject.
The signature must be contained in sfSignature. The signature must be contained in sfSignature.
@@ -43,7 +43,8 @@ sign (STObject& st,
bool bool
verify (STObject const& st, verify (STObject const& st,
HashPrefix const& prefix, HashPrefix const& prefix,
AnyPublicKeySlice const& pk); PublicKey const& pk,
bool mustBeFullyCanonical);
} // ripple } // ripple

View File

@@ -19,7 +19,7 @@
#include <BeastConfig.h> #include <BeastConfig.h>
#include <ripple/protocol/AccountID.h> #include <ripple/protocol/AccountID.h>
#include <ripple/protocol/AnyPublicKey.h> #include <ripple/protocol/PublicKey.h>
#include <ripple/protocol/digest.h> #include <ripple/protocol/digest.h>
#include <ripple/protocol/tokens.h> #include <ripple/protocol/tokens.h>
#include <cstring> #include <cstring>
@@ -139,9 +139,8 @@ parseHexOrBase58 (std::string const& s)
less secure than Bitcoin. So where there was no good reason less secure than Bitcoin. So where there was no good reason
to change something, it was not changed." to change something, it was not changed."
*/ */
AccountID AccountID
calcAccountID (AnyPublicKey const& pk) calcAccountID (PublicKey const& pk)
{ {
ripesha_hasher rsh; ripesha_hasher rsh;
rsh(pk.data(), pk.size()); rsh(pk.data(), pk.size());

View File

@@ -1,104 +0,0 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include <ripple/protocol/AnyPublicKey.h>
#include <ripple/protocol/Serializer.h>
#include <ripple/protocol/STExchange.h>
#include <ed25519-donna/ed25519.h>
#include <cassert>
namespace ripple {
/** Verify a secp256k1 signature. */
bool
verify_secp256k1 (void const* pk,
void const* msg, std::size_t msg_size,
void const* sig, std::size_t sig_size)
{
return false;
}
bool
verify_ed25519 (void const* pk,
void const* msg, std::size_t msg_size,
void const* sig, std::size_t sig_size)
{
if (sig_size != 64)
return false;
ed25519_public_key epk;
ed25519_signature es;
std::memcpy(epk, pk, 32);
std::memcpy(es, sig, sig_size);
return ed25519_sign_open(
reinterpret_cast<unsigned char const*>(msg),
msg_size, epk, es) == 0;
}
//------------------------------------------------------------------------------
KeyType
AnyPublicKeySlice::type() const noexcept
{
auto const pk = data();
auto const pk_size = size();
if (pk_size < 1)
return KeyType::unknown;
auto const len = pk_size - 1;
if (len == 32 &&
pk[0] == 0xED)
return KeyType::ed25519;
if (len == 33 &&
(pk[0] == 0x02 || pk[0] == 0x03))
return KeyType::secp256k1;
return KeyType::unknown;
}
bool
AnyPublicKeySlice::verify (
void const* msg, std::size_t msg_size,
void const* sig, std::size_t sig_size) const
{
switch(type())
{
case KeyType::ed25519:
return verify_ed25519(data() + 1,
msg, msg_size, sig, sig_size);
case KeyType::secp256k1:
return verify_secp256k1(data() + 1,
msg, msg_size, sig, sig_size);
default:
break;
}
// throw?
return false;
}
std::string
toString (AnyPublicKey const& pk)
{
Blob buffer;
buffer.reserve (1 + pk.size ());
buffer.push_back (TOKEN_NODE_PUBLIC);
auto const data = pk.data ();
buffer.insert (buffer.end (), data, data + pk.size ());
return Base58::encodeWithCheck (buffer);
}
} // ripple

View File

@@ -1,143 +0,0 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include <ripple/protocol/AnySecretKey.h>
#include <ripple/protocol/RippleAddress.h>
#include <ripple/protocol/Serializer.h>
#include <ripple/crypto/RandomNumbers.h>
#include <ed25519-donna/ed25519.h>
#include <algorithm>
#include <cassert>
#include <cstring>
namespace ripple {
AnySecretKey::~AnySecretKey()
{
// secure erase
std::fill(p_.data(), p_.data() + p_.size(), 0);
}
AnySecretKey::AnySecretKey (AnySecretKey&& other)
: p_ (std::move(other.p_))
, type_ (other.type_)
{
other.type_ = KeyType::unknown;
}
AnySecretKey&
AnySecretKey::operator= (AnySecretKey&& other)
{
p_ = std::move(other.p_);
type_ = other.type_;
other.type_ = KeyType::unknown;
return *this;
}
AnySecretKey::AnySecretKey (KeyType type,
void const* data, std::size_t size)
: p_ (data, size)
, type_ (type)
{
if (type_ == KeyType::unknown)
throw std::runtime_error(
"AnySecretKey: unknown type");
if (type_ == KeyType::ed25519 &&
size != 32)
throw std::runtime_error(
"AnySecretKey: wrong ed25519 size");
if (type_ == KeyType::secp256k1 &&
size != 32)
throw std::runtime_error(
"AnySecretKey: wrong secp256k1 size");
}
AnyPublicKey
AnySecretKey::publicKey() const
{
switch (type())
{
case KeyType::ed25519:
{
unsigned char buf[33];
buf[0] = 0xED;
ed25519_publickey(p_.data(), &buf[1]);
return AnyPublicKey(buf, sizeof(buf));
}
default:
throw std::runtime_error(
"AnySecretKey: unknown type");
};
}
Buffer
AnySecretKey::sign (
void const* msg, std::size_t msg_len) const
{
switch(type_)
{
case KeyType::ed25519:
{
auto const sk = p_.data();
ed25519_public_key pk;
ed25519_publickey(sk, pk);
Buffer b(64);
ed25519_sign(reinterpret_cast<
unsigned char const*>(msg), msg_len,
sk, pk, b.data());
return b;
}
default:
break;
}
throw std::runtime_error(
"AnySecretKey: unknown type");
}
AnySecretKey
AnySecretKey::make_ed25519()
{
std::uint8_t buf[32];
random_fill(&buf[0], sizeof(buf));
AnySecretKey ask(KeyType::ed25519,
buf, sizeof(buf));
// secure erase
std::fill(buf, buf + sizeof(buf), 0);
return ask;
}
std::pair<AnySecretKey, AnyPublicKey>
AnySecretKey::make_secp256k1_pair()
{
// VFALCO What a pile
RippleAddress s;
s.setSeedRandom();
RippleAddress const g =
RippleAddress::createGeneratorPublic(s);
RippleAddress sk;
sk.setAccountPrivate (g, s, 0);
RippleAddress pk;
pk.setAccountPublic (g, 0);
return std::pair<AnySecretKey, AnyPublicKey>(
std::piecewise_construct, std::make_tuple(
KeyType::secp256k1, sk.data(), sk.size()),
std::make_tuple(pk.data(), pk.size()));
}
} // ripple

View File

@@ -17,6 +17,7 @@
*/ */
//============================================================================== //==============================================================================
#include <BeastConfig.h>
#include <ripple/protocol/STAccount.h> #include <ripple/protocol/STAccount.h>
#include <ripple/protocol/STAmount.h> #include <ripple/protocol/STAmount.h>
#include <ripple/protocol/STArray.h> #include <ripple/protocol/STArray.h>

View File

@@ -17,25 +17,27 @@
*/ */
//============================================================================== //==============================================================================
#include <BeastConfig.h>
#include <ripple/protocol/Sign.h> #include <ripple/protocol/Sign.h>
namespace ripple { namespace ripple {
void void
sign (STObject& st, HashPrefix const& prefix, sign (STObject& st, HashPrefix const& prefix,
AnySecretKey const& sk) KeyType type, SecretKey const& sk)
{ {
Serializer ss; Serializer ss;
ss.add32(prefix); ss.add32(prefix);
st.addWithoutSigningFields(ss); st.addWithoutSigningFields(ss);
set(st, sfSignature, set(st, sfSignature,
sk.sign(ss.data(), ss.size())); sign(type, sk, ss.slice()));
} }
bool bool
verify (STObject const& st, verify (STObject const& st,
HashPrefix const& prefix, HashPrefix const& prefix,
AnyPublicKeySlice const& pk) PublicKey const& pk,
bool mustBeFullyCanonical)
{ {
auto const sig = get(st, sfSignature); auto const sig = get(st, sfSignature);
if (! sig) if (! sig)
@@ -44,8 +46,9 @@ verify (STObject const& st,
ss.add32(prefix); ss.add32(prefix);
st.addWithoutSigningFields(ss); st.addWithoutSigningFields(ss);
return pk.verify( return pk.verify(
ss.data(), ss.size(), Slice(ss.data(), ss.size()),
sig->data(), sig->size()); Slice(sig->data(), sig->size()),
true);
} }
} // ripple } // ripple

View File

@@ -17,6 +17,7 @@
*/ */
//============================================================================== //==============================================================================
#include <BeastConfig.h>
#include <ripple/protocol/tokens.h> #include <ripple/protocol/tokens.h>
#include <ripple/protocol/digest.h> #include <ripple/protocol/digest.h>
#include <cassert> #include <cassert>

View File

@@ -88,7 +88,7 @@ public:
txnSeed.setSeedRandom (); txnSeed.setSeedRandom ();
// VFALCO Generators are no longer supported // VFALCO Generators are no longer supported
RippleAddress txnGenerator = txnSeed.createGeneratorPublic (txnSeed); RippleAddress txnGenerator = txnSeed.createGeneratorPublic (txnSeed);
// VFALCO Use AnyPublicKey here // VFALCO Use PublicKey here
RippleAddress txnPublicAcct = txnSeed.createAccountPublic (txnGenerator, 1); RippleAddress txnPublicAcct = txnSeed.createAccountPublic (txnGenerator, 1);
STTx txn (ttACCOUNT_SET); STTx txn (ttACCOUNT_SET);

View File

@@ -39,7 +39,7 @@ Json::Value accounts (
do do
{ {
// VFALCO Should be AnyPublicKey // VFALCO Should be PublicKey and Generator
RippleAddress pk; RippleAddress pk;
pk.setAccountPublic (naMasterGenerator, uIndex++); pk.setAccountPublic (naMasterGenerator, uIndex++);

View File

@@ -21,6 +21,7 @@
#include <ripple/app/paths/FindPaths.h> #include <ripple/app/paths/FindPaths.h>
#include <ripple/basics/StringUtilities.h> #include <ripple/basics/StringUtilities.h>
#include <ripple/json/json_reader.h> #include <ripple/json/json_reader.h>
#include <ripple/protocol/SecretKey.h>
#include <ripple/protocol/TxFlags.h> #include <ripple/protocol/TxFlags.h>
#include <ripple/rpc/impl/TransactionSign.h> #include <ripple/rpc/impl/TransactionSign.h>
#include <beast/unit_test/suite.h> #include <beast/unit_test/suite.h>
@@ -920,8 +921,14 @@ public:
= RippleAddress::createAccountPublic (rootGeneratorMaster, 0); = RippleAddress::createAccountPublic (rootGeneratorMaster, 0);
std::uint64_t startAmount (100000); std::uint64_t startAmount (100000);
auto const masterAccountID =
calcAccountID(generateKeyPair(
KeyType::secp256k1,
generateSeed("masterpassphrase")).first);
Ledger::pointer ledger (std::make_shared <Ledger> ( Ledger::pointer ledger (std::make_shared <Ledger> (
rootAddress, startAmount)); masterAccountID, startAmount));
using namespace detail; using namespace detail;
TxnSignApiFacade apiFacade (TxnSignApiFacade::noNetOPs, ledger); TxnSignApiFacade apiFacade (TxnSignApiFacade::noNetOPs, ledger);

View File

@@ -20,7 +20,7 @@
#ifndef RIPPLE_TEST_JTX_ACCOUNT_H_INCLUDED #ifndef RIPPLE_TEST_JTX_ACCOUNT_H_INCLUDED
#define RIPPLE_TEST_JTX_ACCOUNT_H_INCLUDED #define RIPPLE_TEST_JTX_ACCOUNT_H_INCLUDED
#include <ripple/protocol/RippleAddress.h> #include <ripple/protocol/SecretKey.h>
#include <ripple/protocol/UintTypes.h> #include <ripple/protocol/UintTypes.h>
#include <ripple/crypto/KeyType.h> #include <ripple/crypto/KeyType.h>
#include <beast/utility/noexcept.h> #include <beast/utility/noexcept.h>
@@ -37,10 +37,8 @@ class Account
{ {
private: private:
std::string name_; std::string name_;
// VFALCO TODO use AnyPublicKey, AnySecretKey PublicKey pk_;
// instead of RippleAddress SecretKey sk_;
RippleAddress pk_;
RippleAddress sk_;
AccountID id_; AccountID id_;
std::string human_; // base58 public key string std::string human_; // base58 public key string
@@ -58,12 +56,14 @@ public:
#endif #endif
/** Create an account from a key pair. */ /** Create an account from a key pair. */
Account (std::string name, KeyPair&& keys); Account (std::string name,
std::pair<PublicKey, SecretKey> const& keys);
/** Create an account from a simple string name. */ /** Create an account from a simple string name. */
/** @{ */ /** @{ */
Account (std::string name, Account (std::string name,
KeyType type = KeyType::secp256k1); KeyType type = KeyType::secp256k1);
Account (char const* name, Account (char const* name,
KeyType type = KeyType::secp256k1) KeyType type = KeyType::secp256k1)
: Account(std::string(name), type) : Account(std::string(name), type)
@@ -79,14 +79,14 @@ public:
} }
/** Return the public key. */ /** Return the public key. */
RippleAddress const& PublicKey const&
pk() const pk() const
{ {
return pk_; return pk_;
} }
/** Return the secret key. */ /** Return the secret key. */
RippleAddress const& SecretKey const&
sk() const sk() const
{ {
return sk_; return sk_;

View File

@@ -34,7 +34,6 @@
#include <ripple/ledger/CachedSLEs.h> #include <ripple/ledger/CachedSLEs.h>
#include <ripple/protocol/Indexes.h> #include <ripple/protocol/Indexes.h>
#include <ripple/protocol/Issue.h> #include <ripple/protocol/Issue.h>
#include <ripple/protocol/RippleAddress.h>
#include <ripple/protocol/STAmount.h> #include <ripple/protocol/STAmount.h>
#include <ripple/protocol/STObject.h> #include <ripple/protocol/STObject.h>
#include <ripple/protocol/STTx.h> #include <ripple/protocol/STTx.h>
@@ -154,7 +153,7 @@ public:
as a public member for interested callers. as a public member for interested callers.
*/ */
static static
std::shared_ptr<Ledger const> std::shared_ptr<Ledger>
genesis(); genesis();
/** Returns the open ledger. /** Returns the open ledger.

View File

@@ -48,14 +48,14 @@ Account::operator= (Account&& rhs)
} }
#endif #endif
Account::Account( Account::Account(std::string name,
std::string name, KeyPair&& keys) std::pair<PublicKey, SecretKey> const& keys)
: name_(std::move(name)) : name_(std::move(name))
, pk_ (keys.first)
, sk_ (keys.second)
, id_ (calcAccountID(pk_))
, human_ (toBase58(id_))
{ {
pk_ = std::move(keys.publicKey);
sk_ = std::move(keys.secretKey);
id_ = calcAccountID(pk_);
human_ = toBase58(id_);
} }
Account::Account (std::string name, Account::Account (std::string name,
@@ -66,9 +66,7 @@ Account::Account (std::string name,
// Fails on Clang and possibly gcc // Fails on Clang and possibly gcc
: Account(std::move(name), : Account(std::move(name),
#endif #endif
generateKeysFromSeed(type, generateKeyPair(type, generateSeed(name)))
RippleAddress::createSeedGeneric(
name)))
{ {
} }

View File

@@ -44,22 +44,21 @@
#include <ripple/protocol/TxFlags.h> #include <ripple/protocol/TxFlags.h>
#include <ripple/protocol/types.h> #include <ripple/protocol/types.h>
#include <memory> #include <memory>
// VFALCO TODO Use AnyPublicKey, AnySecretKey, AccountID
namespace ripple { namespace ripple {
namespace test { namespace test {
namespace jtx { namespace jtx {
std::shared_ptr<Ledger const> std::shared_ptr<Ledger>
Env::genesis() Env::genesis()
{ {
Account master("master", generateKeysFromSeed( Account const master("master",
KeyType::secp256k1, RippleAddress::createSeedGeneric( generateKeyPair(KeyType::secp256k1,
"masterpassphrase"))); generateSeed("masterpassphrase")));
auto const ledger = auto const ledger =
std::make_shared<Ledger>(master.pk(), std::make_shared<Ledger>(
SYSTEM_CURRENCY_START); master.id(), SYSTEM_CURRENCY_START);
ledger->setClosed(); ledger->setClosed();
return ledger; return ledger;
} }
@@ -67,9 +66,9 @@ Env::genesis()
// VFALCO Could wrap the log in a Journal here // VFALCO Could wrap the log in a Journal here
Env::Env (beast::unit_test::suite& test_) Env::Env (beast::unit_test::suite& test_)
: test(test_) : test(test_)
, master("master", generateKeysFromSeed( , master("master", generateKeyPair(
KeyType::secp256k1, RippleAddress::createSeedGeneric( KeyType::secp256k1,
"masterpassphrase"))) generateSeed("masterpassphrase")))
, closed_ (genesis()) , closed_ (genesis())
, cachedSLEs_ (std::chrono::seconds(5), clock) , cachedSLEs_ (std::chrono::seconds(5), clock)
, openLedger (closed_, config, cachedSLEs_, journal) , openLedger (closed_, config, cachedSLEs_, journal)

View File

@@ -102,17 +102,18 @@ msig::operator()(Env const& env, JTx& jt) const
auto const& e = accounts[i]; auto const& e = accounts[i];
auto& jo = js[i]["SigningAccount"]; auto& jo = js[i]["SigningAccount"];
jo[jss::Account] = e.human(); jo[jss::Account] = e.human();
jo[jss::SigningPubKey] = strHex(makeSlice( jo[jss::SigningPubKey] = strHex(e.pk().slice());
e.pk().getAccountPublic()));
Serializer ss; Serializer ss;
ss.add32 (HashPrefix::txMultiSign); ss.add32 (HashPrefix::txMultiSign);
st->addWithoutSigningFields(ss); st->addWithoutSigningFields(ss);
ss.add160(*signFor); ss.add160(*signFor);
ss.add160(e.id()); ss.add160(e.id());
jo["MultiSignature"] = strHex(makeSlice( auto const sig = ripple::sign(
e.sk().accountPrivateSign(ss.getData()))); *publicKeyType(e.pk().slice()),
e.sk(), ss.slice());
jo["MultiSignature"] =
strHex(Slice{ sig.data(), sig.size() });
} }
}; };
} }
@@ -165,17 +166,19 @@ msig2_t::operator()(Env const& env, JTx& jt) const
{ {
auto& jj = js[j.first]["SigningAccount"]; auto& jj = js[j.first]["SigningAccount"];
jj[jss::Account] = j.second->human(); jj[jss::Account] = j.second->human();
jj[jss::SigningPubKey] = strHex(makeSlice( jj[jss::SigningPubKey] = strHex(
j.second->pk().getAccountPublic())); j.second->pk().slice());
Serializer ss; Serializer ss;
ss.add32 (HashPrefix::txMultiSign); ss.add32 (HashPrefix::txMultiSign);
st->addWithoutSigningFields(ss); st->addWithoutSigningFields(ss);
ss.add160(sign_for.id()); ss.add160(sign_for.id());
ss.add160(j.second->id()); ss.add160(j.second->id());
jj["MultiSignature"] = strHex(makeSlice( auto const sig = ripple::sign(
j.second->sk().accountPrivateSign( *publicKeyType(j.second->pk().slice()),
ss.getData()))); j.second->sk(), ss.slice());
jj["MultiSignature"] =
strHex(Slice{ sig.data(), sig.size() });
} }
} }
}; };

View File

@@ -46,14 +46,15 @@ sign (Json::Value& jv,
Account const& account) Account const& account)
{ {
jv[jss::SigningPubKey] = jv[jss::SigningPubKey] =
strHex(makeSlice( strHex(account.pk().slice());
account.pk().getAccountPublic()));
Serializer ss; Serializer ss;
ss.add32 (HashPrefix::txSign); ss.add32 (HashPrefix::txSign);
parse(jv).add(ss); parse(jv).add(ss);
jv[jss::TxnSignature] = strHex(makeSlice( auto const sig = ripple::sign(
account.sk().accountPrivateSign( *publicKeyType(account.pk().slice()),
ss.getData()))); account.sk(), ss.slice());
jv[jss::TxnSignature] =
strHex(Slice{ sig.data(), sig.size() });
} }
void void

View File

@@ -20,8 +20,6 @@
#include <BeastConfig.h> #include <BeastConfig.h>
#include <ripple/protocol/impl/AccountID.cpp> #include <ripple/protocol/impl/AccountID.cpp>
#include <ripple/protocol/impl/AnyPublicKey.cpp>
#include <ripple/protocol/impl/AnySecretKey.cpp>
#include <ripple/protocol/impl/BuildInfo.cpp> #include <ripple/protocol/impl/BuildInfo.cpp>
#include <ripple/protocol/impl/ByteOrder.cpp> #include <ripple/protocol/impl/ByteOrder.cpp>
#include <ripple/protocol/impl/digest.cpp> #include <ripple/protocol/impl/digest.cpp>