rippled
RCLCxPeerPos.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/consensus/RCLCxPeerPos.h>
21 #include <ripple/core/Config.h>
22 #include <ripple/protocol/HashPrefix.h>
23 #include <ripple/protocol/Serializer.h>
24 #include <ripple/protocol/digest.h>
25 #include <ripple/protocol/jss.h>
26 
27 namespace ripple {
28 
29 // Used to construct received proposals
31  PublicKey const& publicKey,
32  Slice const& signature,
33  uint256 const& suppression,
34  Proposal&& proposal)
35  : publicKey_(publicKey)
36  , suppression_(suppression)
37  , proposal_(std::move(proposal))
38 {
39  // The maximum allowed size of a signature is 72 bytes; we verify
40  // this elsewhere, but we want to be extra careful here:
41  assert(signature.size() != 0 && signature.size() <= signature_.capacity());
42 
43  if (signature.size() != 0 && signature.size() <= signature_.capacity())
44  signature_.assign(signature.begin(), signature.end());
45 }
46 
47 bool
49 {
50  return verifyDigest(
51  publicKey(), proposal_.signingHash(), signature(), false);
52 }
53 
56 {
57  auto ret = proposal().getJson();
58 
59  if (publicKey().size())
60  ret[jss::peer_id] = toBase58(TokenType::NodePublic, publicKey());
61 
62  return ret;
63 }
64 
65 uint256
67  uint256 const& proposeHash,
68  uint256 const& previousLedger,
69  std::uint32_t proposeSeq,
70  NetClock::time_point closeTime,
71  Slice const& publicKey,
72  Slice const& signature)
73 {
74  Serializer s(512);
75  s.addBitString(proposeHash);
76  s.addBitString(previousLedger);
77  s.add32(proposeSeq);
78  s.add32(closeTime.time_since_epoch().count());
79  s.addVL(publicKey);
80  s.addVL(signature);
81 
82  return s.getSHA512Half();
83 }
84 
85 } // namespace ripple
ripple::Slice::size
std::size_t size() const noexcept
Returns the number of bytes in the storage.
Definition: Slice.h:80
ripple::RCLCxPeerPos::proposal_
Proposal proposal_
Definition: RCLCxPeerPos.h:103
ripple::RCLCxPeerPos::signature
Slice signature() const
Signature of the proposal (not necessarily verified)
Definition: RCLCxPeerPos.h:71
ripple::Slice
An immutable linear range of bytes.
Definition: Slice.h:44
ripple::ConsensusProposal::getJson
Json::Value getJson() const
Get JSON representation for debugging.
Definition: ConsensusProposal.h:199
ripple::Slice::end
const_iterator end() const noexcept
Definition: Slice.h:158
ripple::toBase58
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition: AccountID.cpp:104
ripple::Serializer::getSHA512Half
uint256 getSHA512Half() const
Definition: Serializer.cpp:194
ripple::RCLCxPeerPos::proposal
Proposal const & proposal() const
Definition: RCLCxPeerPos.h:91
ripple::RCLCxPeerPos::signature_
boost::container::static_vector< std::uint8_t, 72 > signature_
Definition: RCLCxPeerPos.h:104
ripple::base_uint< 256 >
std::chrono::time_point::time_since_epoch
T time_since_epoch(T... args)
ripple::PublicKey
A public key.
Definition: PublicKey.h:59
std::chrono::time_point
ripple::HashPrefix::proposal
@ proposal
proposal for signing
std::uint32_t
ripple::proposalUniqueId
uint256 proposalUniqueId(uint256 const &proposeHash, uint256 const &previousLedger, std::uint32_t proposeSeq, NetClock::time_point closeTime, Slice const &publicKey, Slice const &signature)
Calculate a unique identifier for a signed proposal.
Definition: RCLCxPeerPos.cpp:66
ripple::RCLCxPeerPos::publicKey
PublicKey const & publicKey() const
Public key of peer that sent the proposal.
Definition: RCLCxPeerPos.h:78
ripple::Serializer
Definition: Serializer.h:39
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::Serializer::addBitString
int addBitString(base_uint< Bits, Tag > const &v)
Definition: Serializer.h:97
ripple::RCLCxPeerPos::getJson
Json::Value getJson() const
JSON representation of proposal.
Definition: RCLCxPeerPos.cpp:55
std
STL namespace.
ripple::verifyDigest
bool verifyDigest(PublicKey const &publicKey, uint256 const &digest, Slice const &sig, bool mustBeFullyCanonical) noexcept
Verify a secp256k1 signature on the digest of a message.
Definition: PublicKey.cpp:222
ripple::ConsensusProposal::signingHash
uint256 const & signingHash() const
The digest for this proposal, used for signing purposes.
Definition: ConsensusProposal.h:220
ripple::RCLCxPeerPos::RCLCxPeerPos
RCLCxPeerPos(PublicKey const &publicKey, Slice const &signature, uint256 const &suppress, Proposal &&proposal)
Constructor.
Definition: RCLCxPeerPos.cpp:30
ripple::Serializer::addVL
int addVL(Blob const &vector)
Definition: Serializer.cpp:200
ripple::TokenType::NodePublic
@ NodePublic
ripple::Serializer::add32
int add32(std::uint32_t i)
Definition: Serializer.cpp:38
ripple::RCLCxPeerPos::checkSign
bool checkSign() const
Verify the signing hash of the proposal.
Definition: RCLCxPeerPos.cpp:48
Json::Value
Represents a JSON value.
Definition: json_value.h:145
ripple::Slice::begin
const_iterator begin() const noexcept
Definition: Slice.h:146
ripple::ConsensusProposal< NodeID, uint256, uint256 >