rippled
SetRegularKey.cpp
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012, 2013 Ripple Labs Inc.
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #include <ripple/app/tx/impl/SetRegularKey.h>
21 #include <ripple/basics/Log.h>
22 #include <ripple/protocol/Feature.h>
23 #include <ripple/protocol/TxFlags.h>
24 
25 namespace ripple {
26 
29 {
30  auto const id = tx.getAccountID(sfAccount);
31  auto const spk = tx.getSigningPubKey();
32 
33  if (publicKeyType(makeSlice(spk)))
34  {
35  if (calcAccountID(PublicKey(makeSlice(spk))) == id)
36  {
37  auto const sle = view.read(keylet::account(id));
38 
39  if (sle && (!(sle->getFlags() & lsfPasswordSpent)))
40  {
41  // flag is armed and they signed with the right account
42  return FeeUnit64{0};
43  }
44  }
45  }
46 
48 }
49 
50 NotTEC
52 {
53  auto const ret = preflight1(ctx);
54  if (!isTesSuccess(ret))
55  return ret;
56 
57  std::uint32_t const uTxFlags = ctx.tx.getFlags();
58 
59  if (uTxFlags & tfUniversalMask)
60  {
61  JLOG(ctx.j.trace()) << "Malformed transaction: Invalid flags set.";
62 
63  return temINVALID_FLAG;
64  }
65 
69  {
70  return temBAD_REGKEY;
71  }
72 
73  return preflight2(ctx);
74 }
75 
76 TER
78 {
79  auto const sle = view().peek(keylet::account(account_));
80  if (!sle)
81  return tefINTERNAL;
82 
83  if (!minimumFee(ctx_.app, ctx_.baseFee, view().fees(), view().flags()))
84  sle->setFlag(lsfPasswordSpent);
85 
87  {
88  sle->setAccountID(sfRegularKey, ctx_.tx.getAccountID(sfRegularKey));
89  }
90  else
91  {
92  // Account has disabled master key and no multi-signer signer list.
93  if (sle->isFlag(lsfDisableMaster) &&
94  !view().peek(keylet::signers(account_)))
95  return tecNO_ALTERNATIVE_KEY;
96 
97  sle->makeFieldAbsent(sfRegularKey);
98  }
99 
100  return tesSUCCESS;
101 }
102 
103 } // namespace ripple
ripple::SetRegularKey::calculateBaseFee
static FeeUnit64 calculateBaseFee(ReadView const &view, STTx const &tx)
Definition: SetRegularKey.cpp:28
ripple::sfRegularKey
const SF_Account sfRegularKey(access, STI_ACCOUNT, 8, "RegularKey")
Definition: SField.h:488
ripple::preflight2
NotTEC preflight2(PreflightContext const &ctx)
Checks whether the signature appears valid.
Definition: Transactor.cpp:108
ripple::lsfPasswordSpent
@ lsfPasswordSpent
Definition: LedgerFormats.h:103
ripple::makeSlice
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)
Definition: Slice.h:240
ripple::tefINTERNAL
@ tefINTERNAL
Definition: TER.h:150
beast::Journal::trace
Stream trace() const
Severity stream access functions.
Definition: Journal.h:309
ripple::publicKeyType
boost::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
Definition: PublicKey.cpp:203
ripple::ApplyView::peek
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
ripple::lsfDisableMaster
@ lsfDisableMaster
Definition: LedgerFormats.h:109
ripple::isTesSuccess
bool isTesSuccess(TER x)
Definition: TER.h:580
ripple::temBAD_REGKEY
@ temBAD_REGKEY
Definition: TER.h:93
ripple::sfAccount
const SF_Account sfAccount(access, STI_ACCOUNT, 1, "Account")
Definition: SField.h:481
ripple::PreflightContext::j
const beast::Journal j
Definition: Transactor.h:39
ripple::Transactor::minimumFee
static XRPAmount minimumFee(Application &app, FeeUnit64 baseFee, Fees const &fees, ApplyFlags flags)
Compute the minimum fee required to process a transaction with a given baseFee based on the current s...
Definition: Transactor.cpp:158
ripple::preflight1
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
Definition: Transactor.cpp:56
ripple::ApplyContext::app
Application & app
Definition: ApplyContext.h:47
ripple::temINVALID_FLAG
@ temINVALID_FLAG
Definition: TER.h:106
ripple::tecNO_ALTERNATIVE_KEY
@ tecNO_ALTERNATIVE_KEY
Definition: TER.h:257
ripple::PublicKey
A public key.
Definition: PublicKey.h:59
ripple::keylet::account
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition: Indexes.cpp:129
ripple::STObject::getAccountID
AccountID getAccountID(SField const &field) const
Definition: STObject.cpp:562
ripple::TERSubset
Definition: TER.h:326
ripple::calcAccountID
AccountID calcAccountID(PublicKey const &pk)
Definition: AccountID.cpp:118
ripple::STObject::getFlags
std::uint32_t getFlags() const
Definition: STObject.cpp:454
ripple::fixMasterKeyAsRegularKey
const uint256 fixMasterKeyAsRegularKey
Definition: Feature.cpp:179
ripple::STTx
Definition: STTx.h:42
ripple::Transactor::calculateBaseFee
static FeeUnit64 calculateBaseFee(ReadView const &view, STTx const &tx)
Definition: Transactor.cpp:140
ripple::STTx::getSigningPubKey
Blob getSigningPubKey() const
Definition: STTx.h:111
std::uint32_t
ripple::Rules::enabled
bool enabled(uint256 const &id) const
Returns true if a feature is enabled.
Definition: ReadView.cpp:103
ripple::feeunit::TaggedFee
Definition: FeeUnits.h:70
ripple::ReadView::read
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
ripple::ReadView
A view into a ledger.
Definition: ReadView.h:192
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::SetRegularKey::preflight
static NotTEC preflight(PreflightContext const &ctx)
Definition: SetRegularKey.cpp:51
ripple::Transactor::view
ApplyView & view()
Definition: Transactor.h:108
ripple::STObject::isFieldPresent
bool isFieldPresent(SField const &field) const
Definition: STObject.cpp:401
ripple::FeeUnit64
FeeUnit< std::uint64_t > FeeUnit64
Definition: FeeUnits.h:460
ripple::Transactor::ctx_
ApplyContext & ctx_
Definition: Transactor.h:89
ripple::SetRegularKey::doApply
TER doApply() override
Definition: SetRegularKey.cpp:77
ripple::tfUniversalMask
const std::uint32_t tfUniversalMask
Definition: TxFlags.h:50
ripple::PreflightContext::tx
STTx const & tx
Definition: Transactor.h:36
ripple::PreflightContext
State information when preflighting a tx.
Definition: Transactor.h:32
ripple::ApplyContext::baseFee
const FeeUnit64 baseFee
Definition: ApplyContext.h:50
ripple::keylet::signers
static Keylet signers(AccountID const &account, std::uint32_t page) noexcept
Definition: Indexes.cpp:264
ripple::PreflightContext::rules
const Rules rules
Definition: Transactor.h:37
ripple::tesSUCCESS
@ tesSUCCESS
Definition: TER.h:216
ripple::Transactor::account_
const AccountID account_
Definition: Transactor.h:92
ripple::ApplyContext::tx
STTx const & tx
Definition: ApplyContext.h:48