diff --git a/src/rpc/common/Validators.cpp b/src/rpc/common/Validators.cpp index 9be9275a3..bfa1a64bf 100644 --- a/src/rpc/common/Validators.cpp +++ b/src/rpc/common/Validators.cpp @@ -363,7 +363,7 @@ CustomValidator CustomValidators::authorizeCredentialValidator = } // don't want to change issuer error message to be about credentials - if (!issuerValidator.verify(credObj, "issuer")) { + if (!accountBase58Validator.verify(credObj, "issuer")) { return Error{ Status{ClioError::RpcMalformedAuthorizedCredentials, "issuer NotString"} }; diff --git a/src/rpc/common/Validators.hpp b/src/rpc/common/Validators.hpp index 5c5cccbc3..ee9527b51 100644 --- a/src/rpc/common/Validators.hpp +++ b/src/rpc/common/Validators.hpp @@ -590,7 +590,8 @@ struct CustomValidators final { /** * @brief Provides a validator for validating credential_type. * - * Used by AuthorizeCredentialValidator in deposit_preauth. + * Used by AuthorizeCredentialValidator in deposit_preauth and by the credential + * object lookup in ledger_entry. */ static CustomValidator credentialTypeValidator; }; diff --git a/src/rpc/handlers/LedgerEntry.cpp b/src/rpc/handlers/LedgerEntry.cpp index 20982b628..bef9c8666 100644 --- a/src/rpc/handlers/LedgerEntry.cpp +++ b/src/rpc/handlers/LedgerEntry.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -32,6 +33,7 @@ #include #include +#include #include #include #include @@ -422,20 +424,23 @@ tag_invoke(boost::json::value_to_tag, boost::json::va return xrpl::keylet::oracle(*account, documentId).key; }; - auto const parseCredentialFromJson = [](boost::json::value const& json) { + auto const parseCredentialFromJson = + [](boost::json::value const& json) -> std::optional { auto const subject = util::parseBase58Wrapper( boost::json::value_to(json.at(JS(subject))) ); auto const issuer = util::parseBase58Wrapper( boost::json::value_to(json.at(JS(issuer))) ); - auto const credType = + auto const credTypeOpt = xrpl::strUnHex(boost::json::value_to(json.at(JS(credential_type)))); - return xrpl::keylet::credential( - *subject, *issuer, xrpl::Slice(credType->data(), credType->size()) - ) - .key; + return credTypeOpt.transform([&](xrpl::Blob const& credType) -> xrpl::uint256 { + return xrpl::keylet::credential( + *subject, *issuer, xrpl::Slice(credType.data(), credType.size()) + ) + .key; + }); }; auto const indexFieldType = diff --git a/src/rpc/handlers/LedgerEntry.hpp b/src/rpc/handlers/LedgerEntry.hpp index 8c5b0702e..ea32d9450 100644 --- a/src/rpc/handlers/LedgerEntry.hpp +++ b/src/rpc/handlers/LedgerEntry.hpp @@ -380,6 +380,7 @@ public: meta::WithCustomError{ validation::Type{}, Status(ClioError::RpcMalformedRequest) }, + validation::CustomValidators::credentialTypeValidator, }, }}}, {JS(mpt_issuance), diff --git a/tests/unit/rpc/handlers/LedgerEntryTests.cpp b/tests/unit/rpc/handlers/LedgerEntryTests.cpp index 5a7e66c4f..bece6a52a 100644 --- a/tests/unit/rpc/handlers/LedgerEntryTests.cpp +++ b/tests/unit/rpc/handlers/LedgerEntryTests.cpp @@ -347,6 +347,27 @@ generateTestValuesForParametersTest() .expectedErrorMessage = "issuer NotString" }, + ParamTestCaseBundle{ + .testName = "DepositPreauthAuthorizeCredentialsHexIssuer", + .testJson = fmt::format( + R"JSON({{ + "deposit_preauth": {{ + "owner": "{}", + "authorized_credentials": [ + {{ + "issuer": "0000000000000000000000000000000000000002", + "credential_type": "{}" + }} + ] + }} + }})JSON", + kAccount, + kCredentialType + ), + .expectedError = "malformedAuthorizedCredentials", + .expectedErrorMessage = "issuer NotString" + }, + ParamTestCaseBundle{ .testName = "DepositPreauthAuthorizeCredentialsIncorrectCredentialType", .testJson = fmt::format(