mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Address issues identified by external review:
* RIPD-1617, RIPD-1619, RIPD-1621:
Verify serialized public keys more strictly before
using them.
* RIPD-1618:
* Simplify the base58 decoder logic.
* Reduce the complexity of the base58 encoder and
eliminate a potential out-of-bounds memory access.
* Improve type safety by using an `enum class` to
enforce strict type checking for token types.
* RIPD-1616:
Avoid calling `memcpy` with a null pointer even if the
size is specified as zero, since it results in undefined
behavior.
Acknowledgements:
Ripple thanks Guido Vranken for responsibly disclosing these
issues.
Bug Bounties and Responsible Disclosures:
We welcome reviews of the rippled code and urge researchers
to responsibly disclose any issues that they may find. For
more on Ripple's Bug Bounty program, please visit:
https://ripple.com/bug-bounty
This commit is contained in:
@@ -251,7 +251,7 @@ public:
|
||||
std::string cfgManifest;
|
||||
for (auto const& man : inManifests)
|
||||
s1.push_back (toBase58(
|
||||
TokenType::TOKEN_NODE_PUBLIC, man->masterKey));
|
||||
TokenType::NodePublic, man->masterKey));
|
||||
unl->load (emptyLocalKey, s1, keys);
|
||||
|
||||
m.save (dbCon, "ValidatorManifests",
|
||||
@@ -428,7 +428,7 @@ public:
|
||||
|
||||
{
|
||||
auto const valSecret = parseBase58<SecretKey>(
|
||||
TokenType::TOKEN_NODE_PRIVATE,
|
||||
TokenType::NodePrivate,
|
||||
"paQmjZ37pKKPMrgadBLsuf9ab7Y7EUNzh27LQrZqoexpAs31nJi");
|
||||
|
||||
// Format token string to test trim()
|
||||
|
||||
@@ -1065,8 +1065,21 @@ struct PayChan_test : public beast::unit_test::suite
|
||||
jv.removeMember("PublicKey");
|
||||
env (jv, ter(temMALFORMED));
|
||||
|
||||
jv["PublicKey"] = pkHex;
|
||||
env (jv);
|
||||
{
|
||||
auto const txn = R"*(
|
||||
{
|
||||
|
||||
"channel_id":"5DB01B7FFED6B67E6B0414DED11E051D2EE2B7619CE0EAA6286D67A3A4D5BDB3",
|
||||
"signature":
|
||||
"304402204EF0AFB78AC23ED1C472E74F4299C0C21F1B21D07EFC0A3838A420F76D783A400220154FB11B6F54320666E4C36CA7F686C16A3A0456800BBC43746F34AF50290064",
|
||||
"public_key":
|
||||
"aKijDDiC2q2gXjMpM7i4BUS6cmixgsEe18e7CjsUxwihKfuoFgS5",
|
||||
"amount": "1000000"
|
||||
}
|
||||
)*";
|
||||
auto const r = env.rpc("json", "channel_verify", txn);
|
||||
BEAST_EXPECT(r["result"]["error"] == "publicMalformed");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -82,7 +82,7 @@ public:
|
||||
|
||||
// Keys when using [validation_token]
|
||||
auto const tokenSecretKey = *parseBase58<SecretKey>(
|
||||
TokenType::TOKEN_NODE_PRIVATE, tokenSecretStr);
|
||||
TokenType::NodePrivate, tokenSecretStr);
|
||||
|
||||
auto const tokenPublicKey =
|
||||
derivePublicKey(KeyType::secp256k1, tokenSecretKey);
|
||||
|
||||
@@ -172,7 +172,7 @@ private:
|
||||
PublicKey const &publicKey,
|
||||
char const* comment = nullptr)
|
||||
{
|
||||
auto ret = toBase58 (TokenType::TOKEN_NODE_PUBLIC, publicKey);
|
||||
auto ret = toBase58 (TokenType::NodePublic, publicKey);
|
||||
|
||||
if (comment)
|
||||
ret += comment;
|
||||
@@ -271,7 +271,7 @@ private:
|
||||
manifests, manifests, env.timeKeeper(), journal);
|
||||
|
||||
auto const localSigningPublic = parseBase58<PublicKey> (
|
||||
TokenType::TOKEN_NODE_PUBLIC, cfgKeys.front());
|
||||
TokenType::NodePublic, cfgKeys.front());
|
||||
|
||||
BEAST_EXPECT(trustedKeys->load (
|
||||
*localSigningPublic, cfgKeys, emptyCfgPublishers));
|
||||
@@ -330,7 +330,7 @@ private:
|
||||
badPublishers.clear();
|
||||
for (auto const& key : keys)
|
||||
badPublishers.push_back (
|
||||
toBase58 (TokenType::TOKEN_NODE_PUBLIC, key));
|
||||
toBase58 (TokenType::NodePublic, key));
|
||||
|
||||
BEAST_EXPECT(! trustedKeys->load (
|
||||
emptyLocalKey, emptyCfgKeys, badPublishers));
|
||||
@@ -533,7 +533,7 @@ private:
|
||||
{
|
||||
auto const valKey = randomNode();
|
||||
cfgKeys.push_back (toBase58(
|
||||
TokenType::TOKEN_NODE_PUBLIC, valKey));
|
||||
TokenType::NodePublic, valKey));
|
||||
if (cfgKeys.size () <= n - 5)
|
||||
activeValidators.emplace (valKey);
|
||||
}
|
||||
@@ -550,7 +550,7 @@ private:
|
||||
for (auto const& val : cfgKeys)
|
||||
{
|
||||
if (auto const valKey = parseBase58<PublicKey>(
|
||||
TokenType::TOKEN_NODE_PUBLIC, val))
|
||||
TokenType::NodePublic, val))
|
||||
{
|
||||
BEAST_EXPECT(trustedKeys->listed (*valKey));
|
||||
if (i++ < activeValidators.size ())
|
||||
@@ -567,7 +567,7 @@ private:
|
||||
hash_set<PublicKey> activeValidators;
|
||||
for (auto const valKey : cfgKeys)
|
||||
activeValidators.emplace (*parseBase58<PublicKey>(
|
||||
TokenType::TOKEN_NODE_PUBLIC, valKey));
|
||||
TokenType::NodePublic, valKey));
|
||||
trustedKeys->onConsensusStart (activeValidators);
|
||||
BEAST_EXPECT(trustedKeys->quorum () == cfgKeys.size() * 4/5);
|
||||
}
|
||||
@@ -579,7 +579,7 @@ private:
|
||||
derivePublicKey(KeyType::ed25519, masterPrivate);
|
||||
|
||||
std::vector<std::string> cfgKeys ({
|
||||
toBase58 (TokenType::TOKEN_NODE_PUBLIC, masterPublic)});
|
||||
toBase58 (TokenType::NodePublic, masterPublic)});
|
||||
|
||||
BEAST_EXPECT(trustedKeys->load (
|
||||
emptyLocalKey, cfgKeys, cfgPublishers));
|
||||
@@ -682,8 +682,8 @@ private:
|
||||
std::vector<PublicKey> keys ({ randomNode (), randomNode () });
|
||||
hash_set<PublicKey> activeValidators;
|
||||
std::vector<std::string> cfgKeys ({
|
||||
toBase58 (TokenType::TOKEN_NODE_PUBLIC, keys[0]),
|
||||
toBase58 (TokenType::TOKEN_NODE_PUBLIC, keys[1])});
|
||||
toBase58 (TokenType::NodePublic, keys[0]),
|
||||
toBase58 (TokenType::NodePublic, keys[1])});
|
||||
|
||||
BEAST_EXPECT(trustedKeys->load (
|
||||
emptyLocalKey, cfgKeys, cfgPublishers));
|
||||
@@ -703,7 +703,7 @@ private:
|
||||
|
||||
auto const node = randomNode ();
|
||||
std::vector<std::string> cfgKeys ({
|
||||
toBase58 (TokenType::TOKEN_NODE_PUBLIC, node)});
|
||||
toBase58 (TokenType::NodePublic, node)});
|
||||
hash_set<PublicKey> activeValidators;
|
||||
|
||||
BEAST_EXPECT(trustedKeys->load (
|
||||
@@ -724,8 +724,8 @@ private:
|
||||
std::vector<PublicKey> keys ({ randomNode (), randomNode () });
|
||||
hash_set<PublicKey> activeValidators ({ keys[0] });
|
||||
std::vector<std::string> cfgKeys ({
|
||||
toBase58 (TokenType::TOKEN_NODE_PUBLIC, keys[0]),
|
||||
toBase58 (TokenType::TOKEN_NODE_PUBLIC, keys[1])});
|
||||
toBase58 (TokenType::NodePublic, keys[0]),
|
||||
toBase58 (TokenType::NodePublic, keys[1])});
|
||||
|
||||
auto const localKey = randomNode ();
|
||||
BEAST_EXPECT(trustedKeys->load (
|
||||
@@ -827,7 +827,7 @@ private:
|
||||
{
|
||||
auto const valKey = randomNode();
|
||||
cfgKeys.push_back (toBase58(
|
||||
TokenType::TOKEN_NODE_PUBLIC, valKey));
|
||||
TokenType::NodePublic, valKey));
|
||||
activeValidators.emplace (valKey);
|
||||
|
||||
BEAST_EXPECT(trustedKeys->load (
|
||||
@@ -850,14 +850,14 @@ private:
|
||||
hash_set<PublicKey> activeValidators;
|
||||
|
||||
std::vector<std::string> cfgKeys {
|
||||
toBase58(TokenType::TOKEN_NODE_PUBLIC, localKey)};
|
||||
toBase58(TokenType::NodePublic, localKey)};
|
||||
cfgKeys.reserve(9);
|
||||
|
||||
while (cfgKeys.size() < cfgKeys.capacity())
|
||||
{
|
||||
auto const valKey = randomNode();
|
||||
cfgKeys.push_back (toBase58(
|
||||
TokenType::TOKEN_NODE_PUBLIC, valKey));
|
||||
TokenType::NodePublic, valKey));
|
||||
activeValidators.emplace (valKey);
|
||||
|
||||
BEAST_EXPECT(trustedKeys->load (
|
||||
@@ -950,7 +950,7 @@ private:
|
||||
jtx::Env env(*this);
|
||||
|
||||
auto toStr = [](PublicKey const& publicKey) {
|
||||
return toBase58(TokenType::TOKEN_NODE_PUBLIC, publicKey);
|
||||
return toBase58(TokenType::NodePublic, publicKey);
|
||||
};
|
||||
|
||||
// Config listed keys
|
||||
|
||||
@@ -133,7 +133,7 @@ public:
|
||||
|
||||
auto const node = randomNode ();
|
||||
auto const name = toBase58(
|
||||
TokenType::TOKEN_NODE_PUBLIC,
|
||||
TokenType::NodePublic,
|
||||
node);
|
||||
std::uint32_t load = 0;
|
||||
NetClock::time_point tick = {};
|
||||
@@ -202,7 +202,7 @@ public:
|
||||
char const* comment = nullptr)
|
||||
{
|
||||
auto ret = toBase58(
|
||||
TokenType::TOKEN_NODE_PUBLIC,
|
||||
TokenType::NodePublic,
|
||||
publicKey);
|
||||
|
||||
if (comment)
|
||||
|
||||
@@ -231,12 +231,12 @@ public:
|
||||
void testBase58 (KeyType keyType)
|
||||
{
|
||||
// Try converting short, long and malformed data
|
||||
BEAST_EXPECT(!parseBase58<PublicKey> (TOKEN_NODE_PUBLIC, ""));
|
||||
BEAST_EXPECT(!parseBase58<PublicKey> (TOKEN_NODE_PUBLIC, " "));
|
||||
BEAST_EXPECT(!parseBase58<PublicKey> (TOKEN_NODE_PUBLIC, "!ty89234gh45"));
|
||||
BEAST_EXPECT(!parseBase58<PublicKey> (TokenType::NodePublic, ""));
|
||||
BEAST_EXPECT(!parseBase58<PublicKey> (TokenType::NodePublic, " "));
|
||||
BEAST_EXPECT(!parseBase58<PublicKey> (TokenType::NodePublic, "!ty89234gh45"));
|
||||
|
||||
auto const good = toBase58 (
|
||||
TokenType::TOKEN_NODE_PUBLIC,
|
||||
TokenType::NodePublic,
|
||||
derivePublicKey (
|
||||
keyType,
|
||||
randomSecretKey()));
|
||||
@@ -251,7 +251,7 @@ public:
|
||||
while (!s.empty())
|
||||
{
|
||||
s.erase (r(s) % s.size(), 1);
|
||||
BEAST_EXPECT(!parseBase58<PublicKey> (TOKEN_NODE_PUBLIC, s));
|
||||
BEAST_EXPECT(!parseBase58<PublicKey> (TokenType::NodePublic, s));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,7 +260,7 @@ public:
|
||||
{
|
||||
auto s = good;
|
||||
s.resize (s.size() + i, s[i % s.size()]);
|
||||
BEAST_EXPECT(!parseBase58<PublicKey> (TOKEN_NODE_PUBLIC, s));
|
||||
BEAST_EXPECT(!parseBase58<PublicKey> (TokenType::NodePublic, s));
|
||||
}
|
||||
|
||||
// Strings with invalid Base58 characters
|
||||
@@ -270,7 +270,7 @@ public:
|
||||
{
|
||||
auto s = good;
|
||||
s[i % s.size()] = c;
|
||||
BEAST_EXPECT(!parseBase58<PublicKey> (TOKEN_NODE_PUBLIC, s));
|
||||
BEAST_EXPECT(!parseBase58<PublicKey> (TokenType::NodePublic, s));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,7 +281,7 @@ public:
|
||||
for (auto c : std::string("apsrJqtv7"))
|
||||
{
|
||||
s[0] = c;
|
||||
BEAST_EXPECT(!parseBase58<PublicKey> (TOKEN_NODE_PUBLIC, s));
|
||||
BEAST_EXPECT(!parseBase58<PublicKey> (TokenType::NodePublic, s));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -294,12 +294,12 @@ public:
|
||||
for (std::size_t i = 0; i != keys.size(); ++i)
|
||||
{
|
||||
auto const si = toBase58 (
|
||||
TokenType::TOKEN_NODE_PUBLIC,
|
||||
TokenType::NodePublic,
|
||||
keys[i]);
|
||||
BEAST_EXPECT(!si.empty());
|
||||
|
||||
auto const ski = parseBase58<PublicKey> (
|
||||
TOKEN_NODE_PUBLIC, si);
|
||||
TokenType::NodePublic, si);
|
||||
BEAST_EXPECT(ski && (keys[i] == *ski));
|
||||
|
||||
for (std::size_t j = i; j != keys.size(); ++j)
|
||||
@@ -307,13 +307,13 @@ public:
|
||||
BEAST_EXPECT((keys[i] == keys[j]) == (i == j));
|
||||
|
||||
auto const sj = toBase58 (
|
||||
TokenType::TOKEN_NODE_PUBLIC,
|
||||
TokenType::NodePublic,
|
||||
keys[j]);
|
||||
|
||||
BEAST_EXPECT((si == sj) == (i == j));
|
||||
|
||||
auto const skj = parseBase58<PublicKey> (
|
||||
TOKEN_NODE_PUBLIC, sj);
|
||||
TokenType::NodePublic, sj);
|
||||
BEAST_EXPECT(skj && (keys[j] == *skj));
|
||||
|
||||
BEAST_EXPECT((*ski == *skj) == (i == j));
|
||||
@@ -333,7 +333,7 @@ public:
|
||||
generateSeed ("masterpassphrase")));
|
||||
|
||||
auto const pk2 = parseBase58<PublicKey> (
|
||||
TOKEN_NODE_PUBLIC,
|
||||
TokenType::NodePublic,
|
||||
"n94a1u4jAz288pZLtw6yFWVbi89YamiC6JBXPVUj5zmExe5fTVg9");
|
||||
BEAST_EXPECT(pk2);
|
||||
|
||||
@@ -352,7 +352,7 @@ public:
|
||||
generateSeed ("masterpassphrase")));
|
||||
|
||||
auto const pk2 = parseBase58<PublicKey> (
|
||||
TOKEN_NODE_PUBLIC,
|
||||
TokenType::NodePublic,
|
||||
"nHUeeJCSY2dM71oxM8Cgjouf5ekTuev2mwDpc374aLMxzDLXNmjf");
|
||||
BEAST_EXPECT(pk2);
|
||||
|
||||
|
||||
111
src/test/protocol/STValidation_test.cpp
Normal file
111
src/test/protocol/STValidation_test.cpp
Normal file
@@ -0,0 +1,111 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
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 <BeastConfig.h>
|
||||
#include <ripple/basics/Log.h>
|
||||
#include <ripple/protocol/JsonFields.h>
|
||||
#include <ripple/protocol/SecretKey.h>
|
||||
#include <ripple/protocol/st.h>
|
||||
#include <ripple/json/json_reader.h>
|
||||
#include <ripple/json/to_string.h>
|
||||
#include <ripple/beast/unit_test.h>
|
||||
#include <test/jtx.h>
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
class STValidation_test : public beast::unit_test::suite
|
||||
{
|
||||
public:
|
||||
void testDeserialization ()
|
||||
{
|
||||
testcase ("Deserialization");
|
||||
|
||||
constexpr unsigned char payload1[] =
|
||||
{ // specifies an Ed25519 public key
|
||||
0x72, 0x00, 0x73, 0x21, 0xed, 0x78, 0x00, 0xe6, 0x73, 0x00, 0x72, 0x00, 0x3c, 0x00, 0x00, 0x00,
|
||||
0x88, 0x00, 0xe6, 0x73, 0x38, 0x00, 0x00, 0x8a, 0x00, 0x88, 0x4e, 0x31, 0x30, 0x5f, 0x5f, 0x63,
|
||||
0x78, 0x78, 0x61, 0x62, 0x69, 0x76, 0x31, 0x30, 0x37, 0x5f, 0x5f, 0x63, 0x6c, 0x61, 0x73, 0x73,
|
||||
0x5f, 0x74, 0x79, 0x70, 0x65, 0x5f, 0x69, 0x6e, 0x66, 0x6f, 0x45, 0x00, 0xe6, 0x88, 0x54, 0x72,
|
||||
0x75, 0x73, 0x74, 0x53, 0x65, 0x74, 0x65, 0x61, 0x74, 0x65, 0x88, 0x00, 0xe6, 0x88, 0x00, 0xe6,
|
||||
0x73, 0x00, 0x72, 0x00, 0x8a, 0x00, 0x88, 0x00, 0xe6
|
||||
};
|
||||
|
||||
constexpr unsigned char payload2[] =
|
||||
{
|
||||
0x73, 0x21, 0xed, 0xff, 0x03, 0x1c, 0xbe, 0x65, 0x22, 0x61, 0x9c, 0x5e, 0x13, 0x12, 0x00, 0x3b,
|
||||
0x43, 0x00, 0x00, 0x00, 0xf7, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x13, 0x13, 0x13,
|
||||
0x3a, 0x27, 0xff
|
||||
};
|
||||
|
||||
constexpr unsigned char payload3[] =
|
||||
{ // Has no public key at all
|
||||
0x72, 0x00, 0x76, 0x31, 0x30, 0x37, 0x5f, 0x5f, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x5f, 0x74, 0x79,
|
||||
0x70, 0x65, 0x5f, 0x69, 0x6e, 0x66, 0x6f, 0x45, 0x00, 0xe6, 0x88, 0x54, 0x72, 0x75, 0x73, 0x74,
|
||||
0x53, 0x65, 0x74, 0x65, 0x61, 0x74, 0x65, 0x88, 0x00, 0xe6, 0x88, 0x00, 0xe6, 0x73, 0x00, 0x72,
|
||||
0x00, 0x8a, 0x00, 0x88, 0x00, 0xe6
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
SerialIter sit{payload1, sizeof(payload1)};
|
||||
auto stx = std::make_shared<ripple::STValidation>(sit);
|
||||
fail("An exception should have been thrown");
|
||||
}
|
||||
catch (std::exception const& e)
|
||||
{
|
||||
BEAST_EXPECT(strcmp(e.what(), "Invalid public key in validation") == 0);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
SerialIter sit{payload2, sizeof(payload2)};
|
||||
auto stx = std::make_shared<ripple::STValidation>(sit);
|
||||
fail("An exception should have been thrown");
|
||||
}
|
||||
catch (std::exception const& e)
|
||||
{
|
||||
BEAST_EXPECT(strcmp(e.what(), "Invalid public key in validation") == 0);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
SerialIter sit{payload3, sizeof(payload3)};
|
||||
auto stx = std::make_shared<ripple::STValidation>(sit);
|
||||
fail("An exception should have been thrown");
|
||||
}
|
||||
catch (std::exception const& e)
|
||||
{
|
||||
log << e.what() << "\n";
|
||||
BEAST_EXPECT(strcmp(e.what(), "Invalid public key in validation") == 0);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
run()
|
||||
{
|
||||
testDeserialization();
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(STValidation,protocol,ripple);
|
||||
|
||||
} // ripple
|
||||
@@ -320,7 +320,7 @@ public:
|
||||
generateSeed ("masterpassphrase"));
|
||||
|
||||
auto const sk2 = parseBase58<SecretKey> (
|
||||
TOKEN_NODE_PRIVATE,
|
||||
TokenType::NodePrivate,
|
||||
"pnen77YEeUd4fFKG7iycBWcwKpTaeFRkW2WFostaATy1DSupwXe");
|
||||
BEAST_EXPECT(sk2);
|
||||
|
||||
@@ -333,7 +333,7 @@ public:
|
||||
generateSeed ("masterpassphrase"));
|
||||
|
||||
auto const sk2 = parseBase58<SecretKey> (
|
||||
TOKEN_NODE_PRIVATE,
|
||||
TokenType::NodePrivate,
|
||||
"paKv46LztLqK3GaKz1rG2nQGN6M4JLyRtxFBYFTw4wAVHtGys36");
|
||||
BEAST_EXPECT(sk2);
|
||||
|
||||
@@ -341,12 +341,12 @@ public:
|
||||
}
|
||||
|
||||
// Try converting short, long and malformed data
|
||||
BEAST_EXPECT(!parseBase58<SecretKey> (TOKEN_NODE_PRIVATE, ""));
|
||||
BEAST_EXPECT(!parseBase58<SecretKey> (TOKEN_NODE_PRIVATE, " "));
|
||||
BEAST_EXPECT(!parseBase58<SecretKey> (TOKEN_NODE_PRIVATE, "!35gty9mhju8nfjl"));
|
||||
BEAST_EXPECT(!parseBase58<SecretKey> (TokenType::NodePrivate, ""));
|
||||
BEAST_EXPECT(!parseBase58<SecretKey> (TokenType::NodePrivate, " "));
|
||||
BEAST_EXPECT(!parseBase58<SecretKey> (TokenType::NodePrivate, "!35gty9mhju8nfjl"));
|
||||
|
||||
auto const good = toBase58 (
|
||||
TokenType::TOKEN_NODE_PRIVATE,
|
||||
TokenType::NodePrivate,
|
||||
randomSecretKey());
|
||||
|
||||
// Short (non-empty) strings
|
||||
@@ -359,7 +359,7 @@ public:
|
||||
while (!s.empty())
|
||||
{
|
||||
s.erase (r(s) % s.size(), 1);
|
||||
BEAST_EXPECT(!parseBase58<SecretKey> (TOKEN_NODE_PRIVATE, s));
|
||||
BEAST_EXPECT(!parseBase58<SecretKey> (TokenType::NodePrivate, s));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -368,7 +368,7 @@ public:
|
||||
{
|
||||
auto s = good;
|
||||
s.resize (s.size() + i, s[i % s.size()]);
|
||||
BEAST_EXPECT(!parseBase58<SecretKey> (TOKEN_NODE_PRIVATE, s));
|
||||
BEAST_EXPECT(!parseBase58<SecretKey> (TokenType::NodePrivate, s));
|
||||
}
|
||||
|
||||
// Strings with invalid Base58 characters
|
||||
@@ -378,7 +378,7 @@ public:
|
||||
{
|
||||
auto s = good;
|
||||
s[i % s.size()] = c;
|
||||
BEAST_EXPECT(!parseBase58<SecretKey> (TOKEN_NODE_PRIVATE, s));
|
||||
BEAST_EXPECT(!parseBase58<SecretKey> (TokenType::NodePrivate, s));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -389,7 +389,7 @@ public:
|
||||
for (auto c : std::string("ansrJqtv7"))
|
||||
{
|
||||
s[0] = c;
|
||||
BEAST_EXPECT(!parseBase58<SecretKey> (TOKEN_NODE_PRIVATE, s));
|
||||
BEAST_EXPECT(!parseBase58<SecretKey> (TokenType::NodePrivate, s));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -402,12 +402,12 @@ public:
|
||||
for (std::size_t i = 0; i != keys.size(); ++i)
|
||||
{
|
||||
auto const si = toBase58 (
|
||||
TokenType::TOKEN_NODE_PRIVATE,
|
||||
TokenType::NodePrivate,
|
||||
keys[i]);
|
||||
BEAST_EXPECT(!si.empty());
|
||||
|
||||
auto const ski = parseBase58<SecretKey> (
|
||||
TOKEN_NODE_PRIVATE, si);
|
||||
TokenType::NodePrivate, si);
|
||||
BEAST_EXPECT(ski && keys[i] == *ski);
|
||||
|
||||
for (std::size_t j = i; j != keys.size(); ++j)
|
||||
@@ -415,13 +415,13 @@ public:
|
||||
BEAST_EXPECT((keys[i] == keys[j]) == (i == j));
|
||||
|
||||
auto const sj = toBase58 (
|
||||
TokenType::TOKEN_NODE_PRIVATE,
|
||||
TokenType::NodePrivate,
|
||||
keys[j]);
|
||||
|
||||
BEAST_EXPECT((si == sj) == (i == j));
|
||||
|
||||
auto const skj = parseBase58<SecretKey> (
|
||||
TOKEN_NODE_PRIVATE, sj);
|
||||
TokenType::NodePrivate, sj);
|
||||
BEAST_EXPECT(skj && keys[j] == *skj);
|
||||
|
||||
BEAST_EXPECT((*ski == *skj) == (i == j));
|
||||
|
||||
@@ -136,9 +136,9 @@ public:
|
||||
auto const publicKey = derivePublicKey (
|
||||
KeyType::secp256k1, secretKey);
|
||||
|
||||
BEAST_EXPECT(toBase58(TokenType::TOKEN_NODE_PUBLIC, publicKey) ==
|
||||
BEAST_EXPECT(toBase58(TokenType::NodePublic, publicKey) ==
|
||||
"n94a1u4jAz288pZLtw6yFWVbi89YamiC6JBXPVUj5zmExe5fTVg9");
|
||||
BEAST_EXPECT(toBase58(TokenType::TOKEN_NODE_PRIVATE, secretKey) ==
|
||||
BEAST_EXPECT(toBase58(TokenType::NodePrivate, secretKey) ==
|
||||
"pnen77YEeUd4fFKG7iycBWcwKpTaeFRkW2WFostaATy1DSupwXe");
|
||||
BEAST_EXPECT(to_string(calcNodeID(publicKey)) ==
|
||||
"7E59C17D50F5959C7B158FEC95C8F815BF653DC8");
|
||||
@@ -179,9 +179,9 @@ public:
|
||||
auto const publicKey = derivePublicKey (
|
||||
KeyType::ed25519, secretKey);
|
||||
|
||||
BEAST_EXPECT(toBase58(TokenType::TOKEN_NODE_PUBLIC, publicKey) ==
|
||||
BEAST_EXPECT(toBase58(TokenType::NodePublic, publicKey) ==
|
||||
"nHUeeJCSY2dM71oxM8Cgjouf5ekTuev2mwDpc374aLMxzDLXNmjf");
|
||||
BEAST_EXPECT(toBase58(TokenType::TOKEN_NODE_PRIVATE, secretKey) ==
|
||||
BEAST_EXPECT(toBase58(TokenType::NodePrivate, secretKey) ==
|
||||
"paKv46LztLqK3GaKz1rG2nQGN6M4JLyRtxFBYFTw4wAVHtGys36");
|
||||
BEAST_EXPECT(to_string(calcNodeID(publicKey)) ==
|
||||
"AA066C988C712815CC37AF71472B7CBBBD4E2A0A");
|
||||
@@ -223,9 +223,9 @@ public:
|
||||
|
||||
BEAST_EXPECT(toBase58(calcAccountID(keyPair.first)) ==
|
||||
"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh");
|
||||
BEAST_EXPECT(toBase58(TokenType::TOKEN_ACCOUNT_PUBLIC, keyPair.first) ==
|
||||
BEAST_EXPECT(toBase58(TokenType::AccountPublic, keyPair.first) ==
|
||||
"aBQG8RQAzjs1eTKFEAQXr2gS4utcDiEC9wmi7pfUPTi27VCahwgw");
|
||||
BEAST_EXPECT(toBase58(TokenType::TOKEN_ACCOUNT_SECRET, keyPair.second) ==
|
||||
BEAST_EXPECT(toBase58(TokenType::AccountSecret, keyPair.second) ==
|
||||
"p9JfM6HHi64m6mvB6v5k7G2b1cXzGmYiCNJf6GHPKvFTWdeRVjh");
|
||||
|
||||
auto sig = sign (keyPair.first, keyPair.second, makeSlice(message1));
|
||||
@@ -263,9 +263,9 @@ public:
|
||||
|
||||
BEAST_EXPECT(to_string(calcAccountID(keyPair.first)) ==
|
||||
"rGWrZyQqhTp9Xu7G5Pkayo7bXjH4k4QYpf");
|
||||
BEAST_EXPECT(toBase58(TokenType::TOKEN_ACCOUNT_PUBLIC, keyPair.first) ==
|
||||
BEAST_EXPECT(toBase58(TokenType::AccountPublic, keyPair.first) ==
|
||||
"aKGheSBjmCsKJVuLNKRAKpZXT6wpk2FCuEZAXJupXgdAxX5THCqR");
|
||||
BEAST_EXPECT(toBase58(TokenType::TOKEN_ACCOUNT_SECRET, keyPair.second) ==
|
||||
BEAST_EXPECT(toBase58(TokenType::AccountSecret, keyPair.second) ==
|
||||
"pwDQjwEhbUBmPuEjFpEG75bFhv2obkCB7NxQsfFxM7xGHBMVPu9");
|
||||
|
||||
auto sig = sign (keyPair.first, keyPair.second, makeSlice(message1));
|
||||
@@ -305,16 +305,16 @@ public:
|
||||
auto const node1 = randomKeyPair(KeyType::secp256k1);
|
||||
|
||||
BEAST_EXPECT(!parseGenericSeed (
|
||||
toBase58 (TokenType::TOKEN_NODE_PUBLIC, node1.first)));
|
||||
toBase58 (TokenType::NodePublic, node1.first)));
|
||||
BEAST_EXPECT(!parseGenericSeed (
|
||||
toBase58 (TokenType::TOKEN_NODE_PRIVATE, node1.second)));
|
||||
toBase58 (TokenType::NodePrivate, node1.second)));
|
||||
|
||||
auto const node2 = randomKeyPair(KeyType::ed25519);
|
||||
|
||||
BEAST_EXPECT(!parseGenericSeed (
|
||||
toBase58 (TokenType::TOKEN_NODE_PUBLIC, node2.first)));
|
||||
toBase58 (TokenType::NodePublic, node2.first)));
|
||||
BEAST_EXPECT(!parseGenericSeed (
|
||||
toBase58 (TokenType::TOKEN_NODE_PRIVATE, node2.second)));
|
||||
toBase58 (TokenType::NodePrivate, node2.second)));
|
||||
|
||||
auto const account1 = generateKeyPair(
|
||||
KeyType::secp256k1, randomSeed ());
|
||||
@@ -322,9 +322,9 @@ public:
|
||||
BEAST_EXPECT(!parseGenericSeed (
|
||||
toBase58(calcAccountID(account1.first))));
|
||||
BEAST_EXPECT(!parseGenericSeed (
|
||||
toBase58(TokenType::TOKEN_ACCOUNT_PUBLIC, account1.first)));
|
||||
toBase58(TokenType::AccountPublic, account1.first)));
|
||||
BEAST_EXPECT(!parseGenericSeed (
|
||||
toBase58(TokenType::TOKEN_ACCOUNT_SECRET, account1.second)));
|
||||
toBase58(TokenType::AccountSecret, account1.second)));
|
||||
|
||||
auto const account2 = generateKeyPair(
|
||||
KeyType::ed25519, randomSeed ());
|
||||
@@ -332,9 +332,9 @@ public:
|
||||
BEAST_EXPECT(!parseGenericSeed (
|
||||
toBase58(calcAccountID(account2.first))));
|
||||
BEAST_EXPECT(!parseGenericSeed (
|
||||
toBase58(TokenType::TOKEN_ACCOUNT_PUBLIC, account2.first)));
|
||||
toBase58(TokenType::AccountPublic, account2.first)));
|
||||
BEAST_EXPECT(!parseGenericSeed (
|
||||
toBase58(TokenType::TOKEN_ACCOUNT_SECRET, account2.second)));
|
||||
toBase58(TokenType::AccountSecret, account2.second)));
|
||||
}
|
||||
|
||||
void run() override
|
||||
|
||||
@@ -69,7 +69,7 @@ class AccountCurrencies_test : public beast::unit_test::suite
|
||||
{ // strict mode, using properly formatted bitcoin token
|
||||
Json::Value params;
|
||||
params[jss::account] = base58EncodeTokenBitcoin (
|
||||
TOKEN_ACCOUNT_ID, alice.id().data(), alice.id().size());
|
||||
TokenType::AccountID, alice.id().data(), alice.id().size());
|
||||
params[jss::strict] = true;
|
||||
auto const result = env.rpc ("json", "account_currencies",
|
||||
boost::lexical_cast<std::string>(params)) [jss::result];
|
||||
|
||||
@@ -308,7 +308,7 @@ public:
|
||||
(keyType ? *keyType : "no key_type"));
|
||||
|
||||
auto const publicKey = parseBase58<PublicKey>(
|
||||
TokenType::TOKEN_ACCOUNT_PUBLIC, strings.public_key);
|
||||
TokenType::AccountPublic, strings.public_key);
|
||||
BEAST_EXPECT(publicKey);
|
||||
|
||||
if (!keyType)
|
||||
|
||||
@@ -112,7 +112,7 @@ class NoRippleCheck_test : public beast::unit_test::suite
|
||||
// parsing as a seed to fail
|
||||
Json::Value params;
|
||||
params[jss::account] =
|
||||
toBase58 (TokenType::TOKEN_NODE_PRIVATE, alice.sk());
|
||||
toBase58 (TokenType::NodePrivate, alice.sk());
|
||||
params[jss::role] = "user";
|
||||
params[jss::ledger] = "current";
|
||||
auto const result = env.rpc ("json", "noripple_check",
|
||||
|
||||
@@ -58,7 +58,7 @@ class Peers_test : public beast::unit_test::suite
|
||||
200,
|
||||
env.timeKeeper().now() - 10s);
|
||||
nodes.insert( std::make_pair(
|
||||
toBase58(TokenType::TOKEN_NODE_PUBLIC, kp.first), name));
|
||||
toBase58(TokenType::NodePublic, kp.first), name));
|
||||
}
|
||||
|
||||
// make request, verify nodes we created match
|
||||
|
||||
@@ -327,7 +327,7 @@ public:
|
||||
return;
|
||||
|
||||
std::string const valPublicKey =
|
||||
toBase58 (TokenType::TOKEN_NODE_PUBLIC,
|
||||
toBase58 (TokenType::NodePublic,
|
||||
derivePublicKey (KeyType::secp256k1,
|
||||
generateSecretKey (KeyType::secp256k1, *parsedseed)));
|
||||
|
||||
|
||||
@@ -183,7 +183,7 @@ public:
|
||||
using address_type = boost::asio::ip::address;
|
||||
|
||||
auto toStr = [](PublicKey const& publicKey) {
|
||||
return toBase58(TokenType::TOKEN_NODE_PUBLIC, publicKey);
|
||||
return toBase58(TokenType::NodePublic, publicKey);
|
||||
};
|
||||
|
||||
// Publisher manifest/signing keys
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include <test/protocol/STAmount_test.cpp>
|
||||
#include <test/protocol/STObject_test.cpp>
|
||||
#include <test/protocol/STTx_test.cpp>
|
||||
#include <test/protocol/STValidation_test.cpp>
|
||||
#include <test/protocol/TER_test.cpp>
|
||||
#include <test/protocol/types_test.cpp>
|
||||
#include <test/protocol/XRPAmount_test.cpp>
|
||||
#include <test/protocol/XRPAmount_test.cpp>
|
||||
|
||||
Reference in New Issue
Block a user