rippled
STValidation.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/basics/Log.h>
21 #include <ripple/basics/contract.h>
22 #include <ripple/json/to_string.h>
23 #include <ripple/protocol/HashPrefix.h>
24 #include <ripple/protocol/STValidation.h>
25 
26 namespace ripple {
27 
28 SOTemplate const&
30 {
31  // We can't have this be a magic static at namespace scope because
32  // it relies on the SField's below being initialized, and we can't
33  // guarantee the initialization order.
34  static SOTemplate const format{
51  };
52 
53  return format;
54 };
55 
56 uint256
58 {
60 }
61 
62 uint256
64 {
65  return getFieldH256(sfLedgerHash);
66 }
67 
68 uint256
70 {
72 }
73 
76 {
78 }
79 
82 {
83  return seenTime_;
84 }
85 
86 bool
88 {
89  try
90  {
92  return false;
93 
94  return verifyDigest(
99  }
100  catch (std::exception const&)
101  {
102  JLOG(debugLog().error()) << "Exception validating validation";
103  return false;
104  }
105 }
106 
107 PublicKey
109 {
111 }
112 
113 bool
115 {
116  return (getFlags() & vfFullValidation) != 0;
117 }
118 
119 Blob
121 {
122  return getFieldVL(sfSignature);
123 }
124 
125 Blob
127 {
128  Serializer s;
129  add(s);
130  return s.peekData();
131 }
132 
133 } // namespace ripple
ripple::STValidation::isValid
bool isValid() const
Definition: STValidation.cpp:87
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::sfReserveBase
const SF_UINT32 sfReserveBase
ripple::STValidation::getConsensusHash
uint256 getConsensusHash() const
Definition: STValidation.cpp:69
std::exception
STL class.
ripple::publicKeyType
boost::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
Definition: PublicKey.cpp:203
ripple::sfLedgerSequence
const SF_UINT32 sfLedgerSequence
ripple::STValidation::isFull
bool isFull() const
Definition: STValidation.cpp:114
std::vector< unsigned char >
ripple::sfSigningPubKey
const SF_VL sfSigningPubKey
ripple::STValidation::getLedgerHash
uint256 getLedgerHash() const
Definition: STValidation.cpp:63
std::chrono::duration
ripple::soeREQUIRED
@ soeREQUIRED
Definition: SOTemplate.h:35
ripple::sfCloseTime
const SF_UINT32 sfCloseTime
ripple::STObject::getFieldVL
Blob getFieldVL(SField const &field) const
Definition: STObject.cpp:568
ripple::STValidation::validationFormat
static SOTemplate const & validationFormat()
Definition: STValidation.cpp:29
ripple::STValidation::getSignature
Blob getSignature() const
Definition: STValidation.cpp:120
ripple::debugLog
beast::Journal debugLog()
Returns a debug journal.
Definition: Log.cpp:452
ripple::sfValidatedHash
const SF_HASH256 sfValidatedHash
ripple::sfLedgerHash
const SF_HASH256 sfLedgerHash
ripple::vfFullyCanonicalSig
constexpr std::uint32_t vfFullyCanonicalSig
Definition: STValidation.h:41
ripple::base_uint
Integers of any length that is a multiple of 32-bits.
Definition: base_uint.h:73
ripple::SOTemplate
Defines the fields and their attributes within a STObject.
Definition: SOTemplate.h:82
ripple::sfServerVersion
const SF_UINT64 sfServerVersion
ripple::sfLoadFee
const SF_UINT32 sfLoadFee
ripple::PublicKey
A public key.
Definition: PublicKey.h:59
ripple::sfReserveIncrement
const SF_UINT32 sfReserveIncrement
ripple::soeOPTIONAL
@ soeOPTIONAL
Definition: SOTemplate.h:36
ripple::STValidation::getSerialized
Blob getSerialized() const
Definition: STValidation.cpp:126
ripple::sfCookie
const SF_UINT64 sfCookie
std::chrono::time_point
ripple::STObject::getFlags
std::uint32_t getFlags() const
Definition: STObject.cpp:454
ripple::HashPrefix::validation
@ validation
validation for signing
ripple::STValidation::getSignTime
NetClock::time_point getSignTime() const
Definition: STValidation.cpp:75
ripple::verifyDigest
bool verifyDigest(PublicKey const &publicKey, uint256 const &digest, Slice const &sig, bool mustBeFullyCanonical)
Verify a secp256k1 signature on the digest of a message.
Definition: PublicKey.cpp:218
ripple::STValidation::seenTime_
NetClock::time_point seenTime_
Definition: STValidation.h:214
ripple::KeyType::secp256k1
@ secp256k1
ripple::STValidation::getSeenTime
NetClock::time_point getSeenTime() const
Definition: STValidation.cpp:81
ripple::Serializer
Definition: Serializer.h:39
ripple::sfBaseFee
const SF_UINT64 sfBaseFee
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::STObject::getSigningHash
uint256 getSigningHash(HashPrefix prefix) const
Definition: STObject.cpp:321
ripple::STObject::add
virtual void add(Serializer &s) const override
Definition: STObject.h:352
ripple::sfConsensusHash
const SF_HASH256 sfConsensusHash
ripple::sfFlags
const SF_UINT32 sfFlags
ripple::Serializer::peekData
Blob const & peekData() const
Definition: Serializer.h:166
ripple::sfSignature
const SF_VL sfSignature
ripple::STValidation::getSigningHash
uint256 getSigningHash() const
Definition: STValidation.cpp:57
ripple::STValidation::getSignerPublic
PublicKey getSignerPublic() const
Definition: STValidation.cpp:108
ripple::vfFullValidation
constexpr std::uint32_t vfFullValidation
Definition: STValidation.h:38
ripple::STObject::getFieldU32
std::uint32_t getFieldU32(SField const &field) const
Definition: STObject.cpp:532
ripple::sfSigningTime
const SF_UINT32 sfSigningTime
ripple::soeDEFAULT
@ soeDEFAULT
Definition: SOTemplate.h:37
ripple::sfAmendments
const SF_VECTOR256 sfAmendments
ripple::STObject::getFieldH256
uint256 getFieldH256(SField const &field) const
Definition: STObject.cpp:556