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  ReadView const& view,
30  STTx const& tx)
31 {
32  auto const id = tx.getAccountID(sfAccount);
33  auto const spk = tx.getSigningPubKey();
34 
35  if (publicKeyType (makeSlice (spk)))
36  {
37  if (calcAccountID(PublicKey (makeSlice(spk))) == id)
38  {
39  auto const sle = view.read(keylet::account(id));
40 
41  if (sle && (! (sle->getFlags () & lsfPasswordSpent)))
42  {
43  // flag is armed and they signed with the right account
44  return FeeUnit64{0};
45  }
46  }
47  }
48 
50 }
51 
52 NotTEC
54 {
55  auto const ret = preflight1 (ctx);
56  if (!isTesSuccess (ret))
57  return ret;
58 
59  std::uint32_t const uTxFlags = ctx.tx.getFlags ();
60 
61  if (uTxFlags & tfUniversalMask)
62  {
63  JLOG(ctx.j.trace()) <<
64  "Malformed transaction: Invalid flags set.";
65 
66  return temINVALID_FLAG;
67  }
68 
69 
73  {
74  return temBAD_REGKEY;
75  }
76 
77  return preflight2(ctx);
78 }
79 
80 TER
82 {
83  auto const sle = view ().peek (
85  if (! sle)
86  return tefINTERNAL;
87 
88  if (!minimumFee (ctx_.app, ctx_.baseFee, view ().fees (), view ().flags ()))
89  sle->setFlag (lsfPasswordSpent);
90 
92  {
93  sle->setAccountID (sfRegularKey,
95  }
96  else
97  {
98  // Account has disabled master key and no multi-signer signer list.
99  if (sle->isFlag (lsfDisableMaster) &&
100  !view().peek (keylet::signers (account_)))
101  return tecNO_ALTERNATIVE_KEY;
102 
103  sle->makeFieldAbsent (sfRegularKey);
104  }
105 
106  return tesSUCCESS;
107 }
108 
109 }
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:467
ripple::preflight2
NotTEC preflight2(PreflightContext const &ctx)
Checks whether the signature appears valid.
Definition: Transactor.cpp:90
ripple::lsfPasswordSpent
@ lsfPasswordSpent
Definition: LedgerFormats.h:132
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:199
ripple::tefINTERNAL
@ tefINTERNAL
Definition: TER.h:153
ripple::keylet::signers
static const signers_t signers
Definition: Indexes.h:239
beast::Journal::trace
Stream trace() const
Severity stream access functions.
Definition: Journal.h:287
ripple::publicKeyType
boost::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
Definition: PublicKey.cpp:207
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:136
ripple::isTesSuccess
bool isTesSuccess(TER x)
Definition: TER.h:501
ripple::temBAD_REGKEY
@ temBAD_REGKEY
Definition: TER.h:96
ripple::sfAccount
const SF_Account sfAccount(access, STI_ACCOUNT, 1, "Account")
Definition: SField.h:460
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:152
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:44
ripple::temINVALID_FLAG
@ temINVALID_FLAG
Definition: TER.h:109
ripple::tecNO_ALTERNATIVE_KEY
@ tecNO_ALTERNATIVE_KEY
Definition: TER.h:261
ripple::PublicKey
A public key.
Definition: PublicKey.h:59
ripple::keylet::account
static const account_t account
Definition: Indexes.h:116
ripple::STObject::getAccountID
AccountID getAccountID(SField const &field) const
Definition: STObject.cpp:537
ripple::TERSubset
Definition: TER.h:311
ripple::calcAccountID
AccountID calcAccountID(PublicKey const &pk)
Definition: AccountID.cpp:136
ripple::STObject::getFlags
std::uint32_t getFlags() const
Definition: STObject.cpp:439
ripple::fixMasterKeyAsRegularKey
const uint256 fixMasterKeyAsRegularKey
Definition: Feature.cpp:174
ripple::STTx
Definition: STTx.h:43
ripple::Transactor::calculateBaseFee
static FeeUnit64 calculateBaseFee(ReadView const &view, STTx const &tx)
Definition: Transactor.cpp:126
ripple::STTx::getSigningPubKey
Blob getSigningPubKey() const
Definition: STTx.h:103
std::uint32_t
ripple::Rules::enabled
bool enabled(uint256 const &id) const
Returns true if a feature is enabled.
Definition: ReadView.cpp:107
ripple::feeunit::TaggedFee
Definition: FeeUnits.h:72
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:186
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:53
ripple::Transactor::view
ApplyView & view()
Definition: Transactor.h:98
ripple::STObject::isFieldPresent
bool isFieldPresent(SField const &field) const
Definition: STObject.cpp:392
ripple::FeeUnit64
FeeUnit< std::uint64_t > FeeUnit64
Definition: FeeUnits.h:477
ripple::Transactor::ctx_
ApplyContext & ctx_
Definition: Transactor.h:81
ripple::Transactor::account_
AccountID account_
Definition: Transactor.h:84
ripple::SetRegularKey::doApply
TER doApply() override
Definition: SetRegularKey.cpp:81
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:47
ripple::PreflightContext::rules
const Rules rules
Definition: Transactor.h:37
ripple::tesSUCCESS
@ tesSUCCESS
Definition: TER.h:219
ripple::ApplyContext::tx
STTx const & tx
Definition: ApplyContext.h:45