mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Test handling of secp256r1 signatures (RIPD-1040):
Commit 6ec5fa9cae fixed a bug that
would cause a crash when a transaction signed with a secp256r1 was
presented. This adds a regression test, ensuring that such
signatures fail gracefully.
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
#include <BeastConfig.h>
|
||||
#include <ripple/test/jtx.h>
|
||||
#include <ripple/app/tx/apply.h>
|
||||
#include <ripple/basics/StringUtilities.h>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
@@ -111,10 +112,57 @@ struct Regression_test : public beast::unit_test::suite
|
||||
"next->info().drops == expectedDrops");
|
||||
}
|
||||
|
||||
void testSecp256r1key ()
|
||||
{
|
||||
testcase("Signing with a secp256r1 key should fail gracefully");
|
||||
using namespace jtx;
|
||||
Env env(*this);
|
||||
|
||||
// Test case we'll use.
|
||||
auto test256r1key = [&env] (Account const& acct)
|
||||
{
|
||||
auto const baseFee = env.current()->fees().base;
|
||||
std::uint32_t const acctSeq = env.seq (acct);
|
||||
Json::Value jsonNoop = env.json (
|
||||
noop (acct), fee(baseFee), seq(acctSeq), sig(acct));
|
||||
JTx jt = env.jt (jsonNoop);
|
||||
jt.fill_sig = false;
|
||||
|
||||
// Random secp256r1 public key generated by
|
||||
// https://kjur.github.io/jsrsasign/sample-ecdsa.html
|
||||
std::string const secp256r1PubKey =
|
||||
"045d02995ec24988d9a2ae06a3733aa35ba0741e87527"
|
||||
"ed12909b60bd458052c944b24cbf5893c3e5be321774e"
|
||||
"5082e11c034b765861d0effbde87423f8476bb2c";
|
||||
|
||||
// Set the key in the JSON.
|
||||
jt.jv["SigningPubKey"] = secp256r1PubKey;
|
||||
|
||||
// Set the same key in the STTx.
|
||||
auto secp256r1Sig = std::make_unique<STTx>(*(jt.stx));
|
||||
auto pubKeyBlob = strUnHex (secp256r1PubKey);
|
||||
assert (pubKeyBlob.second); // Hex for public key must be valid
|
||||
secp256r1Sig->setFieldVL
|
||||
(sfSigningPubKey, std::move(pubKeyBlob.first));
|
||||
jt.stx.reset (secp256r1Sig.release());
|
||||
|
||||
env (jt, ter (temINVALID));
|
||||
};
|
||||
|
||||
Account const alice {"alice", KeyType::secp256k1};
|
||||
Account const becky {"becky", KeyType::ed25519};
|
||||
|
||||
env.fund(XRP(10000), alice, becky);
|
||||
|
||||
test256r1key (alice);
|
||||
test256r1key (becky);
|
||||
}
|
||||
|
||||
void run() override
|
||||
{
|
||||
testOffer1();
|
||||
testLowBalanceDestroy();
|
||||
testSecp256r1key();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user