Merge branch 'hotfix/fix-memo-field-encryption' into 'develop'

Fix memo field encryption

See merge request PBSA/peerplays!36
This commit is contained in:
serkixenos 2021-11-30 22:44:56 +00:00
commit 536e07d726
4 changed files with 194 additions and 27 deletions

View file

@ -30,7 +30,10 @@ namespace graphene { namespace chain {
void memo_data::set_message(const fc::ecc::private_key& priv, const fc::ecc::public_key& pub,
const string& msg, uint64_t custom_nonce)
{
if( priv != fc::ecc::private_key() && pub.valid() )
bool should_encrypt = (priv != fc::ecc::private_key() && pub.valid());
should_encrypt = (should_encrypt) && (msg.size()) && (msg.find("#") == 0);
if( should_encrypt )
{
from = priv.get_public_key();
to = pub;
@ -49,6 +52,7 @@ void memo_data::set_message(const fc::ecc::private_key& priv, const fc::ecc::pub
}
else
{
to = public_key_type();
auto text = memo_message(0, msg).serialize();
message = vector<char>(text.begin(), text.end());
}
@ -57,7 +61,7 @@ void memo_data::set_message(const fc::ecc::private_key& priv, const fc::ecc::pub
string memo_data::get_message(const fc::ecc::private_key& priv,
const fc::ecc::public_key& pub)const
{
if( from != public_key_type() && pub.valid() )
if( from != public_key_type() && to != public_key_type() && pub.valid() )
{
auto secret = priv.get_shared_secret(pub);
auto nonce_plus_secret = fc::sha512::hash(fc::to_string(nonce) + secret.str());

View file

@ -156,8 +156,7 @@ void peerplays_sidechain_plugin_impl::plugin_set_program_options(
"Tuple of [Bitcoin public key, Bitcoin private key] (may specify multiple times)");
cli.add_options()("hive-sidechain-enabled", bpo::value<bool>()->default_value(false), "Hive sidechain handler enabled");
cli.add_options()("hive-node-rpc-url", bpo::value<string>()->default_value("127.0.0.1"), "Hive node URL (http(s)://host:port/)");
//cli.add_options()("hive-node-rpc-port", bpo::value<uint32_t>()->default_value(28090), "Deprecated: Hive node RPC port. See: hive-node-rpc-url");
cli.add_options()("hive-node-rpc-url", bpo::value<string>()->default_value("127.0.0.1:28090"), "Hive node RPC URL [http[s]://]host[:port]");
cli.add_options()("hive-node-rpc-user", bpo::value<string>(), "Hive node RPC user");
cli.add_options()("hive-node-rpc-password", bpo::value<string>(), "Hive node RPC password");
cli.add_options()("hive-private-key", bpo::value<vector<string>>()->composing()->multitoken()->DEFAULT_VALUE_VECTOR(std::make_pair("TST6LLegbAgLAy28EHrffBVuANFWcFgmqRMW13wBmTExqFE9SCkg4", "5JNHfZYKGaomSFvd4NUdQ9qMcEAC43kujbfjueTHpVapX1Kzq2n")),
@ -231,8 +230,7 @@ void peerplays_sidechain_plugin_impl::plugin_initialize(const boost::program_opt
//}
sidechain_enabled_hive = options.at("hive-sidechain-enabled").as<bool>();
config_ready_hive = options.count("hive-node-ip") &&
options.count("hive-node-rpc-port") &&
config_ready_hive = options.count("hive-node-rpc-url") &&
/*options.count("hive-node-rpc-user") && options.count("hive-node-rpc-password") &&*/
options.count("hive-private-key");
if (!config_ready_hive) {

View file

@ -122,14 +122,7 @@ sidechain_net_handler_hive::sidechain_net_handler_hive(peerplays_sidechain_plugi
debug_rpc_calls = options.at("debug-rpc-calls").as<bool>();
}
if (options.count("hive-node-rpc-url"))
node_rpc_url = options.at("hive-node-rpc-url").as<std::string>();
// if (options.count("hive-node-rpc-port"))
// node_rpc_port = options.at("hive-node-rpc-port").as<uint32_t>();
// else
// node_rpc_port = 0;
node_rpc_url = options.at("hive-node-rpc-url").as<std::string>();
if (options.count("hive-node-rpc-user")) {
node_rpc_user = options.at("hive-node-rpc-user").as<std::string>();
} else {
@ -157,7 +150,6 @@ sidechain_net_handler_hive::sidechain_net_handler_hive(peerplays_sidechain_plugi
std::string chain_id_str = node_rpc_client->get_chain_id();
if (chain_id_str.empty()) {
// elog("No Hive node running at ${url} or wrong rpc port: ${port}", ("url", node_rpc_url)("port", node_rpc_port));
elog("No Hive node running at ${url}", ("url", node_rpc_url));
FC_ASSERT(false);
}

View file

@ -182,21 +182,194 @@ BOOST_AUTO_TEST_CASE( price_test )
BOOST_AUTO_TEST_CASE( memo_test )
{ try {
memo_data m;
auto sender = generate_private_key("1");
auto receiver = generate_private_key("2");
m.from = sender.get_public_key();
m.to = receiver.get_public_key();
m.set_message(sender, receiver.get_public_key(), "Hello, world!", 12345);
auto sender_private_key = generate_private_key("1");
auto sender_public_key = sender_private_key.get_public_key();
auto receiver_private_key = generate_private_key("2");
auto receiver_public_key = receiver_private_key.get_public_key();
auto dummy_private_key = private_key_type();
auto dummy_public_key = public_key_type();
decltype(fc::digest(m)) hash("8de72a07d093a589f574460deb19023b4aff354b561eb34590d9f4629f51dbf3");
if( fc::digest(m) != hash )
{
// If this happens, notify the web guys that the memo serialization format changed.
edump((m)(fc::digest(m)));
BOOST_FAIL("Memo format has changed. Notify the web guys and update this test.");
memo_data m;
m.from = dummy_public_key;
m.to = dummy_public_key;
m.set_message(dummy_private_key, dummy_public_key, "Hello, world!", 12345);
decltype(fc::digest(m)) hash("b9ad6eb2c466678a911f2f10f29d2a0d98600335b00e4c4ffbeabccb76c77bf0");
if( fc::digest(m) != hash ) {
// If this happens, notify the web guys that the memo serialization format changed.
edump((m)(fc::digest(m)));
BOOST_FAIL("Memo format has changed. Notify the web guys and update this test.");
}
BOOST_CHECK_EQUAL(m.get_message(dummy_private_key, dummy_public_key), "Hello, world!");
}
BOOST_CHECK_EQUAL(m.get_message(receiver, sender.get_public_key()), "Hello, world!");
{
memo_data m;
m.from = dummy_public_key;
m.to = receiver_public_key;
m.set_message(dummy_private_key, receiver_public_key, "Hello, world!", 12345);
decltype(fc::digest(m)) hash("b9ad6eb2c466678a911f2f10f29d2a0d98600335b00e4c4ffbeabccb76c77bf0");
if( fc::digest(m) != hash ) {
// If this happens, notify the web guys that the memo serialization format changed.
edump((m)(fc::digest(m)));
BOOST_FAIL("Memo format has changed. Notify the web guys and update this test.");
}
BOOST_CHECK_EQUAL(m.get_message(receiver_private_key, dummy_public_key), "Hello, world!");
}
{
memo_data m;
m.from = sender_public_key;
m.to = dummy_public_key;
m.set_message(sender_private_key, dummy_public_key, "Hello, world!", 12345);
decltype(fc::digest(m)) hash("b756ef1b27e3bb8e61eea534a0b28e89b0fa72b73f8b7e6bc99b55a92ec3cf9b");
if( fc::digest(m) != hash ) {
// If this happens, notify the web guys that the memo serialization format changed.
edump((m)(fc::digest(m)));
BOOST_FAIL("Memo format has changed. Notify the web guys and update this test.");
}
BOOST_CHECK_EQUAL(m.get_message(dummy_private_key, sender_public_key), "Hello, world!");
}
{
memo_data m;
m.from = sender_public_key;
m.to = receiver_public_key;
m.set_message(sender_private_key, receiver_public_key, "Hello, world!", 12345);
decltype(fc::digest(m)) hash("b756ef1b27e3bb8e61eea534a0b28e89b0fa72b73f8b7e6bc99b55a92ec3cf9b");
if( fc::digest(m) != hash ) {
// If this happens, notify the web guys that the memo serialization format changed.
edump((m)(fc::digest(m)));
BOOST_FAIL("Memo format has changed. Notify the web guys and update this test.");
}
BOOST_CHECK_EQUAL(m.get_message(receiver_private_key, sender_public_key), "Hello, world!");
}
{
memo_data m;
m.from = dummy_public_key;
m.to = dummy_public_key;
m.set_message(dummy_private_key, dummy_public_key, "#Hello, world!", 12345);
decltype(fc::digest(m)) hash("8b17e79255d427b437a8b30beee5d45ca9b0bc8a04afa7a1968a0b73ab6d4b38");
if( fc::digest(m) != hash ) {
// If this happens, notify the web guys that the memo serialization format changed.
edump((m)(fc::digest(m)));
BOOST_FAIL("Memo format has changed. Notify the web guys and update this test.");
}
BOOST_CHECK_EQUAL(m.get_message(dummy_private_key, dummy_public_key), "#Hello, world!");
}
{
memo_data m;
m.from = dummy_public_key;
m.to = receiver_public_key;
m.set_message(dummy_private_key, receiver_public_key, "#Hello, world!", 12345);
decltype(fc::digest(m)) hash("8b17e79255d427b437a8b30beee5d45ca9b0bc8a04afa7a1968a0b73ab6d4b38");
if( fc::digest(m) != hash ) {
// If this happens, notify the web guys that the memo serialization format changed.
edump((m)(fc::digest(m)));
BOOST_FAIL("Memo format has changed. Notify the web guys and update this test.");
}
BOOST_CHECK_EQUAL(m.get_message(receiver_private_key, dummy_public_key), "#Hello, world!");
}
{
memo_data m;
m.from = sender_public_key;
m.to = dummy_public_key;
m.set_message(sender_private_key, dummy_public_key, "#Hello, world!", 12345);
decltype(fc::digest(m)) hash("40dbf5d26ea084d6ab61f9e93de366b7bea6a54eb1203744dd619d878a7d954a");
if( fc::digest(m) != hash ) {
// If this happens, notify the web guys that the memo serialization format changed.
edump((m)(fc::digest(m)));
BOOST_FAIL("Memo format has changed. Notify the web guys and update this test.");
}
BOOST_CHECK_EQUAL(m.get_message(dummy_private_key, sender_public_key), "#Hello, world!");
}
{
memo_data m;
m.from = sender_public_key;
m.to = receiver_public_key;
m.set_message(sender_private_key, receiver_public_key, "#Hello, world!", 12345);
decltype(fc::digest(m)) hash("2f5d44ec922f605663a3b51f1d9633641062c9b669ba4bdd5c60104ceff12c8f");
if( fc::digest(m) != hash ) {
// If this happens, notify the web guys that the memo serialization format changed.
edump((m)(fc::digest(m)));
BOOST_FAIL("Memo format has changed. Notify the web guys and update this test.");
}
BOOST_CHECK_EQUAL(m.get_message(receiver_private_key, sender_public_key), "#Hello, world!");
}
{
memo_data m;
m.from = dummy_public_key;
m.to = dummy_public_key;
m.set_message(dummy_private_key, dummy_public_key, "# Hello, world!", 12345);
decltype(fc::digest(m)) hash("93753b87b409e6532806ea3074553321b04807a675ffc0f41fb270c3141a8af2");
if( fc::digest(m) != hash ) {
// If this happens, notify the web guys that the memo serialization format changed.
edump((m)(fc::digest(m)));
BOOST_FAIL("Memo format has changed. Notify the web guys and update this test.");
}
BOOST_CHECK_EQUAL(m.get_message(dummy_private_key, dummy_public_key), "# Hello, world!");
}
{
memo_data m;
m.from = dummy_public_key;
m.to = receiver_public_key;
m.set_message(dummy_private_key, receiver_public_key, "# Hello, world!", 12345);
decltype(fc::digest(m)) hash("93753b87b409e6532806ea3074553321b04807a675ffc0f41fb270c3141a8af2");
if( fc::digest(m) != hash ) {
// If this happens, notify the web guys that the memo serialization format changed.
edump((m)(fc::digest(m)));
BOOST_FAIL("Memo format has changed. Notify the web guys and update this test.");
}
BOOST_CHECK_EQUAL(m.get_message(receiver_private_key, dummy_public_key), "# Hello, world!");
}
{
memo_data m;
m.from = sender_public_key;
m.to = dummy_public_key;
m.set_message(sender_private_key, dummy_public_key, "# Hello, world!", 12345);
decltype(fc::digest(m)) hash("5a0b4efad48090577a1296fc7221e19bdde4a8067bbbe05faa31c1c9fbdedd19");
if( fc::digest(m) != hash ) {
// If this happens, notify the web guys that the memo serialization format changed.
edump((m)(fc::digest(m)));
BOOST_FAIL("Memo format has changed. Notify the web guys and update this test.");
}
BOOST_CHECK_EQUAL(m.get_message(dummy_private_key, sender_public_key), "# Hello, world!");
}
{
memo_data m;
m.from = sender_public_key;
m.to = receiver_public_key;
m.set_message(sender_private_key, receiver_public_key, "# Hello, world!", 12345);
decltype(fc::digest(m)) hash("948b1b3219950dcaf5a376a502ba1b7631825aef85e0c692d192c06d583b2530");
if( fc::digest(m) != hash ) {
// If this happens, notify the web guys that the memo serialization format changed.
edump((m)(fc::digest(m)));
BOOST_FAIL("Memo format has changed. Notify the web guys and update this test.");
}
BOOST_CHECK_EQUAL(m.get_message(receiver_private_key, sender_public_key), "# Hello, world!");
}
} FC_LOG_AND_RETHROW() }
BOOST_AUTO_TEST_CASE( witness_rng_test_bits )