diff --git a/src/ripple/app/tests/Regression_test.cpp b/src/ripple/app/tests/Regression_test.cpp index 32a32832e..df7fe7639 100644 --- a/src/ripple/app/tests/Regression_test.cpp +++ b/src/ripple/app/tests/Regression_test.cpp @@ -18,6 +18,7 @@ #include #include #include +#include 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(*(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(); } };