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  : data_{std::make_shared<Data>(
36  publicKey,
37  signature,
38  suppression,
39  std::move(proposal))}
40 {
41 }
42 
43 uint256
45 {
46  return sha512Half(
48  std::uint32_t(proposal().proposeSeq()),
49  proposal().closeTime().time_since_epoch().count(),
50  proposal().prevLedger(),
51  proposal().position());
52 }
53 
54 bool
56 {
57  return verifyDigest(publicKey(), signingHash(), signature(), false);
58 }
59 
62 {
63  auto ret = proposal().getJson();
64 
65  if (publicKey().size())
66  ret[jss::peer_id] = toBase58(TokenType::NodePublic, publicKey());
67 
68  return ret;
69 }
70 
71 uint256
73  uint256 const& proposeHash,
74  uint256 const& previousLedger,
75  std::uint32_t proposeSeq,
76  NetClock::time_point closeTime,
77  Slice const& publicKey,
78  Slice const& signature)
79 {
80  Serializer s(512);
81  s.addBitString(proposeHash);
82  s.addBitString(previousLedger);
83  s.add32(proposeSeq);
84  s.add32(closeTime.time_since_epoch().count());
85  s.addVL(publicKey);
86  s.addVL(signature);
87 
88  return s.getSHA512Half();
89 }
90 
92  PublicKey const& publicKey,
93  Slice const& signature,
94  uint256 const& suppress,
95  Proposal&& proposal)
96  : publicKey_{publicKey}
97  , signature_{signature}
98  , suppression_{suppress}
99  , proposal_{std::move(proposal)}
100 {
101 }
102 
103 } // namespace ripple
ripple::RCLCxPeerPos::signature
Slice signature() const
Signature of the proposal (not necessarily verified)
Definition: RCLCxPeerPos.h:74
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:194
ripple::toBase58
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition: AccountID.cpp:29
ripple::Serializer::getSHA512Half
uint256 getSHA512Half() const
Definition: Serializer.cpp:186
ripple::RCLCxPeerPos::proposal
Proposal const & proposal() const
Definition: RCLCxPeerPos.h:94
ripple::uint256
base_uint< 256 > uint256
Definition: base_uint.h:493
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::RCLCxPeerPos::signingHash
uint256 signingHash() const
Create the signing hash for the proposal.
Definition: RCLCxPeerPos.cpp:44
ripple::HashPrefix::proposal
@ proposal
proposal for signing
std::uint32_t
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::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:72
ripple::RCLCxPeerPos::publicKey
PublicKey const & publicKey() const
Public key of peer that sent the proposal.
Definition: RCLCxPeerPos.h:81
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:61
ripple::sha512Half
sha512_half_hasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.
Definition: digest.h:227
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:192
ripple::TokenType::NodePublic
@ NodePublic
ripple::Serializer::add32
int add32(std::uint32_t i)
Definition: Serializer.cpp:38
ripple::RCLCxPeerPos::Data::Data
Data(PublicKey const &publicKey, Slice const &signature, uint256 const &suppress, Proposal &&proposal)
Definition: RCLCxPeerPos.cpp:91
ripple::RCLCxPeerPos::checkSign
bool checkSign() const
Verify the signing hash of the proposal.
Definition: RCLCxPeerPos.cpp:55
Json::Value
Represents a JSON value.
Definition: json_value.h:145
ripple::ConsensusProposal< NodeID, uint256, uint256 >