Merge pull request #2036

89b2f306 tests: fix invalid key image test (moneromooo-monero)
a374a522 wallet2: check key image validity domain in import_key_images (moneromooo-monero)
This commit is contained in:
Riccardo Spagni 2017-05-30 21:23:04 +02:00
commit cd13bcb4d2
No known key found for this signature in database
GPG key ID: 55432DF31CCD4FCD
2 changed files with 14 additions and 2 deletions

View file

@ -5277,6 +5277,10 @@ uint64_t wallet2::import_key_images(const std::vector<std::pair<crypto::key_imag
std::vector<const crypto::public_key*> pkeys; std::vector<const crypto::public_key*> pkeys;
pkeys.push_back(&pkey); pkeys.push_back(&pkey);
THROW_WALLET_EXCEPTION_IF(!(rct::scalarmultKey(rct::ki2rct(key_image), rct::curveOrder()) == rct::identity()),
error::wallet_internal_error, "Key image out of validity domain: input " + boost::lexical_cast<std::string>(n) + "/"
+ boost::lexical_cast<std::string>(signed_key_images.size()) + ", key image " + epee::string_tools::pod_to_hex(key_image));
THROW_WALLET_EXCEPTION_IF(!crypto::check_ring_signature((const crypto::hash&)key_image, key_image, pkeys, &signature), THROW_WALLET_EXCEPTION_IF(!crypto::check_ring_signature((const crypto::hash&)key_image, key_image, pkeys, &signature),
error::wallet_internal_error, "Signature check failed: input " + boost::lexical_cast<std::string>(n) + "/" error::wallet_internal_error, "Signature check failed: input " + boost::lexical_cast<std::string>(n) + "/"
+ boost::lexical_cast<std::string>(signed_key_images.size()) + ", key image " + epee::string_tools::pod_to_hex(key_image) + boost::lexical_cast<std::string>(signed_key_images.size()) + ", key image " + epee::string_tools::pod_to_hex(key_image)

View file

@ -163,6 +163,15 @@ namespace
throw std::runtime_error("invalid public key wasn't found"); throw std::runtime_error("invalid public key wasn't found");
return crypto::public_key(); return crypto::public_key();
} }
crypto::key_image generate_invalid_key_image()
{
crypto::key_image key_image;
// a random key image plucked from the blockchain
if (!epee::string_tools::hex_to_pod("6b9f5d1be7c950dc6e4e258c6ef75509412ba9ecaaf90e6886140151d1365b5e", key_image))
throw std::runtime_error("invalid key image wasn't found");
return key_image;
}
} }
//---------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------
@ -541,8 +550,7 @@ bool gen_tx_key_image_is_invalid::generate(std::vector<test_event_entry>& events
builder.step2_fill_inputs(miner_account.get_keys(), sources); builder.step2_fill_inputs(miner_account.get_keys(), sources);
txin_to_key& in_to_key = boost::get<txin_to_key>(builder.m_tx.vin.front()); txin_to_key& in_to_key = boost::get<txin_to_key>(builder.m_tx.vin.front());
crypto::public_key pub = generate_invalid_pub_key(); in_to_key.k_image = generate_invalid_key_image();
memcpy(&in_to_key.k_image, &pub, sizeof(crypto::ec_point));
builder.step3_fill_outputs(destinations); builder.step3_fill_outputs(destinations);
builder.step4_calc_hash(); builder.step4_calc_hash();