20#include <xrpld/app/misc/CredentialHelpers.h>
21#include <xrpld/ledger/View.h>
23#include <xrpl/protocol/TER.h>
24#include <xrpl/protocol/digest.h>
29namespace credentials {
36 std::uint32_t const exp = (*sleCredential)[~sfExpiration].value_or(
46 bool foundExpired =
false;
48 for (
auto const& h : arr)
52 auto const sleCred = view.
peek(k);
57 <<
"Credentials are expired. Cred: " << sleCred->getText();
77 [&view, &sleCredential, j](
82 JLOG(j.
fatal()) <<
"Internal error: can't retrieve Owner account.";
91 JLOG(j.
fatal()) <<
"Unable to delete Credential from owner.";
101 auto const issuer = sleCredential->getAccountID(sfIssuer);
102 auto const subject = sleCredential->getAccountID(sfSubject);
105 auto err = delSLE(issuer, sfIssuerNode, !
accepted || (subject == issuer));
109 if (subject != issuer)
111 err = delSLE(subject, sfSubjectNode,
accepted);
117 view.
erase(sleCredential);
128 auto const& credentials = tx.
getFieldV256(sfCredentialIDs);
132 <<
"Malformed transaction: Credentials array size is invalid: "
133 << credentials.size();
138 for (
auto const& cred : credentials)
140 auto [it, ins] = duplicates.
insert(cred);
144 <<
"Malformed transaction: duplicates in credentials.";
163 for (
auto const& h : credIDs)
168 JLOG(j.
trace()) <<
"Credential doesn't exist. Cred: " << h;
172 if (sleCred->getAccountID(sfSubject) != src)
175 <<
"Credential doesn't belong to the source account. Cred: "
182 JLOG(j.
trace()) <<
"Credential isn't accepted. Cred: " << h;
201 bool foundExpired =
false;
202 for (
auto const& h : slePD->getFieldArray(sfAcceptedCredentials))
204 auto const issuer = h.getAccountID(sfIssuer);
205 auto const type = h.getFieldVL(sfCredentialType);
206 auto const keyletCredential =
208 auto const sleCredential = view.
read(keyletCredential);
241 for (
auto const& h : credIDs)
248 sorted.
emplace((*sleCred)[sfIssuer], (*sleCred)[sfCredentialType]);
251 lifeExtender.
push_back(std::move(sleCred));
264 for (
auto const& cred : credentials)
266 auto [it, ins] =
out.
emplace(cred[sfIssuer], cred[sfCredentialType]);
276 if (credentials.
empty() || (credentials.
size() > maxSize))
278 JLOG(j.
trace()) <<
"Malformed transaction: "
279 "Invalid credentials size: "
280 << credentials.
size();
290 JLOG(j.
trace()) <<
"Malformed transaction: "
291 "Issuer account is invalid: "
299 JLOG(j.
trace()) <<
"Malformed transaction: "
300 "Invalid credentialType size: "
308 JLOG(j.
trace()) <<
"Malformed transaction: "
309 "duplicates in credenentials.";
333 for (
auto const& h : slePD->getFieldArray(sfAcceptedCredentials))
335 auto const issuer = h.getAccountID(sfIssuer);
336 auto const type = h.getFieldVL(sfCredentialType);
337 auto const keyletCredential =
339 if (view.
exists(keyletCredential))
340 credentials.
push_back(keyletCredential.key);
344 for (
auto const& h : credentials)
372 bool const credentialsPresent = tx.
isFieldPresent(sfCredentialIDs);
374 if (credentialsPresent &&
383 return !credentialsPresent
A generic endpoint for log messages.
Stream trace() const
Severity stream access functions.
Writeable view to a ledger, for applying a transaction.
bool dirRemove(Keylet const &directory, std::uint64_t page, uint256 const &key, bool keepRoot)
Remove an entry from a directory.
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
virtual void erase(std::shared_ptr< SLE > const &sle)=0
Remove a peeked SLE.
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
virtual bool exists(Keylet const &k) const =0
Determine if a state item exists.
virtual LedgerInfo const & info() const =0
Returns information about the ledger.
bool isFieldPresent(SField const &field) const
STVector256 const & getFieldV256(SField const &field) const
void push_back(uint256 const &v)
NotTEC checkFields(STTx const &tx, beast::Journal j)
TER deleteSLE(ApplyView &view, std::shared_ptr< SLE > const &sleCredential, beast::Journal j)
bool removeExpired(ApplyView &view, STVector256 const &arr, beast::Journal const j)
TER validDomain(ReadView const &view, uint256 domainID, AccountID const &subject)
TER valid(STTx const &tx, ReadView const &view, AccountID const &src, beast::Journal j)
TER authorizedDepositPreauth(ApplyView const &view, STVector256 const &credIDs, AccountID const &dst)
NotTEC checkArray(STArray const &credentials, unsigned maxSize, beast::Journal j)
bool checkExpired(std::shared_ptr< SLE const > const &sleCredential, NetClock::time_point const &closed)
std::set< std::pair< AccountID, Slice > > makeSorted(STArray const &credentials)
Keylet permissionedDomain(AccountID const &account, std::uint32_t seq) noexcept
Keylet credential(AccountID const &subject, AccountID const &issuer, Slice const &credType) noexcept
Keylet account(AccountID const &id) noexcept
AccountID root.
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet depositPreauth(AccountID const &owner, AccountID const &preauthorized) noexcept
A DepositPreauth.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
TER verifyDepositPreauth(STTx const &tx, ApplyView &view, AccountID const &src, AccountID const &dst, std::shared_ptr< SLE > const &sleDst, beast::Journal j)
static bool adjustOwnerCount(ApplyContext &ctx, int count)
std::size_t constexpr maxCredentialsArraySize
The maximum number of credentials can be passed in array.
@ accepted
Manifest is valid.
std::size_t constexpr maxCredentialTypeLength
The maximum length of a CredentialType inside a Credential.
std::enable_if_t< std::is_same< T, char >::value||std::is_same< T, unsigned char >::value, Slice > makeSlice(std::array< T, N > const &a)
bool isTesSuccess(TER x) noexcept
std::string to_string(base_uint< Bits, Tag > const &a)
TER verifyValidDomain(ApplyView &view, AccountID const &account, uint256 domainID, beast::Journal j)
@ credential
Credentials signature.
TERSubset< CanCvtToTER > TER
sha512_half_hasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.
T time_since_epoch(T... args)