Skip to content
Snippets Groups Projects

Expose `cpp_check_memo_for_private_keys`functionality to the Wax public interface

Merged Bartek Wrona requested to merge bw_private_key_detection into develop
Files
18
+ 58
0
@@ -4,6 +4,7 @@
#include "core/utils.hpp"
#include "fc/crypto/elliptic.hpp"
#include <fc/reflect/reflect.hpp>
#include <fc/io/json.hpp>
#include <boost/lexical_cast.hpp>
@@ -12,6 +13,7 @@
#include <hive/protocol/asset.hpp>
#include <hive/protocol/key_utils.hpp>
#include <hive/protocol/transaction.hpp>
#include <hive/protocol/transaction_util.hpp>
#include <hive/protocol/crypto_memo.hpp>
#include <hive/protocol/hive_collateral.hpp>
#include <hive/protocol/get_config.hpp>
@@ -379,6 +381,62 @@ std::string foundation::cpp_crypto_memo_dump_string(const crypto_memo& value) co
);
}
void foundation::cpp_check_memo_for_private_keys(const std::string& memo, const std::string& account,
const wax_authorities& auths, const std::string& memo_key, const std::vector<std::string>& imported_keys) const
{
return cpp::safe_exception_wrapper([&]() -> void {
std::vector<hive::protocol::public_key_type> keys;
hive::protocol::collect_potential_keys(&keys, account, memo);
if (keys.empty())
return;
fc::flat_set<std::string> _keys;
_keys.reserve(keys.size());
std::transform(keys.cbegin(), keys.cend(), std::inserter(_keys, _keys.end()), [](const auto& key) { return static_cast<std::string>(key); });
const auto throwException = [&](const char* role, const std::string& publicKey) -> void {
fc::mutable_variant_object vo;
vo["type"] = "WAX_STD_EXCEPTION";
vo["msg"] = "Detected private key leak.";
vo["authority_role"] = role;
vo["public_key"] = publicKey;
std::string msg = fc::json::to_string(vo);
throw std::runtime_error(msg);
};
for (const auto& key_weight_pair : auths.owner.key_auths)
{
if(_keys.contains(key_weight_pair.first))
throwException("owner", key_weight_pair.first);
}
for (const auto& key_weight_pair : auths.active.key_auths)
{
if(_keys.contains(key_weight_pair.first))
throwException("active", key_weight_pair.first);
}
for (const auto& key_weight_pair : auths.posting.key_auths)
{
if(_keys.contains(key_weight_pair.first))
throwException("posting", key_weight_pair.first);
}
if(_keys.contains(memo_key))
throwException("memo", memo_key);
for (const auto& imported_key : imported_keys)
{
if(_keys.contains(imported_key))
throwException("imported", imported_key);
}
});
}
result foundation::cpp_calculate_public_key(const std::string& wif)
{
return method_wrapper([&](result& _result)
Loading