rippled
Loading...
Searching...
No Matches
Sign.cpp
1#include <xrpl/protocol/AccountID.h>
2#include <xrpl/protocol/HashPrefix.h>
3#include <xrpl/protocol/KeyType.h>
4#include <xrpl/protocol/PublicKey.h>
5#include <xrpl/protocol/SField.h>
6#include <xrpl/protocol/STExchange.h>
7#include <xrpl/protocol/STObject.h>
8#include <xrpl/protocol/SecretKey.h>
9#include <xrpl/protocol/Serializer.h>
10#include <xrpl/protocol/Sign.h>
11
12namespace ripple {
13
14void
16 STObject& st,
17 HashPrefix const& prefix,
18 KeyType type,
19 SecretKey const& sk,
20 SF_VL const& sigField)
21{
22 Serializer ss;
23 ss.add32(prefix);
25 set(st, sigField, sign(type, sk, ss.slice()));
26}
27
28bool
30 STObject const& st,
31 HashPrefix const& prefix,
32 PublicKey const& pk,
33 SF_VL const& sigField)
34{
35 auto const sig = get(st, sigField);
36 if (!sig)
37 return false;
38 Serializer ss;
39 ss.add32(prefix);
41 return verify(
42 pk, Slice(ss.data(), ss.size()), Slice(sig->data(), sig->size()));
43}
44
45// Questions regarding buildMultiSigningData:
46//
47// Why do we include the Signer.Account in the blob to be signed?
48//
49// Unless you include the Account which is signing in the signing blob,
50// you could swap out any Signer.Account for any other, which may also
51// be on the SignerList and have a RegularKey matching the
52// Signer.SigningPubKey.
53//
54// That RegularKey may be set to allow some 3rd party to sign transactions
55// on the account's behalf, and that RegularKey could be common amongst all
56// users of the 3rd party. That's just one example of sharing the same
57// RegularKey amongst various accounts and just one vulnerability.
58//
59// "When you have something that's easy to do that makes entire classes of
60// attacks clearly and obviously impossible, you need a damn good reason
61// not to do it." -- David Schwartz
62//
63// Why would we include the signingFor account in the blob to be signed?
64//
65// In the current signing scheme, the account that a signer is `signing
66// for/on behalf of` is the tx_json.Account.
67//
68// Later we might support more levels of signing. Suppose Bob is a signer
69// for Alice, and Carol is a signer for Bob, so Carol can sign for Bob who
70// signs for Alice. But suppose Alice has two signers: Bob and Dave. If
71// Carol is a signer for both Bob and Dave, then the signature needs to
72// distinguish between Carol signing for Bob and Carol signing for Dave.
73//
74// So, if we support multiple levels of signing, then we'll need to
75// incorporate the "signing for" accounts into the signing data as well.
76Serializer
77buildMultiSigningData(STObject const& obj, AccountID const& signingID)
78{
80 finishMultiSigningData(signingID, s);
81 return s;
82}
83
84Serializer
86{
87 Serializer s;
90 return s;
91}
92
93} // namespace ripple
A public key.
Definition PublicKey.h:43
void addWithoutSigningFields(Serializer &s) const
Definition STObject.h:944
A secret key.
Definition SecretKey.h:19
std::size_t size() const noexcept
Definition Serializer.h:53
void const * data() const noexcept
Definition Serializer.h:59
Slice slice() const noexcept
Definition Serializer.h:47
An immutable linear range of bytes.
Definition Slice.h:27
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
void finishMultiSigningData(AccountID const &signingID, Serializer &s)
Definition Sign.h:65
Serializer startMultiSigningData(STObject const &obj)
Break the multi-signing hash computation into 2 parts for optimization.
Definition Sign.cpp:85
bool verify(PublicKey const &publicKey, Slice const &m, Slice const &sig, bool mustBeFullyCanonical=true) noexcept
Verify a signature on a message.
Serializer buildMultiSigningData(STObject const &obj, AccountID const &signingID)
Return a Serializer suitable for computing a multisigning TxnSignature.
Definition Sign.cpp:77
bool set(T &target, std::string const &name, Section const &section)
Set a value from a configuration Section If the named value is not found or doesn't parse as a T,...
Buffer sign(PublicKey const &pk, SecretKey const &sk, Slice const &message)
Generate a signature for a message.
KeyType
Definition KeyType.h:9
T get(Section const &section, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.
HashPrefix
Prefix for hashing functions.
Definition HashPrefix.h:36
@ txMultiSign
inner transaction to multi-sign
A field with a type known at compile time.
Definition SField.h:301